protected void btnSubmit_Click(object sender, EventArgs e) { string name = txtname.Text; if (txtname.Text != string.Empty) { try { Product product = new Product(); product.Name = txtname.Text.Trim(); product.Description = txtDescription.Text.Trim(); product.SeName = txtname.Text.Trim().ToLower().Replace(' ', '-').Replace('_', '-').Replace('.', '-'); product.SeKeywords = txtname.Text.Trim(); product.SeDescription = txtDescription.Text.Trim(); product.Summary = txtSummary.Text.Trim(); product.InStock = true; //Convert.ToBoolean(Convert.ToInt32(dr["InStock"].ToString().Trim())); product.CreatedOn = DateTime.Now; product.ProductGuid = Guid.NewGuid(); //// FileUpload string domain = "http:\\" + Request.Url.Host; if (domain == "localhost") { domain += ":" + Request.Url.Port; //ConfigurationManager.AppSettings["ImageDomain"]; } string image = domain; if (imageFile.HasFile) { string fileExt = Path.GetExtension(imageFile.FileName); if (fileExt == ".png" || fileExt == ".gif" || fileExt == ".jpeg" || fileExt == ".jpg") { try { string trailingPath = Path.GetFileName(imageFile.PostedFile.FileName); string fullPath = Path.Combine(Server.MapPath("Images"), trailingPath); image += "/Images/" + trailingPath; imageFile.PostedFile.SaveAs(fullPath); string filedes = "File name: " + imageFile.PostedFile.FileName + "<br>" + imageFile.PostedFile.ContentLength + " kb<br>" + "Content type: " + imageFile.PostedFile.ContentType; } catch (Exception ex) { lblerror.Text = "ERROR: " + ex.Message.ToString(); } } else { lblerror.Text = "Only .png, .gif and .jpeg files allowed!"; } } else { lblerror.Text = "You have not specified a file."; } //// Product Price product.Costinrupee = Convert.ToDecimal(txtCostinrupee.Text.Trim()); product.Profitpriceinrupee = Convert.ToDecimal(txtProfitpriceinrupee.Text.Trim()); product.Deleted = 0; //// Image product.ImageFilenameOverride = image; int productid = productrep.PreInsertProduct(product); ProductCategory prodcat = new ProductCategory(); prodcat.CategoryId = Convert.ToInt32(ddlCategory.SelectedValue); prodcat.ProductId = productid; prodcat.CreatedOn = DateTime.Now; productcatrep.InsertProductCategory(prodcat); txtname.Text = string.Empty; BindGridviw(); } catch (Exception ex) { Response.Write(ex.ToString() + " " + name); } } else { } }
protected void btnSubmit_Click(object sender, EventArgs e) { ProductRepository productrep = new ProductRepository(); ProductCategoryRepository productcatrep = new ProductCategoryRepository(); string name = txtname.Text; if (txtname.Text != string.Empty) { try { Product product = new Product(); product.Name = txtname.Text.Trim(); product.Description = txtDescription.Text.Trim(); product.SeName = txtSEName.Text.Trim().ToLower().Replace(' ', '-').Replace('_', '-').Replace('.', '-'); product.SeKeywords = txtname.Text.Trim(); product.SeDescription = txtDescription.Text.Trim(); product.Summary = txtSummary.Text.Trim(); product.InStock = true; //Convert.ToBoolean(Convert.ToInt32(dr["InStock"].ToString().Trim())); product.CreatedOn = DateTime.Now; product.ProductGuid = Guid.NewGuid(); //////Product product = new Product(); //////product.Name = dr["Name"].ToString().Trim(); //////product.Description = dr["Description"].ToString().Trim(); //////product.SeName = dr["Name"].ToString().Trim().ToLower().Replace(' ', '-').Replace('_', '-'); //////product.SeKeywords = dr["Name"].ToString().Trim(); //////product.SeDescription = dr["Description"].ToString().Trim(); //////product.Summary = dr["Summary"].ToString().Trim(); //////product.InStock = true; //Convert.ToBoolean(Convert.ToInt32(dr["InStock"].ToString().Trim())); //////product.CreatedOn = DateTime.Now; //////product.ProductGuid = Guid.NewGuid(); //// Product Price product.Costinrupee = Convert.ToDecimal(txtCostinrupee.Text.Trim()); product.Costindollar = Convert.ToDecimal(txtCostindollar.Text.Trim()); product.Profitpriceindollar = Convert.ToDecimal(txtProfitpriceindollar.Text.Trim()); product.Profitpriceinrupee = Convert.ToDecimal(txtProfitpriceinrupee.Text.Trim()); product.Profit = Convert.ToDecimal(txtprofit.Text.Trim()); product.StichedPrice = Convert.ToDecimal(txtStichedPrice.Text.Trim()); product.Deleted = 0; ////product.Costinrupee = Convert.ToDecimal(dr["Costinrupee"].ToString().Trim()); ////product.Costindollar = Convert.ToDecimal(dr["Costindollar"].ToString().Trim()); ////product.Profitpriceindollar = Convert.ToDecimal(dr["Profitpriceindollar"].ToString().Trim()); ////product.Profitpriceinrupee = Convert.ToDecimal(dr["Profitpriceinrupee"].ToString().Trim()); ////product.Profit = Convert.ToDecimal(dr["Profit"].ToString().Trim()); ////product.StichedPrice = Convert.ToDecimal(dr["StichedPrice"].ToString().Trim()); ////product.Deleted = 0; //// Image string image = "~/Images/products/OB/" + ddlType.SelectedValue + "/" + txtimage.Text.Trim().Replace(' ', '_') + ".jpg"; product.ImageFilenameOverride = image; int productid = productrep.PreInsertProduct(product); ProductCategory prodcat = new ProductCategory(); prodcat.CategoryId = Convert.ToInt32(ddlCategory.SelectedValue); prodcat.ProductId = productid; prodcat.CreatedOn = DateTime.Now; productcatrep.InsertProductCategory(prodcat); txtname.Text = string.Empty; BindGridviw(); } catch (Exception ex) { Response.Write(ex.ToString() + " " + name); } } else { } }
private void Productinsertion(DataSet ds, string ImageName) { ////For Product Insertion ProductRepository productrep = new ProductRepository(); ProductCategoryRepository productcatrep = new ProductCategoryRepository(); if (ds != null && ds.Tables[0].Rows.Count != 0) { foreach (DataRow dr in ds.Tables[0].Rows) { string name = dr["Name"].ToString(); if (dr["Name"].ToString() != string.Empty) { try { Product product = new Product(); product.Name = dr["Name"].ToString().Trim(); product.Description = dr["Description"].ToString().Trim(); product.SeName = dr["Name"].ToString().Trim().ToLower().Replace(' ', '-').Replace('_', '-'); product.SeKeywords = dr["Name"].ToString().Trim(); product.SeDescription = dr["Description"].ToString().Trim(); product.Summary = dr["Summary"].ToString().Trim(); product.InStock = true; //Convert.ToBoolean(Convert.ToInt32(dr["InStock"].ToString().Trim())); product.CreatedOn = DateTime.Now; product.ProductGuid = Guid.NewGuid(); //// Product Price product.Costinrupee = Convert.ToDecimal(dr["Costinrupee"].ToString().Trim()); product.Costindollar = Convert.ToDecimal(dr["Costindollar"].ToString().Trim()); product.Profitpriceindollar = Convert.ToDecimal(dr["Profitpriceindollar"].ToString().Trim()); product.Profitpriceinrupee = Convert.ToDecimal(dr["Profitpriceinrupee"].ToString().Trim()); product.Profit = Convert.ToDecimal(dr["Profit"].ToString().Trim()); product.StichedPrice = Convert.ToDecimal(dr["StichedPrice"].ToString().Trim()); //// Image string image = "~/Images/products/OB/" + ImageName + "/" + dr["ImageName"].ToString().Trim().Replace(' ', '_') + ".jpg"; product.ImageFilenameOverride = image; int productid = productrep.PreInsertProduct(product); ProductCategory prodcat = new ProductCategory(); prodcat.CategoryId = Convert.ToInt32(dr["catid"].ToString().Trim()); prodcat.ProductId = productid; prodcat.CreatedOn = DateTime.Now; productcatrep.InsertProductCategory(prodcat); } catch (Exception ex) { Response.Write(ex.ToString() + " " + name); } } else { break; } } } }