using DevExpress.XtraGrid.Columns; using Gs.DevApp.DevFrm.JJGZ; using Gs.DevApp.Entity; using Gs.DevApp.ToolBox; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Net; using System.Threading.Tasks; using System.Windows.Forms; namespace Gs.DevApp.DevFrm.JJGZ { public partial class Frm_YDGZ : DevExpress.XtraEditors.XtraForm { private List _filterList = new List(); private readonly string _webServiceName = "MesJjgzReport/"; private string orgId; private string date; public Frm_YDGZ() { InitializeComponent(); toolBarMenu1.btnLoadClick += ToolBarMenu1_btnLoadClick; toolBarMenu1.btnQueryClick += ToolBarMenu1_btnQueryClick; this.toolBarMenu1.getXmlConfig(); Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameter(gridView1, null, null, "", "", (value) => { }, tips); this.toolBarMenu1.btnOutClick += ToolBarMenu1_btnOutClick; } private void GridView1_ColumnFilterChanged(object sender, EventArgs e) { _filterList = Gs.DevApp.ToolBox.UtilityHelper.GetDilter(gridView1.Columns, gridView1); Task.Delay(100); getPageList(); } /// /// 查询事件 /// /// /// private void ToolBarMenu1_btnQueryClick(object sender, EventArgs e) { var frm = new YDGZCX(orgId,date); //赋值给明细表 frm.UpdateParent += (ss, ee) => { var lst = new List(); lst = ee.StringList; orgId = string.IsNullOrEmpty(lst[0]) ? "" : lst[0]; date = string.IsNullOrEmpty(lst[1]) ? "" : lst[1]; getPageList(); }; frm.ShowDialog(); } /// /// 刷新事件 /// /// /// private void ToolBarMenu1_btnLoadClick(object sender, EventArgs e) { //getPageList(1); getPageList(); } /// /// /// 第几页 /// 每页几条 private void getPageList() { if(string.IsNullOrEmpty(date) || string.IsNullOrEmpty(orgId)) { return; } gcMain1.DataSource = null; var _sbSqlWhere = UtilityHelper.GetSearchWhere(_filterList); var _obj = new { orgId = orgId, date = date }; try { var strReturn = UtilityHelper.HttpPost("", _webServiceName + "GetYDGZList", JsonConvert.SerializeObject(_obj)); ReturnModel _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strReturn); if (_rtn.rtnCode > 0) { dynamic dy = _rtn.rtnData; JObject _job = JObject.Parse(strReturn); JArray array = new JArray(); foreach (var a in _job["rtnData"]["list"]) { array.Add(a); } DataTable dt = JsonConvert.DeserializeObject(array.ToString()); List allDates = new List(); var nowdate = DateTime.Parse(date); DateTime monthStart = new DateTime(nowdate.Year, nowdate.Month, 1); DateTime monthEnd = monthStart.AddMonths(1).AddDays(-1); for (DateTime item = monthStart; item <= monthEnd; item = item.AddDays(1)) { allDates.Add(item); } gridView1.Columns.Clear(); // 添加固定列 AddFixedColumns(); // 添加日期列 foreach (DateTime date in allDates) { string columnName = date.ToString("yyyy-MM-dd"); // 如果数据表中存在该列 if (dt.Columns.Contains(columnName)) { GridColumn colDate = new GridColumn(); colDate.FieldName = columnName; colDate.Caption = date.ToString("MM-dd"); colDate.Visible = true; colDate.OptionsColumn.AllowEdit = false; colDate.Width = 60; gridView1.Columns.Add(colDate); } } gcMain1.BindingContext = new BindingContext(); gridView1.ColumnFilterChanged -= GridView1_ColumnFilterChanged; if (dt.Rows.Count > 0) { gcMain1.DataSource = dt; gcMain1.ForceInitialize(); gridView1.BestFitColumns(); Gs.DevApp.ToolBox.UtilityHelper.SetGridLayout(gridView1); } else UtilityHelper.SetDefaultTable(gcMain1, gridView1); } else ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg); } catch (Exception ex) { MsgHelper.Warning("提示:" + ex.Message); } } private void AddFixedColumns() { // 产线编码 GridColumn colMaterialCode = new GridColumn(); colMaterialCode.FieldName = "lineNo"; colMaterialCode.Caption = "产线编码"; colMaterialCode.Visible = true; colMaterialCode.OptionsColumn.AllowEdit = false; gridView1.Columns.Add(colMaterialCode); // 产线名称 GridColumn colMaterialName = new GridColumn(); colMaterialName.FieldName = "lineName"; colMaterialName.Caption = "产线名称"; colMaterialName.Visible = true; colMaterialName.OptionsColumn.AllowEdit = false; gridView1.Columns.Add(colMaterialName); // 员工编码 GridColumn colMaterialSpec = new GridColumn(); colMaterialSpec.FieldName = "staffNo"; colMaterialSpec.Caption = "员工编码"; colMaterialSpec.Visible = true; colMaterialSpec.OptionsColumn.AllowEdit = false; gridView1.Columns.Add(colMaterialSpec); // 员工名称 GridColumn colTotalRequired = new GridColumn(); colTotalRequired.FieldName = "staffName"; colTotalRequired.Caption = "员工名称"; colTotalRequired.Visible = true; colTotalRequired.OptionsColumn.AllowEdit = false; gridView1.Columns.Add(colTotalRequired); GridColumn colCountSalary = new GridColumn(); colCountSalary.FieldName = "addSalary"; colCountSalary.Caption = "工资汇总"; colCountSalary.Visible = true; colCountSalary.OptionsColumn.AllowEdit = false; gridView1.Columns.Add(colCountSalary); } private void ToolBarMenu1_btnOutClick(object sender, EventArgs e) { using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog()) { folderBrowserDialog.Description = "选择导出文件的保存路径"; DialogResult dialogResult = folderBrowserDialog.ShowDialog(); if (dialogResult == DialogResult.OK) { string _folder = folderBrowserDialog.SelectedPath; var _params = new { inputDate = date }; var _obj = new Gs.DevApp.Entity.XlsOutModel("report_YDGZ", "", "", "", _params); try { string strJson = UtilityHelper.HttpPost("", "XlsInOut/XlsOutView_NEW", JsonConvert.SerializeObject(_obj)); ReturnModel _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson); if (_rtn.rtnCode > 0) { string _file = _rtn.rtnData.fileUrl.ToString(); string _folderName = _folder + "\\" + _file.Replace("down/", ""); string _url = ConfigurationManager.AppSettings["WebApiUrl"].ToString() + _file; using (WebClient client = new WebClient()) { client.DownloadFile(_url, _folderName); } ToolBox.MsgHelper.ShowInformation("导出成功!"); } else { ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg); } } catch (Exception ex) { ToolBox.MsgHelper.Warning("提示:" + ex.Message); } } } } } }