private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     if (!DataGridViewUtil.CheckPerrmisson(this, sender, e))
     {
         return;
     }
     try
     {
         if (e.RowIndex > -1 && e.ColumnIndex > -1)
         {
             if (CommonGlobalUtil.ConvertToString(this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value) == "删除")
             {
                 //DialogResult dialogResult = GlobalMessageBox.Show("确定删除该条数据?", "提示", MessageBoxButtons.OKCancel);
                 //if (dialogResult != DialogResult.OK)
                 //{
                 //    return;
                 //}
                 PfCustomerRetailDetail detail = this.PfCustomerRetailDetailList[e.RowIndex];
                 this.PfCustomerRetailDetailList.RemoveAt(e.RowIndex);
                 dataGridViewPagingSumCtrl.BindingDataSource(this.PfCustomerRetailDetailList);
             }
         }
     }
     catch (Exception ee)
     {
         GlobalUtil.WriteLog(ee);
     }
 }
示例#2
0
 private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     if (!DataGridViewUtil.CheckPerrmisson(this, sender, e))
     {
         return;
     }
     try
     {
         if (e.RowIndex > -1 && e.ColumnIndex > -1)
         {
             if (CommonGlobalUtil.ConvertToString(this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value) == "删除")
             {
                 DialogResult dialogResult = GlobalMessageBox.Show("确定删除该条数据?", "提示", MessageBoxButtons.OKCancel);
                 if (dialogResult != DialogResult.OK)
                 {
                     return;
                 }
                 RetailDetail detail = this.retailDetailList[e.RowIndex];
                 this.retailDetailList.RemoveAt(e.RowIndex);
                 dataGridViewPagingSumCtrl.BindingDataSource(DataGridViewUtil.ListToBindingList(this.retailDetailList));
             }
             if (e.ColumnIndex == GuideName.Index)
             {
                 RetailDetail detail = this.retailDetailList[e.RowIndex];
                 // detail.GuideID = this.retailDetailList[e.ColumnIndex];
                 detail.GuideID = this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
                 //detail.GuideName = CommonGlobalCache.GetUserName(detail.GuideID);
             }
         }
     }
     catch (Exception ee)
     {
         GlobalUtil.WriteLog(ee);
     }
 }
示例#3
0
        private void dataGridView_RefundDetail_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (!DataGridViewUtil.CheckPerrmisson(this, sender, e))
            {
                return;
            }
            if (e.RowIndex < 0 || e.ColumnIndex < 0)
            {
                return;
            }
            clickValue = dataGridView_RefundDetail.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
            String content = CommonGlobalUtil.ConvertToString(clickValue);

            MonthTask item = dataGridView_RefundDetail.Rows[e.RowIndex].DataBoundItem as MonthTask;

            if (content == "设置日目标")
            {
                curMonthTask = item;
                ShowDayTask(null, curMonthTask);
            }
            else if (content == "查看日目标")
            {
                curMonthTask = item;
                ShowDayTask(null, curMonthTask, true);
            }
        }
示例#4
0
        private bool ImportValidate(DataRow row)
        {    //
            bool unValidate = true;

            for (int i = 0; i < 22; i++)
            {
                String value = CommonGlobalUtil.ConvertToString(row[i]);
                if (!String.IsNullOrEmpty(value))
                {
                    //有值
                    unValidate = false;
                    break;
                }
            }
            return(unValidate);
        }
