private void btnSave_Click(object sender, EventArgs e) { if (btnAddNew.Enabled == true && (dgvTemplate.Rows.Count == 0 || dgvTemplate.CurrentCell == null)) { MessageBox.Show("没有选择模板,如果要新建模板,请点击新增后录入模板信息。", "", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { cboType.SelectedIndexChanged -= new EventHandler(cboType_SelectedIndexChanged); ServiceItemController itemController = new ServiceItemController( ); TemplateItem temp = new TemplateItem( ); temp.Py_Code = txtPyCode.Text; temp.Wb_Code = txtWbCode.Text; temp.Tmplate_Name = txtTemplateName.Text.Trim( ); if (txtExecDept.MemberValue != null) { temp.Exec_Dept_Id = Convert.ToInt32(txtExecDept.MemberValue); temp.Exce_Dept_Name = txtExecDept.Text; } else { temp.Exec_Dept_Id = 0; temp.Exce_Dept_Name = ""; } temp.Valid_Flag = chkValid.Checked ? 1 : 0; //明细 temp.Details = new List <TemplateDetailItem>( ); for (int i = 0; i < dgvDetail.Rows.Count; i++) { if (dgvDetail["ITEM_ID", i].Value != null && dgvDetail["ITEM_ID", i].Value.ToString( ) != "" && dgvDetail["ITEM_NAME", i].Value.ToString( ).Trim( ) != "") { TemplateDetailItem detail = new TemplateDetailItem( ); detail.BIGITEMCODE = dgvDetail["BIGITEMCODE", i].Value.ToString( ).Trim( ); detail.COMPLEX_ID = Convert.ToInt32(dgvDetail["COMPLEX_ID", i].Value); detail.DAYS = Convert.ToInt32(dgvDetail["DAYS", i].Value); detail.DOSAGE = Convert.ToDecimal(dgvDetail["DOSAGE", i].Value); detail.FREQUEN_ID = Convert.ToInt32(dgvDetail["FREQUEN_ID", i].Value); detail.FREQUEN_NAME = dgvDetail["FREQUEN_NAME", i].Value.ToString( ).Trim( ); detail.GROUP_FLAG = Convert.ToInt32(dgvDetail["GROUP_FLAG", i].Value); detail.ITEM_ID = Convert.ToInt32(dgvDetail["ITEM_ID", i].Value); detail.ITEM_NAME = dgvDetail["ITEM_NAME", i].Value.ToString( ).Trim( ); detail.SORT_NO = i; detail.STANDARD = dgvDetail["STANDARD", i].Value.ToString( ).Trim( ); detail.TEMPLATE_ID = Convert.ToInt32(dgvDetail["TEMPLATE_ID", i].Value); detail.UNIT = dgvDetail["UNIT", i].Value.ToString( ).Trim( ); detail.USAGE_NAME = dgvDetail["USAGE_NAME", i].Value.ToString( ).Trim( ); detail.AMOUNT = Convert.ToInt32(dgvDetail["AMOUNT", i].Value); temp.Details.Add(detail); } } if (btnAddNew.Enabled == false) { //新增 temp.Create_Date = HIS.SYSTEM.PubicBaseClasses.XcDate.ServerDateTime; temp.Creator_Id = Convert.ToInt32(_currentUser.EmployeeID); temp.Creator_Name = _currentUser.Name; temp.Dept_Id = Convert.ToInt32(_currentDept.DeptID); temp.Dept_Name = _currentDept.Name; temp.Share_Level = 0; //全院共享 temp.Tmplate_Type = cboType.SelectedIndex; itemController.AddTemplateItem(temp); LoadData(false, true, true); } else { //更新 temp.Tmplate_Id = Convert.ToInt32(dgvTemplate["TMPLATE_ID", dgvTemplate.CurrentCell.RowIndex].Value); itemController.UpdateTemplateItem(temp); LoadData(false, true, true); dgvTemplate.CurrentCell = null; } btnAddNew.Enabled = true; } catch (Exception err) { MessageBox.Show(err.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { cboType.SelectedIndexChanged += new EventHandler(cboType_SelectedIndexChanged); } }