public void InsertSN(SNModel sn) { string insert1 = "insert into SN(PRO_Id,SN,Status,LatestModifyTime,OrderNumber,Model,Line,Description,JobNumber,Reserved4,Reserved3) values ("; string insert2 = " \'" + sn.Pro_Id + "\' ,"; string insert3 = " \'" + sn.SN + "\',\'" + sn.Status + "\',\'" + sn.LatestModifyTime + "\',"; string insert4 = " \'" + sn.OrderNumber + "\',\'" + sn.Model + "\',\'" + sn.Line + "\',\'" + sn.Description + "\',\'" + sn.JobNumber + "\',\'" + sn.Reserved4 + "\',\'" + sn.Reserved3 + "\' )"; string insert = insert1 + insert2 + insert3 + insert4; try { SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["PROTravellerConnectionString"].ConnectionString); myConnection.Open(); SqlCommand MyCommand = new SqlCommand(insert, myConnection); MyCommand.ExecuteNonQuery(); myConnection.Close(); } catch (Exception ex) { } }
private void toolStripMenuItem_Click(object sender, EventArgs e) { int index = dataGridViewExecute.CurrentRow.Index; string id = dataGridViewExecute.Rows[index].Cells[0].Value.ToString(); int totalQuantity = int.Parse(dataGridViewExecute.Rows[index].Cells[4].Value.ToString()); string status = dataGridViewExecute.Rows[index].Cells[6].Value.ToString(); string orderNumber = dataGridViewExecute.Rows[index].Cells[3].Value.ToString(); string model = dataGridViewExecute.Rows[index].Cells[5].Value.ToString(); string line1 = dataGridViewExecute.Rows[index].Cells[1].Value.ToString(); string desc = dataGridViewExecute.Rows[index].Cells[9].Value.ToString(); string belongs = dataGridViewExecute.Rows[index].Cells[7].Value.ToString().Substring(2, 6); if (status.Contains("Not")) // not started { da.Update(id); /* string year = DateTime.Now.Year.ToString(); * string month = DateTime.Now.Month.ToString(); * * switch (month) * * { * case "1": * month = "Jan"; * break; * case "2": * month = "Feb"; * break; * case "3": * month = "Mar"; * break; * case "4": * month = "Apr"; * break; * case "5": * month = "May"; * break; * case "6": * month = "June"; * break; * case "7": * month = "July"; * break; * case "8": * month = "Aug"; * break; * case "9": * month = "Sep"; * break; * case "10": * month = "Oct"; * break; * case "11": * month = "Nov"; * break; * case "12": * month = "Dec"; * break; * default: * month = "Jan"; * break; * } * string yearMonthCode = da.GetYearMonthCode(year, month).ToString();*/ SNModel item = new SNModel(); int a = 0; try { a = int.Parse(orderNumber); } catch (Exception e1) { MessageBox.Show(e1.Message); } for (int i = 0; i < totalQuantity; i++) { string sn = belongs + (a + i).ToString().PadLeft(7, '0'); item.Pro_Id = int.Parse(id); item.SN = sn; item.Status = "Not started"; item.LatestModifyTime = DateTime.Now.ToString(); item.Model = model; item.OrderNumber = orderNumber; item.Line = line1; item.Description = desc; item.JobNumber = desc + orderNumber; item.Reserved4 = totalQuantity; item.Reserved3 = (i + 1).ToString() + "/" + totalQuantity.ToString(); da.InsertSN(item); } string line = comboBoxLine.Text; string pronumber = txtProNumber.Text; string proStatus = comboBoxStutus.Text; DataTable dt = da.GetProDb(line, pronumber, proStatus).Tables[0]; if (dt.Rows.Count != 0) { dataGridViewExecute.DataSource = dt; //dataSet.Tables[0].DefaultView dataGridViewExecute.Height = (dataGridViewExecute.RowCount + 2) * dataGridViewExecute.Columns[0].HeaderCell.Size.Height; dataGridViewExecute.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; dataGridViewExecute.Columns[0].Visible = false; dataGridViewExecute.Visible = true; } MessageBox.Show("SN已生成!"); } if (status.Contains("Completed")) { MessageBox.Show("此工单已全部完成!"); } if (status.Contains("progress")) { MessageBox.Show("此工单正在执行!"); } }