using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using Stone.Common; using Stone.Entity; namespace Stone.WinModule.JISAdmin { public partial class frmEdiPrintASNSelect : Form { public string PackingListNumber = ""; public string PartsFamily = ""; public frmEdiPrintASNSelect() { InitializeComponent(); } private void frmEdiPrintASNSelect_Load(object sender, EventArgs e) { try { PackingListNumber = ""; PartsFamily = ""; DataTable dtPackageGroupName = new Entity_t_Sys_AppconfigItem().GetData("[Code]='print_group' and [Value1] is not null and [Value1] not like '%门槛%' and [Value1] not like '%扰流板%'").Tables[0]; DataRow drPackageGroupName = dtPackageGroupName.NewRow(); drPackageGroupName["Value1"] = "门槛条"; dtPackageGroupName.Rows.InsertAt(drPackageGroupName, 2); this.txtPackageGroupName.DataSource = dtPackageGroupName; this.txtPackageGroupName.DisplayMember = "Value1"; this.txtPackageGroupName.ValueMember = "Value1"; UpdateList(); //this.checkedListBox1.DataSource = new Entity_t_Sys_AppconfigItem().GetData("[Code]='print_group' and [Value1] is not null").Tables[0]; //this.checkedListBox1.ValueMember = "Value1"; //this.checkedListBox1.DisplayMember = "Value1"; } catch (Exception ex) { MyMessageBox.ShowErrorMessage(ex.Message); } } private void btnOK_Click(object sender, EventArgs e) { try { if (this.chkPackingList.CheckedItems.Count == 0) throw new Exception("请勾选"); if (!MyMessageBox.ShowQuestionPop("是否要确定打印【" + GetBoxCount() + "】?")) return; PackingListNumber = ""; PartsFamily = ""; List list = new List(); DataTable dtData = new DataTable(); dtData.Columns.Add("supplyGroup"); dtData.Columns.Add("PartsFamily"); dtData.Columns.Add("PagerNumber"); dtData.Columns.Add("PackageGroupName"); for (int i = 0; i < this.chkPackingList.CheckedItems.Count; i++) { string pln = ((DataRowView)this.chkPackingList.CheckedItems[i])["PackingListNumber"].ToString(); string pf = ((DataRowView)this.chkPackingList.CheckedItems[i])["PartsFamily"].ToString(); string sp = ((DataRowView)this.chkPackingList.CheckedItems[i])["supplyGroup"].ToString(); string PagerNumber = ((DataRowView)this.chkPackingList.CheckedItems[i])["PagerNumber"].ToString(); string PackageGroupName = ((DataRowView)this.chkPackingList.CheckedItems[i])["PackageGroupName"].ToString(); PackingListNumber += "'" + pln + "',"; PartsFamily += "'" + pf + "',"; if (list.IndexOf(sp) == -1) { list.Add(sp); } DataRow drNew = dtData.NewRow(); drNew["supplyGroup"] = sp; drNew["PartsFamily"] = pf; drNew["PagerNumber"] = PagerNumber; drNew["PackageGroupName"] = PackageGroupName; dtData.Rows.Add(drNew); } if (PackingListNumber != "") PackingListNumber = PackingListNumber.Substring(0, PackingListNumber.Length - 1); if (PartsFamily != "") PartsFamily = PartsFamily.Substring(0, PartsFamily.Length - 1); //IsContinuous(list, dtData); this.DialogResult = DialogResult.OK; this.Close(); } catch (Exception ex) { MyMessageBox.ShowErrorMessage(ex.Message); } } private void btnClose_Click(object sender, EventArgs e) { this.Close(); } private string GetBoxCount() { //PackingListNumber string ret = ""; DataTable dtTemp = new DataTable(); dtTemp.Columns.Add("PackageGroupName"); dtTemp.Columns.Add("c", typeof(System.Int32)); List lsts = new List(); for (int i = 0; i < this.chkPackingList.Items.Count; i++) { if (this.chkPackingList.GetItemChecked(i)) { DataRowView drData = (DataRowView)this.chkPackingList.Items[i]; string pgnumber = drData["PackageGroupName"].ToString() + "-" + drData["PackingListNumber"].ToString(); if (lsts.IndexOf(pgnumber) < 0){ lsts.Add(pgnumber); DataRow[] drs = dtTemp.Select("[PackageGroupName]='" + drData["PackageGroupName"].ToString() + "'"); if (drs.Length == 0) { DataRow drNew = dtTemp.NewRow(); drNew["PackageGroupName"] = drData["PackageGroupName"].ToString(); drNew["c"] = 1; dtTemp.Rows.Add(drNew); } else { drs[0]["c"] = Convert.ToInt32(drs[0]["c"]) + 1; } } } } foreach (DataRow dr in dtTemp.Rows) { ret += "\r\n" + dr["PackageGroupName"].ToString() + ":" + dr["c"].ToString() + " "; } return ret + "\r\n"; } private void UpdateList() { #region old /* string d1 = MyDateTime.Format(this.dateTimePicker1.Value, MyDateTimeType.Date) + " 00:00:00"; string d2 = MyDateTime.Format(this.dateTimePicker2.Value, MyDateTimeType.Date) + " 23:59:59"; string strWhere = "IsPrintPackingList=1 and IsPrintASN=0 and [SwetTime]>='" + d1 + "' and [SwetTime]<='" + d2 + "'"; if (this.txtPackageGroupName.SelectedValue.ToString() == "门槛条") { strWhere += " and PackageGroupName in('左门槛','右门槛','扰流板')"; } else { strWhere += " and PackageGroupName = '" + this.txtPackageGroupName.SelectedValue.ToString() + "'"; } Entity_t_JIS_Seq5000 t_JIS_Seq5000 = new Entity_t_JIS_Seq5000(); DataSet dsSeq5000 = t_JIS_Seq5000.GetData("distinct PackingListNumber, PartsFamily, supplyGroup, PackageGroupName, (PackingListNumber + ' ' + PartsFamily + ' ' + supplyGroup + ' ' + PackageGroupName + ' ' + PagerNumber + ' ' + CONVERT(varchar(100), min(SwetTime), 20) ) as Name, PagerNumber", strWhere + " group by PackingListNumber, PartsFamily, PackageGroupName, supplyGroup, PagerNumber", "PackingListNumber asc"); this.chkPackingList.DataSource = dsSeq5000.Tables[0]; this.chkPackingList.DisplayMember = "Name"; this.chkPackingList.ValueMember = "PackingListNumber"; this.lblState.Text = "记录:" + dsSeq5000.Tables[0].Rows.Count.ToString(); */ #endregion string strWhere = "IsPrintPackingList=1 and IsPrintASN=0"; if (this.txtPackageGroupName.SelectedValue.ToString() == "门槛条") { strWhere += " and PackageGroupName in('左门槛','右门槛','扰流板')"; } else { strWhere += " and PackageGroupName = '" + this.txtPackageGroupName.SelectedValue.ToString() + "'"; } Entity_t_JIS_Seq5000 t_JIS_Seq5000 = new Entity_t_JIS_Seq5000(); //DataSet dsSeq5000 = t_JIS_Seq5000.GetData("distinct PackingListNumber, PartsFamily, supplyGroup, PackageGroupName, (PackingListNumber + ' ' + PartsFamily + ' ' + supplyGroup + ' ' + PackageGroupName + ' ' + PagerNumber + ' ' + CONVERT(varchar(100), min(SwetTime), 20) ) as Name, PagerNumber", strWhere + " group by PackingListNumber, PartsFamily, PackageGroupName, supplyGroup, PagerNumber", "PackingListNumber asc"); DataSet dsSeq5000 = t_JIS_Seq5000.GetData("distinct PackingListNumber, PartsFamily, supplyGroup, PackageGroupName, (PackingListNumber + ' ' + PackageGroupName + ' ' + PagerNumber + ' ' + CONVERT(varchar(100), min(SwetTime), 20) + ' ' + PartsFamily + ' ' + supplyGroup ) as Name, PagerNumber", strWhere + " group by PackingListNumber, PartsFamily, PackageGroupName, supplyGroup, PagerNumber", "PackingListNumber asc"); this.chkPackingList.DataSource = null; this.chkPackingList.DataSource = dsSeq5000.Tables[0]; this.chkPackingList.DisplayMember = "Name"; this.chkPackingList.ValueMember = "PackingListNumber"; this.lblState.Text = "记录:" + dsSeq5000.Tables[0].Rows.Count.ToString(); } private void btnUpdate_Click(object sender, EventArgs e) { try { UpdateList(); } catch (Exception ex) { MyMessageBox.ShowErrorMessage(ex.Message); } } private void chkAll_CheckedChanged(object sender, EventArgs e) { try { for (int i = 0; i < this.chkPackingList.Items.Count; i++) { this.chkPackingList.SetItemChecked(i, this.chkAll.Checked); } } catch (Exception ex) { MyMessageBox.ShowErrorMessage(ex.Message); } } #region old /* private void IsContinuous(List list, DataTable dtData) { foreach (string supplyGroup in list) { DataRow[] drs = dtData.Select("[supplyGroup]='" + supplyGroup + "'"); if (drs.Length > 1) { int count = drs.Length; int first = Convert.ToInt32(drs[0]["PagerNumber"]); int last = Convert.ToInt32(drs[count - 1]["PagerNumber"]); int jg = last - first; if (jg >= 0) { if (last - first != count-1) { throw new Exception(supplyGroup + " 装箱单页码 " + drs[0]["PagerNumber"].ToString() + " 到 " + drs[drs.Length - 1]["PagerNumber"].ToString() + " 不连续"); } } else { if ((last - first) + 100 != count) { throw new Exception(supplyGroup + " 装箱单页码 " + drs[0]["PagerNumber"].ToString() + " 到 " + drs[drs.Length - 1]["PagerNumber"].ToString() + " 不连续"); } } } } } */ #endregion private void IsContinuous(List list, DataTable dtData) { foreach (string supplyGroup in list) { DataRow[] drs = dtData.Select("[supplyGroup]='" + supplyGroup + "'"); if (drs.Length > 1) { string PackageGroupName = drs[0]["PackageGroupName"].ToString(); int count = drs.Length + 1; //int first = Convert.ToInt32(drs[0]["PagerNumber"]); int first = GetFirstPagerNumber(supplyGroup, PackageGroupName); int last = Convert.ToInt32(drs[count - 2]["PagerNumber"]); int jg = last - first; if (jg >= 0) { if (last - first != count - 1) { throw new Exception(supplyGroup + " 装箱单页码 " + first + " 到 " + last + " 不连续"); } } else { if ((last - first) + 100 != count) { throw new Exception(supplyGroup + " 装箱单页码 " + first + " 到 " + last + " 不连续"); } } } } } private int GetFirstPagerNumber(string supplyGroup, string PackageGroupName) { int ret = 0; Entity_t_JIS_Seq5000 t_JIS_Seq5000 = new Entity_t_JIS_Seq5000(); DataSet dsData = t_JIS_Seq5000.GetData("top 1 PackingListNumber,PagerNumber, SwetTime", "IsPrintPackingList=1 and IsPrintASN=1 and PackageGroupName='" + PackageGroupName + "' and supplyGroup='" + supplyGroup + "'", "SwetTime desc"); if (dsData.Tables[0].Rows.Count > 0) { ret = Convert.ToInt32(dsData.Tables[0].Rows[0]["PagerNumber"]); } return ret; } private void txtPackageGroupName_SelectedIndexChanged(object sender, EventArgs e) { btnUpdate_Click(new object(), new EventArgs()); } private void chkPackingList_ItemCheck(object sender, ItemCheckEventArgs e) { //try //{ // DataRowView drRow = (DataRowView)chkPackingList.Items[e.Index]; // int PagerNumber = Convert.ToInt32(drRow["PagerNumber"]); // for (int i = 0; i < chkPackingList.Items.Count; i++) // { // if (i == e.Index) continue; // int PagerNumberNew = Convert.ToInt32(((DataRowView)chkPackingList.Items[e.Index])["PagerNumber"]); // if (PagerNumber == PagerNumberNew) // { // if (e.NewValue == CheckState.Checked) // { // chkPackingList.SetItemChecked(i, true); // } // else // { // chkPackingList.SetItemChecked(i, false); // } // break; // } // } //} //catch (Exception ex) //{ // MyMessageBox.ShowErrorMessage(ex.Message); //} } private void chkPackingList_MouseClick(object sender, MouseEventArgs e) { } private void chkPackingList_SelectedIndexChanged(object sender, EventArgs e) { try { if (chkPackingList.SelectedIndex >= 0) { int index = chkPackingList.SelectedIndex; bool check = chkPackingList.GetItemChecked(index); DataRowView drRow = (DataRowView)chkPackingList.Items[index]; if (drRow["PackageGroupName"].ToString().IndexOf("门槛") >= 0) { if (drRow["PackageGroupName"].ToString() == "扰流板") return; int PagerNumber = Convert.ToInt32(drRow["PagerNumber"]); for (int i = 0; i < chkPackingList.Items.Count; i++) { if (i == index) continue; int PagerNumberNew = Convert.ToInt32(((DataRowView)chkPackingList.Items[i])["PagerNumber"]); if (PagerNumber == PagerNumberNew) { if (((DataRowView)chkPackingList.Items[i])["PackageGroupName"].ToString() == "扰流板") continue; chkPackingList.SetItemChecked(i, check); //break; } } } else { string plnumber = drRow["PackingListNumber"].ToString(); for (int i = 0; i < chkPackingList.Items.Count; i++) { if (i == index) continue; string plnumberNew = ((DataRowView)chkPackingList.Items[i])["PackingListNumber"].ToString(); if (plnumber == plnumberNew) { chkPackingList.SetItemChecked(i, check); //break; } } } } } catch (Exception ex) { MyMessageBox.ShowErrorMessage(ex.Message); } } } }