Advertisement
Guest User

Untitled

a guest
Jun 6th, 2013
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.57 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Data.SqlClient;
  8. using System.Configuration;
  9. using System.Drawing;
  10.  
  11. public partial class _Default : System.Web.UI.Page
  12. {
  13.     public class Clients
  14.     {
  15.         public int ID { get; set; }
  16.         public string FullName { get; set; }
  17.         public string PhoneNumber { get; set; }
  18.         public string City { get; set; }
  19.         public string EmailAddress { get; set; }
  20.         public string CustomerType { get; set; }
  21.         public string CustomerCategory { get; set; }
  22.         public string OpenDebt { get; set; }
  23.         public string WayOfContacting { get; set; }
  24.         public string ContactName { get; set; }
  25.  
  26.     }
  27.  
  28.     protected void Page_Load(object sender, EventArgs e)
  29.     {
  30.         string welcomeString = "Hello " + Session["name"] + "! welcome to Niloosoft system!";
  31.         LabelUser.Text = welcomeString;
  32.         if (!IsPostBack)
  33.         {
  34.             BindGridViewData();
  35.         }
  36.     }
  37.     protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)//ignore this function it does not work and noone call it
  38.     {
  39.  
  40.         if (e.Row.RowType == DataControlRowType.DataRow)
  41.         {
  42.             // loop all data rows
  43.             foreach (DataControlFieldCell cell in e.Row.Cells)
  44.             {
  45.                 // check all cells in one row
  46.                 foreach (Control control in cell.Controls)
  47.                 {
  48.                     // Must use LinkButton here instead of ImageButton
  49.                     // if you are having Links (not images) as the command button.
  50.                     ImageButton button = control as ImageButton;
  51.                     if (button != null && button.CommandName == "Delete")
  52.                         // Add delete confirmation
  53.                         button.OnClientClick = "if (!confirm('Are you sure " +
  54.                                "you want to delete this record? this operation cannot be undone')) return;";
  55.                 }
  56.             }
  57.         }
  58.  
  59.     }
  60.     protected void ImageNewCustomer_Click(object sender, ImageClickEventArgs e)
  61.     {
  62.         Response.Redirect("~/AddNewClient.aspx");
  63.     }
  64.     protected void ButtonLogout_Click(object sender, ImageClickEventArgs e)
  65.     {
  66.         Session["name"] = string.Empty;
  67.         Response.Redirect("LoginPage.aspx");
  68.     }
  69.     protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
  70.     {
  71.         Response.Redirect("Home.aspx");
  72.     }
  73.     private void BindGridViewData()
  74.     {
  75.         GridView1.DataSource = GetAllClients();
  76.         GridView1.DataBind();
  77.     }
  78.     public static List<Clients> GetAllClients()
  79.     {
  80.         List<Clients> listEmployees = new List<Clients>();
  81.         using (SqlConnection con = new SqlConnection("Data Source=KOBI-PC2\\SQLEXPRESS;Initial Catalog=Niloosoft;Integrated Security=True"))
  82.         {
  83.             SqlCommand com = new SqlCommand("ShowClients", con);
  84.             com.CommandType = System.Data.CommandType.StoredProcedure;
  85.             con.Open();
  86.             SqlDataReader rdr = com.ExecuteReader();
  87.             while (rdr.Read())
  88.             {
  89.                 Clients client = new Clients();
  90.                 client.ID = Convert.ToInt32(rdr["ID"]);
  91.                 client.FullName = rdr["FullName"].ToString();
  92.                 client.City = rdr["City"].ToString();
  93.                 client.PhoneNumber = rdr["PhoneNumber"].ToString();
  94.                 client.City = rdr["City"].ToString();
  95.                 client.CustomerType = rdr["CustomerType"].ToString();
  96.                 client.CustomerCategory = rdr["CustomerCategory"].ToString();
  97.                 client.ContactName = rdr["ContactName"].ToString();
  98.  
  99.                 listEmployees.Add(client);
  100.             }
  101.         }
  102.         return listEmployees;
  103.     }
  104.     protected void ButtonEditClient_Click(object sender, ImageClickEventArgs e)
  105.     {
  106.         foreach (GridViewRow row in GridView1.Rows)
  107.         {
  108.             CheckBox chk = (CheckBox)row.FindControl("SelectedClient");
  109.             if (chk.Checked)
  110.             {
  111.                 string ID = row.Cells[0].Text;
  112.                 string name = row.Cells[1].Text;
  113.                 Response.Redirect("~/EditClient.aspx?ID=" + ID + "&Name=" + name + "&Mode=edit");
  114.             }
  115.             else
  116.             {
  117.                 ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + "לא נבחר לקוח לעריכה" + "');", true);
  118.             }
  119.         }
  120.     }
  121.     protected void ButonDeleteClient_Click(object sender, ImageClickEventArgs e)
  122.     {
  123.         foreach (GridViewRow row in GridView1.Rows)
  124.         {
  125.             CheckBox chk = (CheckBox)row.FindControl("SelectedClient");
  126.             if (chk.Checked)
  127.             {
  128.                 BindGridViewData();
  129.                 string ID = "0" + row.Cells[0].Text;
  130.                 string name = row.Cells[1].Text;
  131.                 using (SqlConnection con = new SqlConnection("Data Source=KOBI-PC2\\SQLEXPRESS;Initial Catalog=Niloosoft;Integrated Security=True"))
  132.                 {
  133.                     SqlCommand cmd = new SqlCommand("DeleteCustomer", con);
  134.                     cmd.CommandType = System.Data.CommandType.StoredProcedure;
  135.                     cmd.Parameters.AddWithValue("@ID", ID);
  136.                     cmd.Parameters.AddWithValue("@FullName", name);
  137.                     con.Open();
  138.                     cmd.ExecuteNonQuery();
  139.                     con.Close();
  140.                 }
  141.             }
  142.             BindGridViewData();
  143.         }
  144.     }
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement