예제 #1
0
 public int Save(PromotionsAmountGiftQuery query)
 {
     try
     {
         return _pagDao.Save(query);
     }
     catch (Exception ex)
     {
         throw new Exception("PromotionsAmountGiftMgr-->Save-->" + ex.Message, ex);
     }
 }
예제 #2
0
 public int Update(PromotionsAmountGiftQuery query, string oldeventid)
 {
     try
     {
         return _pagDao.Update(query, oldeventid);
     }
     catch (Exception ex)
     {
         throw new Exception("PromotionsAmountGiftMgr-->Update-->" + ex.Message, ex);
     }
 }
        public HttpResponseBase GetPromoAmountGiftList()
        {
            List<PromotionsAmountGiftQuery> store = new List<PromotionsAmountGiftQuery>();
            string json = string.Empty;
            try
            {
                PromotionsAmountGiftQuery query = new PromotionsAmountGiftQuery();

                #region 獲取query對象數據
                query.Start = Convert.ToInt32(Request.Params["start"] ?? "0");

                if (!string.IsNullOrEmpty(Request.Form["limit"]))
                {
                    query.Limit = Convert.ToInt32(Request.Params["limit"]);
                }

                if (!string.IsNullOrEmpty(Request.Params["ddlSel"]))
                {
                    query.expired = Convert.ToInt32(Request.Params["ddlSel"]);
                }
                #endregion

                _promoAmountGiftMgr = new PromotionsAmountGiftMgr(mySqlConnectionString);

                int totalCount = 0;

                string type = "'G1','G2'";
                store = _promoAmountGiftMgr.Query(query, out totalCount, type);
                IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
                //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式     
                timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";

                foreach (var item in store)
                {
                    if (item.banner_image != "")
                    {
                        item.banner_image = imgServerPath + promoPath + item.banner_image;
                    }
                    else
                    {
                        item.banner_image = defaultImg;
                    }
                    if (!string.IsNullOrEmpty(item.payment_code))
                    {

                        string[] arryPayment = item.payment_code.Split(',');//將payment_code轉化為payment
                        for (int i = 0; i < arryPayment.Length; i++)
                        {
                            if (arryPayment[i] != "0")
                            {
                                _parasrcMgr = new ParameterMgr(mySqlConnectionString);
                                string nameStr = _parasrcMgr.QueryUsed(new Parametersrc { ParameterType = "payment", Used = 1, ParameterCode = arryPayment[i] }).FirstOrDefault().parameterName;
                                if (!string.IsNullOrEmpty(nameStr))
                                {
                                    item.payment += nameStr;
                                }

                                if (i != arryPayment.Length - 1)
                                {
                                    item.payment += ",";
                                }
                            }

                        }
                    }
                }

                json = "{success:true,totalCount:" + totalCount + ",data:" + JsonConvert.SerializeObject(store, Formatting.Indented, timeConverter) + "}";//返回json數據

            }
            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);
                json = "{success:true,totalCount:0,data:[]}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;


        }
