public bool Insert(DTO_Customer _Cus) { Connet(); string sql = "insert into Customer ( Phone, Name, AccountID, Active, GroupID) values (@Phone, @Name, @AccountID, @Active, @GroupID)"; try { _cmd = new SqlCommand(sql, _conn); _cmd.Parameters.Add("@Phone", SqlDbType.VarChar).Value = _Cus.Phone; _cmd.Parameters.Add("@Name", SqlDbType.NVarChar).Value = _Cus.Name; _cmd.Parameters.Add("@AccountID", SqlDbType.VarChar).Value = _Cus.AccountID; _cmd.Parameters.Add("@Active", SqlDbType.Bit).Value = _Cus.Active; _cmd.Parameters.Add("@GroupID", SqlDbType.VarChar).Value = _Cus.GroupID; _cmd.ExecuteNonQuery(); _cmd.Dispose(); Disconnet(); } catch (Exception ex) { Disconnet(); return(false); throw ex; } return(true); }
private void btnUpdateCustomer_Click(object sender, EventArgs e) { try { DTO_Customer ex = new DTO_Customer(); ex.MaKH = txtIdCustomer.Text; ex.TenKH = txtNameCustomer.Text; ex.ThemBoi = Convert.ToInt32(comboBoxIdStaff.SelectedValue); if (comboBoxSex.SelectedIndex == 0) { ex.GioiTinh = true; } else { ex.GioiTinh = false; } ex.SDT = txtPhoneCustomer.Text; ex.Email = txtEmailCustomer.Text; ex.DiaChi = txtAdressCustomer.Text; dataCustomer.EditCustomer(ex); MessageBox.Show("Cập nhật thành công!"); ShowDataCustomer(); ClearForms(); } catch (Exception a) { MessageBox.Show("lổi" + a); } }
public bool DAL_AddSellingHistory(DTO_Customer customer, DateTime SellingDate, int TotalPrice) { try { _conn.Open(); using (SqlCommand cmd = new SqlCommand("ThemLichSuBanHang", _conn) { CommandType = CommandType.StoredProcedure, }) { cmd.Parameters.AddWithValue("@NgayBan", SellingDate); cmd.Parameters.AddWithValue("@TongTien", TotalPrice); cmd.Parameters.AddWithValue("@TenKH", customer.CustomerName); cmd.Parameters.AddWithValue("@CMND", customer.CustomerID); cmd.Parameters.AddWithValue("@SDT", customer.CustomerPhone); cmd.Parameters.AddWithValue("@DiaChi", customer.CustomerAddress); if (cmd.ExecuteNonQuery() <= 0) { return(false); } } } catch (Exception ex) { return(false); } finally { _conn.Close(); } return(true); }
private void btnAddCustomer_Click(object sender, EventArgs e) { if (txtIdCustomer.Text != "") { DTO_Customer ex = new DTO_Customer(); ex.MaKH = txtIdCustomer.Text; ex.TenKH = txtNameCustomer.Text; ex.ThemBoi = Convert.ToInt32(comboBoxIdStaff.SelectedValue); if (comboBoxSex.SelectedIndex == 0) { ex.GioiTinh = true; } else { ex.GioiTinh = false; } ex.SDT = txtPhoneCustomer.Text; ex.Email = txtEmailCustomer.Text; ex.DiaChi = txtAdressCustomer.Text; dataCustomer.InsertCustomer(ex); MessageBox.Show("Thêm khách hàng thành công!"); ShowDataCustomer(); ClearForms(); } else { MessageBox.Show("Bạn chưa nhập mã khách hàng"); } }
private void txtCusNumber_TextChanged(object sender, EventArgs e) { BUS_Customer busCus = new BUS_Customer(); try { cus = busCus.searchPhone(txtCusPhone1.Text); if (cus != null) { txtCusName.Text = cus.cusName; txtCusAdress.Text = cus.cusAddress; } else { txtCusName.Text = ""; txtCusAdress.Text = ""; } } catch { txtCusName.Text = ""; txtCusAdress.Text = ""; txtCusPhone1.Clear(); } }
private void cmd_Payment_Click(object sender, EventArgs e) { Bus_letter.Kill_process(); DTO_Customer _cus = GlobalVariable.Global_Customer; Bus_letter.Fill_On_Word(_cus.FirstName + " " + _cus.LastName, _cus.Matter_ID, txt_Payment.Text.Trim(), txt_GST.Text.Trim(), txt_Amount.Text.Trim(), txt_ReceiptNo.Text.Trim(), txt_Description.Text.Trim(), _cus.Salutation, _cus.LastName, _cus.Email, txt_Balance.Text.Trim(), GlobalVariable.LocationForPayment); }
public DTO_Customer GetIdCus(string name) { DTO_Customer dt = new DTO_Customer(); dt = dataCustomer.GetIdCustomer(name); return(dt); }
public DTO_Customer SearchCus(string keyword) { DTO_Customer dt = new DTO_Customer(); dt = dataCustomer.searchCustomerForBill(keyword); return(dt); }
public DTO_Customer searchPhone(string phone) { try { cus = null; DataTable dt = new DataTable(); cnn = DataProvider.ConnectData(); string load = string.Format("Select CusPhone, Fullname , Address From Customer where CusPhone = {0}", phone); SqlCommand cmd = new SqlCommand(load, cnn); SqlDataReader dataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection); if (dataReader.HasRows) { if (dataReader.Read()) { phone = dataReader["CusPhone"].ToString(); string Fullname = dataReader["Fullname"].ToString(); string Address = dataReader["Address"].ToString(); cus = new DTO_Customer(phone, Fullname, Address); return(cus); } } cnn.Close(); return(cus); } catch (Exception ex) { throw ex; } }
public List <DTO_Customer> GetCustomer() { List <DTO_Customer> list = new List <DTO_Customer>(); int makh; string hokh, tenkh, sdt, gioitinh, diachithuongtru, email; DateTime ngaysinh; try { string sql = "SELECT * FROM KhachHang"; SqlDataReader dr = dp.ExecuteReader(sql); while (dr.Read()) { makh = dr.GetInt32(0); hokh = dr.GetString(1); tenkh = dr.GetString(2); gioitinh = dr.GetString(3); sdt = dr.GetString(4); ngaysinh = dr.GetDateTime(5); diachithuongtru = dr.GetString(6); email = dr.GetString(7); DTO_Customer emp = new DTO_Customer(makh, hokh, tenkh, gioitinh, sdt, ngaysinh, diachithuongtru, email); list.Add(emp); } return(list); } catch (SqlException ex) { throw ex; } }
public bool Update_state(DTO_Customer _Cus) { Connet(); string sql = "update Customer set Active=@Active Where Phone=@Phone"; try { _cmd = new SqlCommand(sql, _conn); _cmd.Parameters.Add("@Phone", SqlDbType.VarChar).Value = _Cus.Phone; _cmd.Parameters.Add("@Name", SqlDbType.NVarChar).Value = _Cus.Name; _cmd.Parameters.Add("@AccountID", SqlDbType.VarChar).Value = _Cus.AccountID; _cmd.Parameters.Add("@Active", SqlDbType.Bit).Value = _Cus.Active; _cmd.Parameters.Add("@GroupID", SqlDbType.VarChar).Value = _Cus.GroupID; _cmd.ExecuteNonQuery(); _cmd.Dispose(); Disconnet(); } catch (Exception ex) { Disconnet(); return(false); throw ex; } return(true); }
private void btnConfirm_Click(object sender, EventArgs e) { int count = 0; BUS_Order bus = new BUS_Order(); BUS_Orderdetail busOderDetail = new BUS_Orderdetail(); BUS_Customer busCus = new BUS_Customer(); string valid = checkConfirm(); if (valid.Equals("")) { if (cus != null) { string cusphone = cus.cusPhonenumber; string idEmp = employee.Username; long totalPrice = int.Parse(lblTotalPrice.Text); int totalQuantity = int.Parse(lblQuantity.Text); DTO_Order order = new DTO_Order(cusphone, idEmp, totalPrice, totalQuantity); int IDOrder = bus.createOrder(order); foreach (DTO_Product pro in listCart) { DTO_OrderDetail detail = new DTO_OrderDetail(IDOrder, pro.proID, pro.proPrice, pro.discount, pro.proQuantity); int counts = busOderDetail.createOrderDetail(detail); count += counts; } showBill(); MessageBox.Show(count.ToString()); } else { string newCus = txtCusName.Text; string newPhone = txtCusPhone1.Text; string newAdd = txtCusAdress.Text; cus = new DTO_Customer(newPhone, newCus, newAdd); busCus.creatCustomer(cus); string idEmp = employee.Username; int totalQuantity = int.Parse(lblQuantity.Text); long totalPrice = int.Parse(lblTotalPrice.Text); DTO_Order order = new DTO_Order(cus.cusPhonenumber, idEmp, totalPrice, totalQuantity); int IDOrder = bus.createOrder(order); foreach (DTO_Product pro in listCart) { DTO_OrderDetail detail = new DTO_OrderDetail(IDOrder, pro.proID, pro.proPrice, pro.discount, pro.proQuantity); int counts = busOderDetail.createOrderDetail(detail); count += counts; } MessageBox.Show(count.ToString()); showBill(); } clear1(); loadProduct(); } else { MessageBox.Show(valid); } }
public void dropItem(DTO_Customer info) { string[] value = { info.Id.ToString() }; dataCustomer.Delete(value); }
public void Deleted(DTO_Customer ex) { sqlCm.Connection = connectionCustomer.OpenConnection(); sqlCm.CommandText = "DELETEDCUSTOMER"; sqlCm.CommandType = CommandType.StoredProcedure; sqlCm.Parameters.AddWithValue("@maKH", ex.MaKH); sqlCm.ExecuteNonQuery(); sqlCm.Parameters.Clear(); }
private void btnDrop_Click(object sender, EventArgs e) { if (MessageBox.Show("Bạn có chắc là muốn xóa hóa đơn này không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.Yes) { DTO_Customer info = new DTO_Customer(); info.Id = Convert.ToInt32(txtId.Text); bus.dropItem(info); GUI_Customer_Load(sender, e); } }
public bool BUS_InsertNewOrder(DTO_Customer customer, List <DTO_ProductChosen> listProductChosen, DateTime SellingDate, int TotalPrice, List <DTO_Promotion> promotions) { // thêm vào lịch sử bán hàng bool res = dal_SellProducts.DAL_AddSellingHistory(customer, SellingDate, TotalPrice); if (res == false) { return(false); } // lấy ra ID_LICHSUBANHANG gần đây nhất DataTable dtSellingHistory = dal_SellProducts.DAL_GetSellingHistoryByDate(SellingDate); if (dtSellingHistory == null) { return(false); } int ID_SellingHistory = -1; if (dtSellingHistory.Rows.Count > 0) { // lấy dòng đầu tiên ID_SellingHistory = (int)dtSellingHistory.Rows[0]["ID_LICHSUBANHANG"]; } else { return(false); } // thêm từng sản phẩm vào kho foreach (var productChosen in listProductChosen) { bool result = dal_SellProducts.DAL_AddProductChosenToDetailOrder(ID_SellingHistory, productChosen); if (result == true) { // update lại số lượng sản phẩm này trong database DAL_SanPham dal_Product = new DAL_SanPham(); bool res1 = dal_Product.DAL_UpdateProductQuantityAfterSale(productChosen.ProductID, productChosen.ProductQuantity); } } // thêm khuyến mãi vào chi tiết khuyến mãi foreach (var promo in promotions) { int ID_Promotion = promo.PromotionID; bool result = dal_SellProducts.DAL_AddPromotionToOrder(ID_SellingHistory, ID_Promotion); } return(true); }
public void editItem(DTO_Customer info) { string[] value = { info.Fullname, info.PhoneNumber, info.Address, info.Id.ToString() }; dataCustomer.Update(value); }
public Customer(DTO_Customer customer) { this._customerID = customer.CustomerID; this._firstName = customer.FirstName; this._middleName = customer.MiddleName; this._lastName = customer.LastName; this._suffix = customer.Suffix; this._primaryNumber = customer.PrimaryNumber; this._secondaryNumber = customer.SecondaryNumber; this._email = customer.Email; this._mailPromos = customer.MailPromos; }
private void btndelete_Click(object sender, EventArgs e) { if (MessageBox.Show("Bạn có muốn xoá thật không?", "Xác nhận", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { BUS_Customer DL = new BUS_Customer(); DTO_Customer DT = new DTO_Customer(Convert.ToInt32(txtmakh.Text)); DL.DeleteCustomer(DT); dgvkh.DataSource = GetCustomer(); MessageBox.Show(" BẠN ĐÃ XÓA KHÁCH HÀNG THÀNH CÔNG", " Xác nhận"); } }
public int createCustomer(DTO_Customer cus) { SqlConnection cnn = DataProvider.ConnectData(); var cmd = new SqlCommand("createCustomer", cnn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@CusPhone", SqlDbType.Char).Value = cus.cusPhonenumber; cmd.Parameters.Add("@FullName", SqlDbType.NVarChar).Value = cus.cusName; cmd.Parameters.Add("@Address", SqlDbType.NVarChar).Value = cus.cusAddress; int count = cmd.ExecuteNonQuery(); return(count); }
public async Task GetCustomerByID(DTO_Customer token) { try { var response = await client.PostAsJsonAsync(string.Format(@"{0}{1}", URL, "GetCustomerByID"), token); response.EnsureSuccessStatusCode(); Cust = await response.Content.ReadAsAsync <DTO_Customer>(); } catch (Exception ex) { } }
public int DeleteCustomer(DTO_Customer emp) { List <SqlParameter> paras = new List <SqlParameter>(); paras.Add(new SqlParameter("@MaKH", emp.MaKH)); try { return(dp.ExcuteNonQuery("sp_XoaKhachHang", System.Data.CommandType.StoredProcedure, paras)); } catch (SqlException ex) { throw ex; } }
private void txtSearchCus_TextChanged(object sender, EventArgs e) { string keyword = txtSearchCus.Text; if (txtSearchCus.Text == "") { txtNameCustomer.Text = ""; } else { cusDTO = blCus.SearchCus(keyword); txtNameCustomer.Text = cusDTO.TenKH; } }
public DataTable SearchByMaKH(DTO_Customer emp) { SqlConnection cnn = dp.getConnect(); List <SqlParameter> paras = new List <SqlParameter>(); DataTable dt = new DataTable(); SqlCommand cmd = new SqlCommand("sp_TimTheoMaKhachHang", cnn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@MaKH", emp.MaKH)); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(dt); dp.DisConnect(); return(dt); }
public fmBill(DTO_Employee emp, List <DTO_Product> list, DTO_Customer cus, string totalPrice) { InitializeComponent(); txtcashier.Text = "Cashier: " + emp.Fullname; txtCus.Text = "Customer: " + cus.cusName; String bill = String.Format("{0,-4} {1,-60} {2,-40} {3,-40} {4,-40}\n\n\n", "No.", "Product", "Quantity", "Price", "Amount"); for (int i = 0; i < list.Count; i++) { bill += String.Format("{0,-4} {1,-60} {2,-40} {3,-40} {4,-40}\n {5,-1000}\n", (i + 1), list[i].proName, list[i].proQuantity.ToString().Trim(), (list[i].proPrice / list[i].proQuantity), list[i].proPrice, "-" + list[i].discount + "%"); } lblInfoBill.Text = bill; lblTotal.Text = totalPrice; lblDate.Text = "Date: " + DateTime.Today.ToString("d"); }
private void btnTimKiemKH_Click(object sender, EventArgs e) { switch (typeCheck) { case 1: { DTO_Customer emp = new DTO_Customer(Convert.ToInt32(txtbtimkiemkh.Text)); DataTable dt = new DataTable(); BUS_Customer em = new BUS_Customer(); dt = em.SearchByMaKH(emp); dgvtimkiem.DataSource = dt; break; } } }
private void btnDeleteCustomer_Click(object sender, EventArgs e) { if (dataGridViewCustomer.SelectedRows.Count > 0) { DTO_Customer ex = new DTO_Customer(); txtIdCustomer.Text = dataGridViewCustomer.CurrentRow.Cells["Mã khách hàng"].Value.ToString(); ex.MaKH = txtIdCustomer.Text; if (MessageBox.Show("Bạn chắn chắn muốn xóa khách hàng này!", "", MessageBoxButtons.YesNo) == DialogResult.Yes) { dataCustomer.DeletedCustomer(ex); } ShowDataCustomer(); ClearForms(); } }
private void btnEdit_Click(object sender, EventArgs e) { if (CheckData() == true) { DTO_Customer dto_cus = new DTO_Customer(txtCustomerID.Text, txtName.Text, Birthday.Value.ToShortDateString(), txtGender.Text, txtAddress.Text, txtEmail.Text, txtPhonenumber.Text); if (bus_cus.Edit(dto_cus)) { MessageBox.Show("EDITING SUCCESS!", "EDIT", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadData(); } else { MessageBox.Show("EDITING FAIL!", "EDIT", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public void Edit(DTO_Customer ex) { sqlCm.Connection = connectionCustomer.OpenConnection(); sqlCm.CommandText = "EDITCUSTOMER"; sqlCm.CommandType = CommandType.StoredProcedure; sqlCm.Parameters.AddWithValue("@maKH", ex.MaKH); sqlCm.Parameters.AddWithValue("@hoTen", ex.TenKH); sqlCm.Parameters.AddWithValue("@gioiTinh", ex.GioiTinh); sqlCm.Parameters.AddWithValue("@themBoi", ex.ThemBoi); sqlCm.Parameters.AddWithValue("@diaChi", ex.DiaChi); sqlCm.Parameters.AddWithValue("@SDT", ex.SDT); sqlCm.Parameters.AddWithValue("@Email", ex.Email); sqlCm.ExecuteNonQuery(); sqlCm.Parameters.Clear(); }
private void btnPayment_Click(object sender, EventArgs e) { // thêm hóa đơn bilDTO.NVLap = Convert.ToInt32(cmbAddbyStaff.SelectedValue); cusDTO = blCus.GetIdCus(txtNameCustomer.Text); bilDTO.ThongTinKH = cusDTO.MaKH; bilDTO.NgayLap = DateTime.Now; bilDTO.TongTien = Convert.ToDecimal(txtTotalBill.Text); bilDTO.DaThanhToan = true; decimal val; bool result = decimal.TryParse(txtPayAmout.Text, out val); if (!result) { return; } bilDTO.SoTienTra = Convert.ToDecimal(val); bilDTO.SoTienThua = Convert.ToDecimal(txtReturnPay.Text); Bldtb.InsertBill(bilDTO); // thêm chi tiết hóa đơn try { for (int i = 0; i < Bill.Rows.Count; i++) { masp = blProd.GetIDProductBill(Convert.ToString(Bill.Rows[i][0].ToString())); billDTO.MaSP = masp; billDTO.SoLuong = Convert.ToInt32(Bill.Rows[i][1].ToString()); billDTO.GiaBan = decimal.Parse(Bill.Rows[i][2].ToString()); billDTO.ThanhTien = decimal.Parse(Bill.Rows[i][3].ToString()); billDTO.KhuyenMai = int.Parse(txtSaleProduct.Text); bilDTO = Bldtb.GetIdBill(); billDTO.MaHD = bilDTO.MaHD; blProd.DecreaseProd(billDTO.MaSP, billDTO.SoLuong); bldldt.InsertBillDetail(billDTO); } MessageBox.Show("Thanh toán thành công"); ReportB rp = new ReportB(Convert.ToString(billDTO.MaHD)); rp.Show(); clearform(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }