public bool equals(goodSumStruct temp) { return(this.returndate == temp.returndate && this.returnfileNo == temp.returnfileNo && this.custommaterialNo == temp.custommaterialNo && this.ramno == temp.ramno); }
private void exportxmlbutton_Click(object sender, EventArgs e) { DateTime time1 = Convert.ToDateTime(this.dateTimePickerstart.Value.Date.ToString("yyyy-MM-dd", System.Globalization.DateTimeFormatInfo.InvariantInfo)); DateTime time2 = Convert.ToDateTime(this.dateTimePickerend.Value.Date.ToString("yyyy-MM-dd", System.Globalization.DateTimeFormatInfo.InvariantInfo)); if (DateTime.Compare(time1, time2) > 0) //判断日期大小 { MessageBox.Show("开始日期大于结束"); return; } string startTime = this.dateTimePickerstart.Value.ToString("yyyy-MM-dd", System.Globalization.DateTimeFormatInfo.InvariantInfo); string endTime = this.dateTimePickerend.Value.ToString("yyyy-MM-dd", System.Globalization.DateTimeFormatInfo.InvariantInfo); List <ReturnOrderStruct> receiveOrderList = new List <ReturnOrderStruct>(); List <goodSumStruct> goodSumStructList = new List <goodSumStruct>(); List <cidSumStruct> cidSumStructList = new List <cidSumStruct>(); try { SqlConnection mConn = new SqlConnection(Constlist.ConStr); mConn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = mConn; cmd.CommandType = CommandType.Text; cmd.CommandText = "select Id,vendor,product,return_file_no,storehouse,return_date,orderno,custommaterialNo," + "dpkpn,track_serial_no,custom_serial_no,vendor_serail_no,vendormaterialNo,_status,custom_res_type," + "response_describe,tat,inputuser,lenovo_maintenance_no,lenovo_repair_no from returnStore where return_date between '" + startTime + "' and '" + endTime + "'"; SqlDataReader querySdr = cmd.ExecuteReader(); while (querySdr.Read()) { ReturnOrderStruct temp = new ReturnOrderStruct(); temp.Id = querySdr[0].ToString(); temp.vendor = querySdr[1].ToString(); temp.product = querySdr[2].ToString(); temp.return_file_no = querySdr[3].ToString(); temp.storehouse = querySdr[4].ToString(); temp.return_date = querySdr[5].ToString(); temp.orderno = querySdr[6].ToString(); temp.custommaterialNo = querySdr[7].ToString(); temp.dpkpn = querySdr[8].ToString(); temp.track_serial_no = querySdr[9].ToString(); temp.custom_serial_no = querySdr[10].ToString(); temp.vendor_serail_no = querySdr[11].ToString(); temp.vendormaterialNo = querySdr[12].ToString(); temp._status = querySdr[13].ToString(); temp.custom_res_type = querySdr[14].ToString(); temp.response_describe = querySdr[15].ToString(); temp.tat = querySdr[16].ToString(); temp.inputuser = querySdr[17].ToString(); temp.lenovo_maintenance_no = querySdr[18].ToString(); temp.lenovo_repair_no = querySdr[19].ToString(); receiveOrderList.Add(temp); } querySdr.Close(); foreach (ReturnOrderStruct temp in receiveOrderList) { cmd.CommandText = "select order_receive_date,custom_fault,lenovo_custom_service_no,mb_brief from DeliveredTable where track_serial_no='" + temp.track_serial_no + "'"; querySdr = cmd.ExecuteReader(); while (querySdr.Read()) { temp.receive_date = querySdr[0].ToString(); temp.custom_fault = querySdr[1].ToString(); temp.lenovo_custom_service_no = querySdr[2].ToString(); temp.mb_brief = querySdr[3].ToString(); break; } querySdr.Close(); DateTime dt1 = Convert.ToDateTime(temp.receive_date); DateTime dt2 = Convert.ToDateTime(temp.return_date); TimeSpan ts = dt2.Subtract(dt1); int overdays = ts.Days; temp.tat = overdays + ""; } if (this.goodsum.Checked) { foreach (ReturnOrderStruct temp in receiveOrderList) { if (temp._status == "良品") { goodSumStruct temp1 = new goodSumStruct(); temp1.ramno = temp.orderno; temp1.returndate = temp.return_date; temp1.returnfileNo = temp.return_file_no; temp1.custommaterialNo = temp.custommaterialNo; if (goodSumStructList.Count == 0) { goodSumStructList.Add(temp1); } else { bool exist = false; foreach (goodSumStruct oldrecord in goodSumStructList) { if (oldrecord.equals(temp1)) { oldrecord.incrementNum(); exist = true; break; } } if (exist == false) { goodSumStructList.Add(temp1); } } } } foreach (goodSumStruct oldrecord in goodSumStructList) { cmd.CommandText = "select mb_brief from MBMaterialCompare where custommaterialNo='" + oldrecord.custommaterialNo + "'"; querySdr = cmd.ExecuteReader(); while (querySdr.Read()) { oldrecord.mb_brief = querySdr[0].ToString(); break; } querySdr.Close(); } } else if (this.cidsum.Checked) { foreach (ReturnOrderStruct temp in receiveOrderList) { if (temp._status == "不良品") { cidSumStruct temp1 = new cidSumStruct(); temp1.ramno = temp.orderno; temp1.returndate = temp.return_date; temp1.custommaterialNo = temp.custommaterialNo; if (cidSumStructList.Count == 0) { cidSumStructList.Add(temp1); } else { bool exist = false; foreach (cidSumStruct oldrecord in cidSumStructList) { if (oldrecord.equals(temp1)) { oldrecord.incrementNum(); exist = true; break; } } if (exist == false) { cidSumStructList.Add(temp1); } } } } foreach (cidSumStruct oldrecord in cidSumStructList) { cmd.CommandText = "select mb_brief from MBMaterialCompare where custommaterialNo='" + oldrecord.custommaterialNo + "'"; querySdr = cmd.ExecuteReader(); while (querySdr.Read()) { oldrecord.mb_brief = querySdr[0].ToString(); break; } querySdr.Close(); } } mConn.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } if (this.returndetail.Checked) { generateExcelToCheck(receiveOrderList, startTime, endTime); } else if (this.goodsum.Checked) { generategoodExcelToCheck(goodSumStructList, startTime, endTime); } else if (this.cidsum.Checked) { generatecidExcelToCheck(cidSumStructList, startTime, endTime); } }