public void OrderLoadData() { try { lbDetail.Text = "Phiếu " + importExport.ImEx + "\nKiểu " + importExport.Type + "\nSố " + importExport.CheckNo; ieDetail.CheckNo = importExport.CheckNo; customer = customerDAL.GetCustomerbyID(importExport.CustomerID); List<GridViewRow> list = new List<GridViewRow>(); List<IEDetail> iedetail1 = new List<IEDetail>(); iedetail1 = ieDAL.GetIEDetailByCheckNo(importExport.CheckNo); foreach (var item in iedetail1) { GridViewRow gridViewRow = new GridViewRow(); gridViewRow.ISBNBook = item.ISBNBook; Book book1 = new Book(); book1 = bookDAL.GetBookbyISBN(item.ISBNBook); gridViewRow.BookName = book1.BookName; gridViewRow.Unit = book1.Unit; gridViewRow.Quantity = item.Quantity; gridViewRow.Price = book1.Price; gridViewRow.Discount = item.Discount; gridViewRow.Value = item.Value; list.Add(gridViewRow); } dataGridView1.DataSource = list; } catch (Exception ex) { logger.MyLogFile(DateTime.Now.ToString(), "' Error '" + ex.Message + "'"); } }
public List<Customer> GetAllCustomer() { string cs = CocBook.Properties.Settings.Default.connectionString; SqlConnection con = new SqlConnection(cs); SqlCommand cmd = new SqlCommand("SELECT * FROM Customer", con); con.Open(); SqlDataReader sdr = cmd.ExecuteReader(); List<Customer> list = new List<Customer>(); while (sdr.Read()) { Customer customer = new Customer(); customer.CustomerID = (int)sdr["CustomerID"]; customer.CustomerName = (string)sdr["CustomerName"]; customer.Address = (string)sdr["Address"]; customer.Phone = (string)sdr["Phone"]; customer.TaxNo = (string)sdr["TaxNo"]; list.Add(customer); } con.Close(); return list; }
public Customer GetCustomerbyID(int CustomerID) { string cs = CocBook.Properties.Settings.Default.connectionString; SqlConnection con = new SqlConnection(cs); SqlCommand cmd = new SqlCommand("SELECT * FROM Customer WHERE CustomerID = @CustomerID", con); cmd.Parameters.AddWithValue("CustomerID", CustomerID); con.Open(); SqlDataReader sdr = cmd.ExecuteReader(); Customer customer = new Customer(); if (sdr.HasRows) { sdr.Read(); customer.CustomerID = (int)sdr["CustomerID"]; customer.CustomerName = (string)sdr["CustomerName"]; customer.Address = (string)sdr["Address"]; customer.Phone = (string)sdr["Phone"]; customer.TaxNo = (string)sdr["TaxNo"]; return customer; } con.Close(); return null; }
public bool CreateCustomer(Customer customer) { try { string cs = CocBook.Properties.Settings.Default.connectionString; SqlConnection con = new SqlConnection(cs); SqlCommand cmd = new SqlCommand("INSERT INTO Customer (CustomerName,Address,Phone,TaxNo) VALUES (@CustomerName, @Address, @Phone, @TaxNo)", con); cmd.Parameters.AddWithValue("CustomerName", customer.CustomerName); cmd.Parameters.AddWithValue("Address", customer.Address); cmd.Parameters.AddWithValue("Phone", customer.Phone); cmd.Parameters.AddWithValue("TaxNo", customer.TaxNo); con.Open(); int count = cmd.ExecuteNonQuery(); con.Close(); return (count == 1); } catch (Exception) { return false; } }
public bool UpdateCustomer(Customer customer) { try { string cs = CocBook.Properties.Settings.Default.connectionString; SqlConnection con = new SqlConnection(cs); SqlCommand cmd = new SqlCommand("UPDATE Customer SET CustomerName = @CustomerName, Address = @Address, Phone = @Phone, TaxNo = @TaxNo WHERE CustomerID = @CustomerID", con); cmd.Parameters.AddWithValue("CustomerName", customer.CustomerName); cmd.Parameters.AddWithValue("Address", customer.Address); cmd.Parameters.AddWithValue("Phone", customer.Phone); cmd.Parameters.AddWithValue("TaxNo", customer.TaxNo); cmd.Parameters.AddWithValue("CustomerID", customer.CustomerID); con.Open(); int count = cmd.ExecuteNonQuery(); con.Close(); return (count == 1); } catch (Exception) { return false; } }