private bool testLinServer() { string txtip = txtIP.Text.Trim(); btnlinkserver.Enabled = false; btnlinkDB.Enabled = false; cbdbname.Enabled = false; txtdbuser.Enabled = false; txtdbpwd.Enabled = false; if (testl.LinServer(txtip)) { btnlinkDB.Enabled = true; btnlinkserver.Enabled = true; cbdbname.Enabled = true; txtdbuser.Enabled = true; txtdbpwd.Enabled = true; LabelTestLinServer.BackColor = Color.Lime; LabelTestLinServer.Text = "连接服务器" + txtip + "成功!"; return(true); } else { for (int i = 1; i <= 5; i++) { if (!testl.LinServer(txtip)) { LabelTestLinServer.BackColor = Color.Red; LabelTestLinServer.Text = "服务器连接失败!正在尝试重新连接,第 " + i.ToString() + " 次..."; } else { btnlinkDB.Enabled = true; cbdbname.Enabled = true; txtdbuser.Enabled = true; txtdbpwd.Enabled = true; LabelTestLinServer.BackColor = Color.Lime; LabelTestLinServer.Text = "服务器已连接!"; break; } } if (!testl.LinServer(txtip)) { LabelTestLinServer.BackColor = Color.Red; LabelTestLinServer.Text = "服务器连接失败!请检查网络连接!"; // btnlinkDB.Enabled = false; btnlinkserver.Enabled = true; // btnlinkDB.Visible = true; return(false); } return(true); } }
public void getByMyno() { Cursor = Cursors.WaitCursor; this.isbusy = true; this.btSearch.Enabled = false; string my_no = this.txtMyNumber.Text.Trim(); string my_style = this.txtStyle.Text.Trim(); bool onlyStyle = false; if (my_no.Length <= 0 && my_style.Length <= 0) { Cursor = Cursors.Default; this.isbusy = false; this.btSearch.Enabled = true; return; } this.txtLogs.Text = ""; this.txtLogs.Visible = false; TestLinManager tl = new TestLinManager(); string serverIP = "192.168.0.254"; string linkServer = ""; bool LinkSuccess = false; bool testlink = tl.LinServer(serverIP); if (testlink) { linkServer = "BESTconnStr"; //BESTconnStr_KM LinkSuccess = true; } if (!LinkSuccess) { serverIP = "192.168.4.122"; testlink = tl.LinServer(serverIP); if (testlink) { linkServer = "BESTconnStr_KM"; LinkSuccess = true; } } if (!LinkSuccess) { MessageBox.Show("连接服务器 " + serverIP + "失败!请找IT确认网络服务是否OK", "失败", MessageBoxButtons.OK, MessageBoxIcon.Error); Cursor = Cursors.Default; this.isbusy = false; this.btSearch.Enabled = true; return; } if (my_no.Length <= 0) { my_no = null; } if (my_style.Length <= 0) { my_style = null; } if (my_no == null && my_style != null) { this.gbPO.Visible = false; onlyStyle = true; this.gbSize.Height = this.Height - 150; } else { this.gbPO.Visible = true; onlyStyle = false; this.gbSize.Height = this.Height - this.gbPO.Height - 150; } string[] parameters = { my_no, my_style }; // 查询色组 DataTable clr_dt = sizem.getClr_noByMy_no(parameters, linkServer); if (clr_dt.Rows.Count <= 0) { this.txtLogs.Visible = true; this.ckLogs.Checked = true; this.txtLogs.AppendText("没有色组数据,请确认自编单号或款式是否正确 \r\n"); // MessageBox.Show("没有色组数据,请确认自编单号或款式是否正确"); Cursor = Cursors.Default; this.isbusy = false; this.btSearch.Enabled = true; return; } // 查询size组 string my_nos = ""; foreach (DataRow dr in clr_dt.Rows) { my_nos = my_nos + "'" + dr["my_no"].ToString() + "\',"; } my_nos = my_nos.Substring(0, my_nos.Length - 1); DataTable size_dt = sizem.getSizeByMy_no(my_nos, linkServer); if (size_dt.Rows.Count <= 0) { this.txtLogs.Visible = true; this.ckLogs.Checked = true; this.txtLogs.AppendText("没有size组数据,请确认自编单或款式号是否正确 \r\n"); // MessageBox.Show("没有size组数据,请确认自编单或款式号是否正确"); Cursor = Cursors.Default; this.isbusy = false; this.btSearch.Enabled = true; return; } DataTable sizeRunDT = new DataTable(); List <string> sizes = new List <string>(); for (int z = 0; z < size_dt.Rows.Count; z++) { for (int i = 1; i < size_dt.Columns.Count; i++) { sizes.Add(size_dt.Rows[z][i].ToString()); //sizeRunDT.Columns.Add(size_dt.Rows[z][i].ToString()); } } sizes = sizes.Distinct().ToList(); for (int i = 0; i < sizes.Count; i++) { if (sizes[i] == "") { sizes.RemoveAt(i); i--; } } foreach (string s in sizes) { sizeRunDT.Columns.Add(s); } sizeRunDT.Columns.Add("my_no"); sizeRunDT.Columns["my_no"].SetOrdinal(0); sizeRunDT.Columns.Add("style_id"); sizeRunDT.Columns["style_id"].SetOrdinal(1); sizeRunDT.Columns.Add("cust_id"); sizeRunDT.Columns["cust_id"].SetOrdinal(2); sizeRunDT.Columns.Add("clr_no"); sizeRunDT.Columns["clr_no"].SetOrdinal(3); // 生成表SizeRun框架 for (int i = 0; i < clr_dt.Rows.Count; i++) { DataRow dr = sizeRunDT.NewRow();//定义一个新行 dr["clr_no"] = clr_dt.Rows[i]["clr_no"].ToString(); dr["style_id"] = clr_dt.Rows[i]["style_id"].ToString(); dr["my_no"] = clr_dt.Rows[i]["my_no"].ToString(); dr["cust_id"] = clr_dt.Rows[i]["cust_id"].ToString(); sizeRunDT.Rows.Add(dr); } // 生成表框架 for (int z = 0; z < size_dt.Rows.Count; z++) { //查询sizeRun数量 DataTable sizeRunCount_dt = sizem.getSizeRunByMy_no(size_dt.Rows[z]["my_no"].ToString(), linkServer); if (sizeRunCount_dt.Rows.Count <= 0) { this.txtLogs.Visible = true; this.ckLogs.Checked = true; this.txtLogs.AppendText(" 没有 " + size_dt.Rows[z]["my_no"].ToString() + " 的 sizeRun 数据,请确认自编单号是否正确...\r\n"); // MessageBox.Show("没有 " + size_dt.Rows[z]["my_no"].ToString()+" 的sizeRun数量数据,请确认自编单号是否正确"); // Cursor = Cursors.Default; // this.isbusy = false; // this.btSearch.Enabled = true; // return; continue; } // 填入数量 string clr_Size = ""; // 这行的色组的SIZE for (int i = 0; i < sizeRunDT.Rows.Count; i++) { for (int j = 0; j < sizeRunCount_dt.Rows.Count; j++) { if (sizeRunCount_dt.Rows[j]["my_no"].ToString() == sizeRunDT.Rows[i]["my_no"].ToString()) { if (sizeRunCount_dt.Rows[j]["clr_no"].ToString() == sizeRunDT.Rows[i]["clr_no"].ToString()) { if (sizeRunCount_dt.Rows[j]["clr_no"].ToString() == sizeRunDT.Rows[i]["clr_no"].ToString()) { clr_Size = sizeRunCount_dt.Rows[j]["size_code"].ToString(); for (int k = 0; k < sizeRunDT.Columns.Count; k++) { if (clr_Size == sizeRunDT.Columns[k].ColumnName.ToString()) { sizeRunDT.Rows[i][k] = Convert.ToDouble(sizeRunCount_dt.Rows[j]["qty"].ToString()).ToString(); } } } } } } } // DataTable alldt = new DataTable(); // alldt.Rows } //添加一列合计 sizeRunDT.Columns.Add("count"); // 添加一行合计 DataRow countdr = sizeRunDT.NewRow(); //定义一个新行 countdr["my_no"] = "Count"; sizeRunDT.Rows.Add(countdr); // 计算行合计 string rowCountstr = ""; for (int i = 0; i < sizeRunDT.Rows.Count - 1; i++) { double rowCount = 0; for (int j = 4; j < sizeRunDT.Columns.Count - 1; j++) { rowCountstr = sizeRunDT.Rows[i][j].ToString(); if (rowCountstr.Length > 0) { rowCount = rowCount + Convert.ToDouble(rowCountstr); } sizeRunDT.Rows[i][sizeRunDT.Columns.Count - 1] = rowCount.ToString(); } } // 计算列合计 rowCountstr = ""; for (int i = 4; i < sizeRunDT.Columns.Count; i++) { double rowCount = 0; for (int j = 0; j < sizeRunDT.Rows.Count - 1; j++) { rowCountstr = sizeRunDT.Rows[j][i].ToString(); if (rowCountstr.Length > 0) { rowCount = rowCount + Convert.ToDouble(rowCountstr); } } sizeRunDT.Rows[sizeRunDT.Rows.Count - 1][i] = rowCount.ToString(); } this.dgvSizeRun.DataSource = sizeRunDT; // 禁用排序 for (int i = 0; i < this.dgvSizeRun.Columns.Count; i++) { this.dgvSizeRun.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable; } if (!onlyStyle) { //所有原始资料 DataTable allSizerun = sizem.getAllSizeRunByMy_no(my_no, linkServer); if (allSizerun.Rows.Count <= 0) { this.txtLogs.Visible = true; this.ckLogs.Checked = true; this.txtLogs.AppendText("没有详细数据,请确认自编单号是否正确 \r\n"); // MessageBox.Show("没有详细数据,请确认自编单号是否正确"); Cursor = Cursors.Default; this.isbusy = false; this.btSearch.Enabled = true; return; } this.dgvSizeRunAll.DataSource = allSizerun; } Cursor = Cursors.Default; this.btSearch.Enabled = true; this.isbusy = false; }