Ejemplo n.º 1
0
        ///导入数据库
        private void Import()
        {
            string result;

            int i = 0;

            foreach (DataRow reader in datatable.Rows)
            {
                try
                {
                    if (reader["传真"].ToString().Trim().Length == 0)
                    {
                        dtState.Rows.Add(i, "导入失败", "失败原因:'传真'不能为空");
                        continue;
                    }
                    if (reader["邮箱"].ToString().Trim().Length == 0)
                    {
                        dtState.Rows.Add(i, "导入失败", "失败原因:'邮箱'不能为空");
                        continue;
                    }
                    if (reader["网站"].ToString().Trim().Length == 0)
                    {
                        dtState.Rows.Add(i, "导入失败", "失败原因:'网站'不能为空");
                        continue;
                    }
                    if (reader["区域"].ToString().Trim().Length == 0)
                    {
                        dtState.Rows.Add(i, "导入失败", "失败原因:'区域'不能为空");
                        continue;
                    }
                    Guid     DistrictId;
                    District district = PharmacyDatabaseService.QueryDistricts(out result, reader["区域"].ToString(), null, null, true, true).FirstOrDefault();
                    if (district != null)
                    {
                        DistrictId = district.Id;
                    }
                    else
                    {
                        dtState.Rows.Add(i, "导入失败", "失败原因:区域'" + reader["区域"].ToString() + "'不存在");
                        continue;
                    }


                    PurchaseUnit info;
                    bool         IsExist = PharmacyDatabaseService.IsExistPurchaseUnitByName(out result, reader["单位名称"].ToString());
                    //更新
                    if (IsExist)
                    {
                        info = PharmacyDatabaseService.GetPurchaseUnitByName(out result, reader["单位名称"].ToString());
                    }
                    else //新增
                    {
                        info              = new PurchaseUnit();
                        info.CreateTime   = DateTime.Now;
                        info.CreateUserId = Guid.Empty;
                        info.Enabled      = true;
                        info.Name         = reader["单位名称"].ToString();
                    }

                    info.Id            = Guid.NewGuid();
                    info.DistrictId    = DistrictId;
                    info.Code          = reader["唯一编码"].ToString();
                    info.PinyinCode    = reader["拼音码"].ToString();
                    info.ContactName   = reader["联系人"].ToString();
                    info.ContactTel    = reader["联系电话"].ToString();
                    info.Description   = reader["说明"].ToString();
                    info.LegalPerson   = reader["法人"].ToString();
                    info.BusinessScope = reader["生产经营范围"].ToString();
                    info.SalesAmount   = reader["年销售额"].ToString();
                    info.Fax           = reader["传真"].ToString();
                    info.Email         = reader["邮箱"].ToString();
                    info.WebAddress    = reader["网站"].ToString();
                    info.OutDate       = Convert.ToDateTime(reader["过期日"]);
                    //info.GSPGMPLicCode = reader["GSMP证书号"].ToString();
                    //info.GSPGMPLicOutdate = Convert.ToDateTime(reader["GSP/GMP证书有效期止"]);
                    //info.BusinessLicCode = reader["营业执照编号"].ToString();
                    //info.BusinessLicOutdate = Convert.ToDateTime(reader["营业执照有效期止"]);
                    //info.PharmaceuticalTradingLicCode = reader["药品经营许可证号"].ToString();
                    //info.PharmaceuticalTradingLicOutdate = Convert.ToDateTime(reader["药品经营许可证有效期止"]);
                    info.TaxRegistrationCode = reader["税务登记号"].ToString();
                    info.LastAnnualDte       = Convert.ToDateTime(reader["最新年检日期"]);


                    if (IsExist)
                    {
                        PharmacyDatabaseService.UpdatePurchaseUnitByName(out result, reader["单位名称"].ToString(), info);
                        dtState.Rows.Add(i, "更新成功", result);
                    }
                    else
                    {
                        PharmacyDatabaseService.AddPurchaseUnit(out result, info);
                        dtState.Rows.Add(i, "导入成功", result);
                    }
                }
                catch (Exception ex)
                {
                    dtState.Rows.Add(i, "导入失败", "失败原因:" + ex.Message);
                }
                finally
                {
                    progressValue++;
                    i++;
                }
            }
        }