SHARE
TWEET

Untitled

a guest Nov 15th, 2017 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public void userSales()
  2. {
  3.     con.Open();
  4.  
  5.     SqlCommand cmd = new SqlCommand("SELECT SalesActivity.Activity_ID, SalesActivity.Date, SalesActivity.Quatation_Number, CUSTOMER.Customer_Name, PRODUCTS.Machine_Model, SalesActivity.Quantity, SalesActivity.valueGBR, SalesActivity.valueEUR, SalesActivity.Rate, SalesActivity.weightedValue, STATUS.Status, SalesActivity.estDecisionDate, SalesActivity.PromisedDeliveryDate FROM SalesActivity INNER JOIN CUSTOMER ON SalesActivity.Customer_ID = CUSTOMER.Customer_ID INNER JOIN PRODUCTS ON SalesActivity.Product_ID = PRODUCTS.Product_ID INNER JOIN STATUS ON SalesActivity.Status_ID = STATUS.Status_ID ", con);
  6.     SqlDataAdapter da = new SqlDataAdapter(cmd);
  7.     DataSet ds = new DataSet();
  8.     da.Fill(ds);
  9.     con.Close();
  10.  
  11.     if (ds.Tables[0].Rows.Count > 0)
  12.     {
  13.         GridView1.DataSource = ds;
  14.         GridView1.DataBind();
  15.     }
  16.     else
  17.     {
  18.         ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());  // if record not found then returning a blank table structure
  19.         GridView1.DataSource = ds;
  20.         GridView1.DataBind();
  21.  
  22.         int columncount = GridView1.Rows[0].Cells.Count;
  23.  
  24.         GridView1.Rows[0].Cells.Clear();
  25.         GridView1.Rows[0].Cells.Add(new TableCell());
  26.         GridView1.Rows[0].Cells[0].ColumnSpan = columncount;
  27.         GridView1.Rows[0].Cells[0].Text = "No Records Found";
  28.     }
  29. }
  30.  
  31. protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
  32. {
  33.     GridView1.EditIndex = e.NewEditIndex; //this open new index that is edit mode
  34.     userSales();
  35. }
  36.  
  37. protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
  38. {
  39.     GridView1.EditIndex = -1;   //after cancel button want go to one index back that's y -1
  40.     userSales();
  41. }
  42.  
  43. protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
  44. {
  45.     if (e.CommandName.Equals("AddNew"))
  46.     {
  47.         TextBox txtActivity = (TextBox)GridView1.FooterRow.FindControl("ftxtActivity");
  48.         TextBox ftxtDate = (TextBox)GridView1.FooterRow.FindControl("ftxtDate");
  49.         TextBox ftxtQno = (TextBox)GridView1.FooterRow.FindControl("ftxtQno");
  50.         DropDownList fddlCName = GridView1.FooterRow.FindControl("fddlCName") as DropDownList;
  51.         DropDownList fddlMmodel = GridView1.FooterRow.FindControl("fddlMmodel") as DropDownList;
  52.         TextBox ftxtQuantity = (TextBox)GridView1.FooterRow.FindControl("ftxtQuantity");
  53.         TextBox ftxtvalueGBR = (TextBox)GridView1.FooterRow.FindControl("ftxtvalueGBR");
  54.         TextBox ftxtvalueEUR = (TextBox)GridView1.FooterRow.FindControl("ftxtvalueEUR");
  55.         TextBox ftxtRate = (TextBox)GridView1.FooterRow.FindControl("ftxtRate");
  56.         TextBox ftxtweightedValue = (TextBox)GridView1.FooterRow.FindControl("ftxtweightedValue");
  57.         DropDownList fddlStatus = GridView1.FooterRow.FindControl("fddlStatus") as DropDownList;
  58.         TextBox ftxtestDecisionDate = (TextBox)GridView1.FooterRow.FindControl("ftxtestDecisionDate");
  59.         TextBox ftxtPromisedDeliveryDate = (TextBox)GridView1.FooterRow.FindControl("ftxtPromisedDeliveryDate");
  60.  
  61.         con.Open();
  62.  
  63.         SqlCommand cmd = new SqlCommand("INSERT INTO SalesActivity(Activity_ID, Date, Quotation_Number, Customer_Name, Machine_Model,Quantity, valueGBR, valueEUR, Rate, weightedValue, Status, estDecisionDate, PromisedDeliveryDate) VALUES(@Activity_ID, @Date, @Quotation_Number, @Customer_Name, @Machine_Model, @Quantity, @valueGBR, @valueEUR, @Rate, @weightedValue, @Status, @estDecisionDate, @PromisedDeliveryDate)", con);
  64.         cmd.Parameters.AddWithValue("@Activity_ID", txtActivity.Text.Trim());
  65.         cmd.Parameters.AddWithValue("@Date", ftxtDate.Text.Trim());
  66.         cmd.Parameters.AddWithValue("@Quotation_Number", ftxtQno.Text.Trim());
  67.         cmd.Parameters.AddWithValue("@Customer_Name", fddlCName.SelectedItem.Text);
  68.         cmd.Parameters.AddWithValue("@Machine_Model", fddlMmodel.SelectedItem.Text);
  69.         cmd.Parameters.AddWithValue("@Quantity",  ftxtQuantity.Text.Trim());
  70.         cmd.Parameters.AddWithValue("@valueGBR", ftxtvalueGBR.Text.Trim());
  71.         cmd.Parameters.AddWithValue("@valueEUR",  ftxtvalueEUR.Text.Trim());
  72.         cmd.Parameters.AddWithValue("@weightedValue",ftxtweightedValue.Text.Trim());
  73.         cmd.Parameters.AddWithValue("@Rate",  ftxtRate.Text.Trim());
  74.         cmd.Parameters.AddWithValue("@Status",  fddlStatus.SelectedItem.Text);
  75.         cmd.Parameters.AddWithValue("@estDecisionDate", ftxtestDecisionDate.Text.Trim());
  76.         cmd.Parameters.AddWithValue("@PromisedDeliveryDate", ftxtPromisedDeliveryDate.Text.Trim());
  77.  
  78.         int result = cmd.ExecuteNonQuery();
  79.  
  80.         con.Close();
  81.  
  82.         if (result == 1)
  83.         {
  84.             userSales();
  85.             Response.Write("<script language=javascript>alert('" + txtActivity.Text + "'+'Sale Details inserted successfully');</script>");
  86.         }
  87.         else
  88.         {
  89.             Response.Write("<script language=javascript>alert('" + txtActivity.Text + "'+' Sale Details not inserted');</script>");
  90.         }
  91.     }
  92. }
  93.    
  94. SELECT SalesActivity.Activity_ID
  95.     ,SalesActivity.DATE
  96.     ,SalesActivity.Quatation_Number
  97.     ,CUSTOMER.Customer_Name
  98.     ,PRODUCTS.Machine_Model
  99.     ,SalesActivity.Quantity
  100.     ,SalesActivity.valueGBR
  101.     ,SalesActivity.valueEUR
  102.     ,SalesActivity.Rate
  103.     ,SalesActivity.weightedValue
  104.     ,STATUS.STATUS
  105.     ,SalesActivity.estDecisionDate
  106.     ,SalesActivity.PromisedDeliveryDate
  107. FROM SalesActivity
  108. INNER JOIN CUSTOMER ON SalesActivity.Customer_ID = CUSTOMER.Customer_ID
  109. INNER JOIN PRODUCTS ON SalesActivity.Product_ID = PRODUCTS.Product_ID
  110. INNER JOIN STATUS ON SalesActivity.Status_ID = STATUS.Status_ID
RAW Paste Data
Top