/// <summary> /// 保存和更新协定处方信息 /// </summary> private void SaveButtonHandler() { if (this.fsNostrumDetailSheet.Rows.Count == 0) { return; } if (this.IsCanEdit() == false) //不允许进行编辑 { return; } if (MessageBox.Show("请确认已录入的信息是否正确?保存后将不能再进行修改", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } //更新cell值 this.fsNostrumDetail.StopCellEditing(); //{AB3CDE46-C95D-4a6f-96FF-E970F8C84523}防止数量输入过大 if (this.ValidNum() == false) { return; } //用于插入的协定处方列表 List <Neusoft.HISFC.Models.Pharmacy.Nostrum> lstNostrumInsert = new List <Neusoft.HISFC.Models.Pharmacy.Nostrum>(); //用于更新的协定处方列表 List <Neusoft.HISFC.Models.Pharmacy.Nostrum> lstNostrumUpdate = new List <Neusoft.HISFC.Models.Pharmacy.Nostrum>(); //协定处方ID string nostrumID = ""; #region 将协定处方的详细信息列表转化为实体 for (int i = 0, j = this.fsNostrumDetailSheet.Rows.Count; i < j; i++) { Neusoft.HISFC.Models.Pharmacy.Nostrum nostrum = new Neusoft.HISFC.Models.Pharmacy.Nostrum(); nostrum.ID = this.fsNostrumDetailSheet.GetText(i, (int)NostrumDetailColumn.ColID).Trim(); nostrum.Item.ID = this.fsNostrumDetailSheet.GetText(i, (int)NostrumDetailColumn.ColItemID).Trim(); nostrum.Name = this.fsNostrumDetailSheet.GetText(i, (int)NostrumDetailColumn.ColName).Trim().Split('[')[0].ToString(); nostrum.Item.Name = this.fsNostrumDetailSheet.GetText(i, (int)NostrumDetailColumn.ColItemName).Trim(); nostrum.Item.Specs = this.fsNostrumDetailSheet.GetText(i, (int)NostrumDetailColumn.ColName).Trim().Split('[')[1].Split(']')[0].ToString(); nostrum.Qty = NConvert.ToDecimal(this.fsNostrumDetailSheet.GetText(i, (int)NostrumDetailColumn.ColQty).Trim()); nostrum.Item.MinUnit = this.fsNostrumDetailSheet.GetText(i, (int)NostrumDetailColumn.ColUnit).Trim(); nostrum.IsValid = NConvert.ToBoolean(this.fsNostrumDetailSheet.GetText(i, (int)NostrumDetailColumn.ColValid).Trim()); nostrum.SortNO = NConvert.ToInt32(this.fsNostrumDetailSheet.GetText(i, (int)NostrumDetailColumn.ColSortNO)); nostrum.Oper.ID = Neusoft.FrameWork.Management.Connection.Operator.ID; nostrum.Oper.OperTime = itemManager.GetDateTimeFromSysDateTime(); //如果是新插入的列放入插入列表 if (NConvert.ToInt32(this.fsNostrumDetailSheet.GetText(i, (int)NostrumDetailColumn.ColFlug)) == 1) { lstNostrumInsert.Add(nostrum); } //如果是已有的列放入更新列表 else { lstNostrumUpdate.Add(nostrum); } nostrumID = nostrum.ID; } #endregion Neusoft.FrameWork.Management.PublicTrans.BeginTransaction(); itemManager.SetTrans(Neusoft.FrameWork.Management.PublicTrans.Trans); try { //插入新添的数据 for (int i = 0, j = lstNostrumInsert.Count; i < j; i++) { if (itemManager.InsertNostrum(lstNostrumInsert[i]) == -1) { Neusoft.FrameWork.Management.PublicTrans.RollBack(); MessageBox.Show(Neusoft.FrameWork.Management.Language.Msg("保存数据失败") + itemManager.Err); return; } } //更新已有的数据 for (int i = 0, j = lstNostrumUpdate.Count; i < j; i++) { if (itemManager.UpdateNostrum(lstNostrumUpdate[i]) == -1) { Neusoft.FrameWork.Management.PublicTrans.RollBack(); MessageBox.Show(Neusoft.FrameWork.Management.Language.Msg("保存数据失败") + itemManager.Err); return; } } //对新增药品更新价格 if (this.itemManager.UpdateNostrumPrice(nostrumID) == -1) { Neusoft.FrameWork.Management.PublicTrans.RollBack(); MessageBox.Show(Neusoft.FrameWork.Management.Language.Msg("保存数据失败") + this.itemManager.Err); return; } Neusoft.FrameWork.Management.PublicTrans.Commit(); MessageBox.Show(Neusoft.FrameWork.Management.Language.Msg("保存数据成功")); for (int i = 0, j = this.fsDrugListSheet.RowCount; i < j; i++) { this.fsNostrumDetailSheet.SetValue(0, (int)NostrumDetailColumn.ColFlug, 0); } } catch { Neusoft.FrameWork.Management.PublicTrans.RollBack();; MessageBox.Show(Neusoft.FrameWork.Management.Language.Msg("保存数据失败")); } this.tvNostrumList.SelectedNode = this.tvNostrumList.Nodes[0]; }