private void toolStripButton1_Click(object sender, EventArgs e) { this.dataGridView1.CurrentCell = null; if (this.dataGridView1.RowCount == 0) { MessageBox.Show("请添加子级!"); return; } else if (id == -1) { MessageBox.Show("请添加父级!"); return; } int quantity = Convert.ToInt32(numberbox11.TextNumber); if (quantity <= 0) { MessageBox.Show("父级数量大于0!"); return; } BOMMainModel obj = new BOMMainModel(); if (comboBox1.Text == "否") { obj.jump = false; } else { obj.jump = true; } obj.id = id; obj.materiel = materiel; obj.quantity = quantity; obj.list = new List <BOMDetailModel>(); for (int i = this.dataGridView1.RowCount; i > 0; i--) { BOMDetailModel lm = new BOMDetailModel(); lm.materiel = Convert.ToInt32(this.dataGridView1.Rows[i - 1].Cells["id"].Value); lm.quantity = Convert.ToDouble(this.dataGridView1.Rows[i - 1].Cells["dtlquantity"].Value); if (this.dataGridView1.Rows[i - 1].Cells["remark"].Value != null) { lm.remark = this.dataGridView1.Rows[i - 1].Cells["remark"].Value.ToString(); } if (lm.quantity == 0) { MessageBox.Show("子级数量大于0!"); return; } obj.list.Add(lm); } var msg = ctrl.set(obj); MessageBox.Show(msg.Msg); }
private void toolStripButton3_Click(object sender, EventArgs e) { this.dataGridView1.CurrentCell = null; if (this.dataGridView1.RowCount == 0) { MessageBox.Show("请添加子级!"); return; } else if (id == -1) { MessageBox.Show("请添加父级!"); return; } int quantity = Convert.ToInt32(numberbox11.TextNumber); if (quantity <= 0) { MessageBox.Show("父级数量大于0!"); return; } BOMMainModel obj = new BOMMainModel(); if (comboBox1.Text == "否") { obj.jump = false; } else { obj.jump = true; } obj.materiel = id; obj.quantity = quantity; obj.isActive = checkBox1.Checked; obj.list = new List <BOMDetailModel>(); for (int i = this.dataGridView1.RowCount; i > 0; i--) { BOMDetailModel lm = new BOMDetailModel(); lm.materiel = Convert.ToInt32(this.dataGridView1.Rows[i - 1].Cells["id"].Value); lm.quantity = Convert.ToDouble(this.dataGridView1.Rows[i - 1].Cells["quantity"].Value); if (this.dataGridView1.Rows[i - 1].Cells["summary"].Value != null) { lm.remark = this.dataGridView1.Rows[i - 1].Cells["summary"].Value.ToString(); } if (lm.quantity == 0) { MessageBox.Show("子级数量大于0!"); return; } obj.list.Add(lm); } var msg = ctrl.add(obj); if (msg.Code == 0) { MessageBox.Show(msg.Msg); toolStripButton1.Enabled = false; toolStripButton2.Enabled = false; toolStripButton3.Enabled = false; dataGridView1.Enabled = false; DataTable dt = ctrl.getlastinsert(id); textBox5.Text = dt.Rows[0]["num"].ToString(); } else { MessageBox.Show(msg.Msg); } }