public static bool UpdateCustomer(Customer_DTO customer) { SqlConnection con = DataProvider.OpenConnection(); SqlCommand cmd = new SqlCommand("[JEWELRYSTOREMGMT].[dbo].[usp_updateCustomer]", con); try { cmd.CommandType = CommandType.StoredProcedure; SqlParameter p = new SqlParameter("@CustomerID", customer.CustomerID); cmd.Parameters.Add(p); p = new SqlParameter("@CustomerName", customer.CustomerName); cmd.Parameters.Add(p); p = new SqlParameter("@Address", customer.CustomerAddress); cmd.Parameters.Add(p); p = new SqlParameter("@PhoneNo", customer.CustomerPhone); cmd.Parameters.Add(p); cmd.ExecuteNonQuery(); DataProvider.CloseConnection(con); return(true); } catch { DataProvider.CloseConnection(con); return(false); } }
//@Description: // Thêm vào 1 Khách hàng //@Parameter // Customer_DTO customer --------Tham số nhập là 1 Khách hàng //@Proc: // //@Return: // boolean ------------Thành công trả về true, thất bại trả về false; // @name NVARCHAR(100), //@sex bit, //@identity_card VARCHAR(20), //@address nvarchar(200), //@email varchar(80), //@phone varchar(11), //@company nvarchar(50), //@id_history int public bool Add_Customer(Customer_DTO customer) //Sửa lại { string query = "exec USP_InsertCustomer @name , @sex , @identity_card , @address , @email , @phone , @company"; // cái này viết sai tham số, điền đây đủ như trên int x = Connect.Instance.ExecuteNonQuery(query, new object[] { customer.Name, customer.Sex, customer.Identity_card, customer.Address, customer.Email, customer.Phone, customer.Company }); // dưới này tướng ưng với từng tham số | tham khảo Staff, return(x == 1); }
private void btnUpdateCustomer_Click(object sender, EventArgs e) { if (txtIDCustomer.Text == "" || txtNameCustomer.Text == "") { XtraMessageBox.Show("You have to choose at least 1 customer info to update!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); ClearDisplay(); return; } Customer_DTO customer = new Customer_DTO(); customer.CustomerID = (string)dtgvCustomersListOfStore.CurrentRow.Cells["MaKH"].Value; customer.CustomerName = txtNameCustomer.Text; customer.CustomerAddress = txtAddressCustomer.Text; customer.CustomerPhone = txtNumberPhone.Text; if (Customer_BUS.UpdateCustomer(customer)) { LoadCustomer(); ClearDisplay(); XtraMessageBox.Show("Update Customer Sucessfully!", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } XtraMessageBox.Show("Update Failed!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error); }
public void UpdateCustomer(Customer_DTO nv) { conn.Connect(); string a = "UpdateCustomer('" + nv.Id + "','" + nv.TenKhachHang + "','" + nv.Tuoi + "','" + nv.Sdt + "','" + nv.DiaChi + "','" + nv.MaGiamGia + "')"; conn.KetNoi(a); }
public static List <Customer_DTO> LoadCustomerList() { try { SqlConnection con = DataProvider.OpenConnection(); DataTable dt = DataProvider.GetDataTable("[JEWELRYSTOREMGMT].[dbo].[usp_getCustomerList]", con); List <Customer_DTO> customerList = new List <Customer_DTO>(); if (dt.Rows.Count == 0) { return(null); } for (int i = 0; i < dt.Rows.Count; i++) { Customer_DTO customer = new Customer_DTO(); customer.CustomerID = dt.Rows[i]["CustomerID"].ToString(); customer.CustomerName = dt.Rows[i]["CustomerName"].ToString(); customer.CustomerAddress = dt.Rows[i]["Address"].ToString(); customer.CustomerPhone = dt.Rows[i]["PhoneNo"].ToString(); customerList.Add(customer); } DataProvider.CloseConnection(con); return(customerList); } catch (Exception ex) { MessageBox.Show(ex.Message, "Notification", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } }
private void btnLuu_Click(object sender, EventArgs e) { Customer_DTO tg = LayTTKH(); btnSua.Enabled = true; btnXoa.Enabled = true; btnThem.Enabled = true; btnHuy.Enabled = false; btnLuu.Enabled = false; txtTenKhachHang.Enabled = false; txtMaGiamGia.Enabled = false; txtSDT.Enabled = false; txtDiaChi.Enabled = false; txtTuoi.Enabled = false; if (add) { RemoveGridView(); dgBUS.InsertCustomer(tg); Customer_Load(sender, e); } if (update) { RemoveGridView(); dgBUS.UpdateCustomer(tg); Customer_Load(sender, e); } }
public void RemoveCustomer(Customer_DTO pr) { conn.Connect(); string a = "RemoveCustomer('" + pr.Id + "')"; conn.KetNoi(a); }
private void btnAddCustomer_Click(object sender, EventArgs e) { if (txtNameCustomer.Text == "" || txtNumberPhone.Text == "" || txtAddressCustomer.Text == "") { XtraMessageBox.Show("You have to fullfill the customer information!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); ClearDisplay(); return; } Customer_DTO customer = new Customer_DTO(); customer.CustomerID = txtIDCustomer.Text; customer.CustomerName = txtNameCustomer.Text; customer.CustomerAddress = txtAddressCustomer.Text; customer.CustomerPhone = txtNumberPhone.Text; if (Customer_BUS.InsertCustomer(customer)) { XtraMessageBox.Show("Insert Customer Sucessfully!", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadCustomer(); ClearDisplay(); return; } XtraMessageBox.Show("Insert Failed!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error); }
//Cậu dừng sửa têm hàm của tớ nha! hệ thông đã chạy theo ten của tớ đặt //@Description: // Chỉnh sửa 1 khách hàng bằng id //@Parameter // Customer_DTO customer --------Tham số nhập là 1 Khách hàng // int id -------- Mã Khách hàng //@Proc: // //@Return: // boolean ------------Thành công trả về true, thất bại trả về false; public bool Edit_Customer(Customer_DTO customer) // Sửa lại { string query = "exec USP_EditCustomer @id_customer , @name , @sex , @identity_card , @address , @email , @phone , @company "; // cái nàu cung jaor suaw tham só int record = Connect.Instance.ExecuteNonQuery(query, new object[] { customer.Id_customer, customer.Name, customer.Sex, customer.Identity_card, customer.Address, customer.Email, customer.Phone, customer.Company }); return(record == 1); }
//@Description: // Bắt lỗi hàm Thêm vào 1 Khách hàng //@Parameter // Customer_DTO customer --------Tham số nhập là 1 Khách hàng //@Proc: // //@Call: // Customer_DAO.Instance.Add_Customer(customer); //@Return: // boolean ------------Thành công trả về true, thất bại trả về false; public bool Add_Customer(Customer_DTO customer) { try { return(Customer_DAO.Instance.Add_Customer(customer)); } catch (SqlException e) { throw new Exception("Error!"); } }
private Customer_DTO LayTTKH() { Customer_DTO dg = new Customer_DTO(); dg.TenKhachHang = txtTenKhachHang.Text; dg.Tuoi = int.Parse(txtTuoi.Text); dg.DiaChi = txtDiaChi.Text; dg.Sdt = txtSDT.Text; dg.MaGiamGia = txtMaGiamGia.Text; dg.Id = lbID.Text; return(dg); }
//@Description: // Lấy ra danh sách khách hàng trong bảng //@Parameter // nope //@Proc: // //@Return: // List<Customer_DTO> --- Trả về 1 danh sách các khách hàng public List <Customer_DTO> Get_List() // Xong { string query = "exec USP_GetList"; DataTable List_customer = Connect.Instance.ExecuteQuery(query); List <Customer_DTO> list_customer = new List <Customer_DTO>(); foreach (DataRow item in List_customer.Rows) { Customer_DTO customer = new Customer_DTO(item);//thieu item list_customer.Add(customer); } return(list_customer); }
//@Description: // Tìm kiếm khách hàng //@Parameter // String keyword // int type_search ------- tìm kiếm theo mã hay tên, (bên dưới là chú thích loại tìm kiếm) //@Proc: // //@Return: // List<Customer_DTO> ------------ Trả về danh sách thỏa mãn public List <Customer_DTO> Search_Customer(String keyword, int type_search) // Viết tiếp { string query = "exec USP_SearchCustomer @keyword , @type "; //cái này có vấn đề nhé thếu tham só vào!. để tớ sửa lại cho, chút ý lần sau nhé DataTable List_customer = Connect.Instance.ExecuteQuery(query, new object[] { keyword, type_search }); List <Customer_DTO> list_customer = new List <Customer_DTO>(); foreach (DataRow item in List_customer.Rows) { Customer_DTO customer = new Customer_DTO(item);//thieu item list_customer.Add(customer); } return(list_customer); }
//@Description: // Lấy ra thông tin của khách hàng bằng id //@Parameter // string id_customer //@Proc: // //@Return: // Customer_DTO --- Trả về 1 khách hàng public Customer_DTO Get_Info(int id_customer)// Xong { string query = "exec USP_GetInfo @id_customer"; DataTable Customer_info = Connect.Instance.ExecuteQuery(query, new object[] { id_customer }); Customer_DTO customer = null; // Đỗi tượng DataRow là từng dòng trong đối tượng DataTable // (Có thể bỏ vòng lặp này do số lượng dòng ta cấn truy xuất bằng 1 hoặc 0) foreach (DataRow item in Customer_info.Rows) { customer = new Customer_DTO(item);// cái này thiết Item } return(customer); }
private void Load_Data() { Customer_DTO customer_info = Customer_BUS.Instance.Get_Info(this.id_customer); txt_name.Text = customer_info.Name; if (customer_info.Sex == true) { cb_sex.SelectedIndex = 1; } else { cb_sex.SelectedIndex = 0; } txt_passport.Text = customer_info.Identity_card.ToString(); txt_address.Text = customer_info.Address.ToString(); txt_email.Text = customer_info.Email.ToString(); this.Email_old = customer_info.Email; txt_phone.Text = customer_info.Phone.ToString(); txt_company.Text = customer_info.Company.ToString(); }
private void btnXoa_Click(object sender, EventArgs e) { Customer_DTO tg = LayTTKH(); btnSua.Enabled = true; btnThem.Enabled = true; btnHuy.Enabled = false; btnLuu.Enabled = false; if (MessageBox.Show("Bạn có muốn xóa Nhân Viên: " + txtTenKhachHang.Text + " không ?", "Hỏi", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { try { RemoveGridView(); dgBUS.RemoveCustomer(tg); Customer_Load(sender, e); } catch (Exception) { MessageBox.Show("Mời bạn nhập Chọn Sản phẩm cần xóa!!!!!"); } } }
private void dgv_customer_CellClick(object sender, DataGridViewCellEventArgs e) { try { int id_customer = (int)dgv_customer.Rows[e.RowIndex].Cells[0].Value; this.id_customer = id_customer; // Chỉ cần id mình sẽ lấy thông tin từ trong database chứ không phải trong DGV_Customer Customer_DTO customer_info = Customer_BUS.Instance.Get_Info(this.Id_customer); // sau đó set cho lable lb_name.Text = customer_info.Name.ToString(); if (customer_info.Sex == true) { lb_sex.Text = "Men"; } else { lb_sex.Text = "Woman"; } lb_address.Text = customer_info.Address.ToString(); lb_email.Text = customer_info.Email.ToString(); lb_phone.Text = customer_info.Phone.ToString(); } catch { MessageBox.Show("Select error!"); } // Không nên sử dụng //lb_name.Text = dgv_customer.Rows[e.RowIndex].Cells["Column2"].Value.ToString(); //lb_sex.Text = dgv_customer.Rows[e.RowIndex].Cells["Column3"].Value.ToString(); ////lb_passport.Text = dgv_customer.Rows[e.RowIndex].Cells["Column4"].Value.ToString(); //lb_address.Text = dgv_customer.Rows[e.RowIndex].Cells["Column5"].Value.ToString(); //lb_email.Text = dgv_customer.Rows[e.RowIndex].Cells["Column6"].Value.ToString(); //lb_phone.Text = dgv_customer.Rows[e.RowIndex].Cells["Column7"].Value.ToString(); //lb_company.Text = dgv_customer.Rows[e.RowIndex].Cells["Column8"].Value.ToString(); }
private void btn_edit_Click(object sender, EventArgs e) { if (txt_email.Text == this.email_old) { Customer_DTO customer = new Customer_DTO(); customer.Id_customer = this.id_customer; customer.Name = txt_name.Text; if (cb_sex.SelectedIndex == 1) { customer.Sex = true; } else { customer.Sex = false; } customer.Identity_card = txt_passport.Text; customer.Address = txt_address.Text; customer.Email = txt_email.Text; customer.Phone = txt_phone.Text; customer.Company = txt_company.Text; if (Customer_BUS.Instance.Edit_Customer(customer)) { MessageBox.Show("Edit customer is success!"); this.Close(); } else { MessageBox.Show("Error!"); } } else { if (Customer_DAO.Instance.Check_Email(txt_email.Text) == false) { bool flat = true; if (txt_name.Text == "") { MessageBox.Show("Name is not null", "Error validate", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); // Viêt thông báo cho tất cả các điểu kiện flat = false; return; } if (txt_passport.Text == "") { MessageBox.Show("Id Card is not null", "Error validate", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); flat = false; return; } if (txt_passport.Text.Length != 12) { MessageBox.Show("Id Cart is not exist!", "Error validate", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); flat = false; return; } double parsedValue; if (!double.TryParse(txt_passport.Text, out parsedValue)) { MessageBox.Show("Id Cart is number only field", "Error validate", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); flat = false; return; } if (txt_address.Text == "") { MessageBox.Show("Address is not null", "Error validate", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); flat = false; return; } if (txt_email.Text == "") { MessageBox.Show("Email is not null", "Error validate", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); flat = false; return; } try { var addr = new System.Net.Mail.MailAddress(txt_email.Text); flat = true; } catch { MessageBox.Show("Email is not exists", "Error validate", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); flat = false; return; } if (Customer_BUS.Instance.Check_Email(txt_email.Text) == true) { MessageBox.Show("Email exists in system", "Error validate", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); flat = false; return; } if (txt_phone.Text == "") { MessageBox.Show("Phone is not null", "Error validate", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); flat = false; return; } if (txt_phone.Text.Length != 11 && txt_phone.Text.Length != 10) { MessageBox.Show("Phone is not exist!", "Error validate", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); flat = false; return; } double parsedValue1; if (!double.TryParse(txt_phone.Text, out parsedValue1)) { MessageBox.Show("Phone is number only field", "Error validate", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); flat = false; return; } if (txt_company.Text == "") { MessageBox.Show("Company is not null", "Error validate", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); flat = false; return; } if (flat == true) { Customer_DTO customer = new Customer_DTO(); customer.Id_customer = this.id_customer; customer.Name = txt_name.Text; if (cb_sex.SelectedIndex == 1) { customer.Sex = true; } else { customer.Sex = false; } customer.Identity_card = txt_passport.Text; customer.Address = txt_address.Text; customer.Email = txt_email.Text; customer.Phone = txt_phone.Text; customer.Company = txt_company.Text; if (Customer_BUS.Instance.Edit_Customer(customer)) { MessageBox.Show("Edit customer is success!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); this.Close(); } else { MessageBox.Show("Error!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show("Email was exists in system!", "Error Validate", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } }
public static bool DeleteCustomer(Customer_DTO customer) { return(Customer_DAL.DeleteCustomer(customer)); }
public static bool InsertCustomer(Customer_DTO customer) { return(Customer_DAL.InsertCustomer(customer)); }
public static bool UpdateCustomer(Customer_DTO customer) { return(Customer_DAL.UpdateCustomer(customer)); }