platform/Training/LessonEmp.aspx.cs

373 lines
10 KiB
C#
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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(); //分配角色时初始化部门人员树
}
SessionSeting();
}
/// <summary>
/// bound the query list.
/// </summary>
private void Databound()
{
// bindAuth();
// bindRoles();
// if (!isRoleAuth) bindDeptEmp(); //分配角色时初始化部门人员树
bindGV();
UpdateSession();
}
/// <summary>
/// 绑定部门及用户
/// </summary>
private void bindDeptEmp()
{
TreeEmp.Nodes.Clear();
BindEmpTree( "0", TreeEmp.SelectedNode, _logic.GetAllDepartments().DefaultView, _logic.GetAllEmployee().DefaultView);
}
/// <summary>
///绑定角色
/// </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)
//说明是根节点
{
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)
//说明是根节点
{
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("出现异常,保存失败。");
}
}
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)
    {
    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)
{
//--重置人员树的选择
/*
if (TreeDeptEmp.SelectedNode != null) TreeDeptEmp.SelectedNode.Selected = false;
lbAuthRole.Text = "人员角色清单";
GvRole.DataSource = null;
GvRole.DataBind();
* */
//--选择人员树复选框
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( )
{
//人员课程 清单
string nodevalue = TreeEmp.SelectedValue;
if (nodevalue.Length >0 && nodevalue != "0") //selected node is an employee
{
lbEmRole.Text = TreeEmp.SelectedNode.Text + " 人员课程清单";
GvRole.DataSource = _logic.GetLessionsByEmp(Convert.ToInt32(nodevalue));
}
GvRole.DataBind();
//课程对应的人员清单
if (TreeLesson.SelectedNode != null)
{
lbRoleEm.Text = TreeLesson.SelectedNode.Text + " 课程人员清单";
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") ? "是" : "否";
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();
}
}