protected void btnInsert_Click(object sender, EventArgs e) { tProductsTableAdapter sda = new tProductsTableAdapter(); DstProducts ds = new DstProducts(); string ImgExtention = ""; if (FileUpload1.HasFile) { ImgExtention = System.IO.Path.GetExtension(FileUpload1.FileName); } string FileNme = ""; if (ImgExtention != "") { FileNme = GetNameForFile(); } if (dg.SelectedIndex > -1 && txtName.Text.Trim() != "") { bool Success = sda.FillByCode(ds.tProducts, int.Parse(ddlGroups.SelectedValue.ToString())) > 0; if (Success) { ds.tProducts.Rows[0][ds.tProducts.fCodeGroupColumn] = ddlGroups.SelectedValue.ToString(); ds.tProducts.Rows[0][ds.tProducts.fNameColumn] = txtName.Text.Trim(); ds.tProducts.Rows[0][ds.tProducts.fDescColumn] = txtDesc.Text.Trim(); ds.tProducts.Rows[0][ds.tProducts.fPriceColumn] = txtPrice.Text.Trim(); if (FileUpload1.HasFile) { ImageUpload(FileNme, ImgExtention); ds.tProducts.Rows[0][ds.tProducts.fImageNameColumn] = "IMG/" + FileNme.Trim() + ImgExtention; } sda.Update(ds.tProducts); Label6.Text = "ویرایش محصول با موفقیت در سیستم ذخیره گردید"; } } else { DataRow MyRow = ds.tProducts.NewRow(); MyRow[ds.tProducts.fCodeGroupColumn] = ddlGroups.SelectedValue.ToString(); MyRow[ds.tProducts.fNameColumn] = txtName.Text.Trim(); MyRow[ds.tProducts.fPriceColumn] = txtPrice.Text.Trim(); MyRow[ds.tProducts.fDescColumn] = txtDesc.Text.Trim(); if (FileUpload1.HasFile) { ImageUpload(FileNme, ImgExtention); MyRow[ds.tProducts.fImageNameColumn] = "IMG/" + FileNme.Trim() + ImgExtention; } ds.tProducts.Rows.Add(MyRow); sda.Update(ds.tProducts); Label6.Text = "اطلاعات محصول جدید با موفقیت در سیستم ذخیره گردید"; } ClearTextBox(); //BindGrid(); dg.SelectedIndex = -1; }
private void BindGrid() { tProductsTableAdapter sda = new tProductsTableAdapter(); DstProducts ds = new DstProducts(); string ss = ddlGroups.SelectedValue.ToString(); sda.FillByCodeGroup(ds.tProducts, int.Parse(ddlGroups.SelectedValue.ToString())); dg.DataSource = ds.tProducts; dg.DataBind(); }
protected void btnDelete_Click(object sender, EventArgs e) { if (txtName.Text.Trim() != "" && txtPrice.Text.Trim() != "" && dg.SelectedIndex > -1) { tProductsTableAdapter sda = new tProductsTableAdapter(); sda.Delete(int.Parse(dg.SelectedValue.ToString())); Label6.Text = "حذف محصول با موفقیت انجام شد"; BindGrid(); ClearTextBox(); dg.SelectedIndex = -1; } }
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { try { tProductsTableAdapter sdaProduct = new tProductsTableAdapter(); DstSells ds = new DstSells(); ds = (DstSells)Session["ds"]; ds.tSells.Rows.Find(GridView1.SelectedValue).Delete(); GridView1.DataSource = ds.tSells; GridView1.DataBind(); Session["ds"] = ds; } catch { } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { try { tProductsTableAdapter sdaProduct = new tProductsTableAdapter(); DstSells ds = new DstSells(); ds = (DstSells)Session["ds"]; GridView1.DataSource = ds.tSells; for (int i = 0; i < ds.tSells.Rows.Count; i++) { ds.tSells.Rows[i][ds.tSells.fNameProductColumn] = sdaProduct.GetNameByCode(int.Parse(ds.tSells.Rows[i][ds.tSells.fCodeProductColumn].ToString())); ds.tSells.Rows[i][ds.tSells.fPriceColumn] = sdaProduct.GetPriceByCode(int.Parse(ds.tSells.Rows[i][ds.tSells.fCodeProductColumn].ToString())); } GridView1.DataBind(); } catch { Response.Redirect("Default.aspx"); } } }