Ejemplo n.º 1
0
 // 2015-10-14 Kevin Xiao Backup 
 //protected void btnSave_Click(object sender, EventArgs e)
 //{
 //    int total_valid_product = 0;
 //    int total_success_import = 0;
 //    if (upLoadFile.FileName.Length == 0)
 //    {
 //        base.AlertMessage("Please choose product file.");
 //        return;
 //    }
 //    BPSC.Common.ExcelTemplate excelTemplate = new BPSC.Common.ExcelTemplate("Product_Import_Template.xls");
 //    bool isValid = true;
 //    DataTable dt_product = excelTemplate.GetDataFromExcel(upLoadFile, out isValid);
 //    if (!isValid)
 //    {
 //        base.AlertMessage("The format of product file is error. Please check it, try again later.");
 //        return;
 //    }
 //    //Brand,DESC_CN,subcategory,Brand Type,Size,CasePackage,Retail_CasePrice,Specification,DESC_EN
 //    #region 验证所有数据的格式正确性
 //    for (int j = 0; j < dt_product.Rows.Count; j++)
 //    {
 //        try
 //        {
 //            Convert.ToDouble(dt_product.Rows[j][6]);
 //        }
 //        catch (Exception ex)
 //        {
 //            base.AlertMessage("Data format is error, 'Retail case Price'.");
 //            this.upLoadFile.Focus();
 //            return;
 //        }
 //    }
 //    #endregion
 //    Dictionary<string, ProductEntity> products = new Dictionary<string, ProductEntity>();
 //    foreach (DataRow row in dt_product.Rows)
 //    {
 //        try
 //        {
 //            //Brand,DESC_CN,subcategory,Brand Type,Size,CasePackage,Retail_CasePrice,Specification,DESC_EN
 //            string brand = row[0].ToString().Trim().ToLower();
 //            string desc_cn = row[1].ToString().Trim().ToLower();
 //            string sub_category = row[2].ToString().Trim().ToLower();
 //            string brandType = row[3].ToString().Trim().ToLower();
 //            string productSize = row[4].ToString().Trim().ToLower();
 //            string case_package = row[5].ToString().Trim().ToLower();
 //            string retail_unitprice = row[6].ToString().Trim().ToLower();
 //            string specification = row[7].ToString().Trim().ToLower();
 //            string desc_en = row[8].ToString().Trim().ToLower();
 //            string key = brand + desc_cn + sub_category + brandType + productSize;
 //            if (products.ContainsKey(key))
 //                continue;
 //            ProductEntity entity = new ProductEntity();
 //            entity.ProductId = Guid.NewGuid().ToString();
 //            string _brandId = string.Empty;
 //            string _subCategoryId = string.Empty;
 //            MainService.ProductCategoryBLLService.GetBrandID(brand, sub_category, out _brandId, out _subCategoryId);
 //            string _category_id = MainService.ProductCategoryBLLService.GetProductCategoryEntityById(_brandId).Pid;
 //            string _gbu_id = MainService.ProductCategoryBLLService.GetProductCategoryEntityById(_category_id).Pid;
 //            entity.GbuId = _gbu_id;
 //            entity.Gbu = MainService.ProductCategoryBLLService.GetProductCategoryEntityById(_gbu_id).Title;
 //            entity.CategoryId = _category_id;
 //            entity.Category = MainService.ProductCategoryBLLService.GetProductCategoryEntityById(_category_id).Title;
 //            entity.BrandId = _brandId;
 //            entity.Brand = MainService.ProductCategoryBLLService.GetProductCategoryEntityById(_brandId).Title;
 //            entity.SubcategoryId = _subCategoryId;
 //            entity.Subcategory = MainService.ProductCategoryBLLService.GetProductCategoryEntityById(_subCategoryId).Title;
 //            entity.DescCn = desc_cn;
 //            entity.DescEn = desc_en;
 //            entity.BrandtypeId = MainService.BrandtypeBLLService.GetIDByName(brandType);
 //            entity.Brandtype = brandType;
 //            entity.ProductSize = productSize;
 //            entity.ProductSizeId = MainService.ProductsizeBLLService.GetIDByName(productSize);
 //            entity.Specification = specification;
 //            entity.RetailCaseprice = decimal.Parse(retail_unitprice);
 //            //如果Excel中ProductType不为空,则直接上传
 //            //如果为空,查找中文名称中是否包含export或import, 都没有则默认保存为local
 //            if (row[9].ToString().Trim() != "")
 //            {
 //                entity.ProductType = row[9].ToString().Trim().ToLower();
 //            }
 //            else
 //            {
 //                if (desc_cn.Contains("export"))
 //                {
 //                    entity.ProductType = "export";
 //                }
 //                else if (desc_cn.Contains("import"))
 //                {
 //                    entity.ProductType = "import";
 //                }
 //                else
 //                {
 //                    entity.ProductType = "local";
 //                }
 //            }
 //            CasecalculationEntity caseEntity = MainService.CasecalculationBLLService.GetEntity(entity.BrandId, entity.BrandtypeId, entity.ProductSizeId, entity.SubcategoryId);
 //            if (caseEntity != null)
 //            {
 //                entity.CasePackage = caseEntity.CasePackage;
 //                entity.CasecalculationId = caseEntity.CasecalculationId;
 //            }
 //            products.Add(key, entity);
 //        }
 //        catch
 //        {
 //        }
 //    }
 //    total_valid_product = products.Count;
 //    foreach (KeyValuePair<string, ProductEntity> entry in products)
 //    {
 //        if (MainService.ProductBLLService.Insert(entry.Value))
 //            total_success_import += 1;
 //    }
 //    if (total_success_import > 0)
 //    {
 //        base.AlertMessage(total_success_import.ToString() + " products is valid, and import successfully!");
 //    }
 //    else
 //    {
 //        base.AlertMessage("All products is invalid. Please check, try it later.");
 //    }
 //}
 protected void btnSave_Click(object sender, EventArgs e)
 {
     int total_valid_product = 0;
     int total_success_import = 0;
     int total_success_update = 0;
     if (upLoadFile.FileName.Length == 0)
     {
         base.AlertMessage("Please choose product file.");
         return;
     }
     BPSC.Common.ExcelTemplate excelTemplate = new BPSC.Common.ExcelTemplate("Product_Import_Template.xls");
     bool isValid = true;
     DataTable dt_product = excelTemplate.GetDataFromExcel(upLoadFile, out isValid);
     if (!isValid)
     {
         base.AlertMessage("The format of product file is error. Please check it, try again later.");
         return;
     }
     List<string> sapList = MainService.ProductBLLService.GetSAPCodeAllProduct();
     //Brand,DESC_CN,subcategory,Brand Type,Size,CasePackage,Retail_CasePrice,Specification,DESC_EN
     #region 验证所有数据的格式正确性
     for (int j = 0; j < dt_product.Rows.Count; j++)
     {
         try
         {
             Convert.ToDouble(dt_product.Rows[j][11]);
         }
         catch (Exception)
         {
             base.AlertMessage("Data format is error, 'Retail case Price'.");
             this.upLoadFile.Focus();
             return;
         }
         try
         {
             Convert.ToDouble(dt_product.Rows[j][10]);
         }
         catch (Exception)
         {
             base.AlertMessage("Data format is error, 'CasePackage'.");
             this.upLoadFile.Focus();
             return;
         }
     }
     #endregion
     Dictionary<string, DataRow> products_insert = new Dictionary<string, DataRow>();
     Dictionary<string, DataRow> products_update = new Dictionary<string, DataRow>();
     Dictionary<string, DataRow> products_error = new Dictionary<string, DataRow>();        //excel中内部重复
     Dictionary<string, DataRow> products_sap = new Dictionary<string, DataRow>();           //与数据库现有数据重复
     bool isInsert = true;
     foreach (DataRow row in dt_product.Rows)
     {
         isInsert = true;
         if (!string.IsNullOrEmpty(row[0].ToString().Trim().ToLower()))
         {
             isInsert = false;
         }
         ProductEntity entity = convertToEntity(row);
         string key = entity.Brand + entity.DescCn + entity.Subcategory + entity.Brandtype + entity.ProductSize + entity.Product_SAP_Code;
         if (isInsert)
         {
             if (sapList.Contains(entity.Product_SAP_Code + entity.Brandtype))
             {
                 products_sap.Add(key, row);
                 continue;
             }
             if (products_insert.ContainsKey(key))
             {
                 row[0] = "";
                 products_error.Add(key + "_1", products_insert[key]);
                 products_insert.Remove(key);
                 products_error.Add(key + "_2", row);
                 continue;
             }
             row[0] = Guid.NewGuid().ToString();
             products_insert.Add(key, row);
             continue;
         }
         else if (products_update.ContainsKey(key))
         {
             if (!sapList.Contains(entity.Product_SAP_Code + entity.Brandtype))
             {
                 products_sap.Add(key, row);
                 continue;
             }
             products_error.Add(key + "_1", products_update[key]);
             products_update.Remove(key);
             products_error.Add(key + "_2", row);
             continue;
         }
         products_update.Add(key, row);
     }
     total_valid_product = dt_product.Rows.Count;
     if (total_valid_product <= 0)
     {
         base.AlertMessage("All products is invalid. Please check, try it later.");
         return;
     }
     foreach (KeyValuePair<string, DataRow> entry in products_insert)
     {
         if (MainService.ProductBLLService.Insert(convertToEntity(entry.Value)))
             total_success_import += 1;
     }
     foreach (KeyValuePair<string, DataRow> entry in products_update)
     {
         if (MainService.ProductBLLService.Update(convertToEntity(entry.Value)))
             total_success_update += 1;
     }
     int num = total_valid_product - total_success_update - total_success_import;
     bool haderror = total_success_update + total_success_import != total_valid_product;
     string msg = total_valid_product.ToString() + string.Format(" products is valid, and {0} item import successfully, {1} item updated successfully!", total_success_import.ToString(), total_success_update.ToString());
     if (haderror)
     {
         msg += "<red>" + (num).ToString() + "</red> item failed!";
         getErrorDifferentRowData(dt_product.Clone(), products_error, products_sap);
     }
     base.AlertMessage(msg);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 保存关闭弹出框
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void btnSave_Click(object sender, EventArgs e)
 {
     try
     {
         if (!VaValue())
         {
             return;
         }
         //if (this.fldUpload.FileName.Length == 0)
         //{
         //    AlertMessage("Please import raid file.");
         //    return;
         //}
         if (CheckActionNOIsExist())
         {
             return;
         }
         DataTable dt_Owner = new DataTable();
         DataTable dt_Equipment = new DataTable();
         DataTable dt_Store = new DataTable();
         if (OwnerData != null && OwnerData.Tables.Count > 0)
         {
             dt_Owner = OwnerData.Tables[0];
         }
         if (EquipmentData != null && EquipmentData.Tables.Count > 0)
         {
             dt_Equipment = EquipmentData.Tables[0];
         }
         if (StoreData != null && StoreData.Tables.Count > 0)
         {
             dt_Store = StoreData.Tables[0];
         }
         DataTable dt_Fack_Product = null;
         if (this.fldUpload.FileName.Length != 0)
         {
             BPSC.Common.ExcelTemplate excelTemplate = new BPSC.Common.ExcelTemplate("Product_Filter_Template.xls");
             bool isValid = true;
             dt_Fack_Product = excelTemplate.GetDataFromExcel(fldUpload, out isValid);
             if (!isValid)
             {
                 AlertMessage("The format of raid file is error. Please check it, try again later.");
                 return;
             }
             // data type validate
             for (int j = 0; j < dt_Fack_Product.Rows.Count; j++)
             {
                 try
                 {
                     Convert.ToInt32(dt_Fack_Product.Rows[j][10]);
                 }
                 catch (Exception ex)
                 {
                     AlertMessage("Unit item's data format error.");
                     this.fldUpload.Focus();
                     return;
                 }
             }
         }
         GetContent();
         bool isInsert = true;
         if (!string.IsNullOrEmpty(NormalRaidID))
         {
             isInsert = false;
             NormalRaidDomain.masterEntity.ModifyDate = DateTime.Now;
             NormalRaidDomain.masterEntity.ModifyUser = base.CurrentUser.SecUserEntity.UserId;
         }
         else
         {
             NormalRaidDomain.masterEntity.CreateDate = DateTime.Now;
             NormalRaidDomain.masterEntity.CreateUser = base.CurrentUser.SecUserEntity.UserId;
         }
         //
         if (!string.IsNullOrEmpty(NormalRaidID))
         {
             //Update
             isInsert = false;
             NormalRaidDomain.masterEntity.ModifyDate = DateTime.Now;
             NormalRaidDomain.masterEntity.ModifyUser = base.CurrentUser.SecUserEntity.UserId;
         }
         else
         {
             NormalRaidDomain.masterEntity.CreateDate = DateTime.Now;
             NormalRaidDomain.masterEntity.CreateUser = base.CurrentUser.SecUserEntity.UserId;
         }
         //不再使用Raid、UploadRaid、Criminal、UploadCriminal确定是否能修改,而是当月操作没有限制,其他月份需要申请
         //无论是新增还是修改,Raid、UploadRaid、Criminal、UploadCriminal都可修改
         NormalRaidDomain.masterEntity.Allowchangeraid = BPSC.Common.YesOrNo.Yes.GetHashCode().ToString();
         NormalRaidDomain.masterEntity.Allowuploadraid = BPSC.Common.YesOrNo.Yes.GetHashCode().ToString();
         NormalRaidDomain.masterEntity.Allowcriminal = BPSC.Common.YesOrNo.Yes.GetHashCode().ToString();
         NormalRaidDomain.masterEntity.Allowuploadcriminal = BPSC.Common.YesOrNo.Yes.GetHashCode().ToString();
         if (!MainService.NormalRaidBLLService.UpInformation(this.txtNo.Text.Trim(), hfdId))
         {
             AlertMessage(GetMessage("MESSAGE_FAILURE"));
             return;
         }
         if (MainService.NormalRaidBLLService.InsertNormalRaid(NormalRaidDomain.masterEntity, dt_Fack_Product, dt_Owner, dt_Equipment, dt_Store, isInsert))
         {
             AlertAndClose(GetMessage("MESSAGE_SUCCESS"));
             OwnerData = null;
             EquipmentData = null;
             StoreData = null;
         }
         else
         {
             AlertMessage(GetMessage("MESSAGE_FAILURE"));
         }
     }
     catch (Exception ex)
     {
         AlertMessage(ex.ToString());
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 保存关闭弹出框

        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (this.fldUpload.FileName.Length == 0)
            {
                AlertMessage("Please import raid file.");
                return;
            }
            if (CheckActionNOIsExist())
            {
                return;
            }

            DataTable dt_Owner = new DataTable();
            DataTable dt_Equipment = new DataTable();
            DataTable dt_Store = new DataTable();
            if (OwnerData != null)
            {
                dt_Owner = OwnerData.Tables[0];
            }
            if (EquipmentData != null)
            {
                dt_Equipment = EquipmentData.Tables[0];
            }
            if (StoreData != null)
            {
                dt_Store = StoreData.Tables[0];
            }

            BPSC.Common.ExcelTemplate excelTemplate = new BPSC.Common.ExcelTemplate("Product_Filter_Template.xls");
            bool isValid = true;
            DataTable dt_Fack_Product = excelTemplate.GetDataFromExcel(fldUpload, out isValid);
            if (!isValid)
            {
                AlertMessage("The format of raid file is error. Please check it, try again later.");
                return;
            }

            // data type validate
            for (int j = 0; j < dt_Fack_Product.Rows.Count; j++)
            {
                try
                {
                    Convert.ToInt32(dt_Fack_Product.Rows[j][9]);
                }
                catch (Exception ex)
                {
                    AlertMessage("Unit item's data format error.");
                    this.fldUpload.Focus();
                    return;
                }
            }
            bool isInsert = true;
            if (!string.IsNullOrEmpty(NormalRaidID))
            {
                isInsert = false;
            }
            GetContent();

            if (MainService.NormalRaidBLLService.InsertNormalRaid(NormalRaidDomain.masterEntity, dt_Fack_Product, dt_Owner, dt_Equipment, dt_Store, isInsert))
            {
                AlertAndClose(GetMessage("MESSAGE_SUCCESS"));
                OwnerData = null;
                EquipmentData = null;
                StoreData = null;
            }
            else
            {
                AlertMessage(GetMessage("MESSAGE_FAILURE"));
            }
        }