429 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			429 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			C#
		
	
	
	
|  | using System; | |||
|  | using System.Data; | |||
|  | using System.Web.UI; | |||
|  | using System.Web.UI.WebControls; | |||
|  | using DeiNiu.wms.Logical; | |||
|  | using DeiNiu.Utils; | |||
|  | using DeiNiu.wms.Data.Model; | |||
|  | 
 | |||
|  | public partial class DeptMain : PageBase | |||
|  | { | |||
|  |     private LDepartment _logic; | |||
|  |     protected void Page_Load(object sender, EventArgs e) | |||
|  |     { | |||
|  |    | |||
|  |         if (!IsPostBack) | |||
|  |         { | |||
|  |             _logic = new LDepartment(); | |||
|  |             Databound(); | |||
|  |         } | |||
|  |         SessionSeting(); | |||
|  |     } | |||
|  |   | |||
|  |     /*****************************************   private methods   ******************************************/ | |||
|  | 
 | |||
|  |     /// <summary> | |||
|  |     /// bound the query list. | |||
|  |     /// </summary> | |||
|  |     private void Databound() | |||
|  |     {  | |||
|  |         //<2F><EFBFBD><F3B6A8B2><EFBFBD><EFBFBD>б<EFBFBD> | |||
|  |         drplstDept.DataSource = _logic.GetAllActiveData(); | |||
|  |         drplstDept.DataTextField = "dep_name"; | |||
|  |         drplstDept.DataValueField = "ID"; | |||
|  |         drplstDept.DataBind(); | |||
|  |      | |||
|  | 
 | |||
|  | 
 | |||
|  | 
 | |||
|  |         drplstDept.Items.Insert(0, (new ListItem("WMS", "0"))); | |||
|  |         drplstDept.SelectedItem.Selected = false; | |||
|  |         drplstDept.Items.FindByText("WMS").Selected = true; | |||
|  | 
 | |||
|  | 
 | |||
|  | 
 | |||
|  |         //<2F><EFBFBD><F3B6A8B2><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD>б<EFBFBD> | |||
|  |          DropDownList1.DataSource = _logic.GetEmployees(); | |||
|  |         DropDownList1.DataTextField = "em_name"; | |||
|  |         DropDownList1.DataValueField = "ID"; | |||
|  |         DropDownList1.DataBind(); | |||
|  |         DropDownList1.Items.Insert(0,(new ListItem("<22><>ѡ<EFBFBD><D1A1>...","0"))); | |||
|  |         DropDownList1.SelectedItem.Selected = false; | |||
|  |         DropDownList1.Items.FindByText("<22><>ѡ<EFBFBD><D1A1>...").Selected = true; | |||
|  |         //װ<><D7B0>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD>Žڵ<C5BD><DAB5>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>  | |||
|  | 
 | |||
|  |         dlstDeptType.Items.Clear(); | |||
|  |         dlstDeptType.Items.Add(new ListItem("<22><>ͨ", "0"));  | |||
|  |         dlstDeptType.Items.Add(new ListItem("<22>ֹ<EFBFBD>", "1")); | |||
|  |         dlstDeptType.Items.Add(new ListItem("<22>ֿ<EFBFBD>", "2"));  | |||
|  |         dlstDeptType.Items.Add(new ListItem("<22><><EFBFBD><EFBFBD>", "3")); | |||
|  |         DataView dv = _logic.GetAllActiveData().DefaultView; | |||
|  |         string selectedValue = TreeDept.SelectedValue; | |||
|  |         TreeDept.Nodes.Clear(); | |||
|  |         TreeDept.Nodes.Add(new TreeNode("WMS", "0")); | |||
|  |         TreeDept.Nodes[0].Expanded = true; | |||
|  |         BindTree("0", TreeDept.Nodes[0], dv); | |||
|  |         //   TreeDept.SelectedNode.ChildNodes.Clear(); | |||
|  |         //     BindTree(TreeDept.SelectedValue, TreeDept.SelectedNode, dv); | |||
|  |         //     TreeDept.Nodes.AddAt(0, new TreeNode("WMS", "0")); | |||
|  |         if (selectedValue == "0") TreeDept.Nodes[0].Selected = true; | |||
|  |         else | |||
|  |         { | |||
|  |             setTreeDeptSelected(selectedValue, TreeDept.Nodes[0]); | |||
|  |         } | |||
|  |        dv.RowFilter = "dep_mastdept = '" + selectedValue + "'"; | |||
|  |        bindGridview(dv); | |||
|  |         | |||
|  |         UpdateSession(); | |||
|  |     // btnSubmit.Enabled = false; | |||
|  |       //  ClearDetail(); | |||
|  | 
 | |||
|  | 
 | |||
|  |         drplstDept.Items.Clear(); | |||
|  |         initializeDrlstDept(TreeDept.Nodes, drplstDept ,""); | |||
|  |     } | |||
|  | 
 | |||
|  |     void bindGridview(DataView dv ) | |||
|  |     { | |||
|  |         | |||
|  |         //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><D0B1><EFBFBD>ѡ<EFBFBD>еIJ<D0B5><C4B2><EFBFBD><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD>в<EFBFBD><D0B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> | |||
|  |         | |||
|  | 
 | |||
|  |         foreach (DataRowView drv in dv) | |||
|  |         { | |||
|  |             foreach (ListItem li in dlstDeptType.Items) | |||
|  |             { | |||
|  |                 if (drv["dep_type"].ToString().Equals(li.Value)) | |||
|  |                 { | |||
|  |                     drv.Row["typeName"] = li.Text; | |||
|  |                 } | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  |         GridView1.DataSource = dv; | |||
|  |         GridView1.DataBind(); | |||
|  |     } | |||
|  | 
 | |||
|  |     void initializeDrlstDept(TreeNodeCollection nds, DropDownList drplist, string emptyString) | |||
|  |     { | |||
|  |          | |||
|  |         | |||
|  |         foreach (TreeNode nd in nds) | |||
|  |         { | |||
|  |              | |||
|  |             ListItem li = new ListItem(emptyString + nd.Text,nd.Value); | |||
|  |             drplist.Items.Add(li);  | |||
|  |             string NextemptyString = emptyString+ "----"; | |||
|  |             foreach (TreeNode nd1 in nd.ChildNodes) | |||
|  |             { | |||
|  |                li = new ListItem(NextemptyString + nd1.Text, nd1.Value); | |||
|  |                     drplist.Items.Add(li); | |||
|  |                     | |||
|  |                 if (nd1.ChildNodes.Count > 0) | |||
|  |                 { | |||
|  |                     NextemptyString +="----"; | |||
|  |                    initializeDrlstDept(nd1.ChildNodes, drplist, NextemptyString); | |||
|  |                 } | |||
|  | 
 | |||
|  | 
 | |||
|  |             } | |||
|  |         } | |||
|  |     } | |||
|  | 
 | |||
|  | 
 | |||
|  | 
 | |||
|  |     void setTreeDeptSelected(string toFind,TreeNode nd) | |||
|  |     { | |||
|  |         foreach (TreeNode cnd in nd.ChildNodes) | |||
|  |         { | |||
|  |             if (cnd.Value == toFind)  | |||
|  |             { | |||
|  |                 cnd.Selected = true; | |||
|  |                 break; | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  |                 setTreeDeptSelected(toFind,cnd); | |||
|  |             } | |||
|  | 
 | |||
|  |         } | |||
|  |     } | |||
|  |     private void SessionSeting() | |||
|  |     { | |||
|  |         if (IsPostBack) | |||
|  |         { | |||
|  |             _logic = (LDepartment)Session[appScope.PagelevelObj]; | |||
|  |         } | |||
|  |     } | |||
|  | 
 | |||
|  |     private void UpdateSession() | |||
|  |     { | |||
|  |         Session[appScope.PagelevelObj] = _logic; | |||
|  |     } | |||
|  | 
 | |||
|  |     /// <summary> | |||
|  |     /// set data from shift object to page | |||
|  |     /// </summary> | |||
|  |     private void DetailDataBind() | |||
|  |     { | |||
|  |         DataDetail.Visible = true; | |||
|  |         txtDepName.Text = _logic.GetDepartment.dep_name ; | |||
|  |         txtDepcode.Text = _logic.GetDepartment.dep_code; | |||
|  |         txtDepDesc.Text = _logic.GetDepartment.dep_desc; | |||
|  |         txtSvrAddress.Text = _logic.GetDepartment.svrAdress; | |||
|  |        // txtDepType.Text = _logic.GetDepartment.dep_type+""; | |||
|  |         DropDownList1.SelectedItem.Selected = false; | |||
|  |         if(DropDownList1.Items.FindByValue(_logic.GetDepartment.dep_manager.ToString())!=null) | |||
|  |         { | |||
|  |           DropDownList1.Items.FindByValue(_logic.GetDepartment.dep_manager.ToString()).Selected = true;   | |||
|  |         } | |||
|  |         drplstDept.SelectedItem.Selected = false; | |||
|  |         if (drplstDept.Items.FindByValue(_logic.GetDepartment.dep_mastdept.ToString()) != null) | |||
|  |         { | |||
|  |             drplstDept.Items.FindByValue(_logic.GetDepartment.dep_mastdept.ToString()).Selected = true; | |||
|  |         } | |||
|  |         dlstDeptType.SelectedItem.Selected = false; | |||
|  |         if (dlstDeptType.Items.FindByValue(_logic.GetDepartment.dep_type.ToString()) != null) | |||
|  |         { | |||
|  |             dlstDeptType.Items.FindByValue(_logic.GetDepartment.dep_type.ToString()).Selected = true; | |||
|  |         } | |||
|  |          | |||
|  |           | |||
|  | //    chkStatus.Checked = _logic.GetRole.dr; | |||
|  |     } | |||
|  | 
 | |||
|  |     /************************************** protected methods (event listeners) ********************************/ | |||
|  | 
 | |||
|  |     protected void btnAddnew_Click(object sender, EventArgs e) | |||
|  |     { | |||
|  |         chgOperTxt(true); | |||
|  |         _logic.Initialize(); | |||
|  |         DetailDataBind(); | |||
|  |         GridView1.SelectedIndex = -1; | |||
|  |         Databound(); | |||
|  |         drplstDept.SelectedItem.Selected = false; | |||
|  |         if (drplstDept.Items.FindByValue(TreeDept.SelectedNode.Value) != null) | |||
|  |         { | |||
|  |             drplstDept.Items.FindByValue(TreeDept.SelectedNode.Value).Selected = true; | |||
|  |         } | |||
|  |     } | |||
|  | 
 | |||
|  |     protected void DetailsView1_PageIndexChanging(object sender, DetailsViewPageEventArgs e) | |||
|  |     { | |||
|  |     } | |||
|  | 
 | |||
|  |     protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) | |||
|  |     { | |||
|  |         chgOperTxt(false); | |||
|  |         if (GridView1.DataKeys != null) | |||
|  |         { | |||
|  |             string id = GridView1.DataKeys[e.NewEditIndex].Value.ToString(); | |||
|  |             _logic.Initialize(int.Parse(id)); | |||
|  |         } | |||
|  |         Databound(); | |||
|  |         DetailDataBind(); | |||
|  |     } | |||
|  | 
 | |||
|  |     protected void btnSubmit_Click(object sender, EventArgs e) | |||
|  |     { | |||
|  |         SetDataBack(); | |||
|  |         //shifts id eq 0 means this is new one,to add; else an old one, to update | |||
|  | 
 | |||
|  |         if (_logic.GetDepartment.ID > 0) | |||
|  |         { | |||
|  |             _logic.GetDepartment.Update(); | |||
|  |         } | |||
|  |         else | |||
|  |         { | |||
|  |             _logic.GetDepartment.Add(); | |||
|  |             if (_logic.GetDepartment.warehouse == 0 && _logic.GetDepartment.dep_type==1) | |||
|  |             { | |||
|  |                 _logic.GetDepartment.warehouse = _logic.GetDepartment.ID; | |||
|  |                 _logic.GetDepartment.Update(); | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  |          | |||
|  |         ClearDetail(); | |||
|  |         Databound(); | |||
|  |     } | |||
|  | 
 | |||
|  |     protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) | |||
|  |     { | |||
|  |          | |||
|  |         if (GridView1 != null) | |||
|  |         { | |||
|  |             if (GridView1.DataKeys != null) | |||
|  |             { | |||
|  |                 string id = GridView1.DataKeys[e.RowIndex].Value.ToString(); | |||
|  |                 _logic.Initialize(int.Parse(id)); | |||
|  |             } | |||
|  |         } | |||
|  |         /* | |||
|  |         _logic.GetRole.dr = false; | |||
|  |         _logic.GetRole.Update(); | |||
|  |          | |||
|  |        */ | |||
|  |         _logic.GetDepartment.Delete(); | |||
|  |         ClearDetail(); | |||
|  |         Databound(); | |||
|  |     } | |||
|  | 
 | |||
|  |     protected void GridView1_PageIndexChanged(object sender, EventArgs e) | |||
|  |     { | |||
|  |     } | |||
|  | 
 | |||
|  |     protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) | |||
|  |     { | |||
|  |         GridView1.PageIndex = e.NewPageIndex; | |||
|  |         Databound(); | |||
|  | 
 | |||
|  |         //GridView1.DataSource = shiftLgc.getAllShifts().Tables[0]; | |||
|  |         //     GridView1.DataBind();     | |||
|  |     } | |||
|  | 
 | |||
|  |     protected void GridView1_DataBinding(object sender, EventArgs e) | |||
|  |     { | |||
|  |     } | |||
|  | 
 | |||
|  |     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) | |||
|  |     { | |||
|  |         /* | |||
|  |         CheckBox chk; | |||
|  |         if (e.Row.RowType == DataControlRowType.DataRow) | |||
|  |         { | |||
|  |             chk = new CheckBox(); | |||
|  |             chk.Text = "<22><><EFBFBD><EFBFBD>"; | |||
|  |             chk.Enabled = false; | |||
|  |             chk.Checked = e.Row.Cells[3].Text.Trim().Equals("1"); | |||
|  |             e.Row.Cells[3].Controls.Add(chk); | |||
|  |         } | |||
|  |       */ | |||
|  |     } | |||
|  | 
 | |||
|  |     protected void GridView1_Sorting(object sender, GridViewSortEventArgs e) | |||
|  |     { | |||
|  |     } | |||
|  | 
 | |||
|  |     //reset the page | |||
|  |     protected void btnCancel_Click(object sender, EventArgs e) | |||
|  |     { | |||
|  |         _logic.Initialize(); | |||
|  |         Page_Load(this, e); | |||
|  |     } | |||
|  | 
 | |||
|  |     /***************************************** internal methods ********************************************/ | |||
|  | 
 | |||
|  |     /// <summary> | |||
|  |     /// set data from page to shift object | |||
|  |     /// </summary> | |||
|  |     private void SetDataBack() | |||
|  |     { | |||
|  |         //    _logic.GetRole.operater = Session["CurrentUserID"].ToString();  todo: write a public method to handle operater,createtime,lastmodfied ... log info. | |||
|  | 
 | |||
|  |        if (!(_logic.GetDepartment.ID > 0 ))  | |||
|  |        { | |||
|  |          // _logic.GetDepartment.lastmodified = DateTime.Now.ToString();  | |||
|  |           _logic.GetDepartment.dep_mastdept = Convert.ToInt32(TreeDept.SelectedValue); | |||
|  |        } | |||
|  |          | |||
|  |       // _logic.GetDepartment.dr = true; | |||
|  |        _logic.GetDepartment.dep_name = txtDepName.Text; | |||
|  |        _logic.GetDepartment.dep_desc = txtDepDesc.Text; | |||
|  |        _logic.GetDepartment.dep_code = txtDepcode.Text;  | |||
|  |         _logic.GetDepartment.svrAdress =  txtSvrAddress.Text; | |||
|  |        if (dlstDeptType.SelectedItem != null) _logic.GetDepartment.dep_type = Convert.ToInt16(dlstDeptType.SelectedValue);  | |||
|  |         if (DropDownList1.SelectedItem != null ) _logic.GetDepartment.dep_manager = Convert.ToInt32(DropDownList1.SelectedValue); | |||
|  |         if (drplstDept.SelectedItem != null) _logic.GetDepartment.dep_mastdept = Convert.ToInt32(drplstDept.SelectedValue); | |||
|  | 
 | |||
|  |         if (_logic.GetDepartment.dep_type != (int)enumDepartmentType.<EFBFBD>ֿ<EFBFBD>)//<2F><><EFBFBD><EFBFBD><EFBFBD>Ų<EFBFBD><C5B2>Dzֿ<C7B2><D6BF><EFBFBD><EFBFBD><EFBFBD> | |||
|  |         { | |||
|  |             if (_logic.GetDepartment.dep_mastdept > 0) //<2F>̳<EFBFBD><CCB3>ϼ<EFBFBD><CFBC><EFBFBD><EFBFBD>ŵIJֿ<C4B2><D6BF><EFBFBD><EFBFBD><EFBFBD> | |||
|  |             { | |||
|  |                 Department dept = new Department(_logic.GetDepartment.dep_mastdept); | |||
|  |                 if (dept.dep_type != 1) | |||
|  |                 { | |||
|  |                     _logic.GetDepartment.warehouse = dept.warehouse; | |||
|  |                 } | |||
|  |                 else | |||
|  |                 { | |||
|  |                     _logic.GetDepartment.warehouse = dept.ID; | |||
|  |                 } | |||
|  |             } | |||
|  |         } | |||
|  |         else | |||
|  |         { | |||
|  |             _logic.GetDepartment.warehouse = _logic.GetDepartment.ID; | |||
|  |             | |||
|  |         } | |||
|  | 
 | |||
|  | 
 | |||
|  |      | |||
|  |     } | |||
|  | 
 | |||
|  |     private void chgOperTxt(bool addNew) | |||
|  |     { | |||
|  |         DataDetail.Visible = true; | |||
|  |         lbEdit.Text = addNew ? "<22><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>¼" : "<22><EFBFBD><DEB8><EFBFBD><EFBFBD>м<EFBFBD>¼"; | |||
|  |         btnSubmit.Enabled = true; | |||
|  |     } | |||
|  | 
 | |||
|  |     private void ClearDetail() | |||
|  |     { | |||
|  |         txtDepName.Text = ""; | |||
|  |         txtDepcode.Text = ""; | |||
|  |         txtDepDesc.Text = ""; | |||
|  |         //txtDepType.Text =""; | |||
|  |         DataDetail.Visible = false; | |||
|  |     } | |||
|  | 
 | |||
|  |     protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) | |||
|  |     { | |||
|  |         chgOperTxt(false); | |||
|  |         if (GridView1.DataKeys != null) | |||
|  |         { | |||
|  |             string id = GridView1.DataKeys[GridView1.SelectedIndex].Value.ToString(); | |||
|  |             _logic.Initialize(int.Parse(id)); | |||
|  |         } | |||
|  |         Databound(); | |||
|  |         DetailDataBind(); | |||
|  |     } | |||
|  | 
 | |||
