298 lines
		
	
	
		
			8.0 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			298 lines
		
	
	
		
			8.0 KiB
		
	
	
	
		
			C#
		
	
	
	
|  | using System; | |||
|  | using System.Data; | |||
|  | using System.IO; | |||
|  | using System.Text; | |||
|  | using System.Web; | |||
|  | using System.Web.UI; | |||
|  | using System.Web.UI.WebControls; | |||
|  | using DeiNiu.wms.Logical; | |||
|  | using DeiNiu.Utils; | |||
|  | 
 | |||
|  | public partial class ProjectsQuery : PageBase | |||
|  | { | |||
|  |     private LProject _logic; | |||
|  |     protected void Page_Load(object sender, EventArgs e) | |||
|  |     { | |||
|  |    | |||
|  |         if (!IsPostBack) | |||
|  |         { | |||
|  |             btnYear.Text = DateTime.Today.Year.ToString(); | |||
|  |             rdblstMonth.SelectedItem.Selected = false; | |||
|  |             rdblstMonth.Items.FindByValue(DateTime.Today.Month.ToString()).Selected = true; | |||
|  |         | |||
|  |             _logic = new LProject(); | |||
|  |             bindDeptEmp(); | |||
|  |             Databound(); | |||
|  |         } | |||
|  |         SessionSeting(); | |||
|  |     } | |||
|  |   | |||
|  |     /*****************************************   private methods   ******************************************/ | |||
|  | 
 | |||
|  |     /// <summary> | |||
|  |     /// bound the query list. | |||
|  |     /// </summary> | |||
|  |     private void Databound() | |||
|  |     {  | |||
|  |         DataView dv2 = _logic.GetSumProjectsByYearMonth(btnYear.Text, rdblstMonth.SelectedValue).DefaultView; | |||
|  |         if ( TreeDeptEmp.SelectedNode !=null && TreeDeptEmp.SelectedNode.Value!="0") | |||
|  |         { | |||
|  |           string  selectedValue = TreeDeptEmp.SelectedValue; | |||
|  |             string wherecls = "ID= '" + selectedValue + "'"; | |||
|  |           if (TreeDeptEmp.SelectedNode.Text.StartsWith(".")) | |||
|  |           { | |||
|  |               wherecls = "ID= '" + selectedValue + "'"; | |||
|  |           } | |||
|  |           dv2.RowFilter = wherecls; | |||
|  |        }  | |||
|  | 
 | |||
|  |   | |||
|  | 
 | |||
|  |         GridView1.DataSource = dv2 ; | |||
|  |         GridView1.DataBind(); | |||
|  |         if (GridView1.DataKeys != null && GridView1.DataKeys.Count>0 && GridView1.SelectedIndex!=-1) | |||
|  |         {  | |||
|  |             Databound( GridView1.DataKeys[GridView1.SelectedIndex].Value.ToString()); | |||
|  |         }else | |||
|  | 
 | |||
|  |         { | |||
|  |             GridView2.DataSource = null; | |||
|  |             GridView2.DataBind(); | |||
|  |         } | |||
|  |              | |||
|  |       | |||
|  |         | |||
|  |         UpdateSession(); | |||
|  |     // btnSubmit.Enabled = false; | |||
|  |       //  ClearDetail(); | |||
|  |     } | |||
|  | 
 | |||
|  |     private void Databound(string empId) | |||
|  |     { | |||
|  |        // if (empId == null) throw new ArgumentNullException("empId"); | |||
|  |         if (empId == null) return; | |||
|  | 
 | |||
|  |         DataView dv = _logic.GetAllProjectDetail(Convert.ToInt32(empId),btnYear.Text, rdblstMonth.SelectedValue).DefaultView; | |||
|  |         GridView2.DataSource = dv; | |||
|  |         GridView2.DataBind(); | |||
|  |          | |||
|  |     } | |||
|  |     /// <summary> | |||
|  |     /// <20><EFBFBD><F3B6A8B2>ż<EFBFBD><C5BC>û<EFBFBD> | |||
|  |     /// </summary> | |||
|  |     private void bindDeptEmp() | |||
|  |     { | |||
|  |        // TreeDeptEmp.Nodes.Clear(); | |||
|  |         BindEmpTree(TreeDeptEmp, "0", TreeDeptEmp.SelectedNode,lem.GetDepartments().DefaultView, lem.GetActivedEmpDept().DefaultView); | |||
|  | 
 | |||
|  | 
 | |||
|  | 
 | |||
|  |     } | |||
|  | 
 | |||
|  | 
 | |||
|  | 
 | |||
|  |     public void BindEmpTree(TreeView tree, string id, TreeNode pNode, DataView deptdv, DataView empdv) | |||
|  |     { | |||
|  | 
 | |||
|  |         deptdv.RowFilter = "dep_mastdept = '" + id + "'"; | |||
|  |         foreach (DataRowView row in deptdv) | |||
|  |         { | |||
|  |             TreeNode node = new TreeNode(); | |||
|  |             node.Text = "<Strong>" + row["dep_name"] + "</Strong>"; | |||
|  |             node.Value = row["ID"].ToString();  | |||
|  |             node.ShowCheckBox = false; | |||
|  |             node.Expanded = true; | |||
|  |             empdv.RowFilter = "de_dept=" + node.Value; | |||
|  |             foreach (DataRowView emrow in empdv) | |||
|  |             { | |||
|  |                 TreeNode tnEmp = new TreeNode(    "."+emrow["em_name"]   , emrow["ID"].ToString()); | |||
|  |                 node.ChildNodes.Add(tnEmp); | |||
|  |             } | |||
|  |             if (pNode == null) | |||
|  |             //˵<><CBB5><EFBFBD>Ǹ<EFBFBD><C7B8>ڵ<EFBFBD> | |||
|  |             { | |||
|  | 
 | |||
|  |                 tree.Nodes.Add(node); | |||
|  | 
 | |||
|  | 
 | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  | 
 | |||
|  |                 pNode.ChildNodes.Add(node); | |||
|  | 
 | |||
|  |             } | |||
|  |             BindEmpTree(tree, node.Value, node, new DataView(deptdv.Table), new DataView(empdv.Table)); | |||
|  | 
 | |||
|  |         } | |||
|  |     } | |||
|  | 
 | |||
|  |     void setTreeDeptEmpSelected(string toFind,TreeNode nd) | |||
|  |     { | |||
|  |         foreach (TreeNode cnd in nd.ChildNodes) | |||
|  |         { | |||
|  |             if (cnd.Value == toFind)  | |||
|  |             { | |||
|  |                 cnd.Selected = true; | |||
|  |                 break; | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  |                 setTreeDeptEmpSelected(toFind,cnd); | |||
|  |             } | |||
|  | 
 | |||
|  |         } | |||
|  |     } | |||
|  |     private void SessionSeting() | |||
|  |     { | |||
|  |         if (IsPostBack) | |||
|  |         { | |||
|  |             _logic = (LProject)Session[appScope.PagelevelObj]; | |||
|  |         } | |||
|  |     } | |||
|  | 
 | |||
|  |     private void UpdateSession() | |||
|  |     { | |||
|  |         Session[appScope.PagelevelObj] = _logic; | |||
|  |     } | |||
|  | 
 | |||
|  |  <EFBFBD><EFBFBD> | |||
|  | 
 | |||
|  |     protected void DetailsView1_PageIndexChanging(object sender, DetailsViewPageEventArgs e) | |||
|  |     { | |||
|  |     } | |||
|  | 
 | |||
|  |   <EFBFBD><EFBFBD> | |||
|  | 
 | |||
|  |   <EFBFBD><EFBFBD> | |||
|  | 
 | |||
|  |     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 GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e) | |||
|  |     { | |||
|  |         GridView2.PageIndex = e.NewPageIndex; | |||
|  |         Databound(); | |||
|  | 
 | |||
|  |         //GridView1.DataSource = shiftLgc.getAllShifts().Tables[0]; | |||
|  |         //     GridView1.DataBind();     | |||
|  |     } | |||
|  |     protected void GridView1_Sorting(object sender, GridViewSortEventArgs e) | |||
|  |     { | |||
|  |     } | |||
|  | 
 | |||
|  |   <EFBFBD><EFBFBD> | |||
|  |   <EFBFBD><EFBFBD> | |||
|  | 
 | |||
|  |     protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) | |||
|  |      { | |||
|  |         Databound(); | |||
|  |       <EFBFBD><EFBFBD> | |||
|  |     } | |||
|  | 
 | |||
|  | 
 | |||
|  |   | |||
|  |     protected void TreeDeptEmp_SelectedNodeChanged(object sender, EventArgs e) | |||
|  |     { | |||
|  |         GridView1.SelectedIndex = -1; | |||
|  | 
 | |||
|  |         Databound(); | |||
|  |         | |||
|  |     } | |||
|  |     protected void rdblstMonth_SelectedIndexChanged(object sender, EventArgs e) | |||
|  |     { | |||
|  |         GridView1.SelectedIndex = -1; | |||
|  |         Databound(); | |||
|  |     } | |||
|  | 
 | |||
|  |     protected void TxtBtnYear_TextChanged(object sender, EventArgs e) | |||
|  |     { | |||
|  |         //  btnYear.Text = TxtBtnYear.Text; | |||
|  |         rdblstMonth.SelectedItem.Selected = false; | |||
|  |         rdblstMonth.Items[0].Selected = true; | |||
|  |         Databound(); | |||
|  | 
 | |||
|  |     } | |||
|  |     protected void Page_Init() | |||
|  |     { | |||
|  | 
 | |||
|  |         PostBackTrigger trigger = new PostBackTrigger(); | |||
|  |         trigger.ControlID = Button1.UniqueID; | |||
|  |         ((UpdatePanel)Master.FindControl("UpdatePanel1")).Triggers.Add(trigger); | |||
|  |         trigger = new PostBackTrigger(); | |||
|  |         trigger.ControlID = Button2.UniqueID; | |||
|  |         ((UpdatePanel)Master.FindControl("UpdatePanel1")).Triggers.Add(trigger); | |||
|  | 
 | |||
|  |     } | |||
|  |     public override void VerifyRenderingInServerForm(Control control) | |||
|  |     { | |||
|  |     } | |||
|  | 
 | |||
