public HttpResponseBase SavePromotionsAmountDiscountTwo() { try { string jsonStr = string.Empty; PromotionsAmountDiscount model = new PromotionsAmountDiscount(); ProductCategory pmodel = new ProductCategory(); int isTryInt = 0; #region 獲取新增時promotionamountdiscount和productcategory model值 if (!string.IsNullOrEmpty(Request.Params["pid"].ToString())) { model.id = Convert.ToInt32(Request.Params["pid"].ToString()); } PromotionsAmountDiscountCustom oldermodel = _promoAmountDiscountMgr.GetModelById(model.id); model.category_id = oldermodel.category_id; pmodel.category_id = Convert.ToUInt32(oldermodel.category_id); ProductCategory olderpcmodel = _produCateMgr.GetModelById(pmodel.category_id); PromotionsAmountDiscountCustom pacdModel = new PromotionsAmountDiscountCustom(); pacdModel.id = model.id; pacdModel.category_id = model.category_id; if (!string.IsNullOrEmpty(Request.Params["name"].ToString())) { pacdModel.name = Request.Params["name"].ToString(); } if (!string.IsNullOrEmpty(Request.Params["desc"].ToString())) { pacdModel.event_desc = Request.Params["desc"].ToString(); } if (!string.IsNullOrEmpty(Request.Params["e_type"].ToString())) { pacdModel.event_type = Request.Params["e_type"].ToString(); } pacdModel.event_id = CommonFunction.GetEventId(pacdModel.event_type.ToString(), pacdModel.id.ToString()); if (!string.IsNullOrEmpty(Request.Params["url_by"].ToString())) { pacdModel.url_by = Convert.ToInt32(Request.Params["url_by"].ToString()); } else { pacdModel.url_by = oldermodel.url_by; } if (pacdModel.url_by == 1) { #region 上傳圖片 try { if (Request.Files.Count != 0) { string path = Server.MapPath(xmlPath); SiteConfigMgr _siteConfigMgr = new SiteConfigMgr(path); SiteConfig extention_config = _siteConfigMgr.GetConfigByName("PIC_Extention_Format"); SiteConfig minValue_config = _siteConfigMgr.GetConfigByName("PIC_Length_MinValue"); SiteConfig maxValue_config = _siteConfigMgr.GetConfigByName("PIC_Length_MaxValue"); SiteConfig admin_userName = _siteConfigMgr.GetConfigByName("ADMIN_USERNAME"); SiteConfig admin_passwd = _siteConfigMgr.GetConfigByName("ADMIN_PASSWD"); //擴展名、最小值、最大值 string extention = extention_config.Value == "" ? extention_config.DefaultValue : extention_config.Value; string minValue = minValue_config.Value == "" ? minValue_config.DefaultValue : minValue_config.Value; string maxValue = maxValue_config.Value == "" ? maxValue_config.DefaultValue : maxValue_config.Value; string localPromoPath = imgLocalPath + promoPath;//圖片存儲地址 //生成隨機數,用於圖片的重命名 Random rand = new Random(); int newRand = rand.Next(1000, 9999); //獲取上傳的圖片 HttpPostedFileBase file = Request.Files[0]; string fileName = string.Empty;//當前文件名 string fileExtention = string.Empty;//當前文件的擴展名 fileName = Path.GetFileName(file.FileName); if (!string.IsNullOrEmpty(fileName)) { bool result = false; string NewFileName = string.Empty; fileExtention = fileName.Substring(fileName.LastIndexOf(".")).ToLower(); NewFileName = pacdModel.event_id + newRand + fileExtention;//圖片重命名為event_id+4位隨機數+擴展名 string ServerPath = string.Empty; //判斷目錄是否存在,不存在則創建 CreateFolder(localPromoPath.Substring(0, localPromoPath.Length - promoPath.Length + 1), promoPath.Substring(1, promoPath.Length - 2).Split('/')); // returnName += promoPath + NewFileName; fileName = NewFileName; NewFileName = localPromoPath + NewFileName;//絕對路徑 ServerPath = Server.MapPath(imgLocalServerPath + promoPath); string ErrorMsg = string.Empty; //上傳之前刪除已有的圖片 string oldFileName = olderpcmodel.banner_image; FTP ftp = new FTP(localPromoPath, ftpuser, ftppwd); List<string> tem = ftp.GetFileList(); if (tem.Contains(oldFileName)) { //FTP ftps = new FTP(localPromoPath + oldFileName, ftpuser, ftppwd); //ftps.DeleteFile(localPromoPath + oldFileName);//刪除ftp:71.159上的舊圖片 //DeletePicFile(ServerPath + oldFileName);//刪除本地圖片 } try { //上傳 FileManagement fileLoad = new FileManagement(); result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); if (result)//上傳成功 { pacdModel.banner_image = fileName; } } catch (Exception ex) { Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage(); logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name + "->fileLoad.UpLoadFile()", ex.Source, ex.Message); logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name; log.Error(logMessage); jsonStr = "{success:false,msg:'圖片上傳失敗'}"; pacdModel.banner_image = olderpcmodel.banner_image; } } else { pacdModel.banner_image = olderpcmodel.banner_image; } } } catch (Exception ex) { Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage(); logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name + "->圖片上傳失敗!", ex.Source, ex.Message); logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name; log.Error(logMessage); jsonStr = "{success:false,msg:'圖片上傳失敗'}"; pacdModel.banner_image = olderpcmodel.banner_image; } #endregion if (!string.IsNullOrEmpty(Request.Params["banner_url"].ToString()))//存連接地址 { pacdModel.category_link_url = Request.Params["banner_url"].ToString(); } else { pacdModel.category_link_url = olderpcmodel.category_link_url; } if (!string.IsNullOrEmpty(Request.Params["sbrand_id"].ToString())) { int brandTranId = 0; if (int.TryParse(Request.Params["sbrand_id"].ToString(), out brandTranId)) { pacdModel.brand_id = Convert.ToInt32(Request.Params["sbrand_id"].ToString()); } else { pacdModel.brand_id = oldermodel.brand_id; } } else { pacdModel.brand_id = 0; } if (!string.IsNullOrEmpty(Request.Params["sclass_id"].ToString())) { int classTranId = 0; if (int.TryParse(Request.Params["sclass_id"].ToString(), out classTranId)) { pacdModel.class_id = Convert.ToInt32(Request.Params["sclass_id"].ToString()); } else { pacdModel.class_id = oldermodel.class_id; } } else { pacdModel.class_id = 0; } if (Request.Params["allClass"].ToString() == "1")//是否全館 { string allClass = Request.Params["allClass"]; pacdModel.brand_id = 0; pacdModel.class_id = 0; pacdModel.product_id = 999999; } } else { //刪除上傳的圖片 //string oldFileName = olderpcmodel.banner_image; //FTP ftp = new FTP(imgLocalPath + promoPath, ftpuser, ftppwd); //List<string> tem = ftp.GetFileList(); //if (tem.Contains(oldFileName)) //{ //FTP ftps = new FTP(imgLocalPath + promoPath + oldFileName, ftpuser, ftppwd); //ftps.DeleteFile(imgLocalPath + promoPath + oldFileName);//刪除ftp:71.159上的舊圖片 // DeletePicFile(Server.MapPath(imgLocalServerPath + promoPath) + oldFileName);//刪除本地圖片 // } pacdModel.banner_image = ""; pacdModel.category_link_url = ""; if (!string.IsNullOrEmpty(Request.Params["noclass_id"]) && int.TryParse(Request.Params["noclass_id"].ToString(), out isTryInt)) { pacdModel.class_id = Convert.ToInt32(Request.Params["noclass_id"]); } else { pacdModel.class_id = 0; } if (!string.IsNullOrEmpty(Request.Params["nobrand_id"]) && int.TryParse(Request.Params["nobrand_id"].ToString(), out isTryInt)) { pacdModel.brand_id = Convert.ToInt32(Request.Params["nobrand_id"]); } else { pacdModel.brand_id =0; } if (!string.IsNullOrEmpty(Request.Params["product_id"])) { pacdModel.product_id = Convert.ToInt32(Request.Params["product_id"]); } else { pacdModel.product_id = 0; } if (!string.IsNullOrEmpty(Request.Params["no_allClass"])) { if (Request.Params["no_allClass"].ToString() == "1")//是否全館 { string allClass = Request.Params["no_allClass"]; pacdModel.brand_id = 0; pacdModel.class_id = 0; pacdModel.product_id = 999999; } } if (!string.IsNullOrEmpty(Request.Params["no_amount"])) { pacdModel.amount = Convert.ToInt32(Request.Params["no_amount"]); } else { pacdModel.amount = 0; } if (!string.IsNullOrEmpty(Request.Params["no_discount"])) { pacdModel.discount = Convert.ToInt32(Request.Params["no_discount"]); } else { pacdModel.discount = 0; } if (!string.IsNullOrEmpty(Request.Params["no_quantity"])) { pacdModel.quantity = Convert.ToInt32(Request.Params["no_quantity"]); } else { pacdModel.quantity = 0; } } if (Request.Params["group_id"].ToString() != "") { int groupTryId = 0; if (!string.IsNullOrEmpty(Request.Params["group_id"].ToString()) && int.TryParse(Request.Params["group_id"].ToString(), out groupTryId)) { pacdModel.group_id = Convert.ToInt32(Request.Params["group_id"].ToString()); } else { pacdModel.group_id = oldermodel.group_id; } if (Request.Params["condition_id"].ToString() != "" && Request.Params["condition_id"].ToString() != "0") { UserCondition uc = new UserCondition(); uc.condition_id = Convert.ToInt32(Request.Params["condition_id"]); if (_ucMgr.Delete(uc) > 0) { jsonStr = "{success:true}"; } else { jsonStr = "{success:false,msg:'user_condition delete failure!'}"; this.Response.Clear(); this.Response.Write(jsonStr.ToString()); this.Response.End(); return this.Response; } } pacdModel.condition_id = 0; } else { if (Request.Params["condition_id"].ToString() != "" && Request.Params["condition_id"].ToString() != "0") { if (!string.IsNullOrEmpty(Request.Params["condition_id"].ToString()))//condition_id { pacdModel.condition_id = Convert.ToInt32(Request.Params["condition_id"].ToString()); } else { pacdModel.condition_id = oldermodel.condition_id; } pacdModel.group_id = 0; } } if (!string.IsNullOrEmpty(Request.Params["devicename"].ToString()))//device { pacdModel.device = Convert.ToInt32(Request.Params["devicename"].ToString()); } else { pacdModel.device = oldermodel.device; } if (!string.IsNullOrEmpty(Request.Params["start_date"].ToString()))//start { pacdModel.start = Convert.ToDateTime(Request.Params["start_date"].ToString()); } else { pacdModel.start = oldermodel.date_state; } if (!string.IsNullOrEmpty(Request.Params["end_date"].ToString()))//end { pacdModel.end = Convert.ToDateTime(Request.Params["end_date"].ToString()); } else { pacdModel.end = oldermodel.date_end; } if (!string.IsNullOrEmpty(Request.Params["site"].ToString()))//修改時傳的值為siteName { string site = Request.Params["site"].ToString(); Regex reg = new Regex("^([0-9]+,)*[0-9]+$"); if (reg.IsMatch(site)) { pacdModel.site = site;// 將站台改為多選 edit by shuangshuang0420j 20140925 10:08 } else { if (site.LastIndexOf(',') == site.Length - 1)//最後一個字符為,時 { pacdModel.site = site.Substring(0, site.Length - 1); } } } if (!string.IsNullOrEmpty(Request.Params["vendor_coverage"].ToString()))//vendor_coverage { pacdModel.vendor_coverage = Convert.ToInt32(Request.Params["vendor_coverage"].ToString()); } else { pacdModel.vendor_coverage = oldermodel.vendor_coverage; } //獲取pacdModel.category_father_id List<Parametersrc> fatherIdResult = _parasrcMgr.QueryUsed(new Parametersrc { ParameterType = "event_type", Used = 1, ParameterCode = pacdModel.event_type }); if (fatherIdResult.Count > 0) { pacdModel.category_father_id = Convert.ToUInt32(fatherIdResult[0].ParameterProperty); } pacdModel.active = false; pacdModel.category_updatedate = (uint)BLL.gigade.Common.CommonFunction.GetPHPTime(); pacdModel.status = 1; pacdModel.category_ipfrom = Request.UserHostAddress; #endregion if (Request.Params["type"].ToString() == "Add") { pacdModel.kuser = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString(); pacdModel.created = DateTime.Now; pacdModel.muser = pacdModel.kuser; pacdModel.modified = pacdModel.created; return AddPromotionsAmountDiscount(pacdModel); } else { pacdModel.kuser = oldermodel.kuser; pacdModel.created = oldermodel.created; pacdModel.muser = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString(); pacdModel.modified = DateTime.Now; return UpdatePromotionsAmountDiscount(pacdModel, CommonFunction.GetEventId(oldermodel.event_type.ToString(), oldermodel.id.ToString())); } } catch (Exception ex) { Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage(); logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message); logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name; log.Error(logMessage); this.Response.Clear(); this.Response.Write("{success:false,msg:0}"); this.Response.End(); return this.Response; } }
/// <summary> /// 移除幾件幾元或幾件幾折 /// </summary> /// <returns></returns> public HttpResponseBase Deletezhe() { string jsonStr = String.Empty; PromotionsAmountDiscount query = new PromotionsAmountDiscount(); ProductCategory pmodel = new ProductCategory(); ProductCategorySet pmsmodel = new ProductCategorySet(); ProductCategorySet querypcs = new ProductCategorySet(); PromoDiscount querypd = new PromoDiscount(); PromoAll pamodel = new PromoAll(); ProdPromo ppmodel = new ProdPromo(); querypcs.Category_Id = pmodel.category_id; List<ProductCategorySet> smodel = _produCateSetMgr.Query(querypcs); if (!String.IsNullOrEmpty(Request.Params["rowid"])) { try { foreach (string rid in Request.Params["rowid"].ToString().Split('|'))//批次移除 { if (!string.IsNullOrEmpty(rid)) { //刪除peomotion_amount_discount //根據id 獲取整個model query = _promoAmountDiscountMgr.GetModelById(Convert.ToInt32(rid)); var eventid = CommonFunction.GetEventId(query.event_type, query.id.ToString()); if (_promoAmountDiscountMgr.Delete(query, eventid) > 0) { jsonStr = "{success:true}"; } else { jsonStr = "{success:false}"; } } } } catch (Exception ex) { Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage(); logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message); logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name; log.Error(logMessage); jsonStr = "{success:false}"; } } this.Response.Clear(); this.Response.Write(jsonStr); this.Response.End(); return this.Response; }
public HttpResponseBase SavePromotionsAmountDiscount() { string jsonStr = String.Empty; try { PromotionsAmountDiscount model = new PromotionsAmountDiscount(); if (!string.IsNullOrEmpty(Request.Params["name"].ToString())) { model.name = Request.Params["name"].ToString(); } if (!string.IsNullOrEmpty(Request.Params["desc"].ToString())) { model.event_desc = Request.Params["desc"].ToString(); } if (!string.IsNullOrEmpty(Request.Params["e_type"].ToString())) { model.event_type = Request.Params["e_type"].ToString(); } if (!string.IsNullOrEmpty(Request.Params["devicename"].ToString())) { model.device = Convert.ToInt32(Request.Params["devicename"].ToString()); } if (!string.IsNullOrEmpty(Request.Params["start_date"].ToString())) { model.start = Convert.ToDateTime(Request.Params["start_date"].ToString()); } if (!string.IsNullOrEmpty(Request.Params["end_date"].ToString())) { model.end = Convert.ToDateTime(Request.Params["end_date"].ToString()); } if (!string.IsNullOrEmpty(Request.Params["vendor_coverage"].ToString())) { model.vendor_coverage = Convert.ToInt32(Request.Params["vendor_coverage"].ToString()); } if (!string.IsNullOrEmpty(Request.Params["site"].ToString()))//修改時傳的值為siteName { string site = Request.Params["site"].ToString(); Regex reg = new Regex("^([0-9]+,)*[0-9]+$"); if (reg.IsMatch(site)) { model.site = site;// 將站台改為多選 edit by shuangshuang0420j 20140925 10:08 } else { model.site = site.TrimEnd(','); } } model.kuser = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString(); model.created = DateTime.Now; model.muser = model.kuser; model.modified = model.created; model.active = false;//不啟用 model.status = 0; #region 保存第一步到product_category 獲取prodduct_amount_discount的category_id ProductCategory pmodel = new ProductCategory(); pmodel.category_name = model.name; //獲取category_father_id List<Parametersrc> fatherIdResult = _parasrcMgr.QueryUsed(new Parametersrc { ParameterType = "event_type", Used = 1, ParameterCode = model.event_type }); if (fatherIdResult.Count != 0) { pmodel.category_father_id = Convert.ToUInt32(fatherIdResult[0].ParameterProperty); } else { pmodel.category_father_id = 0; } pmodel.category_createdate = (uint)BLL.gigade.Common.CommonFunction.GetPHPTime(); pmodel.category_updatedate = (uint)BLL.gigade.Common.CommonFunction.GetPHPTime(); pmodel.category_ipfrom = CommonFunction.GetIP4Address(Request.UserHostAddress.ToString());// Request.UserHostAddress; pmodel.category_display = Convert.ToUInt32(model.status); model.category_id = Convert.ToUInt32(_produCateMgr.Save(pmodel)); #endregion //修改表serial Serial serial = new Serial(); serial.Serial_id = 12; serial.Serial_Value = Convert.ToUInt32(model.category_id); if (_seriMgr.Update(serial) > 0) { System.Data.DataTable query = _promoAmountDiscountMgr.Save(model); if (query != null) { jsonStr = "{success:true,id:" + query.Rows[0]["id"] + ",cateID:" + query.Rows[0]["category_id"] + "}"; } } else { jsonStr = "{success:false }"; } } catch (Exception ex) { Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage(); logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message); logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name; log.Error(logMessage); jsonStr = "{success:false}"; } this.Response.Clear(); this.Response.Write(jsonStr.ToString()); this.Response.End(); return this.Response; }
/// <summary> /// 刪除數據 /// </summary> /// <param name="query">參數</param> /// <param name="event_id">項目編號</param> /// <returns>返回刪除成功的數量</returns> public int Delete(Model.PromotionsAmountDiscount query, string event_id) { int i = 0; MySqlCommand mySqlCmd = new MySqlCommand(); MySqlConnection mySqlConn = new MySqlConnection(connStr); try { if (mySqlConn != null && mySqlConn.State == System.Data.ConnectionState.Closed) { mySqlConn.Open(); } mySqlCmd.Connection = mySqlConn; mySqlCmd.Transaction = mySqlConn.BeginTransaction(); mySqlCmd.CommandType = System.Data.CommandType.Text; PromotionsAmountDiscount model = new PromotionsAmountDiscount(); model = GetModelById(int.Parse(query.id.ToString())); string sqlDel = ""; sqlDel += _proCateDao.Delete(model.category_id); sqlDel += _prodCategSet.DelProdCateSet(model.category_id); sqlDel += _prodpromoDao.DelProdProm(event_id); sqlDel += _proAllDao.DeletePromAll(event_id); sqlDel += _usconDao.DeleteUserCon(query.condition_id); sqlDel += _promoDisDao.DeleteStr(event_id); mySqlCmd.CommandText = sqlDel + string.Format(" update promotions_amount_discount set status=0 where id={0} ;", query.id); i += mySqlCmd.ExecuteNonQuery(); mySqlCmd.Transaction.Commit(); } catch (Exception ex) { mySqlCmd.Transaction.Rollback(); throw new Exception("PromotionsAmountDiscountDao-->Delete-->" + ex.Message + mySqlCmd.CommandText, ex); } finally { if (mySqlConn != null && mySqlConn.State == System.Data.ConnectionState.Open) { mySqlConn.Close(); } } return i; }