Example #1
0
        private bool DoAdd()
        {
            Model.sales model = new Model.sales();
            BLL.sales   bll   = new BLL.sales();

            string type = ddlType.SelectedValue.Trim();

            model.title     = txtTitle.Text.Trim();
            model.sub_title = txtSubTitle.Text.Trim();
            model.img_url   = txtImgUrl.Text;
            model.company   = Utils.StrToInt(company.SelectedValue, 1);
            model.type      = type;


            model.start_time = Utils.StrToDateTime(txtStartTime.Text.Trim());
            DateTime _end_time;

            if (DateTime.TryParse(txtEndTime.Text.Trim(), out _end_time))
            {
                model.end_time = _end_time;
            }
            if (cbStatus.Checked)
            {
                model.status = 1;
            }
            else
            {
                model.status = 0;
            }
            model.sort_id = Utils.StrToInt(txtSortId.Text.Trim(), 99);

            //內容摘要提取內容前255個字元
            if (string.IsNullOrEmpty(txtZhaiyao.Text.Trim()))
            {
                model.summary = Utils.DropHTML(txtContent.Value, 255);
            }
            else
            {
                model.summary = Utils.DropHTML(txtZhaiyao.Text, 255);
            }
            model.content = txtContent.Value;


            int a = bll.Add(model);


            #region 促銷組合==============
            string[] parentid = Request.Form.GetValues("goods_id");
            if (parentid != null && parentid.Length > 0)
            {
                for (int i = 0; i < parentid.Length; i++)
                {
                    new Tea.BLL.goods().UpdateField(int.Parse(parentid[i].ToString()), "yu_lock=" + a + "");
                }
            }
            #endregion


            #region 減折==============
            string[] zhe1moeny = Request.Form.GetValues("zhe1_moeny");
            string[] zhe1num   = Request.Form.GetValues("zhe1_num");
            if (zhe1moeny != null && zhe1moeny.Length > 0 && zhe1num != null && zhe1num.Length > 0)
            {
                for (int i = 0; i < zhe1moeny.Length; i++)
                {
                    try
                    {
                        Model.goods_sales model_list = new Model.goods_sales();
                        model_list.main_id   = a;
                        model_list.parent_id = int.Parse(zhe1moeny[i].ToString());
                        model_list.goods_id  = int.Parse(zhe1num[i].ToString());

                        bll_list.Add(model_list);
                    }
                    catch (Exception eee) { }
                }
            }
            #endregion



            if (a > 0)
            {
                AddAdminLog(TWEnums.ActionEnum.Add.ToString(), "添加銷售活動:" + model.title); //記錄日誌
                return(true);
            }
            return(false);
        }
Example #2
0
        private bool DoEdit(int _id)
        {
            bool result = false;

            BLL.sales   bll   = new BLL.sales();
            Model.sales model = bll.GetModel(_id);

            string type = ddlType.SelectedValue.Trim();

            model.title     = txtTitle.Text.Trim();
            model.sub_title = txtSubTitle.Text.Trim();
            model.img_url   = txtImgUrl.Text;
            model.company   = Utils.StrToInt(company.SelectedValue, 1);
            model.type      = type;

            model.start_time = Utils.StrToDateTime(txtStartTime.Text.Trim());
            DateTime _end_time;

            if (DateTime.TryParse(txtEndTime.Text.Trim(), out _end_time))
            {
                model.end_time = _end_time;
            }
            if (cbStatus.Checked)
            {
                model.status = 1;
            }
            else
            {
                model.status = 0;
            }
            model.sort_id = Utils.StrToInt(txtSortId.Text.Trim(), 99);

            //內容摘要提取內容前255個字元
            if (string.IsNullOrEmpty(txtZhaiyao.Text.Trim()))
            {
                model.summary = Utils.DropHTML(txtContent.Value, 255);
            }
            else
            {
                model.summary = Utils.DropHTML(txtZhaiyao.Text, 255);
            }
            model.content = txtContent.Value;



            #region 促銷組合==============
            StringBuilder idListA  = new StringBuilder();
            string[]      parentid = Request.Form.GetValues("goods_id");
            if (parentid != null && parentid.Length > 0)
            {
                for (int i = 0; i < parentid.Length; i++)
                {
                    new Tea.BLL.goods().UpdateField(int.Parse(parentid[i].ToString()), "yu_lock=" + id + "");
                    idListA.Append(parentid[i].ToString() + ",");
                }
            }
            string id_listA = Utils.DelLastChar(idListA.ToString(), ",");
            if (!string.IsNullOrEmpty(id_listA))
            {
                Tea.DBUtility.DbHelperSQL.ExecuteSql("update shop_goods set yu_lock=0  where  yu_lock=" + model.id + " and id not in(select id from shop_goods where id in(" + id_listA + "))");
            }
            else
            {
                Tea.DBUtility.DbHelperSQL.ExecuteSql("update shop_goods set yu_lock=0 where yu_lock=" + model.id + "");
            }
            #endregion


            #region 減折==============
            StringBuilder idList1   = new StringBuilder();
            string[]      item1id   = Request.Form.GetValues("item1_id");
            string[]      zhe1moeny = Request.Form.GetValues("zhe1_moeny");
            string[]      zhe1num   = Request.Form.GetValues("zhe1_num");
            if (zhe1moeny != null && zhe1moeny.Length > 0 && zhe1num != null && zhe1num.Length > 0)
            {
                for (int i = 0; i < zhe1moeny.Length; i++)
                {
                    try
                    {
                        Model.goods_sales model_list = null;
                        int  id     = int.Parse(item1id[i].ToString());
                        bool update = true;
                        if (id == 0)
                        {
                            model_list = new Model.goods_sales();
                            update     = false;
                        }
                        else
                        {
                            model_list = bll_list.GetModel(id);
                        }
                        model_list.main_id   = model.id;
                        model_list.parent_id = int.Parse(zhe1moeny[i].ToString());
                        model_list.goods_id  = int.Parse(zhe1num[i].ToString());

                        if (update)
                        {
                            bll_list.Update(model_list);
                            idList1.Append(model_list.id + ",");
                        }
                        else
                        {
                            int a = bll_list.Add(model_list);
                            idList1.Append(a + ",");
                        }
                    }
                    catch (Exception eee) { }
                }
            }
            string id_list1 = Utils.DelLastChar(idList1.ToString(), ",");
            if (!string.IsNullOrEmpty(id_list1))
            {
                Tea.DBUtility.DbHelperSQL.ExecuteSql("delete from shop_goods_sales where main_id=" + model.id + " and id not in(select id from shop_goods_sales where id in(" + id_list1 + "))");
            }
            else
            {
                Tea.DBUtility.DbHelperSQL.ExecuteSql("delete from shop_goods_sales where main_id=" + model.id + "");
            }
            #endregion


            if (bll.Update(model))
            {
                AddAdminLog(TWEnums.ActionEnum.Edit.ToString(), "修改銷售活動:" + model.title); //記錄日誌
                result = true;
            }

            return(result);
        }