protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { KeyWordBind(); //产品I am a DataSet ds = ProductTypeService.GetList("parentId = 0"); if (ds.Tables[0].Rows.Count > 0) { this.ddlProductType.DataSource = ds; ddlProductType.DataTextField = "typeName"; ddlProductType.DataValueField = "id"; ddlProductType.DataBind(); } ddlProductType.Items.Insert(0, new ListItem("Category", "0")); if (id != 0) { ViewState["id"] = id; } ViewState["headImg"] = "images/product_default.png"; BindData(); } }
/// <summary> /// 面包屑 /// </summary> /// <returns></returns> protected string GetBread() { StringBuilder sb = new StringBuilder(); Product item = ProductService.GetModel(id); if (item != null) { sb.Append("<a href=\"/project_" + item.oneId + "_0_0_0_0_0_0_0.html\">All </a> "); if (item.twoId != 0) { sb.Append("<span>></span>"); ProductType pt = ProductTypeService.GetModel(item.twoId); if (pt != null) { sb.Append(" <a href=\"/project_" + item.oneId + "_" + item.twoId + "_0_0_0_0_0_0.html\">" + pt.typeName + "</a> "); } if (item.threeId != 0) { sb.Append("<span>></span>"); pt = ProductTypeService.GetModel(item.threeId); if (pt != null) { sb.Append(" <a href=\"/project_" + item.oneId + "_" + item.twoId + "_" + item.threeId + "_0_0_0_0_0.html\">" + pt.typeName + "</a> "); } } } sb.Append("<span>></span>"); sb.Append(" <a href=\"/project_" + item.oneId + "_" + item.twoId + "_" + item.threeId + "_" + item.productType + "_0_0_0_0.html\">" + item.productTypeName + "</a>"); } return(sb.ToString()); }
public async Task UpdateAsyncShouldUpdateName() { const string id = nameof(id); const string name = nameof(name); const string newName = nameof(newName); ApplicationDbContext dbContext = this.GetNewDbContext(); ProductType productType = new ProductType { Id = id, Name = name, }; dbContext.ProductTypes.Add(productType); await dbContext.SaveChangesAsync(); IRepository <ProductType> repository = new EfRepository <ProductType>(dbContext); IProductTypeService service = new ProductTypeService(repository); bool result = await service.UpdateAsync(id, newName); Assert.True(result); Assert.Equal(newName, productType.Name); }
// GET: /ProductMaster/Create public ActionResult Create(int id) { ProductGroup vm = new ProductGroup(); vm.IsActive = true; vm.ProductTypeId = id; ViewBag.id = id; var settings = new ProductTypeSettingsService(_unitOfWork).GetProductTypeSettingsForDocument(id); if (settings == null && UserRoles.Contains("SysAdmin")) { return(RedirectToAction("Create", "ProductTypeSettings", new { id = id }).Warning("Please create Product Type Settings")); } else if (settings == null && !UserRoles.Contains("SysAdmin")) { return(View("~/Views/Shared/InValidSettings.cshtml")); } //var settings = new ProductTypeSettingsService(_unitOfWork).GetProductTypeSettingsForDocument(id); string ProductTypeName = new ProductTypeService(_unitOfWork).Find(vm.ProductTypeId).ProductTypeName; ViewBag.Name = (settings.ProductGroupCaption ?? "Product Group") + "-" + ProductTypeName; ViewBag.ProductGroupCaption = settings.ProductGroupCaption ?? "Product Group"; ViewBag.SalesTaxProductCodeCaption = "Default " + (settings.SalesTaxProductCodeCaption ?? "Sales Tax Product Code"); ViewBag.IsVisibleSalesTaxProductCode = settings.isVisibleSalesTaxProductCode ?? false; //ViewBag.Name = new ProductTypeService(_unitOfWork).Find(id).ProductTypeName; return(View("Create", vm)); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Session["loginUser"] == null) { Response.Redirect("/admin/login.aspx"); return; } if (userId != 0) { ViewState["userId"] = userId; } DataSet ds = ProductTypeService.GetList("parentId = 0"); if (ds.Tables[0].Rows.Count > 0) { ddlProductType.DataSource = ds; ddlProductType.DataTextField = "typeName"; ddlProductType.DataValueField = "id"; ddlProductType.DataBind(); } ddlProductType.Items.Insert(0, new ListItem("请选择", "0")); this.ddlSon.Items.Insert(0, new ListItem("请选择", "0")); sp.InitBindData(Repeater1, pager1, "Product", "id", sear()); } }
public ProductController(ProductService service, IMapper mapper, ProductTypeService productTypeService, ProviderService providerService) { this.service = service; this.mapper = mapper; this.productTypeService = productTypeService; this.providerService = providerService; }
public ActionResult cPrevPage(int id)//CurrentHeaderId { int ptypeid = new ProductTypeService(_unitOfWork).GetProductTypeByName(ProductTypeConstants.Rug).ProductTypeId; var nextId = _ProductDesignService.PrevId(id, ptypeid); return(RedirectToAction("EditColourWays", new { id = nextId })); }
/// <summary> /// 加载数据 /// </summary> private void LoadData() { //一级类别 DataSet ds = ProductTypeService.GetList("parentId = 0"); if (ds.Tables[0].Rows.Count > 0) { this.ddlOne.DataSource = ds; ddlOne.DataTextField = "typeName"; ddlOne.DataValueField = "id"; ddlOne.DataBind(); ddlSelProductType.DataSource = ds; ddlSelProductType.DataTextField = "typeName"; ddlSelProductType.DataValueField = "id"; ddlSelProductType.DataBind(); } ddlOne.Items.Insert(0, new ListItem("请选择", "0")); ddlSelProductType.Items.Insert(0, new ListItem("请选择", "0")); ddlSelTwo.Items.Insert(0, new ListItem("请选择", "0")); this.ddlSelThree.Items.Insert(0, new ListItem("请选择", "0")); ddlTwo.Items.Insert(0, new ListItem("请选择", "0")); this.ddlThree.Items.Insert(0, new ListItem("请选择", "0")); this.ddlFour.Items.Insert(0, new ListItem("请选择", "0")); }
private void Load_Data() { ProductTypeService productTypeService = new ProductTypeService(); UnitTypeService unitService = new UnitTypeService(); LanguageService languageService = new LanguageService(); CurrencyService currencyService = new CurrencyService(); CategoryService categoryService = new CategoryService(); TypeBox.ItemsSource = productTypeService.GetAll(); TypeBox.SelectedValuePath = "Id"; TypeBox.DisplayMemberPath = "Name"; TypeBox.SelectedIndex = 0; UnitBox.ItemsSource = unitService.GetUnitTypesByLanguage(2); UnitBox.SelectedValuePath = "Id"; UnitBox.DisplayMemberPath = "Name"; LanguageBox.ItemsSource = languageService.GetAll(); LanguageBox.SelectedValuePath = "Id"; LanguageBox.DisplayMemberPath = "Name"; LanguageBox.SelectedIndex = 0; CurrencyBox.ItemsSource = currencyService.GetAll(); CurrencyBox.SelectedValuePath = "Id"; CurrencyBox.DisplayMemberPath = "Name"; CurrencyBox.SelectedIndex = 0; CategoryBox.ItemsSource = categoryService.GetDefaultCategories(2); CategoryBox.SelectedValuePath = "Id"; CategoryBox.DisplayMemberPath = "Name"; }
public ActionResult ProductTypeIndex(int id) { var producttype = new ProductTypeService(_unitOfWork).GetFinishedProductTypeListWithNoCustomUI().ToList(); ViewBag.Sample = ((id == 0)?"False":"True"); return(View("ProductTypeIndex", producttype)); }
public ProductController(ProductService service, IMapper mapper, ProductTypeService productTypeService, IRepository <ProductType> productTypeRepository) { this.service = service; this.mapper = mapper; this.productTypeService = productTypeService; this.productTypeRepository = productTypeRepository; }
/// <summary> /// 获取子类信息 /// </summary> /// <param name="id"></param> /// <returns></returns> protected string GetSon(object id) { StringBuilder sb = new StringBuilder(); DataSet ds = ProductTypeService.GetList("parentId = " + id); if (ds.Tables[0].Rows.Count > 0) { foreach (DataRow dr in ds.Tables[0].Rows) { sb.Append(" <li><dl>"); sb.Append("<dt><a href=\"/project_" + id + "_" + dr["id"] + "_0_0_0_0_0_0.html\">" + dr["typeName"] + "</a></dt>"); sb.Append("<dd>"); DataSet ds2 = ProductTypeService.GetList("parentId = " + dr["id"]); if (ds2.Tables[0].Rows.Count > 0) { for (int i = 0; i < ds2.Tables[0].Rows.Count; i++) { if (i == ds2.Tables[0].Rows.Count - 1) { sb.Append("<p><a href=\"/project_" + id + "_" + dr["id"] + "_" + ds2.Tables[0].Rows[i]["id"] + "_0_0_0_0_0.html\">" + ds2.Tables[0].Rows[i]["typeName"] + " </a></p>"); } else { sb.Append("<p><a href=\"/project_" + id + "_" + dr["id"] + "_" + ds2.Tables[0].Rows[i]["id"] + "_0_0_0_0_0.html\">" + ds2.Tables[0].Rows[i]["typeName"] + " </a>丨</p>"); } } } sb.Append("</dd>"); sb.Append("</dl></li>"); } } return(sb.ToString()); }
// GET: /ProductMaster/Edit/5 public ActionResult EditMaterial(int id) { MaterialViewModel pt = _ProductService.GetMaterialProduct(id); if (pt.ReferenceDocId.HasValue) { var ProductSku = db.Product.Find(pt.ReferenceDocId); pt.ProductSKUId = ProductSku.ProductId; } ProductGroup group = new ProductGroupService(_unitOfWork).Find(pt.ProductGroupId); ProductType Type = new ProductTypeService(_unitOfWork).Find(group.ProductTypeId); ViewBag.Name = Type.ProductTypeName; ViewBag.id = group.ProductTypeId; ViewBag.ProductGroupList = new ProductGroupService(_unitOfWork).GetProductGroupListForItemType(group.ProductTypeId); int DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; int SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; pt.DivisionId = DivisionId; pt.SiteId = SiteId; if (pt == null) { return(HttpNotFound()); } PrepareMaterialViewBag(pt); return(View("CreateMaterial", pt)); }
/// <summary> /// 加载数据 /// </summary> private void LoadData() { //产品类别下拉框 DataSet ds = ProductTypeService.GetList("typeValue = 0"); if (ds.Tables[0].Rows.Count > 0) { ddlProductType.DataSource = ds; ddlProductType.DataTextField = "typeName"; ddlProductType.DataValueField = "id"; ddlProductType.DataBind(); ddlSelProductType.DataSource = ds; ddlSelProductType.DataTextField = "typeName"; ddlSelProductType.DataValueField = "id"; ddlSelProductType.DataBind(); } ddlSelProductType.Items.Insert(0, new ListItem("请选择", "0")); ddlSelOne.Items.Insert(0, new ListItem("请选择", "0")); ddlProductType.Items.Insert(0, new ListItem("请选择", "0")); ddlOne.Items.Insert(0, new ListItem("请选择", "0")); ddlSelTwo.Items.Insert(0, new ListItem("请选择", "0")); ddlTwo.Items.Insert(0, new ListItem("请选择", "0")); }
private void dgvProductTypeList_CellClick(object sender, DataGridViewCellEventArgs e) { if (sender is DataGridView) { DataGridViewCell cell = ((DataGridView)sender).CurrentCell; if (cell.ColumnIndex == ((DataGridView)sender).ColumnCount - 1) { DialogResult result = MessageBox.Show("Bạn có muốn xóa loại sản phẩm này?", "Xoá loại sản phẩm này", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { DataGridViewRow currentRow = dgvProductTypeList.Rows[e.RowIndex]; int id = ObjectHelper.GetValueFromAnonymousType <int>(currentRow.DataBoundItem, "Id"); ProductService productService = new ProductService(); ProductTypeService producTypeService = new ProductTypeService(); List <Product> productList = productService.SelectProductByWhere(pt => pt.ProductType == id); if (productList.Count > 0) { MessageBox.Show("Loại này hiện có nhiều sản phẩm. Không xóa được!"); } else { if (!producTypeService.DeleteProductType(id)) { MessageBox.Show("Hiện tại hệ thống đang có lỗi. Vui lòng thử lại sau!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } loadProductTypeList(); } } } } }
// GET: /ProductMaster/ public ActionResult Index(int id)//ProductTypeId { //return RedirectToAction("Create"); ViewBag.id = id; var settings = new ProductTypeSettingsService(_unitOfWork).GetProductTypeSettingsForDocument(id); if (settings == null && UserRoles.Contains("SysAdmin")) { return(RedirectToAction("Create", "ProductTypeSettings", new { id = id }).Warning("Please create Product Type Settings")); } else if (settings == null && !UserRoles.Contains("SysAdmin")) { return(View("~/Views/Shared/InValidSettings.cshtml")); } string ProductTypeName = new ProductTypeService(_unitOfWork).Find(id).ProductTypeName; ViewBag.Name = (settings.ProductGroupCaption ?? "Product Group") + "-" + ProductTypeName; //ViewBag.Name = new ProductTypeService(_unitOfWork).Find(id).ProductTypeName; var p = _ProductGroupService.GetProductGroupList(id); return(View(p)); }
public ActionResult ProductTypeIndex(int Id) { //var pt = new ProductTypeService(_unitOfWork).GetRawAndOtherMaterialProductTypes().Where(m => m.IsActive != false).ToList(); var pt = new ProductTypeService(_unitOfWork).GetProductTypes(Id).Where(m => m.IsActive != false).ToList(); return(View("ProductTypeIndex", pt)); }
// GET: Admin/ProductTypeAdmin public ActionResult Index(string search, int page = 1, int pageSize = 8) { var service = new ProductTypeService(); var model = service.DanhSachLSPPaging(search).ToPagedList(page, pageSize); ViewBag.Search = search; return(View(model)); }
public ActionResult OnDelete(int id) { var result = ProductTypeService.Delete(id); SetFlashMessage(result == Result.Ok ? "Xóa Loại sản phẩm thành công." : "Loại sản phẩm không tồn tại trên hệ thống."); return(RedirectToAction("Index")); }
public ActionResult OnChangeState(int id) { var result = ProductTypeService.ChangeState(id); SetFlashMessage(result == Result.Ok ? "Thay đổi trạng thái Loại sản phẩm thành công." : "Loại sản phẩm không tồn tại trên hệ thống."); return(RedirectToAction("Index")); }
public JsonResult ChangeStatus(int id) { var result = new ProductTypeService().ChangeStatus(id); return(Json(new { status = result })); }
/// <summary> /// 产品类别名称 /// </summary> /// <returns></returns> protected string GetProductName(object productTypeId) { ProductType item = ProductTypeService.GetModel(Convert.ToInt32(productTypeId)); if (item != null) { return(item.typeName); } return(""); }
public void GetProductType() { //List<ProductType> list = (List<ProductType>)BaoHienRepository.SelectAll<ProductType>().Where<ProductType>(item => item.st == false).ToList<ProductType>(); //int count = list.Count; ProductTypeService productTypeService = new ProductTypeService(); ProductType productType = productTypeService.GetProductType(4); Assert.AreEqual <int>(4, productType.Id);; }
public void GetProductTypes() { //List<ProductType> list = (List<ProductType>)BaoHienRepository.SelectAll<ProductType>().Where<ProductType>(item => item.st == false).ToList<ProductType>(); //int count = list.Count; ProductTypeService productTypeService = new ProductTypeService(); List<ProductType> productTypes = productTypeService.GetProductTypes(); Assert.AreEqual<bool>(true, productTypes.Count > 0); ; }
public void GetProductTypes() { //List<ProductType> list = (List<ProductType>)BaoHienRepository.SelectAll<ProductType>().Where<ProductType>(item => item.st == false).ToList<ProductType>(); //int count = list.Count; ProductTypeService productTypeService = new ProductTypeService(); List <ProductType> productTypes = productTypeService.GetProductTypes(); Assert.AreEqual <bool>(true, productTypes.Count > 0);; }
public void product_type_service_should_add_item_to_the_underlying_repository() { var productTypeService = new ProductTypeService(_unitOfWorkMock.Object); var productType = new ProductType { Id = 10 }; productTypeService.AddProductType(productType); _productTypeRepositoryMock.Verify(r => r.Add(It.Is <ProductType>(p => p.Id == productType.Id)), Times.Once()); }
public void GetProductType() { //List<ProductType> list = (List<ProductType>)BaoHienRepository.SelectAll<ProductType>().Where<ProductType>(item => item.st == false).ToList<ProductType>(); //int count = list.Count; ProductTypeService productTypeService = new ProductTypeService(); ProductType productType = productTypeService.GetProductType(4); Assert.AreEqual<int>(4, productType.Id); ; }
/// <summary> /// 绑定数据 /// </summary> private void BindData() { DataSet ds = ProductTypeService.GetList("parentId = 0"); if (ds.Tables[0].Rows.Count > 0) { repOne.DataSource = ds; repOne.DataBind(); } }
/// <summary> /// /// </summary> /// <param name="id"></param> /// <returns></returns> protected string GetName(object id) { ProductType pt = ProductTypeService.GetModel(Convert.ToInt32(id)); if (pt != null) { return(pt.typeName); } return(""); }
/// <summary> /// 获取对象 /// </summary> private void LoadModelInfo() { Product item = ProductService.GetModel(id); if (item != null) { txtTjOrder.Text = item.speed.ToString(); txtStoreCount.Text = item.proType.ToString(); txtMobileGood.Text = item.stopTypeName; ddlRelieve.SelectedValue = item.relieveId.ToString(); ddlCook.SelectedValue = item.cookId.ToString(); this.content2.Value = item.advantage; lblImgUrl.Text = item.listImgUrl; Label1.Text = item.detailImg1; txtFrom.Text = item.fromName; ddlOne.SelectedValue = item.oneId.ToString(); txtProductName.Text = item.proName; content1.Value = item.proContent; content3.Value = item.ImgDesc; ddlTwo.Items.Clear(); DataSet ds = ProductTypeService.GetList("parentId = " + ddlOne.SelectedValue); if (ds.Tables[0].Rows.Count > 0) { ddlTwo.DataSource = ds; ddlTwo.DataTextField = "typeName"; ddlTwo.DataValueField = "id"; ddlTwo.DataBind(); } ddlTwo.Items.Insert(0, new ListItem("请选择", "0")); ddlTwo.SelectedValue = item.twoId.ToString(); ddlThree.Items.Clear(); ds = ProductTypeService.GetList("parentId = " + ddlTwo.SelectedValue); if (ds.Tables[0].Rows.Count > 0) { ddlThree.DataSource = ds; ddlThree.DataTextField = "typeName"; ddlThree.DataValueField = "id"; ddlThree.DataBind(); } this.ddlThree.Items.Insert(0, new ListItem("请选择", "0")); ddlThree.SelectedValue = item.threeId.ToString(); ddlVariety.SelectedValue = item.varietyId.ToString(); prodesc.Text = item.proDesc; unit1.Text = item.unit1; price1.Text = item.price1.ToString("0.00"); ViewState["userId"] = item.useId; } }
private void fAddProduct_Load(object sender, EventArgs e) { ProductTypeService productTypeService = new ProductTypeService(new CoffeShopContext()); cbbProductType.Properties.Items.AddRange(productTypeService.GetAllName()); UnitService unitService = new UnitService(new CoffeShopContext()); cbbUnit.Properties.Items.AddRange(unitService.GetAllName()); }
public void loadProductTypeList() { ProductTypeService productTypeService = new ProductTypeService(); List <ProductType> productTypes = productTypeService.GetProductTypes(); if (productTypes != null) { setUpDataGrid(productTypes); //dgvProductTypeList.DataSource = productTypes; } }
public void loadProductTypeList() { ProductTypeService productTypeService = new ProductTypeService(); List<ProductType> productTypes = productTypeService.GetProductTypes(); if (productTypes != null) { setUpDataGrid(productTypes); //dgvProductTypeList.DataSource = productTypes; } }
public void loadDataForEditProductType(int productTypeId) { this.Text = "Chỉnh sửa loại sản phẩm này"; this.btnAdd.Text = "Cập nhật"; ProductTypeService productTypeService = new ProductTypeService(); productType = productTypeService.GetProductType(productTypeId); if (productType != null) { txtDescription.Text = productType.Description; txtCode.Text = productType.TypeCode; txtName.Text = productType.TypeName; } }
public void AddProductType() { //List<ProductType> list = (List<ProductType>)BaoHienRepository.SelectAll<ProductType>().Where<ProductType>(item => item.st == false).ToList<ProductType>(); //int count = list.Count; ProductType productType = new ProductType { Description = "P Type 1", ProductName = "Product 1", TypeCode = "Type code 1" }; ProductTypeService productTypeService = new ProductTypeService(); bool result = productTypeService.AddProductType(productType); Assert.AreEqual<bool>(true, result); ; }
private void searchProductType() { ProductTypeSearchCriteria producTypeSearchCriteria = new ProductTypeSearchCriteria { ProductTypeCode = string.IsNullOrEmpty(txtCode.Text) ? "" : txtCode.Text.ToLower(), ProductTypeName = string.IsNullOrEmpty(txtName.Text) ? "" : txtName.Text.ToLower() }; ProductTypeService producTypeService = new ProductTypeService(); List<ProductType> productTypes = producTypeService.SearchingProductType(producTypeSearchCriteria); if (productTypes != null) { dgvProductTypeList.DataSource = productTypes; lblTotalResult.Text = productTypes.Count.ToString(); } }
public void loadProductList() { ProductService productService = new ProductService(); List<Product> products = productService.GetProducts().OrderBy(x => x.ProductCode).ToList(); setUpDataGrid(products); ProductTypeService productTypeService = new ProductTypeService(); List<ProductType> productTypes = productTypeService.GetProductTypes(); productTypes.Add(new ProductType() { Id = 0, TypeName = "Tất cả" }); productTypes = productTypes.OrderBy(x => x.Id).ToList(); if (productTypes != null) { cbProductTypes.DataSource = productTypes; cbProductTypes.DisplayMember = "TypeName"; cbProductTypes.ValueMember = "Id"; } }
private void btnAdd_Click(object sender, EventArgs e) { if (validator1.Validate()) { if (productType != null && productType.Id > 0)//edit { productType.Description = txtDescription.Text; productType.TypeName = txtName.Text; productType.TypeCode = txtCode.Text; ProductTypeService productTypeService = new ProductTypeService(); bool result = productTypeService.UpdateProductType(productType); if (result) { MessageBox.Show("Loại sản phẩm đã được cập nhật vào hệ thống"); ((ucProductType)this.CallFromUserControll).loadProductTypeList(); this.Close(); } else { MessageBox.Show("Hiện tại hệ thống đang có lỗi. Vui lòng thử lại sau!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else//add new { productType = new ProductType { Description = txtDescription.Text, TypeName = txtName.Text, TypeCode = txtCode.Text }; ProductTypeService productTypeService = new ProductTypeService(); bool result = productTypeService.AddProductType(productType); if (result) { MessageBox.Show("Loại sản phẩm đã được thêm mới vào hệ thống"); ((ucProductType)this.CallFromUserControll).loadProductTypeList(); this.Close(); } else { MessageBox.Show("Hiện tại hệ thống đang có lỗi. Vui lòng thử lại sau!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
void LoadDataCombobox() { ProductTypeService productTypeService = new ProductTypeService(); ProductType pt = new ProductType { Id = 0, TypeName = "Tất cả" }; productTypes = productTypeService.GetProductTypes(); productTypes.Add(pt); productTypes = productTypes.OrderBy(pts => pts.Id).ToList(); if (productTypes != null) { cbmProductTypes.DataSource = productTypes; cbmProductTypes.DisplayMember = "TypeName"; cbmProductTypes.ValueMember = "Id"; } LoadProducts(0); }
private void dgvProductTypeList_CellClick(object sender, DataGridViewCellEventArgs e) { if (sender is DataGridView) { DataGridViewCell cell = ((DataGridView)sender).CurrentCell; if (cell.ColumnIndex == ((DataGridView)sender).ColumnCount - 1) { DialogResult result = MessageBox.Show("Bạn có muốn xóa loại sản phẩm này?", "Xoá loại sản phẩm này", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { DataGridViewRow currentRow = dgvProductTypeList.Rows[e.RowIndex]; int id = ObjectHelper.GetValueFromAnonymousType<int>(currentRow.DataBoundItem, "Id"); ProductService productService = new ProductService(); ProductTypeService producTypeService = new ProductTypeService(); List<Product> productList = productService.SelectProductByWhere(pt => pt.ProductType == id); if (productList.Count > 0) { MessageBox.Show("Loại này hiện có nhiều sản phẩm. Không xóa được!"); } else { if (!producTypeService.DeleteProductType(id)) { MessageBox.Show("Hiện tại hệ thống đang có lỗi. Vui lòng thử lại sau!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } loadProductTypeList(); } } } } }
/// <summary> /// /// </summary> /// <param name="portalid"></param> /// <param name="prodtype"></param> /// <param name="connString"></param> /// <returns></returns> private static int ZnodeProductTypeInsert(int portalid, string prodtypeName, string connString) { int prodtypeid = 0; try { SqlConnection conn = new SqlConnection(connString); SqlCommand SKUCMD = new SqlCommand("ZNODE_NT_ZNodeProductType_Find", conn); SKUCMD.CommandType = CommandType.StoredProcedure; SqlParameter param; param = new SqlParameter("@portalid", SqlDbType.Int); param.Value = portalid; SKUCMD.Parameters.Add(param); param = new SqlParameter("@Name", SqlDbType.VarChar); param.Value = prodtypeName; SKUCMD.Parameters.Add(param); conn.Open(); SqlDataReader dr = SKUCMD.ExecuteReader(); if (dr.HasRows) { if (dr.Read()) { prodtypeid = Convert.ToInt32(dr["ProducttypeId"]); } } else { ProductTypeService prodTypeServ = new ProductTypeService(); ProductType prodType = new ProductType(); prodType.PortalId = portalid; prodType.Name = prodtypeName; prodTypeServ.Insert(prodType); prodtypeid = prodType.ProductTypeId; } conn.Close(); return prodtypeid; } catch (Exception) { return 0; } }
private void loadSomeData() { if (productTypes == null) { ProductTypeService productTypeService = new ProductTypeService(); productTypes = productTypeService.GetProductTypes(); } if (productTypes != null) { cmbType.DataSource = productTypes; cmbType.DisplayMember = "TypeName"; cmbType.ValueMember = "Id"; } BaseAttributeService baseAttributeService = new BaseAttributeService(); if (baseAttributes == null) { baseAttributes = baseAttributeService.GetBaseAttributes(); } }