コード例 #1
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();
            }
        }
コード例 #2
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();
            }
        }
コード例 #3
0
        /// <summary>
        /// 导入数据
        /// </summary>
        private void DoImport()
        {
            try
            {
                List <Costume> emptyStore         = new List <Costume>();
                List <Costume> stores             = new List <Costume>();
                List <Costume> repeatItems        = new List <Costume>();
                DataTable      dt                 = NPOIHelper.FormatToDatatable(path, 0);
                List <int>     NoNullRows         = new List <int>(); //必填项不为空集合
                List <int>     IDRepeatRows       = new List <int>(); //款号重复集合
                List <int>     ErrorSizeRows      = new List <int>(); //尺码格式不正确
                List <int>     ErrorGroupNameRows = new List <int>(); //尺码组名称不存在
                List <int>     ErrorIdOrName      = new List <int>(); //款号或名称长度不正确

                List <EmCostumePhoto> listPhoto = ExcelToImage(path, GlobalUtil.EmallDir);

                #region //数据处理
                for (int i = 1; i < dt.Rows.Count; i++)
                {
                    DataRow row   = dt.Rows[i];
                    int     index = 0;
                    Costume store = new Costume();
                    try
                    {
                        if (!ImportValidate(row))
                        {
                            //款号 商品名称    颜色名称(使用逗号分隔)	吊牌价 成本价 售价 品牌  供应商名称 年份  季节 类别编码    尺码组名称 含有的尺码(使用逗号分隔)	备注

                            store.ID            = CommonGlobalUtil.ConvertToString(row[index++]);
                            store.Name          = CommonGlobalUtil.ConvertToString(row[index++]);
                            store.Colors        = CommonGlobalUtil.ConvertToString(row[index++]);
                            store.Price         = CommonGlobalUtil.ConvertToDecimal(row[index++]);
                            store.CostPrice     = 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++]);
                            // Image image =(Image) 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.SizeGroupName = CommonGlobalUtil.ConvertToString(row[index++]);
                            store.SizeNames     = CommonGlobalUtil.ConvertToString(row[index++]);
                            store.Remarks       = CommonGlobalUtil.ConvertToString(row[index++]);
                            //图片放最后面
                            index++;
                            int curRow = i + 2;
                            if (String.IsNullOrEmpty(store.ID) || String.IsNullOrEmpty(store.Name) || String.IsNullOrEmpty(store.Colors) || String.IsNullOrEmpty(store.SizeGroupName) || String.IsNullOrEmpty(store.SizeNames))
                            {
                                //必填项为空
                                // emptyStore.Add(store);
                                NoNullRows.Add(curRow);
                                continue;
                            }
                            else
                            {
                                /* if (store.ID.Length > 50 || store.Name.Length > 50)
                                 * {
                                 *   ErrorIdOrName.Add(curRow);
                                 *   continue;
                                 * }*/
                                //判断尺码组以及尺码是否格式正确 CommonGlobalCache.SizeGroupList
                                List <SizeGroup> SizeGroupList = CommonGlobalCache.SizeGroupList;

                                int isNoGName = 0;
                                foreach (var sGroup in SizeGroupList)
                                {
                                    if (sGroup.ShowName == store.SizeGroupName)  //尺码组名称存在
                                    {
                                        //判断尺码格式是否正确  M,S,XL
                                        //sGroup.NameOfF
                                        String[] tempSizeList = store.SizeNames.Split(',');
                                        if (tempSizeList != null)
                                        {
                                            bool isRight = true; //当前尺码是否格式完全正确
                                            for (int t = 0; t < tempSizeList.Length; t++)
                                            {
                                                if (tempSizeList[t] == sGroup.NameOfF || tempSizeList[t] == sGroup.NameOfL ||
                                                    tempSizeList[t] == sGroup.NameOfM || tempSizeList[t] == sGroup.NameOfS ||
                                                    tempSizeList[t] == sGroup.NameOfXL || tempSizeList[t] == sGroup.NameOfXL2 ||
                                                    tempSizeList[t] == sGroup.NameOfXL3 || tempSizeList[t] == sGroup.NameOfXL4 ||
                                                    tempSizeList[t] == sGroup.NameOfXL5 || tempSizeList[t] == sGroup.NameOfXL6 ||
                                                    tempSizeList[t] == sGroup.NameOfXS)
                                                {
                                                    //逗号分隔后当前尺码跟数据库尺码匹配
                                                }
                                                else
                                                {
                                                    isRight = false; //当前含有的尺码有错误的格式
                                                    ErrorSizeRows.Add(curRow);
                                                    continue;
                                                }
                                            }
                                            if (isRight == false)
                                            {
                                                continue; //跳出循环,正确的尺码组没有正确的尺码
                                            }
                                        }
                                        else
                                        {
                                            ErrorSizeRows.Add(curRow);   //格式不正确,没有尺码
                                        }
                                    }
                                    else
                                    {
                                        isNoGName++;
                                        if (isNoGName == SizeGroupList.Count)
                                        {
                                            ErrorGroupNameRows.Add(curRow);   //尺码组不存在,格式不正确
                                        }
                                    }
                                }

                                //判断是否重复款号
                                if (stores.Find(t => t.ID == store.ID) != null)
                                {
                                    IDRepeatRows.Add(curRow);
                                    continue;
                                }

                                stores.Add(store);
                            }
                        }
                    }
                    //catch (IOException ex)
                    //{
                    //    ShowMessage(ex.Message);
                    //}
                    catch (Exception ex)
                    {
                    }
                }
                #endregion


                #region  //数据检验
                if (NoNullRows.Count > 0)
                {
                    String str = string.Empty;
                    foreach (var item in NoNullRows)
                    {
                        str += "第" + item + "行\r\n";
                    }
                    ShowError("必填项没有填写,请补充完整!\r\n" + str);
                    return;
                }
                if (ErrorIdOrName.Count > 0)
                {
                    String str = string.Empty;
                    foreach (var item in ErrorGroupNameRows)
                    {
                        str += "第" + item + "行" + "\r\n";
                    }
                    ShowError("款号超过50个字符或商品名称超过50个汉字,请检查列表信息!\r\n" + str);
                    return;
                }
                if (IDRepeatRows.Count > 0)
                {
                    String str = string.Empty;
                    foreach (var item in IDRepeatRows)
                    {
                        str += "第" + item + "行" + "\r\n";
                    }
                    ShowError("重复的款号,系统已过滤,详见错误报告!\r\n" + str);
                    //  return;
                }

                if (ErrorGroupNameRows.Count > 0)
                {
                    String str = string.Empty;
                    foreach (var item in ErrorGroupNameRows)
                    {
                        str += "第" + item + "行" + "\r\n";
                    }
                    ShowError("尺码组不存在,请检查列表信息!\r\n" + str);
                    return;
                }

                if (ErrorSizeRows.Count > 0)
                {
                    String str = string.Empty;
                    foreach (var item in ErrorSizeRows)
                    {
                        str += "第" + item + "行" + "\r\n";
                    }
                    ShowError("尺码不存在或尺码格式错误,请检查列表信息!\r\n" + str);
                    return;
                }

                if (stores != null && stores.Count > 0)
                {
                    if (stores.Count == listPhoto.Count)
                    {
                    }
                    else
                    {
                        if (GlobalMessageBox.Show("导入的数据和图片不对应,如果导入会影响到导入的图片与款号不对应,是否确认操作?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
                        {
                            return;
                        }
                    }
                }
                else
                {
                    ShowMessage("没有数据可以导入,请检查列表信息!");
                    return;
                }

                #endregion

                path = null;


                #region  //数据录入
                InteractResult result = GlobalCache.ServerProxy.ImportCostumes(stores);
                switch (result.ExeResult)
                {
                case ExeResult.Error:
                    GlobalMessageBox.Show(result.Msg);
                    break;

                case ExeResult.Success:
                    foreach (var item in stores)
                    {
                        Costume costume = CommonGlobalCache.GetCostume(item.ID);
                        if (costume != null)
                        {
                            //重新给商品名称
                            //ShowMessage(item.ID);
                            item.Name = costume.Name;
                        }
                    }

                    for (int i = 0; i < stores.Count; i++)
                    {
                        if (listPhoto.Count > 0 && listPhoto.Count > i)
                        {
                            listPhoto[i].CostumeID = stores[i].ID;

                            //这里还是要给新图片名称,下面取回来对应过去。才有LINKADDRESS
                            PhotoData para = new PhotoData()
                            {
                                Datas          = listPhoto[i].Bytes,
                                EmCostumePhoto = listPhoto[i],
                                Name           = listPhoto[i].PhotoName,
                            };
                            GlobalCache.ServerProxy.UploadPhotoToCos(para);

                            /* GlobalCache.ServerProxy.UploadCostumePhoto(new UploadCostumePhotoPara()
                             * {
                             *
                             *   ID = stores[i].ID,
                             *   Photo = listPhoto[i].Photo,
                             *
                             * });*/
                        }
                    }
                    // AddItems4Display(stores);

                    ShowMessage("导入成功!");
                    break;

                default:
                    break;
                }

                #endregion
            }
            catch (Exception ex)
            {
                ShowError(ex);
            }
            finally
            {
                UnLockPage();
            }
        }