예제 #4
0
 public int UpdateActive(PromotionsAmountGiftQuery model)
 {
     try
     {
         return _pagDao.UpdateActive(model);
     }
     catch (Exception ex)
     {
         throw new Exception("PromotionsAmountGiftMgr-->UpdateActive-->" + ex.Message, ex);
     }
 }
        public HttpResponseBase FirstSaveGift()
        {
            string jsonStr = String.Empty;
            try
            {
                PromotionsAmountGiftQuery model = new PromotionsAmountGiftQuery();

                #region 獲取第一步保存model的數據
                if (!string.IsNullOrEmpty(Request.Params["name"]))
                {
                    model.name = Request.Params["name"].ToString();
                }
                else
                {
                    model.name = string.Empty;
                }
                if (!string.IsNullOrEmpty(Request.Params["desc"]))
                {
                    model.event_desc = Request.Params["desc"].ToString();
                }
                else
                {
                    model.event_desc = string.Empty;
                }
                if (!string.IsNullOrEmpty(Request.Params["vendor_coverage"]))
                {
                    model.vendor_coverage = Convert.ToInt32(Request.Params["vendor_coverage"].ToString());
                }
                else
                {
                    model.vendor_coverage = 0;
                }
                if (!string.IsNullOrEmpty(Request.Params["amount"]))
                {
                    model.amount = Convert.ToInt32(Request.Params["amount"].ToString());
                }
                else
                {
                    model.amount = 0;
                }
                if (!string.IsNullOrEmpty(Request.Params["quantity"]))
                {
                    model.quantity = Convert.ToInt32(Request.Params["quantity"].ToString());
                }
                else
                {
                    model.quantity = 0;
                }
                model.kuser = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString();
                model.created = DateTime.Now;
                model.status = 0;

                if (!string.IsNullOrEmpty(Request.Params["event_type_name"]))
                {
                    //獲取event_type和category_father_id
                    _parasrcMgr = new ParameterMgr(mySqlConnectionString);
                    List<Parametersrc> fatherIdResult = _parasrcMgr.QueryUsed(new Parametersrc { ParameterType = "event_type", parameterName = Request.Params["event_type_name"].ToString(), Used = 1 });
                    if (fatherIdResult.Count == 1)
                    {
                        model.event_type = fatherIdResult[0].ParameterCode;
                        model.category_father_id = Convert.ToUInt32(fatherIdResult[0].ParameterProperty);
                    }
                }
                else
                {
                    model.event_type = string.Empty;
                    model.category_father_id = 0;
                }
                model.category_ipfrom = Request.UserHostAddress;
                #endregion

                _promoAmountGiftMgr = new PromotionsAmountGiftMgr(mySqlConnectionString);
                int id = _promoAmountGiftMgr.Save(model);
                // DataTable dt = _promoAmountGiftMgr.SelectDt(query);
                PromotionsAmountGift pag = _promoAmountGiftMgr.GetModel(id);

                string event_id = CommonFunction.GetEventId(pag.event_type.ToString(), pag.id.ToString());
                if (pag != null)
                {
                    jsonStr = "{success:true,\"id\":\"" + pag.id + "\",\"cateID\":\"" + pag.category_id + "\",\"event_type\":\"" + pag.event_type + "\",\"event_id\":\"" + event_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;

        }
        public HttpResponseBase SecondSaveGift()
        {
            string jsonStr = String.Empty;
            try
            {
                string rowID = Request.Params["rowid"].ToString();
                string isEdit = Request.Params["isEdit"].ToString();
                _promoAmountGiftMgr = new PromotionsAmountGiftMgr(mySqlConnectionString);
                PromotionsAmountGiftQuery model = new PromotionsAmountGiftQuery();
                PromotionsAmountGiftQuery OldModel = _promoAmountGiftMgr.Select(Convert.ToInt32(rowID));
                OldModel.event_id = CommonFunction.GetEventId(OldModel.event_type, OldModel.id.ToString());

                #region 獲取數據
                if (!string.IsNullOrEmpty(Request.Params["rowid"]))
                {
                    model.id = Convert.ToInt32(Request.Params["rowid"]);
                }
                else
                {
                    model.id = OldModel.id;
                }
                model.category_id = OldModel.category_id;
                if (!string.IsNullOrEmpty(Request.Params["event_name"]))
                {
                    model.name = Request.Params["event_name"].ToString();
                }
                else
                {
                    model.name = OldModel.name;
                }
                if (!string.IsNullOrEmpty(Request.Params["event_desc"]))
                {
                    model.event_desc = Request.Params["event_desc"].ToString();
                }
                else
                {
                    model.event_desc = OldModel.event_desc;
                }
                if (!string.IsNullOrEmpty(Request.Params["vendor_coverage"]))
                {
                    model.vendor_coverage = Convert.ToInt32(Request.Params["vendor_coverage"].ToString());
                }
                else
                {
                    model.vendor_coverage = 0;
                }
                if (!string.IsNullOrEmpty(Request.Params["event_type"]))
                {
                    model.event_type = Request.Params["event_type"].ToString();
                }
                else
                {
                    model.event_type = OldModel.event_type;
                }
                if (Request.Params["amount"].ToString() != "" && Request.Params["amount"].ToString() != "0")
                {
                    if (!string.IsNullOrEmpty(Request.Params["amount"]))
                    {

                        model.amount = Convert.ToInt32(Request.Params["amount"].ToString());
                        model.quantity = 0;
                    }
                    else
                    {
                        model.amount = OldModel.amount;
                        model.quantity = 0;
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(Request.Params["quantity"]))
                    {
                        model.quantity = Convert.ToInt32(Request.Params["quantity"].ToString());
                        model.amount = 0;
                    }
                    else
                    {
                        model.quantity = OldModel.quantity;
                        model.amount = 0;
                    }
                }

                if (model.id != 0)
                {
                    model.event_id = CommonFunction.GetEventId(model.event_type, model.id.ToString());
                }
                else
                {
                    model.event_id = CommonFunction.GetEventId(OldModel.event_type, OldModel.id.ToString());
                }
                #endregion

                #region 講圖片和鏈接保存至product_category中
                ////講圖片和鏈接保存至product_category中
                if (!string.IsNullOrEmpty(Request.Params["url_by"]))
                {
                    model.url_by = Convert.ToInt32(Request.Params["url_by"].ToString());
                    if (model.url_by == 1)//是專區
                    {
                        #region 上傳圖片
                        try
                        {
                            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);

                            FileManagement fileLoad = new FileManagement();

                            for (int iFile = 0; iFile < Request.Files.Count; iFile++)
                            {
                                HttpPostedFileBase file = Request.Files[iFile];
                                string fileName = string.Empty;//當前文件名

                                string fileExtention = string.Empty;//當前文件的擴展名

                                fileName = Path.GetFileName(file.FileName);

                                // string returnName = imgServerPath;
                                bool result = false;
                                string NewFileName = string.Empty;

                                fileExtention = fileName.Substring(fileName.LastIndexOf(".")).ToLower();
                                NewFileName = model.event_id + newRand + fileExtention;

                                string ServerPath = string.Empty;
                                //判斷目錄是否存在,不存在則創建
                                //string[] mapPath = new string[1];
                                //mapPath[0] = promoPath.Substring(1, promoPath.Length - 2);
                                //string s = localPromoPath.Substring(0, localPromoPath.Length - promoPath.Length + 1);
                                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 = OldModel.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
                                {
                                    //上傳
                                    result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd);
                                    if (result)//上傳成功
                                    {
                                        model.banner_image = fileName;
                                    }
                                }
                                catch (Exception)
                                {
                                    model.banner_image = OldModel.banner_image;
                                }
                            }
                        }
                        catch (Exception)
                        {
                            model.banner_image = OldModel.banner_image;
                        }

                        #endregion
                        if (!string.IsNullOrEmpty(Request.Params["banner_url"]))
                        {
                            model.category_link_url = Request.Params["banner_url"].ToString();
                        }
                        else
                        {
                            model.category_link_url = OldModel.category_link_url;
                        }

                        if (!string.IsNullOrEmpty(Request.Params["sbrand_id"].ToString()))
                        {
                            int brandTranId = 0;
                            if (int.TryParse(Request.Params["sbrand_id"].ToString(), out  brandTranId))
                            {
                                model.brand_id = Convert.ToInt32(Request.Params["sbrand_id"].ToString());
                            }
                            else
                            {
                                model.brand_id = OldModel.brand_id;
                            }
                        }
                        else
                        {
                            model.brand_id = 0;
                        }


                        if (!string.IsNullOrEmpty(Request.Params["sclass_id"].ToString()))
                        {
                            int classTranId = 0;
                            if (int.TryParse(Request.Params["sclass_id"].ToString(), out classTranId))
                            {
                                model.class_id = Convert.ToInt32(Request.Params["sclass_id"].ToString());

                            }
                            else
                            {
                                model.class_id = OldModel.class_id;
                            }
                        }
                        else
                        {
                            model.class_id = 0;
                        }

                        if (!string.IsNullOrEmpty(Request.Params["allClass"]))
                        {
                            if (Request.Params["allClass"] == "1")
                            {
                                model.quanguan = 1;
                                model.class_id = 0;
                                model.brand_id = 0;
                                model.product_id = 999999;
                            }
                            else
                            {
                                model.quanguan = 0;
                            }
                        }
                    }
                    else//非專區
                    {
                        model.category_link_url = "";
                        model.banner_image = "";

                        if (!string.IsNullOrEmpty(Request.Params["nobrand_id"].ToString()))
                        {
                            int brandTranId = 0;
                            if (int.TryParse(Request.Params["nobrand_id"].ToString(), out  brandTranId))
                            {
                                model.brand_id = Convert.ToInt32(Request.Params["nobrand_id"].ToString());
                            }
                            else
                            {
                                model.brand_id = OldModel.brand_id;
                            }
                        }
                        else
                        {
                            model.brand_id = OldModel.brand_id;
                        }


                        if (!string.IsNullOrEmpty(Request.Params["noclass_id"].ToString()))
                        {
                            int classTranId = 0;
                            if (int.TryParse(Request.Params["noclass_id"].ToString(), out classTranId))
                            {
                                model.class_id = Convert.ToInt32(Request.Params["noclass_id"].ToString());

                            }
                            else
                            {
                                model.class_id = OldModel.class_id;
                            }
                        }
                        else
                        {
                            model.class_id = OldModel.class_id;
                        }

                        if (!string.IsNullOrEmpty(Request.Params["product_id"]))
                        {
                            model.product_id = Convert.ToInt32(Request.Params["product_id"].ToString());
                        }
                        else
                        {
                            model.product_id = OldModel.product_id;
                        }

                        if (!string.IsNullOrEmpty(Request.Params["noallClass"]))
                        {
                            if (Request.Params["noallClass"] == "1" || Request.Params["noallClass"] == "true")
                            {
                                model.quanguan = 1;
                                model.class_id = 0;
                                model.brand_id = 0;
                                model.product_id = 999999;
                            }
                            else
                            {
                                model.quanguan = 0;
                            }
                        }
                    }
                }
                else
                {
                    model.url_by = OldModel.url_by;
                }
                #endregion

                #region 獲取數據
                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))
                    {
                        model.group_id = Convert.ToInt32(Request.Params["group_id"].ToString());
                    }
                    else
                    {
                        model.group_id = OldModel.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}";
                            model.condition_id = 0;
                        }
                        else
                        {
                            jsonStr = "{success:false,msg:'user_condition刪除出錯!'}";
                            this.Response.Clear();
                            this.Response.Write(jsonStr.ToString());
                            this.Response.End();
                            return this.Response;
                        }
                    }
                }
                else if (Request.Params["condition_id"].ToString() != "" && Request.Params["condition_id"].ToString() != "0")
                {
                    if (!string.IsNullOrEmpty(Request.Params["condition_id"]))//condition_id
                    {
                        model.condition_id = Convert.ToInt32(Request.Params["condition_id"].ToString());
                    }
                    else
                    {
                        model.condition_id = OldModel.condition_id;
                    }
                    model.group_id = 0;
                }


                if (!string.IsNullOrEmpty(Request.Params["count_by"]))
                {
                    model.count_by = Convert.ToInt32(Request.Params["count_by"].ToString());
                }
                else
                {
                    model.count_by = OldModel.count_by;
                }
                if (!string.IsNullOrEmpty(Request.Params["numLimit"]))
                {
                    model.num_limit = Convert.ToInt32(Request.Params["numLimit"].ToString());
                }
                else
                {
                    model.num_limit = OldModel.num_limit;
                }
                if (!string.IsNullOrEmpty(Request.Params["IsRepeat"]))
                {
                    model.repeat = Convert.ToInt32(Request.Params["IsRepeat"].ToString()) == 1 ? true : false;
                }
                else
                {
                    model.repeat = OldModel.repeat;
                }
                if (!string.IsNullOrEmpty(Request.Params["frieghttype"].ToString()))
                {
                    int typeId = 0;
                    if (int.TryParse(Request.Params["frieghttype"].ToString(), out typeId))
                    {
                        model.type = Convert.ToInt32(Request.Params["frieghttype"].ToString());
                    }
                    else
                    {
                        model.type = OldModel.type;
                    }
                }
                else
                {
                    model.type = OldModel.type;
                }
                if (!string.IsNullOrEmpty(Request.Params["devicename"]))
                {
                    model.device = Convert.ToInt32(Request.Params["devicename"].ToString());
                }
                else
                {
                    model.device = OldModel.device;
                }
                if (!string.IsNullOrEmpty(Request.Params["payment"].ToString()))
                {
                    Regex reg = new Regex("^([0-9]+,)*[0-9]+$");
                    if (reg.IsMatch(Request.Params["payment"].ToString()))
                    {
                        model.payment_code = Request.Params["payment"].ToString();
                    }
                    else
                    {
                        model.payment_code = OldModel.payment_code;
                    }
                }

                if (!string.IsNullOrEmpty(Request.Params["start_time"]))
                {
                    model.startdate = Convert.ToDateTime(Request.Params["start_time"].ToString());
                }
                else
                {
                    model.startdate = OldModel.startdate;
                }
                if (!string.IsNullOrEmpty(Request.Params["end_time"]))
                {
                    model.enddate = Convert.ToDateTime(Request.Params["end_time"].ToString());
                }
                else
                {
                    model.enddate = OldModel.enddate;
                }
                //int siteTranId = 0;
                //if (!string.IsNullOrEmpty(Request.Params["site"].ToString()) && int.TryParse(Request.Params["site"].ToString(), out siteTranId))//site
                //{
                //    model.site = Convert.ToInt32(Request.Params["site"].ToString());
                //}
                //else
                //{
                //    model.site = OldModel.site;
                //}
                if (!string.IsNullOrEmpty(Request.Params["site"].ToString()))//修改時傳的值為siteName
                {

                    Regex reg = new Regex("^([0-9]+,)*[0-9]+$");
                    if (reg.IsMatch(Request.Params["site"].ToString()))
                    {
                        model.site = Request.Params["site"].ToString();// 將站台改為多選 edit by shuangshuang0420j 20140925 10:08
                    }
                    else
                    {
                        model.site = OldModel.site;
                    }
                }
                #endregion

                #region 贈品處理
                if (!string.IsNullOrEmpty(Request.Params["gift_type"]))//gift_type when 1 then '商品' WHEN 2 then '機會' when 3  then '購物金' when 4 then '抵用券' 
                {
                    model.gift_type = Convert.ToInt32(Request.Params["gift_type"].ToString());
                    if (OldModel.gift_type == 2)
                    {
                        if (model.gift_type == 2)
                        {
                            if (OldModel.ticket_id != 0)
                            {
                                model.ticket_id = OldModel.ticket_id;
                            }
                            else
                            {
                                model.ticket_id = 0;
                            }
                            model.ticket_name = model.name;
                        }
                        else
                        {
                            if (_ptMgr.Delete(OldModel.ticket_id) > 0)
                            {
                                jsonStr = "{success:success}";
                                model.ticket_id = 0;
                                model.ticket_name = "";
                            }
                            else
                            {
                                jsonStr = "{success:false,msg:'promo_ticket刪除出錯!'}";
                                this.Response.Clear();
                                this.Response.Write(jsonStr.ToString());
                                this.Response.End();
                                return this.Response;
                            }
                        }
                    }
                    if (model.gift_type == 1)
                    {
                        model.gift_id = Convert.ToInt32(Request.Params["gift_id"].ToString());
                        model.gift_product_number = Convert.ToInt32(Request.Params["gift_product_number"].ToString());
                    }
                    else if (model.gift_type == 3)
                    {
                        model.bonus_type = 1;
                    }
                    else if (model.gift_type == 4)
                    {
                        model.bonus_type = 2;
                    }



                    if (!string.IsNullOrEmpty(Request.Params["activeNow"]))
                    {
                        model.active_now = Convert.ToInt32(Request.Params["activeNow"].ToString());
                    }
                    else
                    {
                        model.active_now = OldModel.active_now;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["startdate"]))
                    {
                        model.use_start = Convert.ToDateTime(Request.Params["startdate"].ToString());
                    }
                    else
                    {

                        model.use_start = OldModel.use_start;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["enddate"]))
                    {
                        model.use_end = Convert.ToDateTime(Request.Params["enddate"].ToString());
                    }
                    else
                    {

                        model.use_end = OldModel.use_end;
                    }
                    try
                    {
                        TimeSpan ts1 = new TimeSpan(model.use_end.Ticks);
                        TimeSpan ts2 = new TimeSpan(model.use_start.Ticks);
                        TimeSpan ts3 = ts1.Subtract(ts2).Duration();
                        int isAddDay = ts3.Hours > 0 ? 1 : 0;
                        model.valid_interval = ts3.Days + isAddDay;
                    }
                    catch
                    {
                        model.valid_interval = OldModel.valid_interval;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["bonusAmount"]))
                    {
                        model.deduct_welfare = Convert.ToUInt32(Request.Params["bonusAmount"].ToString());
                    }
                    else
                    {
                        model.deduct_welfare = OldModel.deduct_welfare;
                    }
                }
                else
                {
                    model.gift_type = OldModel.gift_type;
                    model.ticket_id = OldModel.ticket_id;
                    model.ticket_name = OldModel.ticket_name;
                }
                #endregion

                model.status = 1;


                _promoAmountGiftMgr = new PromotionsAmountGiftMgr(mySqlConnectionString);
                if (string.IsNullOrEmpty(isEdit))
                {
                    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;
                    if (_promoAmountGiftMgr.Update(model, OldModel.event_id) > 0)
                    {
                        jsonStr = "{success:true,msg:0}";//返回json數據
                    }
                    else
                    {
                        jsonStr = "{success:false,msg:0}";//返回json數據
                    }
                }
                else
                {
                    model.kuser = OldModel.kuser;
                    model.created = OldModel.created;
                    model.muser = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString();
                    model.modified = DateTime.Now;

                    if (_promoAmountGiftMgr.Update(model, OldModel.event_id) > 0)
                    {

                        jsonStr = "{success:true,msg:0}";//返回json數據
                    }
                    else
                    {
                        jsonStr = "{success:false,msg:0}";//返回json數據
                    }
                }
            }
            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:0}";
            }
            this.Response.Clear();
            this.Response.Write(jsonStr.ToString());
            this.Response.End();
            return this.Response;
        }
