private void SaveData(bool isAdd) { try { string msg = string.Empty; #region bind control data to entity entity.ProductName = this.txtProductName.Text.Trim(); entity.BarCode = this.txtBarCode.Text.Trim().ToUpper(); entity.FactoryName = this.txtFactoryName.Text.Trim(); entity.FactoryNameAbbreviation = this.txtFactoryNameAbbre.Text.Trim(); entity.ProductGeneralName = this.txtGeneralName.Text.Trim(); entity.ProductOtherName = this.txtProductOtherName.Text.Trim(); entity.Code = this.txtCode.Text.Trim(); entity.Description = this.rtbDescription.Text.Trim(); entity.Enabled = this.ckEnable.Checked; entity.LicensePermissionNumber = this.txtLicensePermissionNumber.Text.Trim().ToUpper(); entity.DictionaryMeasurementUnitCode = this.cmbMeasureUnitCode.Text; entity.DictionaryDosageCode = this.cmbDrugDosageCode.Text; entity.DictionarySpecificationCode = this.cmbDrugSpecificationCode.Text; entity.DrugCategoryCode = this.cmbDrugCategoryCode.Text.Trim(); entity.DictionaryUserDefinedTypeCode = this.cmbDictionaryUserDefinedTypeCode.SelectedValue.ToString(); entity.DictionaryPiecemealUnitCode = this.cmbDictionaryPiecemealUnitCode.SelectedValue.ToString(); entity.PiecemealSpecification = this.txtPiecemealSpecification.Text.Trim(); entity.BusinessScopeCode = this.cmbBusinessScopeCode.SelectedValue.ToString(); entity.DrugStorageTypeCode = this.cmbDrugStorageTypeCode.SelectedValue.ToString(); if (this.cmbMedicalCategoryDetailCode.SelectedIndex > -1) { entity.MedicalCategoryDetailCode = this.cmbMedicalCategoryDetailCode.SelectedValue.ToString(); } if (this.cmbDrugClinicalCategoryCode.SelectedIndex > -1) { entity.DrugClinicalCategoryCode = this.cmbDrugClinicalCategoryCode.SelectedValue.ToString(); } if (this.cmbPurchaseManageCategoryDetailCode.SelectedIndex > -1) { entity.PurchaseManageCategoryDetailCode = this.cmbPurchaseManageCategoryDetailCode.SelectedValue.ToString(); } if (this.cmbSpecialDrugCategoryCode.SelectedIndex > -1) { entity.SpecialDrugCategoryCode = this.cmbSpecialDrugCategoryCode.SelectedValue.ToString(); } entity.PiecemealNumber = (int)this.nudPiecemealNumber.Value; entity.Package = this.txtPackage.Text.Trim(); entity.NationalSalePrice = this.nudNationalSalePrice.Value; entity.TagPrice = this.nudTagPrice.Value; entity.PurchasePrice = this.nudPurchasePrice.Value; entity.WholeSalePrice = this.nudWholeSalePrice.Value; entity.RetailPrice = this.nudRetailPrice.Value; entity.LimitedLowPrice = this.nudLimitedLowPrice.Value; entity.LimitedUpPrice = this.nudLimitedUpPrice.Value; entity.LowSalePrice = this.nudLowSalePrice.Value; entity.Price = this.nudPrice.Value; entity.SalePrice = this.nudPrice.Value; //弃用? //entity.IsMainMaintenance = this.chkIsMainMaintenance.Checked; entity.IsMedicalInsurance = this.chkIsMedicalInsurance.Checked; entity.IsPrescription = this.chkIsPrescription.Checked; entity.IsImport = this.chkIsImport.Checked; entity.StandardCode = this.txtStandardCode.Text; entity.MinInventoryCount = (int)this.nudMinInventory.Value; entity.MaxInventoryCount = (int)this.nudMaxInventory.Value; #endregion if (isAdd) { entity.Id = Guid.NewGuid(); entity.CreateTime = DateTime.Now; entity.CreateUserId = AppClientContext.CurrentUser.Id; entity.IsApproval = false; //entity.ApprovalDate = DateTime.Parse(string.Empty); //?? PharmacyDatabaseService.AddDrugInfo(out msg, entity); #region insert to InventoryRecord table InventoryRecord record = new InventoryRecord(); record.Id = Guid.NewGuid(); record.DrugInfoId = entity.Id; record.MaxInventoryCount = (int)this.nudMaxInventory.Value; record.MinInventoryCount = (int)this.nudMinInventory.Value; PharmacyDatabaseService.AddInventoryRecord(out msg, record); #endregion } else { entity.IsApproval = false; entity.UpdateTime = DateTime.Now; entity.UpdateUserId = AppClientContext.CurrentUser.Id; PharmacyDatabaseService.SaveDrugInfo(out msg, entity); #region update InventoryRecord table InventoryRecord record = PharmacyDatabaseService.GetInventoryRecordByDrugInfoID(out msg, entity.Id); record.MaxInventoryCount = (int)this.nudMaxInventory.Value; record.MinInventoryCount = (int)this.nudMinInventory.Value; PharmacyDatabaseService.SaveInventoryRecord(out msg, record); #endregion } if (string.IsNullOrEmpty(msg)) { MessageBox.Show("数据保存成功!"); } } catch (Exception ex) { Log.Error(ex); MessageBox.Show("数据保存失败!", "系统错误", MessageBoxButtons.OK); } }