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);
            }
        }
Exemple #2
0
        ///导入数据库
        private void Import()
        {
            string result;

            int i = 0;

            foreach (DataRow reader in dtDrug.Rows)
            {
                try
                {
                    if (reader["药品本位码"].ToString().Trim().Length != 14)
                    {
                        dtState.Rows.Add(i, "导入失败", "失败原因:'药品本位码'必须为14位");
                        continue;
                    }

                    DrugInfo info = new DrugInfo();
                    info.Id                      = Guid.NewGuid();
                    info.Code                    = reader["编码"].ToString();
                    info.Description             = reader["描述"].ToString();
                    info.BarCode                 = reader["条形码"].ToString();
                    info.StandardCode            = reader["药品本位码"].ToString();
                    info.ProductName             = reader["药品名称"].ToString();
                    info.ProductGeneralName      = reader["药品通用名"].ToString();
                    info.ProductOtherName        = reader["药品其他名称"].ToString();
                    info.FactoryName             = reader["厂家全称"].ToString();
                    info.FactoryNameAbbreviation = reader["厂家简称"].ToString();
                    info.PiecemealSpecification  = reader["拆零规格"].ToString();
                    info.PiecemealNumber         = Convert.ToInt32(ConvertToDecimal(reader["拆零数量"]));
                    info.Price                   = ConvertToDecimal(reader["价格"]);
                    info.NationalSalePrice       = ConvertToDecimal(reader["国家零售价"]);
                    info.PurchasePrice           = ConvertToDecimal(reader["采购价"]);
                    info.SalePrice               = ConvertToDecimal(reader["销售价"]);
                    info.WholeSalePrice          = ConvertToDecimal(reader["批发价"]);
                    info.RetailPrice             = ConvertToDecimal(reader["零售价"]);
                    info.TagPrice                = ConvertToDecimal(reader["挂价"]);
                    info.LowSalePrice            = ConvertToDecimal(reader["最低售价"]);
                    info.LimitedLowPrice         = ConvertToDecimal(reader["最低限价"]);
                    info.LimitedUpPrice          = ConvertToDecimal(reader["最高限价"]);

                    info.IsMedicalInsurance    = Convert.ToBoolean(reader["是否医保"]);
                    info.IsPrescription        = Convert.ToBoolean(reader["是否处方药"]);
                    info.IsImport              = Convert.ToBoolean(reader["是否进口药"]);
                    info.IsMainMaintenance     = Convert.ToBoolean(reader["是否重点养护"]);
                    info.IsSpecialDrugCategory = Convert.ToBoolean(reader["是否特殊管理药品"]);

                    info.SpecialDrugCategoryCode = reader["特殊管理药品类型"].ToString();
                    info.ValidPeriod             = Convert.ToInt32(ConvertToDecimal(reader["有效期"]));
                    info.LicensePermissionNumber = reader["批准文号"].ToString();
                    info.PerformanceStandards    = reader["执行标准"].ToString();
                    info.Package      = reader["包装"].ToString();
                    info.IsApproval   = true;
                    info.ApprovalDate = Convert.ToDateTime(reader["审批日期"]);

                    info.CreateTime   = DateTime.Now;
                    info.CreateUserId = Guid.Empty;

                    info.BusinessScopeCode = reader["经营范围"].ToString();
                    info.PurchaseManageCategoryDetailCode = reader["药品管理分类详细"].ToString();
                    info.DrugCategoryCode              = reader["药品分类"].ToString();
                    info.MedicalCategoryDetailCode     = reader["医疗详细分类"].ToString();
                    info.DrugClinicalCategoryCode      = reader["临床分类"].ToString();
                    info.DictionaryUserDefinedTypeCode = reader["自定义类型"].ToString();
                    info.DrugStorageTypeCode           = reader["存储方式"].ToString();
                    info.DictionaryMeasurementUnitCode = reader["药品单位"].ToString();
                    info.DictionaryDosageCode          = reader["剂型"].ToString();
                    info.DictionarySpecificationCode   = reader["规格"].ToString();
                    info.DictionaryPiecemealUnitCode   = reader["拆零单位"].ToString();

                    try
                    {
                        if (!PharmacyDatabaseService.IsExistDrugInfo(out result, info))
                        {
                            dtState.Rows.Add(i, "导入失败", "失败原因:" + result);
                        }
                        else
                        {
                            PharmacyDatabaseService.AddDrugInfo(out result, info);
                            dtState.Rows.Add(i, "导入成功", result);
                        }
                    }
                    catch (Exception e)
                    {
                        dtState.Rows.Add(i, "导入失败", "失败原因:" + e.Message);
                    }
                }
                catch (Exception ex)
                {
                    dtState.Rows.Add(i, "导入失败", "失败原因:" + ex.Message);
                }
                finally
                {
                    progressValue++;
                    i++;
                }
            }
        }