protected void BtnSaveProduct_Click(object sender, EventArgs e) { Product prod = new Product(); if (productID>0) { prod.LoadByPrimaryKey(productID); } else { prod.AddNew(); } prod.NameEn = txtProdName.Text; prod.CatID = int.Parse(Session["CategoryID"].ToString()); prod.DescriptionEn = txtProdDesc.Text; if (FileUploadMainImg.HasFile) { Bitmap UpImg = (Bitmap)Bitmap.FromStream(FileUploadMainImg.PostedFile.InputStream); string path = "UploadedFiles/Products/" + DateTime.Now.ToString("ddMMyyyyhhmmss") + FileUploadMainImg.FileName; UpImg.Save(MapPath(path), System.Drawing.Imaging.ImageFormat.Png); prod.MainImagePath = path; } prod.YouTubeLink = txtVidLink.Text; prod.AppearInHome = chkAvailHome.Checked; prod.IsActive = chkActive.Checked; prod.Save(); Response.Redirect("Products.aspx?cid=" + Session["CategoryID"]); }
protected void GrdViewProducts_RowCommand(object sender, GridViewCommandEventArgs e) { switch (e.CommandName.ToString()) { case "EditProduct": Response.Redirect("Products.aspx?EditProd=" + e.CommandArgument.ToString()); break; case "AddFiles": Response.Redirect("Products.aspx?AddFiles=" + e.CommandArgument.ToString()); break; case "AddImgs": Response.Redirect("Products.aspx?AddImgs=" + e.CommandArgument.ToString()); break; case "DeleteProduct": Product delProd = new Product(); delProd.LoadByPrimaryKey(int.Parse(e.CommandArgument.ToString())); delProd.MarkAsDeleted(); delProd.Save(); GrdCatsBind(); break; default: break; } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { if (!string.IsNullOrEmpty(Request.QueryString["Cid"])) { Session["CategoryID"] = int.Parse(Request.QueryString["Cid"]); lblCatNameTitle.Text = "Category : " + getCatName(); GrdCatsBind(); } if (!string.IsNullOrEmpty(Request.QueryString["NewProd"])) { PlaceHolderEditProd.Visible = true; PlaceHolderFiles.Visible = false; PlaceHolderGrd.Visible = false; PlaceHolderImgs.Visible = false; lblCatName.Text = getCatName(); } else if (productID > 0) { if (!string.IsNullOrEmpty(Request.QueryString["EditProd"])) { PlaceHolderEditProd.Visible = true; PlaceHolderFiles.Visible = false; PlaceHolderGrd.Visible = false; PlaceHolderImgs.Visible = false; RequiredFieldValidator4.Enabled = false; BtnSaveProduct.Text = "Update Product"; Product prod = new Product(); prod.LoadByPrimaryKey(productID); txtProdName.Text = prod.NameEn; txtProdDesc.Text = prod.DescriptionEn; txtVidLink.Text = prod.YouTubeLink; if (!string.IsNullOrWhiteSpace(prod.MainImagePath)) { ProdImg.Src = prod.MainImagePath; } chkAvailHome.Checked = prod.AppearInHome; chkActive.Checked = prod.IsActive; } else if (!string.IsNullOrEmpty(Request.QueryString["AddFiles"])) { PlaceHolderEditProd.Visible = false; PlaceHolderFiles.Visible = true; PlaceHolderGrd.Visible = false; PlaceHolderImgs.Visible = false; FilesGrdBind(); } else if (!string.IsNullOrEmpty(Request.QueryString["AddImgs"])) { PlaceHolderEditProd.Visible = false; PlaceHolderFiles.Visible = false; PlaceHolderGrd.Visible = false; PlaceHolderImgs.Visible = true; galleryBind(); } else { PlaceHolderGrd.Visible = true; } } else { PlaceHolderGrd.Visible = true; } } }
private void PopulateFields() { try { if (_itemId == 0) return; Items itm = new Items(); itm.LoadByPrimaryKey(_itemId); SubCategory cat = new SubCategory(); DataTable dtCat = cat.GetSubCategoryOfItem(_itemId); foreach (DataRow drcat in dtCat.Rows) { DataTable dtProd = cat.GetSubCategoryByID(Convert.ToInt32(drcat["SubCategoryID"])); //txtCategory.Text = dtProd.Rows[0]["CategoryName"].ToString(); //txtSubCategory.Text = dtProd.Rows[0]["SubCategoryName"].ToString(); string[] categor = { dtProd.Rows[0]["CategoryName"].ToString(), dtProd.Rows[0]["SubCategoryName"].ToString() }; ListViewItem listCat = new ListViewItem(categor) { Tag = dtProd.Rows[0]["ID"] }; lstCat.Items.Add(listCat); } cboIIN.SelectedValue = itm.IINID.ToString(); Product nInn = new Product(); nInn.LoadByPrimaryKey(itm.IINID); //txtATC.Text = nInn.ATC; txtStrength.Text = itm.Strength; ckIsDiscontinued.Checked = itm.IsDiscontinued; ckIsEDL.Checked = itm.EDL; ckIsFree.Checked = itm.IsFree; ckIsPedatric.Checked = itm.Pediatric; ckIsRefrigerated.Checked = itm.Refrigeratored; cboDosageForm.SelectedValue = itm.DosageFormID.ToString(); cboUnit.SelectedValue = itm.UnitID.ToString(); string code = itm.StockCode; txtStockCode.Text = code; txtStock2.Text = itm.Code; txtStock3.Text = itm.StockCodeDACA; } catch { } }