Ejemplo n.º 1
0
        private void btnImport_Click(object sender, RoutedEventArgs e)
        {
            if (this.model.TemplateType.ToString() == "VIP")
            {
                fromLinkList.Add(new ValidationEntity(ValidationEnum.IsNotEmpty, null, ResBatchImportCustomer.Validate_FromLinkNotNull));
                if (!ValidationHelper.Validation(this.tbCustomerSource, fromLinkList))
                {
                    return;
                }
            }
            else
            {
                fromLinkList.Clear();
            }
            ValidationManager.Validate(this.gdBatchImportSetting);
            if (BatchVM.HasValidationErrors)
            {
                return;
            }
            CustomerBatchImportInfo importInfo = BatchVM.ConvertVM <BatchImportCustomerVM, CustomerBatchImportInfo>();

            new CustomerFacade(CPApplication.Current.CurrentPage).BatchImportCustomers(importInfo, (obj, args) =>
            {
                if (args.FaultsHandle())
                {
                    return;
                }
                if (!string.IsNullOrEmpty(args.Result))
                {
                    CPApplication.Current.CurrentPage.Context.Window.Alert(args.Result);
                    Dialog.ResultArgs.DialogResult = DialogResultType.OK;
                    Dialog.Close();
                }
            });
        }
        /// <summary>
        /// 批量导入用户
        /// </summary>
        /// <param name="customers">用户列表</param>
        /// <returns>执行批量操作返回的错误信息</returns>
        public virtual string BatchImportCustomer(CustomerBatchImportInfo batchInfo)
        {
            StringBuilder       sb        = new StringBuilder();
            DataTable           excelData = null;
            List <CustomerInfo> customers = null;

            string tempFilePath = Path.Combine(FileUploadManager.BaseFolder, Encoding.UTF8.GetString(Convert.FromBase64String(batchInfo.ImportFilePath)));

            try
            {
                excelData = ReadExcelFileToDataTable(tempFilePath);
                if (excelData != null && excelData.Rows != null && excelData.Rows.Count > 0)
                {
                    customers = ParseExcelData(excelData, batchInfo);
                }
            }
            catch (Exception ex)
            {
                //读取文件格式异常
                sb.AppendLine(ResouceManager.GetMessageString("Customer.BatchImportCustomer", "ExcelFormatError") + "\n" + ex.Message);
                throw new BizException(sb.ToString());
            }

            sb.AppendLine(ResouceManager.GetMessageString("Customer.BatchImportCustomer", "PromptingMessage"));
            int successCount = 0;
            int failedCount  = 0;

            if (customers != null && customers.Count > 0)
            {
                var processor = ObjectFactory <CustomerProcessor> .Instance;
                foreach (var customer in customers)
                {
                    try
                    {
                        processor.CreateCustomer(customer);
                        successCount++;
                    }
                    catch (Exception exp)
                    {
                        sb.AppendLine(exp.Message);
                        failedCount++;
                    }
                }
                return(string.Format(sb.ToString(), customers.Count, successCount, failedCount));
            }
            return(ResouceManager.GetMessageString("Customer.BatchImportCustomer", "NullExcel"));
        }
        private List <CustomerInfo> ParseExcelData(DataTable table, CustomerBatchImportInfo batchInfo)
        {
            BuildDataDelegate buildDataDelegate = GetBuildDelegate(batchInfo.TemplateType.Value);

            if (buildDataDelegate != null)
            {
                List <CustomerInfo> customers = buildDataDelegate.Invoke(table, batchInfo);
                if (customers != null && customers.Count > 0)
                {
                    CommonUtility.RemoveRepeatEntity <CustomerInfo>(customers, (customer1, customer2) =>
                    {
                        if (customer1 == null)
                        {
                            return(customer2 == null ? 0 : -1);
                        }
                        else if (customer2 == null)
                        {
                            return(1);
                        }
                        else
                        {
                            return(string.Compare(customer1.BasicInfo.CustomerID, customer2.BasicInfo.CustomerID, true));
                        }
                    });
                    CustomerInfo customer = new CustomerInfo();
                    customer.BasicInfo.CustomerID = string.Empty;
                    //以下比较的作用?
                    //int index = customers.BinarySearch(customer);
                    //if (index > -1)
                    //{
                    //    customers.RemoveAt(index);
                    //}
                    return(customers);
                }
            }
            return(null);
        }
        private List <CustomerInfo> BuildVipCustomerData(DataTable table, object extend)
        {
            CustomerBatchImportInfo batchInfo = (CustomerBatchImportInfo)extend;
            CustomerInfo            customer  = null;
            List <CustomerInfo>     customers = new List <CustomerInfo>();
            string custExcelName = string.Empty;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                if (table.Rows[i]["CustomerID"] != DBNull.Value &&
                    !string.IsNullOrEmpty(table.Rows[i]["CustomerID"].ToString()))
                {
                    customer = new CustomerInfo();

                    customer.BasicInfo.CustomerID = StringUtility.TrimNull(table.Rows[i]["CustomerID"]);
                    if (table.Rows[i]["Email"] != DBNull.Value &&
                        StringUtility.IsEmailAddress(table.Rows[i]["Email"].ToString().Trim()))
                    {
                        customer.BasicInfo.Email = table.Rows[i]["Email"].ToString().Trim();
                    }
                    else
                    {
                        customer.BasicInfo.Email = string.Empty;
                    }
                    customer.BasicInfo.CustomerName   = StringUtility.TrimNull(table.Rows[i]["联系人名称"]);
                    customer.BasicInfo.Phone          = StringUtility.TrimNull(table.Rows[i]["电话/手机"]);
                    customer.BasicInfo.CellPhone      = customer.BasicInfo.Phone;
                    customer.BasicInfo.FromLinkSource = batchInfo.FromLinkSource.ToString();
                    customer.BasicInfo.DwellAddress   = StringUtility.TrimNull(table.Rows[i]["客户名称"]);
                    ApplyVIPDefaultValue(customer, i);
                    customers.Add(customer);
                }
            }

            return(customers);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 批量导入用户
        /// </summary>
        /// <param name="customerList"></param>
        /// <param name="callback"></param>
        public void BatchImportCustomers(CustomerBatchImportInfo importInfo, EventHandler <RestClientEventArgs <string> > callback)
        {
            string relativeUrl = "/CustomerService/Customer/BatchImportCustomers";

            restClient.Create(relativeUrl, importInfo, callback);
        }
Ejemplo n.º 6
0
 public string BatchImportCustomer(CustomerBatchImportInfo batchInfo)
 {
     return(ObjectFactory <CustomerBatchImportAppService> .Instance.BatchImportCustomer(batchInfo));
 }