示例#5
0
        private void dataGridView_MonthTask_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (!DataGridViewUtil.CheckPerrmisson(this, sender, e))
            {
                return;
            }
            if (e.RowIndex < 0 || e.ColumnIndex < 0)
            {
                return;
            }
            clickValue = dataGridView_MonthTask.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
            MonthTaskSearch search  = dataGridView_MonthTask.Rows[e.RowIndex].DataBoundItem as MonthTaskSearch;
            String          content = CommonGlobalUtil.ConvertToString(clickValue);

            if (content == "设置日目标")
            {
                curMonthTask = null;

                int month = Decimal.ToInt32(numericUpDown_year.Value) * 100 + DateTime.Now.Month;
                // int month = new Date( DateTime.Now).ToDateInteger();
                foreach (var item in search.MonthTasks)
                {
                    if (item.Month == month)
                    {
                        curMonthTask = item;
                        break;
                    }
                }
                ShowDayTask(search, curMonthTask);
            }
            else if (content == "查看日目标")
            {
                curMonthTask = null;
                int month = Decimal.ToInt32(numericUpDown_year.Value) * 100 + DateTime.Now.Month;
                // int month = new Date( DateTime.Now).ToDateInteger();
                foreach (var item in search.MonthTasks)
                {
                    if (item.Month == month)
                    {
                        curMonthTask = item;
                        break;
                    }
                }
                ShowDayTask(search, curMonthTask, false);
            }
        }
示例#6
0
 public static string GetModelValue(string fieldName, object obj)
 {
     try
     {
         Type   Ts    = obj.GetType();
         object o     = Ts.GetProperty(fieldName).GetValue(obj, null);
         string Value = CommonGlobalUtil.ConvertToString(o);
         if (string.IsNullOrEmpty(Value))
         {
             return(null);
         }
         return(Value);
     }
     catch
     {
         return(null);
     }
 }