|  | 
 | |||
|  | 
 | |||
|  |     public void BindTree(string id, TreeNode pNode, DataView dv) | |||
|  |     { | |||
|  |          | |||
|  |         dv.RowFilter = "dep_mastdept = '" + id + "'"; | |||
|  |         foreach (DataRowView row in dv) | |||
|  |         { | |||
|  |             TreeNode node = new TreeNode(); | |||
|  |             node.Text = row["dep_name"].ToString(); | |||
|  |             node.Value = row["ID"].ToString(); | |||
|  |             if (pNode == null) | |||
|  |                 //˵<><CBB5><EFBFBD>Ǹ<EFBFBD><C7B8>ڵ<EFBFBD> | |||
|  |             { | |||
|  |              | |||
|  |                 TreeDept.Nodes.Add(node); | |||
|  |                 node.Expanded = true; | |||
|  |        | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  |                 pNode.ChildNodes.Add(node); | |||
|  |                 node.Expanded = true; | |||
|  |                  | |||
|  |             } | |||
|  |             BindTree(node.Value, node, new DataView(dv.Table)); | |||
|  | 
 | |||
|  |         } | |||
|  |     } | |||
|  |     protected void TreeDept_SelectedNodeChanged(object sender, EventArgs e) | |||
|  |     { | |||
|  |        GridView1.SelectedIndex = -1;  | |||
|  |         DataView dv = new DataView(_logic.GetAllActiveData());  | |||
|  |         dv.RowFilter = "dep_mastdept = '" + TreeDept.SelectedValue + "'";  | |||
|  |         bindGridview(dv); | |||
|  |         ClearDetail(); | |||
|  |     } | |||
|  | } |