예제 #7
0
        //新添加
        #region 新增數據 第一步試吃/紅利抵用保存
        #region 事物新增主表數據和product_category表數據 + int Save(PromotionsAmountGiftQuery query)
        public int TryEatAndDiscountSave(PromotionsAmountGiftQuery query)
        {
            _proCateDao = new ProductCategoryDao(connStr);
            query.Replace4MySQL();
            int id = 0;
            MySqlCommand mySqlCmd = new MySqlCommand();
            MySqlConnection mySqlConn = new MySqlConnection(connStr);
            StringBuilder sbExSql = new StringBuilder();
            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;
                //#region 保存第一步到product_category 獲取prodduct_amount_fare的category_id
                ProductCategory pmodel = new ProductCategory();
                pmodel.category_name = query.name;
                pmodel.category_createdate = (uint)BLL.gigade.Common.CommonFunction.GetPHPTime();
                pmodel.category_father_id = query.category_father_id;
                pmodel.category_ipfrom = query.category_ipfrom;
                pmodel.category_display = Convert.ToUInt32(query.status);

                mySqlCmd.CommandText = _proCateDao.SaveCategory(pmodel);
                sbExSql.Append(mySqlCmd.CommandText);
                query.category_id = Convert.ToUInt32(mySqlCmd.ExecuteScalar());

                //修改表serial
                Serial serial = new Serial();
                serial.Serial_id = 12;
                serial.Serial_Value = Convert.ToUInt32(query.category_id);
                mySqlCmd.CommandText = _serialDao.UpdateAutoIncreament(serial);
                sbExSql.Append(mySqlCmd.CommandText);
                id = Convert.ToInt32(mySqlCmd.ExecuteScalar());
                //#endregion

                PromotionsAmountGift pgmodel = new PromotionsAmountGift();
                pgmodel.name = query.name;
                pgmodel.event_desc = query.event_desc;
                pgmodel.vendor_coverage = query.vendor_coverage;
                pgmodel.event_type = query.event_type;
                pgmodel.freight_price = query.freight_price;
                pgmodel.kuser = query.kuser;
                pgmodel.created = query.created;
                pgmodel.status = query.status;
                pgmodel.category_id = query.category_id;
                pgmodel.dividend = query.dividend;
                mySqlCmd.CommandText = TryEatAndDiscountSavePromoGift(pgmodel);
                sbExSql.Append(mySqlCmd.CommandText);
                id = Convert.ToInt32(mySqlCmd.ExecuteScalar());
                mySqlCmd.Transaction.Commit();
            }
            catch (Exception ex)
            {
                mySqlCmd.Transaction.Rollback();
                throw new Exception("PromotionsAmountGiftDao-->Save-->" + ex.Message + sbExSql.ToString(), ex);
            }
            finally
            {
                if (mySqlConn != null && mySqlConn.State == System.Data.ConnectionState.Open)
                {
                    mySqlConn.Close();
                }
            }
            return id;
        }