示例#7
0
        private void DoImport()
        {
            try
            {
                List <CostumeClass2> emptyStore  = new List <CostumeClass2>();
                List <CostumeClass2> stores      = new List <CostumeClass2>();
                List <CostumeClass2> repeatItems = new List <CostumeClass2>();
                DataTable            dt          = NPOIHelper.FormatToDatatable(path, 0);
                for (int i = 1; i < dt.Rows.Count; i++)
                {
                    DataRow       row   = dt.Rows[i];
                    int           index = 0;
                    CostumeClass2 store = new CostumeClass2();
                    try
                    {
                        if (!CommonGlobalUtil.ImportValidate(row, 5))
                        {
                            store.Index        = (i + 2);
                            store.AutoID       = CommonGlobalUtil.ConvertToInt32(row[index++]);
                            store.ClassName    = CommonGlobalUtil.ConvertToString(row[index++]);
                            store.ParentAutoID = CommonGlobalUtil.ConvertToInt32(row[index++]);
                            store.OrderNo      = CommonGlobalUtil.ConvertToInt32(row[index++]);
                            store.ClassCode    = CommonGlobalUtil.ConvertToString(row[index++]);
                            //  store.FirstCharSpell = DisplayUtil.GetPYString(store.Name);
                            if (store.AutoID == 0 || String.IsNullOrEmpty(store.ClassName))
                            {
                                //必填项为空
                                emptyStore.Add(store);
                                continue;
                            }
                            else
                            {
                                //判断是否重复款号/颜色
                                if (stores.Find(t => t.AutoID == store.AutoID) != 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.Index + "行\r\n";
                    }
                    ShowError("必填项没有填写,请补充完整!\r\n" + str);
                    return;
                }
                if (repeatItems.Count > 0)
                {
                    String str = string.Empty;
                    foreach (var item in repeatItems)
                    {
                        str += "第" + item.Index + "行" + "\r\n";
                    }
                    ShowError("名称重复,系统已过滤,详见错误报告!\r\n" + str);
                    //  return;
                }
                if (stores != null && stores.Count > 0)
                {
                }
                else
                {
                    ShowMessage("没有数据可以导入,请检查列表信息!");
                    return;
                }
                path = null;
                //檢查結果
                InteractResult result = GlobalCache.ServerProxy.ImportCostumeClass(stores);
                switch (result.ExeResult)
                {
                case ExeResult.Error:
                    ShowMessage(result.Msg);
                    break;

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

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                ShowError(ex);
            }
            finally
            {
                UnLockPage();
            }
        }
示例#8
0
        private void ImportExcel(String importPath)
        {
            try
            {
                List <ImportPfInfosPara> items          = new List <ImportPfInfosPara>();
                List <ImportPfInfosPara> incorrectItems = new List <ImportPfInfosPara>();
                DataTable dt = NPOIHelper.FormatToDatatable(importPath, 0);


                if (dt.Rows.Count == 0)
                {
                    //没有任何记录
                    ShowMessage("没有可以导入的信息!");
                    CompleteEdit();
                    return;
                }
                InitProgress(dt.Rows.Count);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    UpdateProgress("加载数据:");
                    if (progressStop)
                    {
                        break;
                    }

                    DataRow           row  = dt.Rows[i];
                    ImportPfInfosPara item = new ImportPfInfosPara();
                    try
                    {
                        item.Index        = i + 1;
                        item.CostumeID    = CommonGlobalUtil.ConvertToString(row[0]);
                        item.BarCodeValue = CommonGlobalUtil.ConvertToString(row[1]);
                        item.Name         = CommonGlobalUtil.ConvertToString(row[2]);
                        item.Colors       = CommonGlobalUtil.ConvertToString(row[3]).Replace(",", ",");
                        item.BigClass     = CommonGlobalUtil.ConvertToString(row[4]);
                        item.Price        = Convert.ToDecimal(row[5]);
                        item.PhotoName    = CommonGlobalUtil.ConvertToString(row[6]);
                        item.IsNew        = CommonGlobalUtil.ConvertToString(row[7]) == "是";
                        item.IsHot        = CommonGlobalUtil.ConvertToString(row[8]) == "是";
                    }
                    catch (Exception ex)
                    {
                    }

                    if (!(String.IsNullOrEmpty(item.CostumeID) || String.IsNullOrEmpty(item.Name)))
                    {
                        item.CostumeID = CommonGlobalCache.GetCorrectCostumeID(item.CostumeID);
                        items.Add(item);
                    }
                    else
                    {
                        incorrectItems.Add(item);
                    }
                }
                if (incorrectItems.Count > 0)
                {
                    String str = string.Empty;
                    str = str.Substring(0, str.LastIndexOf(","));
                    ShowError("以下行数中,款号/名称为空,请重新检查!\r\n" + str);
                    return;
                }
                if (items == null || items.Count == 0)
                {
                    ShowMessage("没有数据可以导入,请检查会员信息!");
                    return;
                }

                String failImgs     = String.Empty;
                String tooLargeImgs = String.Empty;
                InitProgress(items.Count);
                foreach (var item in items)
                {
                    if (progressStop)
                    {
                        break;
                    }
                    UpdateProgress("检查图片:");
                    //if (!String.IsNullOrEmpty(item.PhotoName))
                    //{
                    //找图片并上传
                    try
                    {
                        String imagePath = Path.GetDirectoryName(path) + "//" + item.PhotoName;
                        if (!File.Exists(imagePath))
                        {
                            failImgs += "第" + item.Index + "行 款号:" + item.CostumeID;
                            failImgs += "\r\n";
                        }
                        else
                        {
                            Image        img    = JGNet.Core.ImageHelper.FromFileStream(imagePath);
                            MemoryStream stream = new MemoryStream();
                            byte[]       photo  = stream.ToArray();
                            img    = JGNet.Core.ImageHelper.GetNewSizeImage(img, 800);
                            stream = new MemoryStream();
                            img.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
                            photo = stream.ToArray();
                            if (photo.Length > 2097152)
                            {
                                tooLargeImgs += "第" + item.Index + "行 款号:" + item.CostumeID;
                                tooLargeImgs += "\r\n";
                                //return;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        FailedProgress(ex);
                    }
                    // }
                }

                if (!String.IsNullOrEmpty(failImgs))
                {
                    FailedProgress(new Exception("以下图片不存在:" + "\r\n" + failImgs));

                    return;
                }
                else if (!String.IsNullOrEmpty(tooLargeImgs))
                {
                    FailedProgress(new Exception("以下图片太大:" + "\r\n" + tooLargeImgs));
                    return;
                }

                InteractResult result = GlobalCache.ServerProxy.ImportPfInfos(items);
                switch (result.ExeResult)
                {
                case ExeResult.Success:
                    break;

                case ExeResult.Error:
                    // ShowMessage(result.Msg);
                    FailedProgress(new Exception(result.Msg));
                    return;

                default:
                    break;
                }
                try
                {
                    InitProgress(items.Count);
                    foreach (var item in items)
                    {
                        if (progressStop)
                        {
                            break;
                        }

                        UpdateProgress("图片上传:");
                        //if (!String.IsNullOrEmpty(item.PhotoName))
                        //{
                        //找图片并上传
                        String[] colors = item.Colors.Split(',');

                        String       imagePath   = Path.GetDirectoryName(path) + "//" + item.PhotoName;
                        String       newFileName = JGNet.Core.ImageHelper.GetNewFileName(item.CostumeID, item.PhotoName);
                        Image        img         = JGNet.Core.ImageHelper.FromFileStream(imagePath);
                        MemoryStream stream      = new MemoryStream();
                        byte[]       photo       = stream.ToArray();
                        img    = JGNet.Core.ImageHelper.GetNewSizeImage(img, 800);
                        stream = new MemoryStream();
                        img.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
                        photo = stream.ToArray();
                        EmCostumePhoto emPhoto = new EmCostumePhoto()
                        {
                            Image     = img,
                            SavePath  = imagePath,
                            IsMain    = true,
                            CostumeID = item.CostumeID,
                            //ColorName = ValidateUtil.CheckEmptyValue(this.skinComboBox_Color.SelectedValue),
                            Bytes     = photo,
                            PhotoName = newFileName
                        };
                        PhotoData data = new PhotoData()
                        {
                            Datas          = emPhoto.Bytes,
                            EmCostumePhoto = emPhoto,
                            Name           = item.PhotoName
                        };

                        WriteLog("UploadPhotoToCos:" + item.CostumeID);
                        GlobalCache.ServerProxy.UploadPhotoToCos(data);
                        //  Thread.Sleep(1000);
                    }
                    ShowMessage("导入成功!");
                }
                catch (Exception ex)
                {
                    FailedProgress(ex);
                }

                CompleteEdit();
            }
            catch (Exception ex)
            {
                ShowError(ex);
            }
            finally
            {
                UnLockPage();
                EnablePanel();
            }
        }
示例#9
0
        private void DoImport()
        {
            try
            {
                List <Member> items            = new List <Member>();
                List <Member> incorrectItems   = new List <Member>();
                List <Member> checkTel         = new List <Member>();
                List <Member> checkMemberNo    = new List <Member>(); //导入时会员卡号不为数字或英文字母的集合
                List <int>    checkMemberNoRow = new List <int>();
                DataTable     dt = NPOIHelper.FormatToDatatable(importPath, 0);
                //20190223根据模板过滤第一行的注释和列标题
                for (int i = 1; i < dt.Rows.Count; i++)
                {
                    DataRow row  = dt.Rows[i];
                    Member  item = new Member();
                    try
                    {
                        if (!ImportValidate(row))
                        {
                            //20190218过滤第一列店铺列
                            int index = 1;
                            item.Index       = i + 2;
                            item.ShopID      = importShopID;
                            item.PhoneNumber = CommonGlobalUtil.ConvertToString(row[index++]);
                            item.Name        = CommonGlobalUtil.ConvertToString(row[index++]);
                            item.Phone       = CommonGlobalUtil.ConvertToString(row[index++]);
                            try
                            {
                                item.Sex = CommonGlobalUtil.ConvertToString(row[index++]) == "男";
                            }
                            catch
                            {
                                item.Sex = false;
                            }
                            try
                            {
                                item.Balance = Convert.ToDecimal(row[index++]);
                            }
                            catch
                            {
                                item.Balance = 0;
                            }
                            try
                            {
                                item.CurrentIntegration = Convert.ToInt32(row[index++]);
                            }
                            catch
                            {
                                item.CurrentIntegration = 0;
                            }
                            try
                            {
                                item.AccruedIntegration = Convert.ToInt32(row[index++]);
                            }
                            catch
                            {
                                item.AccruedIntegration = 0;
                            }
                            try
                            {
                                item.AccruedSpend = Convert.ToDecimal(row[index++]);
                            }
                            catch
                            {
                                item.AccruedSpend = 0;
                            }
                            try
                            {
                                item.BuyCount = Convert.ToInt32(row[index++]);
                            }
                            catch
                            {
                                item.BuyCount = 0;
                            }
                            try
                            {
                                item.QuantityOfBuy = Convert.ToInt32(row[index++]);
                            }
                            catch
                            {
                                item.BuyCount = 0;
                            }
                            item.GuideName   = CommonGlobalUtil.ConvertToString(row[index++]);
                            item.GuideID     = CommonGlobalCache.GetUserIDByUserName(item.GuideName);
                            item.CreatedTime = DateTimeUtil.ConvertToDateTime(CommonGlobalUtil.ConvertToString(row[index++]));
                            item.Birthday    = DateTimeUtil.ConvertToDateTime(CommonGlobalUtil.ConvertToString(row[index++]));
                            item.State       = 1;


                            if (!(String.IsNullOrEmpty(item.Name) && String.IsNullOrEmpty(item.PhoneNumber)))
                            {
                                items.Add(item);
                            }
                            if (checkPhoneNumber(item.PhoneNumber) == false)
                            {
                                checkMemberNo.Add(item);
                                checkMemberNoRow.Add(item.Index);
                            }
                            //else
                            //{
                            //    /*验证电话号码*/
                            //    if (!IstelNumber(item.PhoneNumber)) {
                            //        checkTel.Add(item);
                            //    }
                            //    incorrectItems.Add(item);
                            //}
                        }
                    }
                    catch
                    {
                        //   incorrectItems.Add(item);
                    }
                }

                if (incorrectItems.Count > 0)
                {
                    String str = string.Empty;
                    foreach (var item in incorrectItems)
                    {
                        str += item.Index + ",";
                    }
                    str = str.Substring(0, str.LastIndexOf(","));
                    ShowError("以下行数中,会员卡号/姓名为空,请重新检查!\r\n" + str);
                    ImportFormCancel();
                    return;
                }
                if (checkMemberNo.Count > 0)
                {
                    String rowStr = string.Empty;
                    for (int i = 0; i < checkMemberNoRow.Count; i++)
                    {
                        rowStr += checkMemberNoRow[i] + ",";
                    }
                    rowStr = rowStr.Substring(0, rowStr.LastIndexOf(","));
                    ShowError("以下有效数据行数中,会员卡号格式错误,请重新检查!\r\n" + rowStr);
                    ImportFormCancel();
                    return;
                }

                /*  if (checkTel.Count > 0)
                 * {
                 *    String telstr = string.Empty;
                 *    foreach (var item in checkTel)
                 *    {
                 *        telstr += item.Index + ",";
                 *    }
                 *    telstr = telstr.Substring(0, telstr.LastIndexOf(","));
                 *    ShowError("以下行数中,手机号码不正确,请重新检查!\r\n" + telstr);
                 *     ImportFormCancel();
                 *    return;
                 * }*/

                if (items != null && items.Count > 0)
                {
                }
                else
                {
                    ShowMessage("没有数据可以导入,请检查会员信息!");
                    ImportFormCancel();
                    return;
                }

                InteractResult result = CommonGlobalCache.ServerProxy.ImportMembers(items);
                switch (result.ExeResult)
                {
                case ExeResult.Success:
                    //导入
                    ImportFormDialogResult(DialogResult.OK);
                    ShowMessage("导入成功!");
                    //importForm.DialogResult = DialogResult.OK;
                    break;

                case ExeResult.Error:
                    ShowMessage(result.Msg);
                    // ImportFormDialogResult(DialogResult.OK);
                    ImportFormCancel();
                    break;

                default:
                    break;
                }
            }

            catch (Exception ex)
            {
                ImportFormCancel();
                ShowError(ex);
            }
            finally
            {
                UnLockPage();
            }
        }
        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();
            }
        }
示例#11
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();
            }
        }
示例#12
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();
            }
        }