|  |     protected void Excel_Click(object sender, EventArgs e) | |||
|  |     { | |||
|  |         Master.ScriptMgr.RegisterPostBackControl(Button1); | |||
|  |         GridView1.AllowPaging = false; | |||
|  |         GridView1.Columns[GridView1.Columns.Count-1].Visible = false; | |||
|  |         Databound(); | |||
|  |         Export1("application/ms-excel", "<22><>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>.xls"); | |||
|  |         GridView1.AllowPaging = false; | |||
|  |         GridView1.Columns[GridView1.Columns.Count - 1].Visible = true; | |||
|  |         Databound(); | |||
|  | 
 | |||
|  |     } | |||
|  | 
 | |||
|  |     protected void Excel_Click2(object sender, EventArgs e) | |||
|  |     { | |||
|  |         Master.ScriptMgr.RegisterPostBackControl(Button1); | |||
|  |         GridView2.AllowPaging = false; | |||
|  |          | |||
|  |         Databound(); | |||
|  |         Export2("application/ms-excel", "<22><>Ŀ<EFBFBD><C4BF>ϸ<EFBFBD>б<EFBFBD>.xls"); | |||
|  |         GridView2.AllowPaging = false; | |||
|  |          | |||
|  |         Databound(); | |||
|  | 
 | |||
|  |     } | |||
|  | 
 | |||
|  | 
 | |||
|  |     private void Export1(string FileType, string FileName) | |||
|  |     { | |||
|  | 
 | |||
|  |         Response.Charset = "GB2312"; | |||
|  |         Response.ContentEncoding = Encoding.UTF7; | |||
|  |         Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString()); | |||
|  |         Response.ContentType = FileType; | |||
|  |         EnableViewState = false; | |||
|  |         StringWriter tw = new StringWriter(); | |||
|  |         HtmlTextWriter hw = new HtmlTextWriter(tw); | |||
|  |         GridView1.RenderControl(hw); | |||
|  |         Response.Write(tw.ToString()); | |||
|  |         Response.End(); | |||
|  | 
 | |||
|  |     } | |||
|  |     private void Export2(string FileType, string FileName) | |||
|  |     { | |||
|  | 
 | |||
|  |         Response.Charset = "GB2312"; | |||
|  |         Response.ContentEncoding = Encoding.UTF7; | |||
|  |         Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString()); | |||
|  |         Response.ContentType = FileType; | |||
|  |         EnableViewState = false; | |||
|  |         StringWriter tw = new StringWriter(); | |||
|  |         HtmlTextWriter hw = new HtmlTextWriter(tw); | |||
|  |         GridView2.RenderControl(hw); | |||
|  |         Response.Write(tw.ToString()); | |||
|  |         Response.End(); | |||
|  | 
 | |||
|  |     } | |||
|  | } |