Ejemplo n.º 1
0
        /// <summary>
        /// 商品录入
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            int id = MyCommFun.Str2Int(hidid.Value);

            #region 商品基本信息
            string strErr = "";

            if (this.txtproductName.Text.Trim().Length == 0)
            {
                strErr += "商品名称不能为空!\\n";
            }

            if (!MyCommFun.isDecimal(txtcostPrice.Text))
            {
                strErr += "成本格式错误!\\n";
            }
            if (!MyCommFun.isDecimal(txtmarketPrice.Text))
            {
                strErr += "市场价格式错误!\\n";
            }
            if (!MyCommFun.isDecimal(txtsalePrice.Text))
            {
                strErr += "销售价格式错误!\\n";
            }
            if (!MyCommFun.isNumber(txtstock.Text))
            {
                strErr += "库存格式错误!\\n";
            }

            if (!MyCommFun.isNumber(txtsort_id.Text))
            {
                strErr += "排序号格式错误!\\n";
            }


            if (strErr != "")
            {
                JscriptMsg(strErr, "back", "Error");
                return;
            }

            Model.wx_userweixin weixin = GetWeiXinCode();


            int    wid        = weixin.id;
            int    categoryId = int.Parse(this.ddlCategoryId.SelectedItem.Value);
            int    catalogId  = int.Parse(this.ddlCatalog.SelectedItem.Value);
            int    brandId    = 0;
            string sku        = this.txtsku.Text;//货号
            if (sku.Trim() == "")
            {
                sku = Utils.Number(8, true);
            }
            string  productName = this.txtproductName.Text;
            string  shortDesc   = this.txtshortDesc.Text;
            string  unit        = "";
            decimal weight      = 0;
            string  description = this.txtdescription.Value;
            //string seo_title = this.txtseo_title.Text;
            //string seo_keywords = this.txtseo_keywords.Text;
            //string seo_description = this.txtseo_description.Text;
            //string focusImgUrl = this.txtfocusImgUrl.Text;
            //string thumbnailsUrll = this.txtthumbnailsUrll.Text;

            bool recommended  = false;
            bool latest       = false;
            bool hotsale      = false;
            bool specialOffer = false;

            int count = cblActionType.Items.Count;

            for (int i = 0; i < count; i++)
            {
                if (cblActionType.Items[i].Selected)
                {
                    if (cblActionType.Items[i].Value == "latest")
                    {
                        latest = true;
                    }
                    else if (cblActionType.Items[i].Value == "hotsale")
                    {
                        hotsale = true;
                    }
                    else if (cblActionType.Items[i].Value == "recommended")
                    {
                        recommended = true;
                    }
                    else if (cblActionType.Items[i].Value == "specialOffer")
                    {
                        specialOffer = true;
                    }
                }
            }

            decimal costPrice   = decimal.Parse(this.txtcostPrice.Text);
            decimal marketPrice = decimal.Parse(this.txtmarketPrice.Text);
            decimal salePrice   = decimal.Parse(this.txtsalePrice.Text);

            bool upselling = true;//上架
            if (radType.SelectedItem.Value == "2")
            {
                upselling = false;
            }
            int      stock       = int.Parse(this.txtstock.Text);
            DateTime addDate     = DateTime.Now;
            int      vistiCounts = 0;
            int      sort_id     = int.Parse(this.txtsort_id.Text);
            //DateTime productionDate = DateTime.Parse(this.txtproductionDate.Text);
            //DateTime ExpiryEndDate = DateTime.Parse(this.txtExpiryEndDate.Text);
            DateTime updateDate = DateTime.Now;

            WechatBuilder.Model.wx_shop_product model = spBll.GetModel(id);
            //  model.wid = wid;
            model.categoryId  = categoryId;
            model.brandId     = brandId;
            model.sku         = sku;
            model.productName = productName;
            model.shortDesc   = shortDesc;
            model.unit        = unit;
            model.weight      = weight;
            model.description = description;
            //model.seo_title = seo_title;
            //model.seo_keywords = seo_keywords;
            //model.seo_description = seo_description;
            //model.focusImgUrl = focusImgUrl;
            //model.thumbnailsUrll = thumbnailsUrll;
            model.recommended  = recommended;
            model.latest       = latest;
            model.hotsale      = hotsale;
            model.specialOffer = specialOffer;
            model.costPrice    = costPrice;
            model.marketPrice  = marketPrice;
            model.salePrice    = salePrice;
            model.upselling    = upselling;
            model.stock        = stock;
            model.addDate      = addDate;
            model.vistiCounts  = vistiCounts;
            model.sort_id      = sort_id;
            //model.productionDate = productionDate;
            //model.ExpiryEndDate = ExpiryEndDate;
            model.updateDate = updateDate;
            model.catalogId  = catalogId;
            #endregion

            #region 保存相册====================
            //检查是否有自定义图片
            if (model.albums != null)
            {
                model.albums.Clear();
            }
            string[] albumArr  = Request.Form.GetValues("hid_photo_name");
            string[] remarkArr = Request.Form.GetValues("hid_photo_remark");
            if (albumArr != null)
            {
                List <Model.wx_shop_albums> ls = new List <Model.wx_shop_albums>();
                for (int i = 0; i < albumArr.Length; i++)
                {
                    string[] imgArr = albumArr[i].Split('|');
                    int      img_id = Utils.StrToInt(imgArr[0], 0);
                    if (imgArr.Length == 3)
                    {
                        if (!string.IsNullOrEmpty(remarkArr[i]))
                        {
                            ls.Add(new Model.wx_shop_albums {
                                id = img_id, productId = id, original_path = imgArr[1], thumb_path = imgArr[2], remark = remarkArr[i]
                            });
                        }
                        else
                        {
                            ls.Add(new Model.wx_shop_albums {
                                id = img_id, productId = id, original_path = imgArr[1], thumb_path = imgArr[2]
                            });
                        }
                    }
                }
                model.albums = ls;
            }

            #endregion

            //属性和sku配件列表
            model.attrs   = AddAttr();
            model.skulist = AddSku();


            WechatBuilder.BLL.wx_shop_product bll = new WechatBuilder.BLL.wx_shop_product();
            bll.Update(model);
            AddAdminLog(MXEnums.ActionEnum.Edit.ToString(), "编辑商品信息,商品信息主键id:" + id); //记录日志

            string frompage = MyCommFun.QueryString("frompage");

            JscriptMsg("***商品编辑成功***!", frompage, "Success");
        }
Ejemplo n.º 2
0
        //保存
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string strErr = "";

            if (this.txtTitle.Text.Trim().Length == 0)
            {
                strErr += "名称不能为空!";
            }
            if (this.txtpSubject.Text.Trim().Length == 0)
            {
                strErr += "主题不能为空!";
            }


            if (ddlCategoryId.Items.Count <= 0)
            {
                strErr += "请先添加类别!";
            }
            if (!(txtPrice.Text != "" && MyCommFun.isDecimal(txtPrice.Text)))
            {
                strErr += "价格的格式不正确!";
            }

            if (txtbeginDate.Text.Trim() != "")
            {
                if (MyCommFun.isDateTime(txtbeginDate.Text))
                {
                }
                else
                {
                    strErr += "开始时间格式错误!";
                }
            }

            if (txtendDate.Text.Trim() != "")
            {
                if (MyCommFun.isDateTime(txtendDate.Text))
                {
                }
                else
                {
                    strErr += "结束时间格式错误!";
                }
            }
            if (strErr != "")
            {
                JscriptMsg(strErr, "back", "Error");
                return;
            }


            if (action == MXEnums.ActionEnum.Edit.ToString())                     //修改
            {
                ChkAdminLevel("productlist", MXEnums.ActionEnum.Edit.ToString()); //检查权限
                if (!DoEdit(this.id))
                {
                    JscriptMsg("保存过程中发生错误啦!", "", "Error");
                    return;
                }
                JscriptMsg("修改信息成功!", "product_list.aspx", "Success");
            }
            else //添加
            {
                ChkAdminLevel("productlist", MXEnums.ActionEnum.Add.ToString()); //检查权限
                if (!DoAdd())
                {
                    JscriptMsg("保存过程中发生错误啦!", "", "Error");
                    return;
                }
                JscriptMsg("添加信息成功!", "product_list.aspx", "Success");
            }
        }