コード例 #1
0
        private void DoImport()
        {
            try
            {
                List <PfCustomer> emptyStore  = new List <PfCustomer>();
                List <PfCustomer> stores      = new List <PfCustomer>();
                List <PfCustomer> repeatItems = new List <PfCustomer>();
                DataTable         dt          = NPOIHelper.FormatToDatatable(path, 0);
                for (int i = 1; i < dt.Rows.Count; i++)
                {
                    DataRow    row   = dt.Rows[i];
                    int        index = 0;
                    PfCustomer store = new PfCustomer();
                    try
                    {
                        if (!CommonGlobalUtil.ImportValidate(row, 10))
                        {
                            // 名称 进货折扣    联系人 联系电话    银行账户信息 应付款结余(正数表示欠供应商)	最后一次记账时间 创建时间    序号 备注

                            store.ID              = "" + (i + 2);
                            store.Name            = CommonGlobalUtil.ConvertToString(row[index++]);
                            store.PfDiscount      = CommonGlobalUtil.ConvertToDecimal(row[index++]);
                            store.Contact         = CommonGlobalUtil.ConvertToString(row[index++]);
                            store.ContactPhone    = CommonGlobalUtil.ConvertToString(row[index++]);
                            store.BankInfo        = CommonGlobalUtil.ConvertToString(row[index++]);
                            store.PaymentBalance  = CommonGlobalUtil.ConvertToDecimal(row[index++]);
                            store.LastAccountTime = DateTimeUtil.ConvertToDateTime(CommonGlobalUtil.ConvertToString(row[index++]));
                            store.Balance         = CommonGlobalUtil.ConvertToDecimal(CommonGlobalUtil.ConvertToString(row[index++]));
                            store.CreateTime      = DateTimeUtil.ConvertToDateTime(CommonGlobalUtil.ConvertToString(row[index++]));
                            store.Remarks         = CommonGlobalUtil.ConvertToString(row[index++]);
                            store.FirstCharSpell  = DisplayUtil.GetPYString(store.Name);
                            int tempindex = index++;

                            store.CustomerType = (byte)CommonGlobalUtil.ConvertToInt16(row[tempindex]);
                            if (String.IsNullOrEmpty(store.Name) || String.IsNullOrEmpty(row[tempindex].ToString()))
                            {
                                //必填项为空
                                emptyStore.Add(store);
                                continue;
                            }
                            else
                            {
                                //判断是否重复款号/颜色
                                if (stores.Find(t => t.Name == store.Name) != null)
                                {
                                    repeatItems.Add(store);
                                    continue;
                                }

                                stores.Add(store);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
                if (emptyStore.Count > 0)
                {
                    String str = string.Empty;
                    foreach (var item in emptyStore)
                    {
                        str += "第" + item.ID + "行\r\n";
                    }
                    ShowError("必填项没有填写,请补充完整!\r\n" + str);
                    return;
                }
                if (repeatItems.Count > 0)
                {
                    String str = string.Empty;
                    foreach (var item in repeatItems)
                    {
                        str += "第" + item.ID + "行" + "\r\n";
                    }
                    ShowError("名称重复,系统已过滤,详见错误报告!\r\n" + str);
                    //  return;
                }
                if (stores != null && stores.Count > 0)
                {
                }
                else
                {
                    ShowMessage("没有数据可以导入,请检查列表信息!");
                    return;
                }
                path = null;
                //檢查結果
                InteractResult result = GlobalCache.ServerProxy.ImportPfCustomer(stores);
                switch (result.ExeResult)
                {
                case ExeResult.Error:
                    GlobalMessageBox.Show(result.Msg);
                    break;

                case ExeResult.Success:
                    RefreshPage();
                    ShowMessage("导入成功!");
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                ShowError(ex);
            }
            finally
            {
                UnLockPage();
            }
        }
コード例 #2
0
        private void DoImport()
        {
            try
            {
                List <PfCustomerStore> unableStore  = new List <PfCustomerStore>();
                List <PfCustomerStore> stores       = new List <PfCustomerStore>();
                List <PfCustomerStore> repeatStores = new List <PfCustomerStore>();
                DataTable dt = NPOIHelper.FormatToDatatable(importPath, 0);
                for (int i = 1; i < dt.Rows.Count; i++)
                {
                    DataRow         row   = dt.Rows[i];
                    int             index = 0;
                    PfCustomerStore store = new PfCustomerStore();
                    try
                    {
                        if (!ImportValidate(row))
                        {
                            //款号	商品名称	色号	颜色名称	吊牌价	成本价	品牌	供应商名称	年份	季节	大类	小类	款型	风格	XS	S	M	L	XL	2XL	3XL	4XL	5XL	6XL	F
                            store.AutoID         = i + 2;
                            store.CostumeID      = CommonGlobalUtil.ConvertToString(row[index]);
                            store.CostumeID      = CommonGlobalUtil.ConvertToString(row[index++]);
                            store.CostumeName    = CommonGlobalUtil.ConvertToString(row[index++]);
                            store.CostumeColorID = CommonGlobalUtil.ConvertToString(row[index++]);
                            store.ColorName      = CommonGlobalUtil.ConvertToString(row[index++]);
                            //store.Price = CommonGlobalUtil.ConvertToString(row[index++]);
                            store.Price   = CommonGlobalUtil.ConvertToDecimal(row[index++]);
                            store.PfPrice = CommonGlobalUtil.ConvertToDecimal(row[index++]);

                            //store.SalePrice = CommonGlobalUtil.ConvertToDecimal(row[index++]);
                            //store.EmOnlinePrice = CommonGlobalUtil.ConvertToDecimal(row[index++]);
                            //store.PfOnlinePrice = CommonGlobalUtil.ConvertToDecimal(row[index++]);
                            store.BrandName    = CommonGlobalUtil.ConvertToString(row[index++]);
                            store.SupplierName = CommonGlobalUtil.ConvertToString(row[index++]);
                            store.Year         = CommonGlobalUtil.ConvertToInt32(row[index++]);
                            store.Season       = CommonGlobalUtil.ConvertToString(row[index++]);
                            // store.ClassCode = CommonGlobalUtil.ConvertToString(row[index++]);
                            store.BigClass      = CommonGlobalUtil.ConvertToString(row[index++]);
                            store.SmallClass    = CommonGlobalUtil.ConvertToString(row[index++]);
                            store.SubSmallClass = CommonGlobalUtil.ConvertToString(row[index++]);
                            // store.Style = CommonGlobalUtil.ConvertToString(row[index++]);
                            //  store.Models = CommonGlobalUtil.ConvertToString(row[index++]);
                            store.SizeGroupShowName = CommonGlobalUtil.ConvertToString(row[index++]);
                            store.XS  = CommonGlobalUtil.ConvertToInt16(row[index++]);
                            store.S   = CommonGlobalUtil.ConvertToInt16(row[index++]);
                            store.M   = CommonGlobalUtil.ConvertToInt16(row[index++]);
                            store.L   = CommonGlobalUtil.ConvertToInt16(row[index++]);
                            store.XL  = CommonGlobalUtil.ConvertToInt16(row[index++]);
                            store.XL2 = CommonGlobalUtil.ConvertToInt16(row[index++]);
                            store.XL3 = CommonGlobalUtil.ConvertToInt16(row[index++]);
                            store.XL4 = CommonGlobalUtil.ConvertToInt16(row[index++]);
                            store.XL5 = CommonGlobalUtil.ConvertToInt16(row[index++]);
                            store.XL6 = CommonGlobalUtil.ConvertToInt16(row[index++]);
                            store.F   = CommonGlobalUtil.ConvertToInt16(row[index++]);

                            store.PfCustomerID = pfCustomeId;
                            if ((String.IsNullOrEmpty(store.CostumeID) || String.IsNullOrEmpty(store.CostumeName) ||
                                 String.IsNullOrEmpty(store.ColorName) ||
                                 String.IsNullOrEmpty(store.SizeGroupShowName)))
                            {
                                unableStore.Add(store);
                            }
                            else
                            {
                                if (stores.Find(t => t.CostumeID == store.CostumeID && t.CostumeName == store.CostumeName &&
                                                t.ColorName == store.ColorName
                                                ) != null)
                                {
                                    repeatStores.Add(store);
                                }
                                else
                                {
                                    //store.CostumeID = CommonGlobalCache.GetCorrectCostumeID(store.CostumeID);

                                    /* if (!String.IsNullOrEmpty(store.ClassCode))
                                     * {
                                     *    store.ClassName = CommonGlobalCache.ServerProxy.GetCostumeClass4Code(store.ClassCode)?.ClassName;
                                     * }*/
                                    stores.Add(store);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }

                if (unableStore.Count > 0)
                {
                    String str = string.Empty;
                    foreach (var item in unableStore)
                    {
                        str += "第" + item.AutoID + "行\r\n";
                    }

                    ShowError("必填项没有填写,请补充完整!\r\n" + str);
                    ImportFormCancel();
                    return;
                }
                if (repeatStores.Count > 0)
                {
                    String str = string.Empty;
                    foreach (var item in repeatStores)
                    {
                        str += "第" + item.AutoID + "行\r\n";
                    }

                    //这个与已导入的列表数据无关
                    ShowError("重复的款号与颜色,系统已过滤,详见错误报告!\r\n" + str);
                    ImportFormCancel();
                    return;
                }
                if (stores != null && stores.Count > 0)
                {
                }
                else
                {
                    ShowMessage("没有数据可以导入,请检查列表信息!");
                    ImportFormCancel();
                    return;
                }

                importPath = null;
                AddItems4Display(stores);
                //    ShowMessage("导入成功!");
                ImportFormDialogResult(DialogResult.OK);
            }
            catch (Exception ex)
            {
                ImportFormCancel();
                ShowError(ex);
            }
            finally
            {
                UnLockPage();
            }
        }