public void add(int i) { string id = ""; string bname = ""; string name = ""; string color = ""; string size = ""; string material = ""; string clean = ""; string madeby = ""; string season = ""; string remark = ""; /** * 将表中的数据赋值给以上定义的变量; * */ id = this.dataGridView1.Rows[i].Cells[0].Value.ToString(); bname = this.dataGridView1.Rows[i].Cells[1].Value.ToString(); name = this.dataGridView1.Rows[i].Cells[2].Value.ToString(); color = this.dataGridView1.Rows[i].Cells[3].Value.ToString(); size = this.dataGridView1.Rows[i].Cells[4].Value.ToString(); material = this.dataGridView1.Rows[i].Cells[5].Value.ToString(); clean = this.dataGridView1.Rows[i].Cells[6].Value.ToString(); madeby = this.dataGridView1.Rows[i].Cells[7].Value.ToString(); season = this.dataGridView1.Rows[i].Cells[8].Value.ToString(); remark = this.dataGridView1.Rows[i].Cells[9].Value.ToString(); DBCL2.Goods model = new DBCL2.Goods(); model.Goods_ID = id; model.Brand_Name = bname; model.Goods_Name = name; model.Goods_Colour = color; model.Goods_Size = size; model.Goods_Material = material; model.Goods_Clean = clean; model.Goods_MadeBy = madeby; model.Goods_Season = season; model.Goods_ramarks = remark; try { db.Goods.Add(model); db.SaveChanges(); } catch { MessageBox.Show("添加失败!"); return; } MessageBox.Show("添加成功!"); }
private void buttonX1_Click(object sender, EventArgs e) { string strID = ""; string strBName = ""; string strName = ""; string strColour = ""; string strSize = ""; string strMaterial = ""; string strClean = ""; string strSeason = ""; string strMadeBy = ""; string strRemark = ""; if (textBoxX1.Text.Trim() == "") { MessageBox.Show("商品编号不能为空!"); textBoxX1.Focus(); return; } if (db.Goods.Any(m => m.Goods_ID == textBoxX1.Text.Trim()) == true) { MessageBox.Show("商品编号重复!"); textBoxX1.Focus(); return; } strID = textBoxX1.Text.Trim(); strBName = comboBox2.SelectedValue.ToString(); strName = textBoxX3.Text.Trim(); strColour = textBoxX4.Text.Trim(); strSize = comboBox3.SelectedValue.ToString(); strMaterial = textBoxX6.Text.Trim(); strClean = textBoxX7.Text.Trim(); strSeason = comboBox4.SelectedValue.ToString(); strMadeBy = textBoxX8.Text.Trim(); //MessageBox.Show(comboBoxEx1.SelectedItem.ToString()); strRemark = textBoxX9.Text.Trim(); DBCL2.Goods model = new DBCL2.Goods(); model.Goods_ID = strID; model.Goods_Name = strName; model.Brand_Name = strBName; model.Goods_Colour = strColour; model.Goods_Size = strSize; model.Goods_Material = strMaterial; model.Goods_Clean = strClean; model.Goods_Season = strSeason; model.Goods_MadeBy = strMadeBy; model.Goods_ramarks = strRemark; model.Goods_Sum_Number = "0"; model.Goods_danjia = "0"; try { db.Goods.Add(model); db.SaveChanges(); } catch { MessageBox.Show("添加失败!"); return; } MessageBox.Show("添加成功!"); }
private void buttonX1_Click(object sender, EventArgs e) { string Document_ID = ""; string good_id1 = ""; string good_danjia1 = ""; string good_number1 = ""; string good_id2 = ""; string good_danjia2 = ""; string good_number2 = ""; string good_id3 = ""; string good_danjia3 = ""; string good_number3 = ""; string good_id4 = ""; string good_danjia4 = ""; string good_number4 = ""; string good_id5 = ""; string good_danjia5 = ""; string good_number5 = ""; string good_id6 = ""; string good_danjia6 = ""; string good_number6 = ""; string due = ""; string Real_payment = ""; string client_ID = ""; string worker_ID = ""; string account = ""; string sell_Rrmarks = ""; ///** // * 将表中的数据赋值给以上定义的变量; // * */ int b = this.dataGridViewX2.RowCount; Document_ID = this.textBoxX1.Text; for (int i = 0; i < b - 1; i++) { if (i == 0) { good_id1 = this.dataGridViewX2.Rows[i].Cells[1].Value.ToString(); good_danjia1 = this.dataGridViewX2.Rows[i].Cells[3].Value.ToString(); good_number1 = this.dataGridViewX2.Rows[i].Cells[2].Value.ToString(); } if (i == 1) { good_id2 = this.dataGridViewX2.Rows[i].Cells[1].Value.ToString(); good_danjia2 = this.dataGridViewX2.Rows[i].Cells[3].Value.ToString(); good_number2 = this.dataGridViewX2.Rows[i].Cells[2].Value.ToString(); } if (i == 2) { good_id3 = this.dataGridViewX2.Rows[i].Cells[1].Value.ToString(); good_danjia3 = this.dataGridViewX2.Rows[i].Cells[3].Value.ToString(); good_number3 = this.dataGridViewX2.Rows[i].Cells[2].Value.ToString(); } if (i == 3) { good_id4 = this.dataGridViewX2.Rows[i].Cells[1].Value.ToString(); good_danjia4 = this.dataGridViewX2.Rows[i].Cells[3].Value.ToString(); good_number4 = this.dataGridViewX2.Rows[i].Cells[2].Value.ToString(); } if (i == 4) { good_id5 = this.dataGridViewX2.Rows[i].Cells[1].Value.ToString(); good_danjia5 = this.dataGridViewX2.Rows[i].Cells[3].Value.ToString(); good_number5 = this.dataGridViewX2.Rows[i].Cells[2].Value.ToString(); } if (i == 5) { good_id6 = this.dataGridViewX2.Rows[i].Cells[1].Value.ToString(); good_danjia6 = this.dataGridViewX2.Rows[i].Cells[3].Value.ToString(); good_number6 = this.dataGridViewX2.Rows[i].Cells[2].Value.ToString(); } } textBoxX2.Text = textBoxX3.Text; due = textBoxX2.Text; Real_payment = textBoxX4.Text; client_ID = textBoxX5.Text; worker_ID = textBoxX6.Text; account = textBoxX7.Text; sell_Rrmarks = textBoxX8.Text; DBCL2.sell model = new DBCL2.sell(); model.Document_ID = Document_ID; model.Goods_ID1 = good_id1; model.Goods_ID2 = good_id2; model.Goods_ID3 = good_id3; model.Goods_ID4 = good_id4; model.Goods_ID5 = good_id5; model.Goods_ID6 = good_id6; model.Goods_danjia1 = good_danjia1; model.Goods_danjia2 = good_danjia2; model.Goods_danjia3 = good_danjia3; model.Goods_danjia4 = good_danjia4; model.Goods_danjia5 = good_danjia5; model.Goods_danjia6 = good_danjia6; model.Goods_Number1 = good_number1; model.Goods_Number2 = good_number2; model.Goods_Number3 = good_number3; model.Goods_Number4 = good_number4; model.Goods_Number5 = good_number5; model.Goods_Number6 = good_number6; model.Due = due; model.Real_Payment = Real_payment; model.Worker_ID = worker_ID; model.Client_ID = client_ID; model.Account = account; model.Sell_Remarks = sell_Rrmarks; try { db.sell.Add(model); db.SaveChanges(); } catch { MessageBox.Show("添加失败!"); return; } MessageBox.Show("添加成功!"); DBCL2.Goods model1 = new DBCL2.Goods(); var model2 = db.Goods.FirstOrDefault(m => m.Goods_ID == good_id1); if (model2 == null) { return; } else { int m = Convert.ToInt32(model2.Goods_Sum_Number); model2.Goods_Sum_Number = (m + Convert.ToInt32(good_number1)).ToString(); try { db.SaveChanges(); } catch { MessageBox.Show("更新失败!"); return; } MessageBox.Show("更新成功!"); this.Close(); } var model3 = db.Goods.FirstOrDefault(m => m.Goods_ID == good_id2); if (model3 == null) { return; } else { int m = Convert.ToInt32(model3.Goods_Sum_Number); model3.Goods_Sum_Number = (m + Convert.ToInt32(good_number2)).ToString(); try { db.SaveChanges(); } catch { MessageBox.Show("更新失败!"); return; } MessageBox.Show("更新成功!"); this.Close(); } var model4 = db.Goods.FirstOrDefault(m => m.Goods_ID == good_id3); if (model4 == null) { return; } else { int m = Convert.ToInt32(model4.Goods_Sum_Number); model4.Goods_Sum_Number = (m + Convert.ToInt32(good_number3)).ToString(); try { db.SaveChanges(); } catch { MessageBox.Show("更新失败!"); return; } MessageBox.Show("更新成功!"); this.Close(); } var model5 = db.Goods.FirstOrDefault(m => m.Goods_ID == good_id4); if (model5 == null) { return; } else { int m = Convert.ToInt32(model5.Goods_Sum_Number); model5.Goods_Sum_Number = (m + Convert.ToInt32(good_number4)).ToString(); try { db.SaveChanges(); } catch { MessageBox.Show("更新失败!"); return; } MessageBox.Show("更新成功!"); this.Close(); } var model6 = db.Goods.FirstOrDefault(m => m.Goods_ID == good_id5); if (model6 == null) { return; } else { int m = Convert.ToInt32(model6.Goods_Sum_Number); model6.Goods_Sum_Number = (m + Convert.ToInt32(good_number5)).ToString(); try { db.SaveChanges(); } catch { MessageBox.Show("更新失败!"); return; } MessageBox.Show("更新成功!"); this.Close(); } var model7 = db.Goods.FirstOrDefault(m => m.Goods_ID == good_id6); if (model7 == null) { return; } else { int m = Convert.ToInt32(model7.Goods_Sum_Number); model7.Goods_Sum_Number = (m + Convert.ToInt32(good_number6)).ToString(); try { db.SaveChanges(); } catch { MessageBox.Show("更新失败!"); return; } MessageBox.Show("更新成功!"); this.Close(); } }