예제 #8
0
        /// <summary>
        /// 根據gift對象 更新啟用狀態
        /// </summary>
        /// <param name="model"> PromotionsAmountGiftQuery 對象</param>
        /// <returns>執行結果</returns>
        public int UpdateActive(PromotionsAmountGiftQuery model)
        {
            int i = 0;
            //聲明鏈接數據庫
            MySqlCommand mySqlCmd = new MySqlCommand();
            MySqlConnection mySqlConn = new MySqlConnection(connStr);
            StringBuilder sql = new StringBuilder();
            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;
                StringBuilder Sql = new StringBuilder();

                Sql.Append(_prodpromoDao.DeleteProdProm(model.event_id));//先刪除在新增當active=0時照樣刪除只有active=1時才新增
                if (model.active == 1)
                {
                    ProductCategorySet querySet = new ProductCategorySet();
                    querySet.Category_Id = Convert.ToUInt32(model.category_id);
                    ProductCategorySetDao _setDao = new ProductCategorySetDao(connStr);
                    List<ProductCategorySet> lmodelSet = _setDao.Query(querySet);

                    foreach (ProductCategorySet item in lmodelSet)
                    {
                        ProdPromo ppmodel = new ProdPromo();
                        ppmodel.product_id = Convert.ToInt32(item.Product_Id);
                        ppmodel.event_id = model.event_id;
                        ppmodel.event_type = model.event_type;
                        ppmodel.event_desc = model.event_desc;
                        ppmodel.start = model.startdate;
                        ppmodel.end = model.enddate;
                        ppmodel.page_url = model.category_link_url;
                        if (model.group_id == 0 && model.condition_id == 0)
                        {
                            ppmodel.user_specified = 0;
                        }
                        else
                        {
                            ppmodel.user_specified = 1;
                        }
                        ppmodel.kuser = model.muser;
                        ppmodel.kdate = model.modified;
                        ppmodel.muser = model.muser;
                        ppmodel.mdate = model.modified;
                        ppmodel.status = model.status;
                        Sql.Append(_prodpromoDao.SaveProdProm(ppmodel));
                    }
                }

                //PromotionsAmountGiftDao proAmoGiftDao = new PromotionsAmountGiftDao(connStr);
                Sql.Append(UpdatePromoGift(model));
                mySqlCmd.CommandText = Sql.ToString();
                sql.Append(mySqlCmd.CommandText);
                i += mySqlCmd.ExecuteNonQuery();
                mySqlCmd.Transaction.Commit();
            }
            catch (Exception ex)
            {
                mySqlCmd.Transaction.Rollback();
                throw new Exception("PromotionsAmountGiftDao-->UpdateActive-->" + ex.Message + sql.ToString(), ex);
            }
            finally
            {
                if (mySqlConn != null && mySqlConn.State == System.Data.ConnectionState.Open)
                {
                    mySqlConn.Close();
                }
            }
            return i;
        }
