public List<OpenImportExport> GetAllOpenIE(List<ImportExport> listIE) { List<OpenImportExport> result = new List<OpenImportExport>(); listIE = GetAllIE(); foreach (var item in listIE) { OpenImportExport openIE = new OpenImportExport(); CustomerDAL customerDAL = new CustomerDAL(); openIE.CheckNo = item.CheckNo; openIE.Date = item.Date; openIE.Type = item.Type; openIE.ImEx = item.ImEx; openIE.CustomerName = customerDAL.GetCustomerbyID(item.CustomerID).CustomerName; result.Add(openIE); } return result; }
private void btnDelete_Click(object sender, EventArgs e) { try { if (MessageBox.Show("Bạn có muốn xóa khách hàng này không?", "Xóa", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { int customerID = (int)CustomerDataGridView.SelectedRows[0].Cells[0].Value; CustomerDAL customerDAL = new CustomerDAL(); customerDAL.DeleteCustomer(customerID); } loadAllData(); } catch (SqlException sqlEx) { MessageBox.Show("Vui lòng xóa toàn bộ các đơn hàng của khách hàng này trước khi xóa !"); logger.MyLogFile(DateTime.Now.ToString(), "' Error '" + sqlEx.Message + "'"); } catch (Exception ex) { logger.MyLogFile(DateTime.Now.ToString(), "' Error '" + ex.Message + "'"); } }
public void loadAllData() { CustomerDAL cusDAL = new CustomerDAL(); List<Customer> list = cusDAL.GetAllCustomer(); CustomerDataGridView.DataSource = list; }
private void SaveToDB() { customer.CustomerName = txtName.Text; customer.Address = txtAddress.Text; customer.Phone = txtPhone.Text; customer.TaxNo = txtTaxNo.Text; CustomerDAL customerDAL = new CustomerDAL(); bool rs; if (isAdd) { rs = customerDAL.CreateCustomer(customer); } else { rs = customerDAL.UpdateCustomer(customer); } if (rs) { MessageBox.Show("Đã lưu !"); loadAllData(); } else { MessageBox.Show("Không thể lưu !"); } }
private void SaveToDB() { try { ImportExportDAL importExportDAL = new ImportExportDAL(); if (ValidateData()) { importExport.CheckNo = int.Parse(txtCheckNo.Text); importExport.Date = DateTime.ParseExact(txtDay.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture); if (radioButtonImport.Checked) { importExport.ImEx = "Nhập"; } else if (radioButtonExport.Checked) { importExport.ImEx = "Xuất"; } importExport.Type = cbType.SelectedItem.ToString(); CustomerDAL customerDAL = new CustomerDAL(); importExport.CustomerID = customerDAL.GetCustomerbyName(txtCustomerName.Text).CustomerID; } bool rs; if (isAdd) { rs = importExportDAL.CreateIE(importExport); } else { rs = importExportDAL.UpdateIE(importExport); } if (rs) { MessageBox.Show("Đã lưu !"); groupBoxDetail.Enabled = false; txtCheckNo.ReadOnly = true; LoadAllData(); } else { MessageBox.Show("Không thể lưu !"); } } catch (Exception ex) { logger.MyLogFile(DateTime.Now.ToString(), "' Error '" + ex.Message + "'"); } }
private void dataGridView1_Click(object sender, EventArgs e) { try { isAdd = false; radioButtonExport.Enabled = false; radioButtonImport.Enabled = false; importExport.CheckNo = (int)dataGridView1.SelectedRows[0].Cells[0].Value; importExport.Date = (DateTime)dataGridView1.SelectedRows[0].Cells[1].Value; importExport.ImEx = dataGridView1.SelectedRows[0].Cells[3].Value.ToString(); importExport.Type = dataGridView1.SelectedRows[0].Cells[2].Value.ToString(); groupBoxDetail.Enabled = true; CustomerDAL cusDAL = new CustomerDAL(); string CusName = dataGridView1.SelectedRows[0].Cells[4].Value.ToString(); importExport.CustomerID = cusDAL.GetCustomerbyName(CusName).CustomerID; txtCheckNo.Text = dataGridView1.SelectedRows[0].Cells[0].Value.ToString(); txtCheckNo.ReadOnly = true; txtDay.Text = String.Format("{0:dd/MM/yyyy}", dataGridView1.SelectedRows[0].Cells[1].Value); string ImEx = dataGridView1.SelectedRows[0].Cells[3].Value.ToString(); if (String.Compare(ImEx, "Nhập", true) == 0) { radioButtonImport.Checked = true; } else { radioButtonExport.Checked = true; } string type = dataGridView1.SelectedRows[0].Cells[2].Value.ToString(); if (String.Compare(type, "Ký gửi", true) == 0) { cbType.SelectedIndex = 0; } if (String.Compare(type, "Bán lẻ", true) == 0) { cbType.SelectedIndex = 1; } if (String.Compare(type, "Nhập trả", true) == 0 && String.Compare(importExport.ImEx, "Nhập", true) == 0) { cbType.SelectedIndex = 2; } if (String.Compare(type, "Lưu kho", true) == 0 && String.Compare(importExport.ImEx, "Xuất", true) == 0) { cbType.SelectedIndex = 2; } if (String.Compare(type, "Trả hàng", true) == 0 && String.Compare(importExport.ImEx, "Xuất", true) == 0) { cbType.SelectedIndex = 3; } txtCustomerName.Text = dataGridView1.SelectedRows[0].Cells[4].Value.ToString(); } catch (Exception ex) { logger.MyLogFile(DateTime.Now.ToString(), "' Error '" + ex.Message + "'"); } }
public List<OpenImportExport> GetExport() { List<OpenImportExport> list = new List<OpenImportExport>(); ImportExportDAL IEDAL = new ImportExportDAL(); string cs = CocBook.Properties.Settings.Default.connectionString; SqlConnection con = new SqlConnection(cs); SqlCommand cmd = new SqlCommand("Select * from ImportExport where ImportExport = @E", con); cmd.Parameters.AddWithValue("E", "Xuất"); con.Open(); SqlDataReader sdr = cmd.ExecuteReader(); while (sdr.Read()) { OpenImportExport openIE = new OpenImportExport(); CustomerDAL customerDAL = new CustomerDAL(); openIE.CheckNo = (int)sdr["CheckNo"]; openIE.Date = (DateTime)sdr["Date"]; openIE.Type = (string)sdr["Type"]; openIE.ImEx = (string)sdr["ImportExport"]; int customerID = (int)sdr["CustomerID"]; openIE.CustomerName = customerDAL.GetCustomerbyID(customerID).CustomerName; list.Add(openIE); } con.Close(); return list; }