private void btnSave_Click(object sender, EventArgs e) { int res = 0; foreach (DataGridViewRow dr in dgvUseList.Rows) { ConsumablesUseModel cu = new ConsumablesUseModel(); cu.MzjldId = MzjldId; cu.PatId = PatId; cu.Id = UserFunction.ToInt32(dr.Cells["Id"].Value); cu.Name = Convert.ToString(dr.Cells["Name"].Value); cu.Dosage = UserFunction.ToInt32(dr.Cells["Dosage"].Value); cu.Price = UserFunction.ToDouble(dr.Cells["Price"].Value); cu.Unit = Convert.ToString(dr.Cells["Unit"].Value); cu.IsCost = UserFunction.ToInt32(dr.Cells["IsCost"].Value); res = dal.Update(cu); res += 1; } if (res == 0) { MessageBox.Show("保存失败!"); } else { MessageBox.Show("保存成功!"); BindGridView(); } }
private void BindGridView() { DataTable dt = dal.GetByMzjldId(MzjldId); if (dt.Rows.Count == 0) { DataTable dtCon = dal.GetConsumablesAll(); foreach (DataRow dr in dtCon.Rows) { ConsumablesUseModel cu = new ConsumablesUseModel(); cu.MzjldId = MzjldId; cu.PatId = PatId; cu.Name = Convert.ToString(dr["Name"]); cu.Dosage = 0; cu.Price = UserFunction.ToDouble(dr["Price"]); cu.Unit = Convert.ToString(dr["Unit"]); cu.IsCost = 1; dal.Insert(cu); } dt = dal.GetByMzjldId(MzjldId); this.dgvUseList.DataSource = dt; } else { this.dgvUseList.DataSource = dt; } }