//保时捷汇总导出线程方法 public void porscheExport() { try { ProcessForm pf = new ProcessForm(); pf.Show(); //获取显示的产品型号和日期信息 CafcService.FuelCAFCDetails[] dataSource = (CafcService.FuelCAFCDetails[]) this.gcDetail.DataSource; int total = 0; foreach (CafcService.FuelCAFCDetails sd in dataSource) { total += sd.Sl_hs; } pf.TotalMax = total; pf.ShowProcessBar(); //根据型号和日期(需要把开始日期和结束日期设为月份的第一天和最后一天)从服务器获取车型详细参数 List <FuelDataService.VehicleBasicInfo> listVB = new List <FuelDataService.VehicleBasicInfo>(); string startTime = this.dtStartTime.Text.Trim(); string endTime = this.dtEndTime.Text.Trim(); int pageCount = 1; while (true) { try { FuelDataService.VehicleBasicInfo[] fuelData = Utils.service.QueryUploadedFuelData(Utils.userId, Utils.password, pageCount, 500, string.Empty, String.Empty, string.Empty, string.Empty, startTime, endTime, "MANUFACTURE_TIME"); if (fuelData != null) { if (fuelData.Length == 0) { break; } listVB.AddRange(fuelData); pageCount++; pf.progressBarControl1.Properties.Step = fuelData.Length; pf.progressBarControl1.PerformStep(); Application.DoEvents(); } else { break; } } catch (WebException ex) { MessageBox.Show("请本地检测网络"); return; } } pf.Close(); if (listVB.Count == 0) { return; } //转换成为本地结构 List <HZDCModule> listHzdc = Utils.VehicleBasicInfoTo <HZDCModule>(listVB.ToArray()); PorscheUtils porscheUtils = new PorscheUtils(true, startTime); List <exportModel> getMBZResult = new List <exportModel>(); //对vin信息进行分组 var vehicleBasicInfoGroupResult = (from t in listHzdc group t by new { t.ClXH, t.TYMC, t.ZHGKRLXHL, t.RLLX, t.ZCZBZL, t.BSQXS, t.ZWPS, t.EDZK } into g select new { g.Key.ClXH, g.Key.BSQXS, g.Key.EDZK, g.Key.RLLX, g.Key.TYMC, g.Key.ZCZBZL, g.Key.ZHGKRLXHL, g.Key.ZWPS, SL = g.Count() }).ToList(); if (Convert.ToDateTime(startTime).Year < 2016) { getMBZResult = (from s in vehicleBasicInfoGroupResult select new exportModel { bsqxs = s.BSQXS, clxh = s.ClXH, edzk = s.EDZK, rllx = s.RLLX, tymc = s.TYMC, zczbzl = Convert.ToInt32(s.ZCZBZL), zhgkrlxhlmbz = Convert.ToDecimal((from t in porscheUtils.dtTargetFuel.AsEnumerable() where (s.BSQXS.Equals("MT") ? "MT" : "OT").Equals(t.Field <string>("BSQXS")) && (Convert.ToInt32(s.ZWPS) < 3 ? "2" : "3").Equals(t.Field <string>("ZWPS")) && Convert.ToDouble(s.ZCZBZL) > t.Field <double>("MIN_ZCZBZL") && Convert.ToDouble(s.ZCZBZL) <= t.Field <double>("MAX_ZCZBZL") select t.Field <string>("TGT_ZHGKRLXHL")).FirstOrDefault()), zhgkrlxhl = Convert.ToDecimal(s.ZHGKRLXHL), zwps = s.ZWPS, sl = s.SL, }).ToList(); } else { getMBZResult = (from s in vehicleBasicInfoGroupResult select new exportModel { bsqxs = s.BSQXS, clxh = s.ClXH, edzk = s.EDZK, rllx = s.RLLX, tymc = s.TYMC, zczbzl = Convert.ToInt32(s.ZCZBZL), zhgkrlxhlmbz = Convert.ToDecimal((from t in porscheUtils.dtTargetFuel.AsEnumerable() where (Convert.ToInt32(s.ZWPS) < 3 ? "2" : "3").Equals(t.Field <string>("ZWPS")) && Convert.ToDouble(s.ZCZBZL) > t.Field <double>("MIN_ZCZBZL") && Convert.ToDouble(s.ZCZBZL) <= t.Field <double>("MAX_ZCZBZL") select t.Field <string>("TGT_ZHGKRLXHL")).FirstOrDefault()), zhgkrlxhl = Convert.ToDecimal(s.ZHGKRLXHL), zwps = s.ZWPS, sl = s.SL, }).ToList(); } var vinGroupResult = (from s in getMBZResult group s by s.clxh into result select new { clxh = result.First().clxh, rdzhgkrlxhl = result.Max(s => s.zhgkrlxhl), rdzhgkrlxhlmbz = result.Min(s => s.zhgkrlxhlmbz) }).ToList(); var allInfoReadyResult = (from s1 in getMBZResult join s2 in vinGroupResult on s1.clxh equals s2.clxh select new { bsqxs = s1.bsqxs.ToString(), clxh = s1.clxh.ToString(), edzk = s1.edzk.ToString(), rllx = s1.rllx.ToString(), tymc = s1.tymc.ToString(), zczbzl = Convert.ToInt16(s1.zczbzl), zhgkrlxhlmbz = Convert.ToDecimal(s1.zhgkrlxhlmbz), zhgkrlxhl = Convert.ToDecimal(s1.zhgkrlxhl), zwps = s1.zwps.ToString(), rdzhgkrlxhl = s2.rdzhgkrlxhl, rdzhgkrlxhlmbz = s2.rdzhgkrlxhlmbz, sl = s1.sl, }).ToList(); //将信息转化成datatable然后导出到excel当中 DataTable dtOutput = new DataTable(); String[] header = new String[] { "CLXH", "TYMC", "SL;int", "ZHGKRLXHL;decimal", "RDZHGKRLXHL;decimal", "SL*ZHGKRLXHL;decimal", "SL*RDZHGKRLXHL;decimal", "RLLX", "ZCZBZL;int", "BSQXS", "ZWPS", "EDZK", "ZHGKRLXHLMBZ;decimal", "RDZHGKRLXHLMBZ;decimal", "SL*ZHGKRLXHLMBZ;decimal", "SL*RDZHGKRLXHLMBZ;decimal" }; foreach (String s in header) { String type = "string", expression = ""; String[] expGroup = s.Split(new String[] { ";" }, StringSplitOptions.RemoveEmptyEntries); if (expGroup.First().Contains("*")) { expression = expGroup.First().Replace("*", " * "); } if (expGroup.Length > 1) { type = expGroup.Last(); } dtOutput.Columns.Add(expGroup.First(), Utils.GetTypeByString(type), expression); } foreach (var vb in allInfoReadyResult) { DataRow dr = dtOutput.NewRow(); foreach (DataColumn dc in dtOutput.Columns) { String columnName = dc.ColumnName; bool found = false; PropertyInfo[] properties = vb.GetType().GetProperties(); foreach (PropertyInfo pi in properties) { if (pi.Name.Equals(columnName, StringComparison.OrdinalIgnoreCase)) { object result = pi.GetValue(vb, null); if (result is DateTime) { DateTime dt = (DateTime)result; dr[columnName] = dt.ToString("yyyy-MM-dd"); } else { dr[columnName] = pi.GetValue(vb, null); } found = true; break; } } } dtOutput.Rows.Add(dr); } if (Convert.ToDateTime(startTime).Year < 2016) { porscheUtils.ExportExcel(dtOutput, this, PorscheUtils.HZBGExport); } else { porscheUtils.ExportExcel(dtOutput, this, PorscheUtils.HZBGExport_New); } } catch (Exception ex) { MessageBox.Show("导出失败:" + ex.Message + "\r\n" + ex.StackTrace, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
// 保时捷——导出Excel private void extractDataAndExport() { ProcessForm pf = new ProcessForm(); pf.Show(); //获取显示的车辆型号和日期信息 CafcService.StatisticsData[] dataSource = (CafcService.StatisticsData[]) this.gcStatistic.DataSource; int total = 0; foreach (CafcService.StatisticsData sd in dataSource) { total += sd.Sl; } pf.TotalMax = total; pf.ShowProcessBar(); //根据型号和日期(需要把开始日期和结束日期设为月份的第一天和最后一天)从服务器获取车型详细参数 List <FuelDataService.VehicleBasicInfo> listVB = new List <FuelDataService.VehicleBasicInfo>(); string startTime = this.dtStartTime.Text.Trim(); string endTime = this.dtEndTime.Text.Trim(); int pageCount = 1; while (true) { try { FuelDataService.VehicleBasicInfo[] fuelData = Utils.service.QueryUploadedFuelData(Utils.userId, Utils.password, pageCount, 500, string.Empty, String.Empty, string.Empty, string.Empty, startTime, endTime, "MANUFACTURE_TIME"); if (fuelData != null) { if (fuelData.Length == 0) { break; } listVB.AddRange(fuelData); pageCount++; pf.progressBarControl1.Properties.Step = fuelData.Length; pf.progressBarControl1.PerformStep(); Application.DoEvents(); } else { break; } } catch (WebException ex) { MessageBox.Show("请本地检测网络"); return; } } pf.Close(); //} if (listVB.Count == 0) { return; } //转换成为本地结构 List <VehicleBasicInfo> listConvertedVB = Utils.FuelInfoS2C(listVB.ToArray()); //将信息转化成datatable然后导出到excel当中 DataTable dtOutput = new DataTable(); String[] header = new String[] { "VIN", "CLXH", "TYMC", "RLLX", "EDZK", "ZWPS", "BSQXS", "ZCZBZL", "CLZZRQ", "ZHGKRLXHL", "LJ", "LTGG", "UPDATETIME" }; foreach (String s in header) { dtOutput.Columns.Add(s); } foreach (VehicleBasicInfo vb in listConvertedVB) { DataRow dr = dtOutput.NewRow(); foreach (DataColumn dc in dtOutput.Columns) { String columnName = dc.ColumnName; bool found = false; PropertyInfo[] properties = new VehicleBasicInfo().GetType().GetProperties(); foreach (PropertyInfo pi in properties) { if (pi.Name.Equals(columnName, StringComparison.OrdinalIgnoreCase)) { object result = pi.GetValue(vb, null); if (result is DateTime) { DateTime dt = (DateTime)result; dr[columnName] = dt.ToString("yyyy-MM-dd"); } else { dr[columnName] = pi.GetValue(vb, null); } found = true; break; } } if (!found) { RllxParamEntity[] rllxParams = vb.EntityList; if (rllxParams == null || rllxParams.Length == 0) { continue; } foreach (RllxParamEntity rpe in rllxParams) { if (rpe.Param_Code.Contains(columnName)) { dr[columnName] = rpe.Param_Value; break; } } } } dtOutput.Rows.Add(dr); } PorscheUtils utils = new PorscheUtils(true); utils.ExportExcel(dtOutput, this, PorscheUtils.CLMXExport); }
private void btnCtnyExport_Click(object sender, EventArgs e) { DataTable source = (DataTable)this.dgvCtny.DataSource; pu.ExportExcel(source, this, PorscheUtils.CTNYExport); }