Example #1
0
        private void LoadFormData()
        {
            int id = GetQueryIntValue("id");

            if (id > 0)
            {
                Infobasis.Data.DataEntity.Material material = DB.Materials.Find(id);
                if (material == null)
                {
                    // 参数错误,首先弹出Alert对话框然后关闭弹出窗口
                    Alert.Show("参数错误!");
                    return;
                }

                tbxCode.Text           = material.Code;
                tbxName.Text           = material.Name;
                tbxBrand.Text          = material.BrandName;
                tbxBrandHidden.Text    = material.BrandID.HasValue ? material.BrandID.ToString() : "";
                tbxModel.Text          = material.Model;
                tbxSpec.Text           = material.Spec;
                tbxIsActive.Checked    = material.IsActive;
                tbxPurchasePrice.Text  = material.PurchasePrice.ToString();
                tbxEarningFactor.Text  = material.EarningFactor.ToString();
                tbxSalePrice.Text      = material.SalePrice.ToString();
                tbxNoSalePrice.Checked = material.NoSalePrice;
                tbxReturnFactor.Text   = material.ReturnFactor.ToString();
                tbxUpgradePrice.Text   = material.UpgradePrice.ToString();

                if (material.ProvinceID.HasValue)
                {
                    DropDownProvince.SelectedValue = material.ProvinceID.Value.ToString();
                    DropDownProvince.Text          = material.ProvinceName;
                }

                if (material.UnitID.HasValue)
                {
                    DropDownUnit.SelectedValue = material.UnitID.Value.ToString();
                    DropDownUnit.Text          = material.UnitName;
                }

                if (material.CustomizationTypeID.HasValue)
                {
                    DropDownCustomizationType.SelectedValue = material.CustomizationTypeID.Value.ToString();
                    DropDownCustomizationType.Text          = material.CustomizationTypeName;
                }

                if (material.MainMaterialTypeID.HasValue)
                {
                    DropDownMainMaterialType.SelectedValue = material.MainMaterialTypeID.Value.ToString();
                    DropDownMainMaterialType.Text          = material.MainMaterialTypeName;
                }

                if (material.MaterialTypeID.HasValue)
                {
                    DropDownMaterialType.SelectedValue = material.MaterialTypeID.Value.ToString();
                    DropDownMaterialType.Text          = material.MaterialTypeName;
                }

                if (!string.IsNullOrEmpty(material.BudgetTypeIDs))
                {
                    DropDownBoxBudgetType.Values = material.BudgetTypeIDs.Split(',');
                    DropDownBoxBudgetType.Text   = material.BudgetTypeNames;

                    CheckBoxListBudgetType.SelectedValueArray = DropDownBoxBudgetType.Values;
                }

                if (!string.IsNullOrEmpty(material.RoomTypeIDs))
                {
                    DropDownBoxRoomType.Values = material.RoomTypeIDs.Split(',');
                    DropDownBoxRoomType.Text   = material.RoomTypeNames;
                    CheckBoxListRoomType.SelectedValueArray = DropDownBoxRoomType.Values;
                }

                if (material.VendorID.HasValue)
                {
                    ddbVendor.Value = material.VendorID.ToString();
                    ddbVendor.Text  = material.VendorName;
                }

                tbxRemark.Text = material.Remark;

                if (material.VendorID != null)
                {
                    ddbVendor.Value = material.VendorID.ToString();
                    ddbVendor.Text  = material.VendorName;
                }

                if (!string.IsNullOrEmpty(material.PicPath))
                {
                    materialImg.ImageUrl         = material.PicPath;
                    materialImgUpload.ButtonText = "修改图片";
                }
                else
                {
                    materialImgUpload.ButtonText = "上传图片";
                }

                InitDropDownMaterialType(material.MaterialTypeID);
            }
            else
            {
                tbxIsActive.Checked = true;
                tbxCode.Text        = GenerateNum("MA-", false);
            }
        }
