private void buttonproadd_Click(object sender, EventArgs e) { Product product = new Product(); product.Name = textBoxproname.Text; product.Author = textBoxauthor.Text; product.CategoryId = (int)comboBoxprocat.SelectedValue; var Varmi = productBusiness.GetProductByName(product.Name); if (Varmi) { DialogResult dialog = new DialogResult(); dialog = MessageBox.Show($"{product.Name} book is on the list.Would you like doing adding? ", "", MessageBoxButtons.YesNo); if (dialog == DialogResult.Yes) { productBusiness.AddProduct(product); ShowProducts(); ShowProductsComboBox(); } else { textBoxproname.Clear(); textBoxauthor.Clear(); } } else { productBusiness.AddProduct(product); ShowProducts(); ShowProductsComboBox(); } }
public ActionResult CreateProduct(Product product) { if (ModelState.IsValid) { if (product.Id == 0) { result = ProductBusiness.AddProduct(product, out productId); if (result) { ProductViewModel viewmodel = new ProductViewModel(); viewmodel.Id = productId; viewmodel.CategoryDescription = Request.Form["CategoryDescription"]; viewmodel.ManufacturerName = Request.Form["ManufacturerName"]; viewmodel.Name = product.Name; viewmodel.Description = product.Description; viewmodel.Model = product.Model; viewmodel.ReleasedDate = product.ReleasedDate; viewmodel.ReleasedYear = product.ReleasedYear; return(Json(new { data = viewmodel, success = result + "Add", JsonRequestBehavior.AllowGet })); } } else if (product.Id != 0) { var x = Request.Form["CategoryDescription"]; var y = Request.Form["ManufacturerName"]; result = ProductBusiness.EditProduct(product); if (result) { ProductViewModel viewmodel = new ProductViewModel(); viewmodel.Id = product.Id; viewmodel.CategoryDescription = x; viewmodel.ManufacturerName = y; viewmodel.Name = product.Name; viewmodel.Description = product.Description; viewmodel.Model = product.Model; viewmodel.ReleasedDate = product.ReleasedDate; viewmodel.ReleasedYear = product.ReleasedYear; return(Json(new { data = viewmodel, success = result + "Edit", JsonRequestBehavior.AllowGet })); } } } return(Json(new { success = result }, JsonRequestBehavior.AllowGet)); }
// Create Product public async Task <ActionResult> CreateProduct(Product product) { ModelState.Remove("CreatedBy"); ModelState.Remove("ModifiedBy"); ModelState.Remove("CreatedDate"); ModelState.Remove("ModifiedDate"); var viewmodel = new ProductViewModel(); if (ModelState.IsValid) { if (product.Id <= 0) { viewmodel = await ProductBusiness.AddProduct(product); if (viewmodel.Id != 0) { success = true; } else { success = false; } return(Json(new { success = success, data = viewmodel, IsEdit = false, JsonRequestBehavior.AllowGet })); } else { viewmodel = await ProductBusiness.EditProduct(product); if (viewmodel.Id != 0) { success = true; } else { success = false; } return(Json(new { success = success, data = viewmodel, IsEdit = true, JsonRequestBehavior.AllowGet })); } } return(RedirectToAction("AddProduct")); }
private void btnAddData_Click(object sender, EventArgs e) { product.TenSanPham = txtProductName.Text.Trim(); product.GiaBan = int.Parse(txtPrice.Text); product.SoLuongSP = int.Parse(txtQuantity.Text); product.MaLoaiSP = int.Parse(cbProductTypeID.SelectedValue.ToString()); product.NhaSanXuat = txtFrom.Text.Trim(); if (isAdd == true) { int result = productBusiness.AddProduct(product); if (result == 1) { MessageBox.Show("Added successfully!", "Add a new product"); pnlPostData.Hide(); } else { MessageBox.Show("Failed to add a new product!", "Add a new product"); } } else { product.MaSanPham = int.Parse(txtProductID.Text); int result = productBusiness.EditProduct(product); if (result == 1) { MessageBox.Show("Edited successfully!", "Edit a product"); pnlPostData.Hide(); } else { MessageBox.Show("Failed to edit a product!", "Edit a product"); } } loadData(); }
protected void btnSave_Click(object sender, EventArgs e) { #region 验证 if (txtProductName.Text.Trim().Length == 0) { Alert("请填写产品名称!"); Select(txtProductName); return; } if (CommonMethod.FinalString(Request.Form["fun"]).Length == 0) { Alert("请选择产品拥有的功能!"); return; } #endregion #region 基础信息和日志记录 USER_SHARE_PRODUCTMODEL uspModel = null; //日志记录 USER_SHARE_LOGMODEL logModel = new USER_SHARE_LOGMODEL(); logModel.LOGID = CommonBusiness.GetSeqID("S_USER_SHARE_LOG"); logModel.OPERATEDATE = DateTime.Now; logModel.OPERATORID = AccountId; logModel.PROJECTID = ProjectId; logModel.COMPANYID = CompanyId; //修改 if (ProductId > 0) { uspModel = ProductBusiness.GetProductModel(ProductId); logModel.OPERATETYPE = int.Parse(ShareEnum.LogType.EditProduct.ToString("d")); logModel.OPERATECONTENT = string.Format("修改产品信息,产品Id:{0},修改后的名称:{1}", ProductId, txtProductName.Text.Trim()); } //新增 else { uspModel = new USER_SHARE_PRODUCTMODEL(); uspModel.PRODUCTID = CommonBusiness.GetSeqID("S_USER_SHARE_PRODUCT"); uspModel.PRODUCTFLAG = int.Parse(ShareEnum.ProductFlag.Normal.ToString("d")); logModel.OPERATETYPE = int.Parse(ShareEnum.LogType.AddProduct.ToString("d")); logModel.OPERATECONTENT = string.Format("新增产品信息,产品Id:{0}, 名称:{1}", uspModel.PRODUCTID, txtProductName.Text.Trim()); } uspModel.PRODUCTNAME = txtProductName.Text.Trim(); uspModel.PROJECTID = ValidatorHelper.ToInt(ddlProjects.SelectedValue, 0); uspModel.PRODUCTDESC = txtProductDesc.Text.Trim(); #endregion #region 产品功能 string strFunIds = CommonMethod.FinalString(Request.Form["fun"]); List <USER_SHARE_PRODUCTFUNMODEL> lstModels = new List <USER_SHARE_PRODUCTFUNMODEL>(); if (strFunIds.Length > 0) { USER_SHARE_PRODUCTFUNMODEL funModel = null; string[] funs = strFunIds.Split(','); foreach (string funid in funs) { funModel = new USER_SHARE_PRODUCTFUNMODEL(); funModel.PROCUTID = uspModel.PRODUCTID; funModel.FUNID = ValidatorHelper.ToInt(funid, 0); lstModels.Add(funModel); } } else { Alert("请先选择此产品包含的功能!"); return; } #endregion #region 保存 bool isSuccess = false; string strTip = ProductId > 0 ? "修改" : "新增"; if (ProductId > 0) { isSuccess = ProductBusiness.EditProduct(uspModel, lstModels, logModel); } else { isSuccess = ProductBusiness.AddProduct(uspModel, lstModels, logModel); } if (isSuccess) { Alert(strTip + "产品成功!"); ExecScript("parent.__doPostBack('ctl00$MainContent$btnSearch','');"); } else { Alert(strTip + "产品失败,请重试!"); } #endregion }
public IActionResult AddProduct(Product product) { return(new JsonResult(productBusiness.AddProduct(product))); }
/// <summary> /// Request a new product to be added to the distributor. /// </summary> private void CreateProduct() { string productName, distributorName; decimal price; Console.Clear(); Console.WriteLine(new string('-', 41)); Console.WriteLine(new string(' ', 15) + "ADD PRODUCT"); Console.WriteLine(new string('-', 41) + '\n'); while (true) { Console.Write("Distributor name: "); distributorName = Console.ReadLine(); Console.WriteLine(); if (DistributorBusiness.DistributorExists(DistributorBusiness.GetID(distributorName))) { break; } Console.WriteLine(new string('-', 26)); Console.WriteLine("Please enter a valid distributor name!"); Console.WriteLine(new string('-', 26) + '\n'); } while (true) { Console.Write("Product name: "); productName = Console.ReadLine(); Console.WriteLine(); if (!ProductBusiness.CheckForProduct(ProductBusiness.GetID(productName))) { break; } Console.WriteLine(new string('-', 26)); Console.WriteLine("Please enter a valid name!"); Console.WriteLine(new string('-', 26) + '\n'); } while (true) { Console.Write("Price for one product: "); price = decimal.Parse(Console.ReadLine()); Console.WriteLine(); if (!(price <= 0)) { break; } Console.WriteLine(new string('-', 27)); Console.WriteLine("Please enter a valid price!"); Console.WriteLine(new string('-', 27) + '\n'); } ProductBusiness.AddProduct(DistributorBusiness.GetID(distributorName), productName, price); }