예제 #9
0
        /// <summary>
        /// 刪除列表頁數據
        /// </summary>
        /// <param name="id"></param>
        /// <param name="event_id">event_type+id</param>
        /// <returns>執行結果</returns>
        public int Delete(int id, string event_id)
        {
            int i = 0;
            MySqlCommand mySqlCmd = new MySqlCommand();
            MySqlConnection mySqlConn = new MySqlConnection(connStr);
            string sqlSW = "";
            StringBuilder sql = new StringBuilder();
            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;

                PromotionsAmountGiftQuery query = new PromotionsAmountGiftQuery();
                if (id != 0)
                {
                    //更新主表數據 設置status為0
                    query = Select(id);

                    //更新表promo_ticket 軟刪除
                    //sqlSW += _promAmountReduceDao.Delete(querys.id);
                    if (query.ticket_id != 0)
                    {
                        sqlSW += _ptDao.DeleteSql(query.ticket_id);
                    }
                    //軟刪除表user_conditon
                    if (query.condition_id != 0)
                    {
                        sqlSW += _usconDao.DeleteUserCon(query.condition_id);
                    }

                    //軟刪除product_cate 和 product_category_set 
                    if (query.category_id != 0)
                    {
                        sqlSW += _proCateDao.Delete(query.category_id);

                        sqlSW += _prodCategSetDao.DelProdCateSet(query.category_id);
                    }
                    //軟刪除promo_all 和 prod_promo
                    if (!string.IsNullOrEmpty(event_id))
                    {
                        sqlSW += _prodpromoDao.DelProdProm(event_id);
                        sqlSW += _proAllDao.DeletePromAll(event_id);
                    }
                    //軟刪除主表
                    sqlSW += DeletePromoGift(query.id);
                }
                mySqlCmd.CommandText = sqlSW.ToString();
                sql.Append(mySqlCmd.CommandText);
                i += mySqlCmd.ExecuteNonQuery();
                mySqlCmd.Transaction.Commit();
            }
            catch (Exception ex)
            {
                mySqlCmd.Transaction.Rollback();
                throw new Exception("PromotionsAmountGiftDao-->Delete-->" + ex.Message + sql.ToString(), ex);
            }
            finally
            {
                if (mySqlConn != null && mySqlConn.State == System.Data.ConnectionState.Open)
                {
                    mySqlConn.Close();
                }
            }
            return i;
        }
예제 #10
0
 /// <summary>
 /// 更新主表數據
 /// </summary>
 /// <param name="model">PromotionsAmountGiftQuery對象</param>
 /// <returns>更新主表數據的sql語句</returns>
 public string UpdatePromoGift(PromotionsAmountGiftQuery model)
 {
     model.Replace4MySQL();
     StringBuilder sql = new StringBuilder();
     try
     {
         sql.AppendFormat("update  promotions_amount_gift  set ");
         sql.AppendFormat("name='{0}',group_id='{1}',class_id='{2}',brand_id='{3}',category_id='{4}',", model.name, model.group_id, model.class_id, model.brand_id, model.category_id);
         sql.AppendFormat("product_id='{0}',  type='{1}',  amount='{2}' ,  quantity='{3}' , `repeat` ='{4}' ,  gift_id='{5}' , ", model.product_id, model.type, model.amount, model.quantity, model.repeat ? '1' : '0', model.gift_id);
         sql.AppendFormat("deduct_welfare='{0}' , bonus_type='{1}' , mailer_id='{2}' , start='{3}' , end='{4}' , created='{5}' , ", model.deduct_welfare, model.bonus_type, model.mailer_id, CommonFunction.DateTimeToString(model.startdate), CommonFunction.DateTimeToString(model.enddate), CommonFunction.DateTimeToString(model.created));
         sql.AppendFormat(" modified='{0}' , active='{1}' , event_desc='{2}' , event_type='{3}' , condition_id='{4}' , device='{5}' , ", CommonFunction.DateTimeToString(model.modified), model.active, model.event_desc, model.event_type, model.condition_id, model.device);
         sql.AppendFormat(" payment_code='{0}' , gift_type='{1}' , ticket_id='{2}' , ticket_name='{3}' , count_by='{4}' , number='{5}' , num_limit='{6}' , active_now='{7}' , valid_interval='{8}' ,  ", model.payment_code, model.gift_type, model.ticket_id, model.ticket_name, model.count_by, model.number, model.num_limit, model.active_now, model.valid_interval);
         sql.AppendFormat("use_start='{0}' , use_end ='{1}',  muser='******'  , site='{3}', url_by='{4}' , status='{5}',vendor_coverage='{6}',gift_product_number='{7}'", CommonFunction.DateTimeToString(model.use_start), CommonFunction.DateTimeToString(model.use_end), model.muser, model.site, model.url_by, model.status, model.vendor_coverage, model.gift_product_number);
         sql.AppendFormat("  where id='{0}';", model.id);
         return sql.ToString();
     }
     catch (Exception ex)
     {
         throw new Exception("PromotionsAmountGiftDao-->UpdatePromoGift-->" + ex.Message + sql.ToString(), ex);
     }
 }
예제 #11
0
        /// <summary>
        /// 第二步保存和編輯數據  更新主表和product_category數據 處理product_category_set prod_promo prom_all prom_ticket
        /// </summary>
        /// <param name="model">query對象</param>
        /// <param name="oldeventid">原來的event_type</param>
        /// <returns>執行結果</returns>
        public int Update(PromotionsAmountGiftQuery model, string oldeventid)
        {
            //實例dao對象
            _ptDao = new PromoTicketDao(connStr);
            _proCateDao = new ProductCategoryDao(connStr);
            _prodCategSetDao = new ProductCategorySetDao(connStr);
            _prodpromoDao = new ProdPromoDao(connStr);

            int i = 0;
            //聲明鏈接數據庫
            MySqlCommand mySqlCmd = new MySqlCommand();
            MySqlConnection mySqlConn = new MySqlConnection(connStr);
            StringBuilder sbExSql = new StringBuilder();
            try
            {
                model.Replace4MySQL();
                if (mySqlConn != null && mySqlConn.State == System.Data.ConnectionState.Closed)
                {
                    mySqlConn.Open();
                }
                mySqlCmd.Connection = mySqlConn;
                //開啟事物
                mySqlCmd.Transaction = mySqlConn.BeginTransaction();
                mySqlCmd.CommandType = System.Data.CommandType.Text;
                StringBuilder Sql = new StringBuilder();


                mySqlCmd.CommandText = _prodpromoDao.DeleteProdProm(oldeventid);
                sbExSql.Append(mySqlCmd.CommandText);
                mySqlCmd.ExecuteNonQuery();//刪除ProdPromo

                mySqlCmd.CommandText = _proAllDao.DelPromAll(oldeventid);
                sbExSql.Append(mySqlCmd.CommandText);
                mySqlCmd.ExecuteNonQuery();//刪除PromAll


                //Sql.AppendFormat(_prodpromoDao.DeleteProdProm(model.event_id));
                //處理表product_category_set 和 prod_promo
                if (model.quanguan == 1)
                {
                    //根據category_id刪除product_category_set表數據
                    Sql.Clear();
                    Sql.AppendFormat(_prodCategSetDao.DeleteProdCateSet(model.category_id));
                    ////添加product_category_set數據
                    ProductCategorySet pcs = new ProductCategorySet();
                    pcs.Category_Id = model.category_id;
                    pcs.Product_Id = 999999;
                    pcs.Brand_Id = 0;
                    Sql.AppendFormat(_prodCategSetDao.SaveProdCategorySet(pcs));
                    mySqlCmd.CommandText = Sql.ToString();
                    sbExSql.Append(mySqlCmd.CommandText);
                    mySqlCmd.ExecuteNonQuery();//添加全館商品到PromAll
                    Sql.Clear();

                }
                else//非全館
                {
                    //刪除全館商品
                    ProductCategorySet qgSet = new ProductCategorySet();
                    qgSet.Category_Id = model.category_id;
                    qgSet.Product_Id = 999999;//全館商品刪除 id=999999
                    //根據category_id刪除product_category_set表數據
                    mySqlCmd.CommandText = _prodCategSetDao.DelProdCateSetByCPID(qgSet);
                    sbExSql.Append(mySqlCmd.CommandText);
                    mySqlCmd.ExecuteNonQuery();//刪除全館別商品999999

                    if (model.url_by == 1)//專區時 add by shuangshuang0420j 20150309 11:25 區分專區和非專區
                    {
                        //  Sql.Append(_prodpromoDao.DeleteProdProm(oldeventid));//修改前先刪除已有的數據
                        //選擇brand_id 的時候處理prod_promo  和product_category_set
                        if (model.brand_id != 0)//當品牌不為空時講該品牌下的所有商品加入set表
                        {

                            Sql.Append(_prodCategSetDao.DeleteProdCateSet(model.category_id));
                            mySqlCmd.CommandText = Sql.ToString();
                            sbExSql.Append(mySqlCmd.CommandText);
                            mySqlCmd.ExecuteNonQuery();
                            Sql.Clear();
                            QueryVerifyCondition query = new QueryVerifyCondition();
                            query.brand_id = Convert.ToUInt32(model.brand_id);
                            query.site_ids = model.site.ToString();
                            PromotionsMaintainDao _promoMainDao = new PromotionsMaintainDao(connStr);
                            int totalCount = 0;
                            List<QueryandVerifyCustom> qvcList = _promoMainDao.QueryByProSite(query, out totalCount, 0);

                            List<uint> categorysetProduct = new List<uint>();
                            foreach (QueryandVerifyCustom qvcItem in qvcList)
                            {
                                if (categorysetProduct.Contains(qvcItem.product_id))
                                {
                                    continue;
                                }
                                categorysetProduct.Add(qvcItem.product_id);
                                ProductCategorySet pcsModel = new ProductCategorySet();
                                pcsModel.Product_Id = qvcItem.product_id;
                                pcsModel.Brand_Id = Convert.ToUInt32(model.brand_id);
                                pcsModel.Category_Id = model.category_id;
                                Sql.Append(_prodCategSetDao.SaveProdCategorySet(pcsModel));
                            }
                            if (!string.IsNullOrEmpty(Sql.ToString()))
                            {
                                mySqlCmd.CommandText = Sql.ToString();
                                sbExSql.Append(mySqlCmd.CommandText);
                                mySqlCmd.ExecuteNonQuery();
                                Sql.Clear();
                            }
                        }
                    }
                    else
                    { //非專區時
                        mySqlCmd.CommandText = _prodCategSetDao.DeleteProdCateSet(model.category_id);
                        sbExSql.Append(mySqlCmd.CommandText);
                        mySqlCmd.ExecuteNonQuery();
                        if (model.product_id != 0)
                        {
                            ProductCategorySet pcsModel = new ProductCategorySet();
                            pcsModel.Product_Id = Convert.ToUInt32(model.product_id);
                            pcsModel.Brand_Id = _prodDao.Query(new Product { Product_Id = pcsModel.Product_Id }).FirstOrDefault().Brand_Id;
                            pcsModel.Category_Id = model.category_id;
                            //Sql.Append(_prodCategSetDao.SaveProdCategorySet(pcsModel));
                            mySqlCmd.CommandText = _prodCategSetDao.SaveProdCategorySet(pcsModel);
                            sbExSql.Append(mySqlCmd.CommandText);
                            mySqlCmd.ExecuteNonQuery();//新增商品關係
                        }
                        else if (model.brand_id != 0)
                        {
                            QueryVerifyCondition query = new QueryVerifyCondition();
                            query.brand_id = Convert.ToUInt32(model.brand_id);
                            query.site_ids = model.site;
                            query.combination = 1;
                            int totalCount = 0;
                            List<QueryandVerifyCustom> qvcList = _promoMainDao.QueryByProSite(query, out totalCount, 0);
                            foreach (QueryandVerifyCustom qvcItem in qvcList)
                            {
                                ProductCategorySet pcsModel = new ProductCategorySet();
                                pcsModel.Product_Id = qvcItem.product_id;
                                pcsModel.Brand_Id = Convert.ToUInt32(model.brand_id);
                                pcsModel.Category_Id = model.category_id;
                                // arryList.Add(_prodCategSet.SaveProdCategorySet(pcsModel));
                                mySqlCmd.CommandText = _prodCategSetDao.SaveProdCategorySet(pcsModel);
                                sbExSql.Append(mySqlCmd.CommandText);
                                mySqlCmd.ExecuteNonQuery();//新增商品關係
                            }
                        }
                        else if (model.class_id != 0)
                        {
                            List<VendorBrand> brandIDs = _vendorBrandDao.GetClassBrandList(new VendorBrand { }, (uint)model.class_id);
                            foreach (VendorBrand item in brandIDs)
                            {
                                QueryVerifyCondition query = new QueryVerifyCondition();
                                query.brand_id = item.Brand_Id;
                                query.site_ids = model.site;
                                query.combination = 1;
                                int totalCount = 0;
                                List<QueryandVerifyCustom> qvcList = _promoMainDao.QueryByProSite(query, out totalCount, 0);
                                foreach (QueryandVerifyCustom qvcItem in qvcList)
                                {
                                    ProductCategorySet pcsModel = new ProductCategorySet();
                                    pcsModel.Product_Id = qvcItem.product_id;
                                    pcsModel.Brand_Id = Convert.ToUInt32(model.brand_id);
                                    pcsModel.Category_Id = model.category_id;
                                    //arryList.Add(_prodCategSet.SaveProdCategorySet(pcsModel));
                                    mySqlCmd.CommandText = _prodCategSetDao.SaveProdCategorySet(pcsModel);
                                    sbExSql.Append(mySqlCmd.CommandText);
                                    mySqlCmd.ExecuteNonQuery();//新增商品關係
                                }
                            }
                        }
                    }
                }
                //新增表promo_all數據
                //  Sql.AppendFormat(_proAllDao.DelPromAll(model.event_id));
                Sql.Clear();
                PromoAll pamodel = new PromoAll();
                pamodel.event_id = model.event_id;
                pamodel.product_id = model.product_id;
                pamodel.class_id = model.class_id;
                pamodel.brand_id = model.brand_id;
                pamodel.event_type = model.event_type;
                pamodel.category_id = Convert.ToInt32(model.category_id);
                pamodel.startTime = model.startdate;
                pamodel.end = model.enddate;
                pamodel.status = model.status;
                pamodel.kuser = model.kuser;
                pamodel.kdate = model.created;
                pamodel.muser = model.muser;
                pamodel.mdate = model.modified;
                Sql.AppendFormat(_proAllDao.SavePromAll(pamodel));
                //更新product_category表數據
                ProductCategory pcmodel = _proCateDao.GetModelById(Convert.ToUInt32(model.category_id));
                pcmodel.category_id = Convert.ToUInt32(model.category_id);
                pcmodel.banner_image = model.banner_image;
                pcmodel.category_link_url = model.category_link_url;
                pcmodel.category_display = Convert.ToUInt32(model.status);
                Sql.AppendFormat(_proCateDao.UpdateProdCate(pcmodel));

                //判斷送禮類型是否是機會,若是的話 修改編輯表promo_ticket
                if (model.gift_type == 2)
                { //新增數據到promo_ticket                   
                    if (model.ticket_id == 0)
                    {
                        PromoTicket pt = new PromoTicket();
                        pt.ticket_name = model.name;//機會name
                        pt.event_id = model.event_id;
                        pt.event_type = model.event_type;
                        pt.active_now = model.active_now;
                        pt.use_start = model.use_start;
                        pt.use_end = model.use_end;
                        pt.kuser = model.kuser;
                        pt.kdate = model.created;
                        pt.muser = model.muser;
                        pt.mdate = model.modified;
                        pt.valid_interval = model.valid_interval;
                        pt.status = model.status;
                        model.ticket_id = _ptDao.Save(pt);
                        model.ticket_name = pt.ticket_name;
                    }
                    //更新表數據
                    else
                    {
                        PromoTicket pt = _ptDao.Query(model.ticket_id);

                        pt.kuser = model.kuser;
                        pt.kdate = model.created;
                        pt.muser = model.muser;
                        pt.mdate = model.modified;

                        pt.ticket_name = model.ticket_name;//機會name
                        pt.event_id = model.event_id;
                        pt.event_type = model.event_type;
                        pt.active_now = model.active_now;
                        pt.use_start = model.use_start;
                        pt.use_end = model.use_end;
                        pt.valid_interval = model.valid_interval;
                        pt.status = model.status;

                        Sql.AppendFormat(_ptDao.UpdateSql(pt));
                    }
                }
                else if (model.ticket_id != 0)
                {
                    Sql.AppendFormat(_ptDao.DeleteSql(model.ticket_id));
                }


                if (model.gift_type == 3 || model.gift_type == 4)//當贈送購物金或抵用券時產生gift_id
                {
                    PromotionsAmountGiftCustom promGiftCustom = new PromotionsAmountGiftCustom();

                    promGiftCustom.product_id = 5669;
                    promGiftCustom.spec_type = 1;
                    promGiftCustom.spec_name = model.name;

                    promGiftCustom.Item_Alarm = 5;
                    promGiftCustom.Item_Stock = 9999;



                    mySqlCmd.CommandText = SaveProSpec(promGiftCustom);
                    uint specId = Convert.ToUInt32(mySqlCmd.ExecuteScalar());

                    promGiftCustom.Spec_Id_1 = specId;

                    mySqlCmd.CommandText = SaveProItem(promGiftCustom);

                    model.gift_id = Convert.ToInt32(mySqlCmd.ExecuteScalar());


                }

                //更新主表數據
                Sql.AppendFormat(UpdatePromoGift(model));
                mySqlCmd.CommandText = Sql.ToString();
                sbExSql.Append(mySqlCmd.CommandText);
                i += mySqlCmd.ExecuteNonQuery();
                mySqlCmd.Transaction.Commit();
            }
            catch (Exception ex)
            {//事物回滾
                mySqlCmd.Transaction.Rollback();
                throw new Exception("PromotionsAmountGiftDao-->Update-->" + ex.Message + sbExSql.ToString(), ex);
            }
            finally
            {
                if (mySqlConn != null && mySqlConn.State == System.Data.ConnectionState.Open)
                {
                    mySqlConn.Close();
                }
            }
            return i;
        }