Example #2
0
        private void SaveItem()
        {
            int    userID   = UserInfo.Current.ID;
            string userName = UserInfo.Current.ChineseName;

            int id = GetQueryIntValue("id");

            if (id > 0)
            {
                Infobasis.Data.DataEntity.Material material = DB.Materials.Find(id);
                material.Name      = tbxName.Text.Trim();
                material.Code      = tbxCode.Text.Trim();
                material.IsActive  = tbxIsActive.Checked;
                material.BrandName = tbxBrand.Text;
                if (Infobasis.Web.Util.Change.ToInt(tbxBrandHidden.Text) > 0)
                {
                    material.BrandID = Infobasis.Web.Util.Change.ToInt(tbxBrandHidden.Text);
                }

                material.Model    = tbxModel.Text;
                material.Spec     = tbxSpec.Text;
                material.UnitName = DropDownUnit.SelectedText;
                if (Infobasis.Web.Util.Change.ToInt(DropDownUnit.SelectedValue) > 0)
                {
                    material.UnitID = Infobasis.Web.Util.Change.ToInt(DropDownUnit.SelectedValue);
                }

                material.PurchasePrice         = Infobasis.Web.Util.Change.ToDecimal(tbxPurchasePrice.Text);
                material.SalePrice             = Infobasis.Web.Util.Change.ToDecimal(tbxSalePrice.Text);
                material.NoSalePrice           = tbxNoSalePrice.Checked;
                material.ReturnFactor          = Infobasis.Web.Util.Change.ToDecimal(tbxReturnFactor.Text);
                material.UpgradePrice          = Infobasis.Web.Util.Change.ToDecimal(tbxUpgradePrice.Text);
                material.CustomizationTypeName = DropDownCustomizationType.SelectedText;

                if (Infobasis.Web.Util.Change.ToInt(DropDownCustomizationType.SelectedValue) > 0)
                {
                    material.CustomizationTypeID = Infobasis.Web.Util.Change.ToInt(DropDownCustomizationType.SelectedValue);
                }

                material.EarningFactor        = Infobasis.Web.Util.Change.ToDecimal(tbxEarningFactor.Text);
                material.MainMaterialTypeName = DropDownMainMaterialType.SelectedText;

                if (Infobasis.Web.Util.Change.ToInt(DropDownMainMaterialType.SelectedValue) > 0)
                {
                    material.MainMaterialTypeID = Infobasis.Web.Util.Change.ToInt(DropDownMainMaterialType.SelectedValue);
                }

                material.MaterialTypeName = DropDownMaterialType.SelectedText;

                if (Infobasis.Web.Util.Change.ToInt(DropDownMaterialType.SelectedValue) > 0)
                {
                    material.MaterialTypeID = Infobasis.Web.Util.Change.ToInt(DropDownMaterialType.SelectedValue);
                }

                if (Infobasis.Web.Util.Change.ToInt(DropDownProvince.SelectedValue) > 0)
                {
                    material.ProvinceID   = Infobasis.Web.Util.Change.ToInt(DropDownProvince.SelectedValue);
                    material.ProvinceName = DropDownProvince.SelectedText;
                }


                material.BudgetTypeIDs   = string.Join(",", DropDownBoxBudgetType.Values);
                material.BudgetTypeNames = string.Join(",", CheckBoxListBudgetType.SelectedItemArray.Where(item => item.Selected).Select(item => item.Text).ToArray());

                material.RoomTypeIDs   = string.Join(",", DropDownBoxRoomType.Values);
                material.RoomTypeNames = string.Join(",", CheckBoxListRoomType.SelectedItemArray.Where(item => item.Selected).Select(item => item.Text).ToArray());

                material.Remark         = tbxRemark.Text;
                material.SpellCode      = ChinesePinyin.GetPinyin(material.Name);
                material.FirstSpellCode = ChinesePinyin.GetFirstPinyin(material.Name);
                material.PicPath        = materialImg.ImageUrl;

                if (Infobasis.Web.Util.Change.ToInt(ddbVendor.Value) > 0)
                {
                    material.VendorID   = Infobasis.Web.Util.Change.ToInt(ddbVendor.Value);
                    material.VendorName = ddbVendor.Text;
                }

                material.LastUpdateDatetime = DateTime.Now;
                material.LastUpdateByID     = userID;
                material.LastUpdateByName   = userName;
            }
            else
            {
                Infobasis.Data.DataEntity.Material material = new Infobasis.Data.DataEntity.Material();
                material.Name      = tbxName.Text.Trim();
                material.Code      = tbxCode.Text.Trim();
                material.IsActive  = tbxIsActive.Checked;
                material.BrandName = tbxBrand.Text;
                if (Infobasis.Web.Util.Change.ToInt(tbxBrandHidden.Text) > 0)
                {
                    material.BrandID = Infobasis.Web.Util.Change.ToInt(tbxBrandHidden.Text);
                }

                material.Model    = tbxModel.Text;
                material.Spec     = tbxSpec.Text;
                material.UnitName = DropDownUnit.SelectedText;
                if (Infobasis.Web.Util.Change.ToInt(DropDownUnit.SelectedValue) > 0)
                {
                    material.UnitID = Infobasis.Web.Util.Change.ToInt(DropDownUnit.SelectedValue);
                }

                material.PurchasePrice         = Infobasis.Web.Util.Change.ToDecimal(tbxPurchasePrice.Text);
                material.SalePrice             = Infobasis.Web.Util.Change.ToDecimal(tbxSalePrice.Text);
                material.NoSalePrice           = tbxNoSalePrice.Checked;
                material.ReturnFactor          = Infobasis.Web.Util.Change.ToDecimal(tbxReturnFactor.Text);
                material.UpgradePrice          = Infobasis.Web.Util.Change.ToDecimal(tbxUpgradePrice.Text);
                material.CustomizationTypeName = DropDownCustomizationType.SelectedText;

                if (Infobasis.Web.Util.Change.ToInt(DropDownCustomizationType.SelectedValue) > 0)
                {
                    material.CustomizationTypeID = Infobasis.Web.Util.Change.ToInt(DropDownCustomizationType.SelectedValue);
                }

                material.EarningFactor        = Infobasis.Web.Util.Change.ToDecimal(tbxEarningFactor.Text);
                material.MainMaterialTypeName = DropDownMainMaterialType.SelectedText;

                if (Infobasis.Web.Util.Change.ToInt(DropDownMainMaterialType.SelectedValue) > 0)
                {
                    material.MainMaterialTypeID = Infobasis.Web.Util.Change.ToInt(DropDownMainMaterialType.SelectedValue);
                }

                material.MaterialTypeName = DropDownMaterialType.SelectedText;

                if (Infobasis.Web.Util.Change.ToInt(DropDownMaterialType.SelectedValue) > 0)
                {
                    material.MaterialTypeID = Infobasis.Web.Util.Change.ToInt(DropDownMaterialType.SelectedValue);
                }

                if (Infobasis.Web.Util.Change.ToInt(DropDownProvince.SelectedValue) > 0)
                {
                    material.ProvinceID   = Infobasis.Web.Util.Change.ToInt(DropDownProvince.SelectedValue);
                    material.ProvinceName = DropDownProvince.SelectedText;
                }

                material.BudgetTypeIDs   = string.Join(",", DropDownBoxBudgetType.Values);
                material.BudgetTypeNames = string.Join(",", CheckBoxListBudgetType.SelectedItemArray.Where(item => item.Selected).Select(item => item.Text).ToArray());

                material.RoomTypeIDs   = string.Join(",", DropDownBoxRoomType.Values);
                material.RoomTypeNames = string.Join(",", CheckBoxListRoomType.SelectedItemArray.Where(item => item.Selected).Select(item => item.Text).ToArray());

                material.Remark         = tbxRemark.Text;
                material.SpellCode      = ChinesePinyin.GetPinyin(material.Name);
                material.FirstSpellCode = ChinesePinyin.GetFirstPinyin(material.Name);
                material.PicPath        = materialImg.ImageUrl;

                if (Infobasis.Web.Util.Change.ToInt(ddbVendor.Value) > 0)
                {
                    material.VendorID   = Infobasis.Web.Util.Change.ToInt(ddbVendor.Value);
                    material.VendorName = ddbVendor.Text;
                }

                material.CreateDatetime = DateTime.Now;
                material.CreateByID     = userID;
                material.CreateByName   = userName;
                DB.Materials.Add(material);
            }
            if (!string.IsNullOrEmpty(tbxBrand.Text))
            {
                if (!DB.Brands.Where(item => item.Name == tbxBrand.Text.Trim()).Any())
                {
                    Infobasis.Data.DataEntity.Brand brand = new Infobasis.Data.DataEntity.Brand();
                    brand.Code           = GenerateNum("brand");
                    brand.Name           = tbxBrand.Text.Trim();
                    brand.SpellCode      = Infobasis.Web.Util.ChinesePinyin.GetPinyin(brand.Name);
                    brand.FirstSpellCode = Infobasis.Web.Util.ChinesePinyin.GetFirstPinyin(brand.Name);
                    brand.IsActive       = true;
                    brand.CreateDatetime = DateTime.Now;

                    DB.Brands.Add(brand);
                }
            }
            DB.SaveChanges();
        }
Example #3
0
 protected void Grid1_RowDataBound(object sender, GridRowEventArgs e)
 {
     Infobasis.Data.DataEntity.Material material = e.DataItem as Infobasis.Data.DataEntity.Material;
 }