platform/Training/LessonEmp.aspx.cs

373 lines
10 KiB
C#
Raw Normal View History

2024-02-18 23:33:54 +08:00
using System;
using System.Collections;
using System.Data;
using System.Transactions;
using System.Web.UI;
using System.Web.UI.WebControls;
using DeiNiu.wms.Logical;
using DeiNiu.Utils;
public partial class LessonEmp : PageBase
{
private LlessonEmp _logic;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
_logic = new LlessonEmp();
Databound();
bindLessons();
bindDeptEmp(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫʱ<C9AB><CAB1>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1>
}
SessionSeting();
}
/// <summary>
/// bound the query list.
/// </summary>
private void Databound()
{
// bindAuth();
// bindRoles();
// if (!isRoleAuth) bindDeptEmp(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫʱ<C9AB><CAB1>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1>
bindGV();
UpdateSession();
}
/// <summary>
/// <20>󶨲<EFBFBD><F3B6A8B2>ż<EFBFBD><C5BC>û<EFBFBD>
/// </summary>
private void bindDeptEmp()
{
TreeEmp.Nodes.Clear();
BindEmpTree( "0", TreeEmp.SelectedNode, _logic.GetAllDepartments().DefaultView, _logic.GetAllEmployee().DefaultView);
}
/// <summary>
///<2F>󶨽<EFBFBD>ɫ
/// </summary>
private void bindLessons()
{
BindLessonTree("0",TreeLesson.SelectedNode,_logic.GetAllCategories().DefaultView,_logic.GetAllActiveData().Tables[0].DefaultView );
}
public void BindLessonTree(string id, TreeNode pNode, DataView deptdv, DataView empdv)
{
deptdv.RowFilter = "lc_uplevel = '" + id + "'";
foreach (DataRowView row in deptdv)
{
TreeNode node = new TreeNode();
node.Text = "<em>" + row["lc_name"] + "</em>" + row["ID"];
node.Value = row["ID"].ToString();
node.SelectAction = TreeNodeSelectAction.None;
node.Expanded = true;
empdv.RowFilter = "le_category=" + node.Value;
foreach (DataRowView emrow in empdv)
{
TreeNode tnEmp = new TreeNode("<Strong>" + emrow["le_name"] + "</Strong>", emrow["ID"].ToString());
node.ChildNodes.Add(tnEmp);
}
if (pNode == null)
//˵<><CBB5><EFBFBD>Ǹ<EFBFBD><C7B8>ڵ<EFBFBD>
{
TreeLesson.Nodes.Add(node);
}
else
{
pNode.ChildNodes.Add(node);
}
BindLessonTree(node.Value, node, new DataView(deptdv.Table), new DataView(empdv.Table));
}
}
public void BindEmpTree(string id, TreeNode pNode, DataView deptdv,DataView empdv)
{
deptdv.RowFilter = "dep_mastdept = '" + id + "'";
foreach (DataRowView row in deptdv)
{
TreeNode node = new TreeNode();
node.Text = "<em>" + row["dep_name"] + "</em>" + row["ID"];
node.Value = row["ID"].ToString();
node.SelectAction = TreeNodeSelectAction.None;
node.ShowCheckBox = false;
node.Expanded = true;
empdv.RowFilter = "em_dept=" + node.Value;
foreach (DataRowView emrow in empdv)
{
TreeNode tnEmp = new TreeNode("<Strong>" + emrow["em_name"] + "</Strong>" , emrow["ID"].ToString());
tnEmp.ShowCheckBox = true;
node.ChildNodes.Add(tnEmp);
}
if (pNode == null)
//˵<><CBB5><EFBFBD>Ǹ<EFBFBD><C7B8>ڵ<EFBFBD>
{
TreeEmp.Nodes.Add(node);
}
else
{
pNode.ChildNodes.Add(node);
}
BindEmpTree(node.Value, node, new DataView(deptdv.Table), new DataView(empdv.Table));
}
}
private void SessionSeting()
{
if (IsPostBack)
{
_logic = (LlessonEmp)Session[appScope.PagelevelObj];
}
}
private void UpdateSession()
{
Session[appScope.PagelevelObj] = _logic;
}
/************************************** protected methods (event listeners) ********************************/
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (TreeLesson.SelectedValue == string.Empty) return;
ArrayList al = new ArrayList();
ArrayList al2del = new ArrayList();
GetCheckedNode(TreeEmp.Nodes, al);
string tmpid;
DataTable dt = _logic.GetEmpByLesson(Convert.ToInt32(TreeLesson.SelectedValue));
for (int i = 0; i < dt.Rows.Count;i++ )
{
tmpid = dt.Rows[i]["train_student"].ToString().Trim();
if (al.Contains(tmpid ))
{
al.Remove(tmpid);
}
else
{
al2del.Add(tmpid);
}
}
if(al.Count >0 || al2del.Count >0)
{
_logic.Initialize();
// using (TransactionScope trans = new TransactionScope())
{
try
{
// _logic.GetLesson.Delete(Convert.ToInt32(TreeLesson.SelectedValue));
foreach (string id in al2del)
{
_logic.GetTrainingDetail.ID = Convert.ToInt32(id);
_logic.GetTrainingDetail.getModel();
_logic.GetTrainingDetail.Delete();
}
foreach (string id in al)
{
_logic.GetTrainingDetail.train_lesson = Convert.ToInt32(TreeLesson.SelectedValue);
_logic.GetTrainingDetail.train_student = Convert.ToInt32(id);
_logic.GetTrainingDetail.Add();
}
// trans.Complete();
}
catch (MyException)
{
throw;
}
catch (Exception)
{
throw new Exception("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><ECB3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܡ<EFBFBD>");
}
}
Databound();
}
}
/***************************************** internal methods ********************************************/
/// <summary>
/// set data from page to shift object
/// </summary>
private void SetDataBack()
{
}
void GetCheckedNode(TreeNodeCollection tnc, ArrayList checkedvalues )
{
foreach(TreeNode node in tnc)
{
if(node.Checked)
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> {
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> checkedvalues.Add(node.Value);
}
GetCheckedNode(node.ChildNodes, checkedvalues);
}
}
void SetCheckedNode(TreeNodeCollection tnc, ArrayList setcheckedvalues)
{
foreach (TreeNode node in tnc)
{
node.Checked = setcheckedvalues.Contains(Convert.ToInt32(node.Value));
SetCheckedNode(node.ChildNodes, setcheckedvalues);
}
}
private void chgOperTxt(bool addNew)
{
btnSubmit.Enabled = true;
}
protected void listRoles_SelectedIndexChanged(object sender, EventArgs e)
{
//--<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>
/*
if (TreeDeptEmp.SelectedNode != null) TreeDeptEmp.SelectedNode.Selected = false;
lbAuthRole.Text = "<22><>Ա<EFBFBD><D4B1>ɫ<EFBFBD>嵥";
GvRole.DataSource = null;
GvRole.DataBind();
* */
//--ѡ<><D1A1><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>
GvRole.SelectedIndex = -1;
ArrayList empList = new ArrayList();
DataTable dt =_logic.GetEmpByLesson(Convert.ToInt32(TreeLesson.SelectedValue)) ;
foreach (DataRow dr in dt.Rows)
{
empList.Add(dr["ID"]);
}
SetCheckedNode(TreeEmp.Nodes, empList);
bindGV();
}
void bindGV( )
{
//<2F><>Ա<EFBFBD>γ<EFBFBD> <20>
string nodevalue = TreeEmp.SelectedValue;
if (nodevalue.Length >0 && nodevalue != "0") //selected node is an employee
{
lbEmRole.Text = TreeEmp.SelectedNode.Text + " <20><>Ա<EFBFBD>γ<EFBFBD><CEB3>嵥";
GvRole.DataSource = _logic.GetLessionsByEmp(Convert.ToInt32(nodevalue));
}
GvRole.DataBind();
//<2F>γ̶<CEB3>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD>Ա<EFBFBD>
if (TreeLesson.SelectedNode != null)
{
lbRoleEm.Text = TreeLesson.SelectedNode.Text + " <20>γ<EFBFBD><CEB3><EFBFBD>Ա<EFBFBD>嵥";
GvEm.DataSource = _logic.GetEmpByLesson(Convert.ToInt32(TreeLesson.SelectedValue));
}
GvEm.DataBind();
}
protected void TreeLesson_SelectedNodeChanged(object sender, EventArgs e)
{
GvEm.SelectedIndex = -1;
bindGV();
}
protected void GvRole_RowDataBound(object sender, GridViewRowEventArgs e)
{
Label lb;
switch (e.Row.RowType)
{
case DataControlRowType.DataRow:
lb = new Label();
lb.Text = e.Row.Cells[1].Text.Trim().Equals("True") ? "<22><>" : "<22><>";
e.Row.Cells[1].Controls.Add(lb);
break;
}
}
protected void GvEm_RowEditing(object sender, GridViewEditEventArgs e)
{
GvEm.EditIndex = e.NewEditIndex;
GvEm.SelectedIndex = e.NewEditIndex;
bindGV();
}
protected void GvEm_RowCommand(object sender, GridViewCommandEventArgs e)
{
}
protected void GvEm_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
if (GvEm.DataKeys != null)
{
string id = GvEm.DataKeys[e.RowIndex].Value.ToString();
_logic.GetTrainingDetail.ID = Convert.ToInt32(id);
_logic.GetTrainingDetail.getModel();
_logic.GetTrainingDetail.train_passed = ((CheckBox)GvEm.Rows[e.RowIndex].Cells[3].Controls[1]).Checked;
_logic.GetTrainingDetail.train_passedDate = DateTime.Now.ToShortDateString();
//_logic.GetTrainingDetail.operater =
_logic.GetTrainingDetail.Update();
}
GvEm.EditIndex = -1;
GvEm.SelectedIndex = e.RowIndex;
bindGV();
}
protected void GvEm_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GvEm.EditIndex = -1;
GvEm.SelectedIndex = e.RowIndex;
bindGV();
}
}