protected void uiButtonUpdate_Click(object sender, EventArgs e) { Product product= new Product(); if (CurrentProduct != null) { product = CurrentProduct; } else { product.AddNew(); } product.ProductCode = uiTextBoxCode.Text; product.Name = uiTextBoxName.Text; product.Description = Server.HtmlEncode(uiFCKeditorDesc.Value); product.CategoryID = Convert.ToInt32(uiDropDownListCategory.SelectedValue); if (!string.IsNullOrEmpty(uiDropDownListSubCat.SelectedValue)) product.SubCategoryID = Convert.ToInt32(uiDropDownListSubCat.SelectedValue); if(!string.IsNullOrEmpty(uiTextBoxPrice.Text)) product.Price = decimal.Parse(uiTextBoxPrice.Text); string file = ""; if (uiFileUploadImg.HasFile) { uiFileUploadImg.SaveAs(Server.MapPath("~/UploadFolder/products/" + uiFileUploadImg.FileName)); file = "/UploadFolder/products/" + uiFileUploadImg.FileName; product.PicPath = file; } product.Save(); uiPanelEdit.Visible = false; uiPanelViewProducts.Visible = true; Clearfields(); BindData(); CurrentProduct = null; }
protected void uiButtonCancel_Click(object sender, EventArgs e) { uiPanelEdit.Visible = false; uiPanelViewProducts.Visible = true; Clearfields(); CurrentProduct = null; }
private void BindData() { Product prod = new Product(); prod.GetAllProducts(); uiGridViewProducts.DataSource = prod.DefaultView; uiGridViewProducts.DataBind(); }
protected void uiGridViewProducts_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "EditProduct") { Product product = new Product(); product.LoadByPrimaryKey(Convert.ToInt32(e.CommandArgument)); CurrentProduct = product; uiTextBoxName.Text = product.Name; uiTextBoxCode.Text = product.ProductCode; if(!product.IsColumnNull("Price")) uiTextBoxPrice.Text = product.Price.ToString(); uiFCKeditorDesc.Value = Server.HtmlDecode(product.Description); uiDropDownListCategory.SelectedValue = product.CategoryID.ToString(); if (!product.IsColumnNull("SubCategoryID")) uiDropDownListSubCat.SelectedValue = product.SubCategoryID.ToString(); uiPanelViewProducts.Visible = false; uiPanelEdit.Visible = true; } else if (e.CommandName == "DeleteProduct") { try { Product product = new Product(); product.LoadByPrimaryKey(Convert.ToInt32(e.CommandArgument)); product.MarkAsDeleted(); product.Save(); BindData(); } catch (Exception ex) { uiLabelError.Visible = true; } } }
private void LoadDDLs() { Users users = new Users(); users.GetAllUsers(); uiDropDownListUsers.DataSource = users.DefaultView; uiDropDownListUsers.DataTextField = "DisplayName"; uiDropDownListUsers.DataValueField = "UserID"; uiDropDownListUsers.DataBind(); uiDropDownListUsers.Items.Insert(0, new ListItem("Choose user", "")); Product product = new Product(); product.GetAllProducts(); uiDropDownListProducts.DataSource = product.DefaultView; uiDropDownListProducts.DataTextField = "Name"; uiDropDownListProducts.DataValueField = "ProductID"; uiDropDownListProducts.DataBind(); uiDropDownListProducts.Items.Insert(0, new ListItem("Choose product", "")); OrderStatus orderStatus = new OrderStatus(); orderStatus.LoadAll(); uiDropDownListStatus.DataSource = orderStatus.DefaultView; uiDropDownListStatus.DataTextField = "Name"; uiDropDownListStatus.DataValueField = "OrderStatusID"; uiDropDownListStatus.DataBind(); uiDropDownListStatus.Items.Insert(0, new ListItem("Choose status", "")); }
protected void uiDropDownListProducts_SelectedIndexChanged(object sender, EventArgs e) { Product pro = new Product(); pro.LoadByPrimaryKey(Convert.ToInt32(uiDropDownListProducts.SelectedValue)); if(!pro.IsColumnNull("Price")) uiTextBoxPrice.Text = pro.Price.ToString(); }