/// <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()); } }
protected void btnExportTemplate_Click(object sender, EventArgs e) { if (this.lib.Items.Count == 0) { AlertMessage("Select Condition"); return; } DataTable dt = MainService.ProductBLLService.GetProductDataForNormalRaid(GetProductFilters(), ActionDate); if (dt.Rows.Count == 0) { AlertMessage("No found data!"); return; } #region Wrap DataTable // Activity ,GBU,Category,Brand,"Brand Tpye",Subcategory,"SAP Item ChineseDescription","Brand Size",CasePackage,"Unit item","产品规格说明 (促销产品请列明内含的所有规格及赠品)","SAP 产品英文注释" DataTable dtWrap = new DataTable(); dtWrap.Columns.Add("Activity", typeof(string)); dtWrap.Columns.Add("GBU", typeof(string)); dtWrap.Columns.Add("Category", typeof(string)); dtWrap.Columns.Add("Brand", typeof(string)); dtWrap.Columns.Add("BrandTpye", typeof(string)); dtWrap.Columns.Add("Subcategory", typeof(string)); dtWrap.Columns.Add("DESC_CN", typeof(string)); dtWrap.Columns.Add("Product_Type", typeof(string)); dtWrap.Columns.Add("BrandSize", typeof(string)); dtWrap.Columns.Add("CasePackage", typeof(string)); dtWrap.Columns.Add("Unit_Item", typeof(string)); dtWrap.Columns.Add("Specification", typeof(string)); dtWrap.Columns.Add("DESC_EN", typeof(string)); DataRow rowWrap = null; foreach (DataRow row in dt.Rows) { rowWrap = dtWrap.NewRow(); rowWrap["Activity"] = ActivityName; rowWrap["GBU"] = row[ProductTable.C_GBU]; rowWrap["Category"] = row[ProductTable.C_Category]; rowWrap["Brand"] = row[ProductTable.C_Brand]; rowWrap["BrandTpye"] = row[ProductTable.C_BrandType]; rowWrap["Subcategory"] = row[ProductTable.C_SubCategory]; rowWrap["DESC_CN"] = row[ProductTable.C_DESC_CN]; rowWrap["Product_Type"] = row[ProductTable.C_Product_Type]; rowWrap["BrandSize"] = row[ProductTable.C_Product_Size]; rowWrap["CasePackage"] = row[ProductTable.C_Case_Package]; rowWrap["Unit_Item"] = "0"; rowWrap["Specification"] = row[ProductTable.C_Specification]; rowWrap["DESC_EN"] = row[ProductTable.C_DESC_EN]; dtWrap.Rows.Add(rowWrap); } #endregion //BPS.Common.ExcelHelper.ExportToCsvFile(this, dt, ActivityName, ActivityName + "_" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss")); BPSC.Common.ExcelTemplate excelTemplalte = new BPSC.Common.ExcelTemplate("Product_Filter_Template.xls"); excelTemplalte.Export(dtWrap, ActivityName.Replace(' ', '_') + "_" + DateTime.Now.ToString("yyyy-MM-dd") + ".xls"); }
protected void btnDownloadTemplate_Click(object sender, EventArgs e) { BPSC.Common.ExcelTemplate excelTemplalte = new BPSC.Common.ExcelTemplate("Product_Import_Template.xls"); excelTemplalte.Export("Product_Import_Template" + DateTime.Now.ToString("yyyy-MM-dd") + ".xls"); }
protected void btnErrFileClick(object sender, EventArgs e) { BPSC.Common.ExcelTemplate excelTemplalte = new BPSC.Common.ExcelTemplate("Product_Import_Template.xls"); excelTemplalte.Export(errFile.CommandArgument, "ProductErrorRowData" + DateTime.Now.ToString("yyyy-MM-dd") + ".xls"); errFile.Visible = false; }
private void getErrorDifferentRowData(DataTable dt, Dictionary<string, DataRow> products_error, Dictionary<string, DataRow> products_sap) { int index = 0; List<string> colorList = new List<string>(); foreach (KeyValuePair<string, DataRow> entry in products_error) { DataRow _row = dt.NewRow(); _row.ItemArray = entry.Value.ItemArray; dt.Rows.Add(_row); colorList.Add(index % 2 == 0 ? "green" : "yellow"); index++; } //MainService.ProductBLLService.GetDTBySAP() foreach (KeyValuePair<string, DataRow> entry in products_sap) { DataRow _row = dt.NewRow(); DataRow _r = MainService.ProductBLLService.GetDTBySAP(entry.Value[6].ToString().Trim(), entry.Value[4].ToString().Trim()); if (_r != null) { _row.ItemArray = _r.ItemArray; dt.Rows.Add(_row); colorList.Add("green"); } _row = dt.NewRow(); _row.ItemArray = entry.Value.ItemArray; dt.Rows.Add(_row); colorList.Add("red"); } BPSC.Common.ExcelTemplate excelTemplalte = new BPSC.Common.ExcelTemplate("Product_Import_Template.xls"); errFile.CommandArgument = excelTemplalte.ExportAndChangeBackColor(dt, "ProductErrorRowData" + DateTime.Now.ToString("yyyy-MM-dd") + ".xls", colorList.ToArray()); errFile.Visible = true; return; }
// 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); }
/// <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")); } }