Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Data.SqlClient;
- using System.Configuration;
- using System.Drawing;
- public partial class _Default : System.Web.UI.Page
- {
- public class Clients
- {
- public int ID { get; set; }
- public string FullName { get; set; }
- public string PhoneNumber { get; set; }
- public string City { get; set; }
- public string EmailAddress { get; set; }
- public string CustomerType { get; set; }
- public string CustomerCategory { get; set; }
- public string OpenDebt { get; set; }
- public string WayOfContacting { get; set; }
- public string ContactName { get; set; }
- }
- protected void Page_Load(object sender, EventArgs e)
- {
- string welcomeString = "Hello " + Session["name"] + "! welcome to Niloosoft system!";
- LabelUser.Text = welcomeString;
- if (!IsPostBack)
- {
- BindGridViewData();
- }
- }
- protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)//ignore this function it does not work and noone call it
- {
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- // loop all data rows
- foreach (DataControlFieldCell cell in e.Row.Cells)
- {
- // check all cells in one row
- foreach (Control control in cell.Controls)
- {
- // Must use LinkButton here instead of ImageButton
- // if you are having Links (not images) as the command button.
- ImageButton button = control as ImageButton;
- if (button != null && button.CommandName == "Delete")
- // Add delete confirmation
- button.OnClientClick = "if (!confirm('Are you sure " +
- "you want to delete this record? this operation cannot be undone')) return;";
- }
- }
- }
- }
- protected void ImageNewCustomer_Click(object sender, ImageClickEventArgs e)
- {
- Response.Redirect("~/AddNewClient.aspx");
- }
- protected void ButtonLogout_Click(object sender, ImageClickEventArgs e)
- {
- Session["name"] = string.Empty;
- Response.Redirect("LoginPage.aspx");
- }
- protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
- {
- Response.Redirect("Home.aspx");
- }
- private void BindGridViewData()
- {
- GridView1.DataSource = GetAllClients();
- GridView1.DataBind();
- }
- public static List<Clients> GetAllClients()
- {
- List<Clients> listEmployees = new List<Clients>();
- using (SqlConnection con = new SqlConnection("Data Source=KOBI-PC2\\SQLEXPRESS;Initial Catalog=Niloosoft;Integrated Security=True"))
- {
- SqlCommand com = new SqlCommand("ShowClients", con);
- com.CommandType = System.Data.CommandType.StoredProcedure;
- con.Open();
- SqlDataReader rdr = com.ExecuteReader();
- while (rdr.Read())
- {
- Clients client = new Clients();
- client.ID = Convert.ToInt32(rdr["ID"]);
- client.FullName = rdr["FullName"].ToString();
- client.City = rdr["City"].ToString();
- client.PhoneNumber = rdr["PhoneNumber"].ToString();
- client.City = rdr["City"].ToString();
- client.CustomerType = rdr["CustomerType"].ToString();
- client.CustomerCategory = rdr["CustomerCategory"].ToString();
- client.ContactName = rdr["ContactName"].ToString();
- listEmployees.Add(client);
- }
- }
- return listEmployees;
- }
- protected void ButtonEditClient_Click(object sender, ImageClickEventArgs e)
- {
- foreach (GridViewRow row in GridView1.Rows)
- {
- CheckBox chk = (CheckBox)row.FindControl("SelectedClient");
- if (chk.Checked)
- {
- string ID = row.Cells[0].Text;
- string name = row.Cells[1].Text;
- Response.Redirect("~/EditClient.aspx?ID=" + ID + "&Name=" + name + "&Mode=edit");
- }
- else
- {
- ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + "לא נבחר לקוח לעריכה" + "');", true);
- }
- }
- }
- protected void ButonDeleteClient_Click(object sender, ImageClickEventArgs e)
- {
- foreach (GridViewRow row in GridView1.Rows)
- {
- CheckBox chk = (CheckBox)row.FindControl("SelectedClient");
- if (chk.Checked)
- {
- BindGridViewData();
- string ID = "0" + row.Cells[0].Text;
- string name = row.Cells[1].Text;
- using (SqlConnection con = new SqlConnection("Data Source=KOBI-PC2\\SQLEXPRESS;Initial Catalog=Niloosoft;Integrated Security=True"))
- {
- SqlCommand cmd = new SqlCommand("DeleteCustomer", con);
- cmd.CommandType = System.Data.CommandType.StoredProcedure;
- cmd.Parameters.AddWithValue("@ID", ID);
- cmd.Parameters.AddWithValue("@FullName", name);
- con.Open();
- cmd.ExecuteNonQuery();
- con.Close();
- }
- }
- BindGridViewData();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement