Exemplo n.º 1
0
        private void save()
        {
            this.commdodityModel.CommodityName = this.tbName.Text;
            if (this.isReplaceImg)
            {
                this.commdodityModel.CommodityImg = this.newImageGUID + Path.GetExtension(this.tbImg.Text);
            }

            this.commdodityModel.CommodityGeneral  = this.tbGeneral.Text;
            this.commdodityModel.CommodityPrice    = double.Parse(this.tbPrice.Text);
            this.commdodityModel.UnitIdName        = this.cmbUnit.SelectedText;
            this.commdodityModel.CommodityUnitId   = (this.cmbUnit.SelectedItem as UnitModel).UnitIdId;
            this.commdodityModel.CommoditySpec     = int.Parse(this.tbSpec.Text);
            this.commdodityModel.BrandName         = this.cmbBrand.SelectedText;
            this.commdodityModel.CommodityBrandId  = (this.cmbBrand.SelectedItem as BrandModel).BrandId;
            this.commdodityModel.CommodityFamilyId = (this.cmbCommodityType.SelectedItem as CommodityTypeModel).TypeId;
            this.commdodityModel.CommodityIndex    = this.tbIndex.Text;
            this.commdodityModel.CommodityCode     = this.tbCode.Text;
            this.commdodityModel.CommodityHOT      = int.Parse(this.cmbHot.SelectedItem.ToString());
            this.commdodityModel.CommodityRH       = this.tbRH.Text;
            this.commdodityModel.CommodityRM       = this.tbRM.Text;
            this.commdodityModel.CommodityFL       = this.tbFL.Text;
            this.commdodityModel.CommodityRemark   = this.rtbRemark.Text;
            if (this.maintainType == MaintainType.New)
            {
                this.commdodityModel.CommoditySuper = 1;
                var addResult = WebRequestUtil.AddCommodity(JsonUtil.Serialize(this.commdodityModel));
                if (addResult == null || addResult.StatusCode != System.Net.HttpStatusCode.OK)
                {
                    MessageBox.Show("新建商品失败");
                }
            }
            else
            {
                var updateResult = WebRequestUtil.UpdateCommodity(this.commdodityModel.CommodityId, JsonUtil.Serialize(this.commdodityModel));
                if (updateResult == null || updateResult.StatusCode != System.Net.HttpStatusCode.OK)
                {
                    MessageBox.Show("更新商品失败");
                }
            }
            //replace image
            if (this.isReplaceImg)
            {
                this.ReplaceImge();
            }
        }
Exemplo n.º 2
0
        private void save()
        {
            this.commdodityModel.CommodityName = this.tbName.Text;
            if (this.isReplaceImg)
            {
                this.commdodityModel.CommodityImg = this.commdodityModel.CommodityId + "1" + Path.GetExtension(this.tbImg.Text); //当前图片数量加1
            }

            this.commdodityModel.CommodityGeneral  = this.tbGeneral.Text;
            this.commdodityModel.CommodityPrice    = double.Parse(this.tbPrice.Text);
            this.commdodityModel.UnitIdName        = this.cmbUnit.SelectedText;
            this.commdodityModel.CommodityUnitId   = (this.cmbUnit.SelectedItem as UnitModel).UnitIdId;
            this.commdodityModel.CommoditySpec     = int.Parse(this.tbSpec.Text);
            this.commdodityModel.BrandName         = this.cmbBrand.SelectedText;
            this.commdodityModel.CommodityBrandId  = (this.cmbBrand.SelectedItem as BrandModel).BrandId;
            this.commdodityModel.CommodityFamilyId = (this.cmbCommodityType.SelectedItem as CommodityTypeModel).TypeId;
            this.commdodityModel.CommodityIndex    = this.tbIndex.Text;
            this.commdodityModel.CommodityCode     = this.tbCode.Text;
            // this.commdodityModel.CommodityHOT = int.Parse(this.cmbHot.SelectedItem.ToString());
            this.commdodityModel.CommodityRH = this.tbRH.Text;
            //this.commdodityModel.CommodityRM = this.tbRM.Text;
            this.commdodityModel.CommodityFL     = this.tbFL.Text;
            this.commdodityModel.CommodityRemark = string.Empty;
            switch (this.cmbHot.SelectedItem.ToString())
            {
            case "正常":
                this.commdodityModel.CommoditySuper = 0;
                break;

            case "首页":
                this.commdodityModel.CommoditySuper = 1;
                break;
            }
            if (this.maintainType == MaintainType.New)
            {
                var addResult = WebRequestUtil.AddCommodity(JsonUtil.Serialize(this.commdodityModel));
                if (addResult == null || addResult.StatusCode != System.Net.HttpStatusCode.OK)
                {
                    MessageBox.Show("新建商品失败");
                }
                else
                {
                    var data = JsonUtil.Deserialize <QSWResponse <CommodityModel> >(addResult.Content).Data;
                    this.commdodityModel.CommodityId  = data.CommodityId;
                    this.commdodityModel.CommodityImg = data.CommodityImg;
                }
            }
            else
            {
                var updateResult = WebRequestUtil.UpdateCommodity(this.commdodityModel.CommodityId, JsonUtil.Serialize(this.commdodityModel));
                if (updateResult == null || updateResult.StatusCode != System.Net.HttpStatusCode.OK)
                {
                    MessageBox.Show("更新商品失败");
                }
            }
            //replace image
            if (this.isReplaceImg)
            {
                this.ReplaceImge();
            }
        }