public static bool InsertCustomer(Customer cus) { string sql = "spAddCustomer"; SqlParameter CustomerID = new SqlParameter("CustomerID",cus.CustomerID); SqlParameter Name = new SqlParameter("Name", cus.Name); SqlParameter Address = new SqlParameter("Address", cus.Address); SqlParameter Phone = new SqlParameter("Phone", cus.Phone); return DataProvider.ExecuteNonQuery(sql, System.Data.CommandType.StoredProcedure, CustomerID,Name,Address,Phone); }
private void btnOk_Click(object sender, RoutedEventArgs e) { try { Customer cus = new Customer(); cus.CustomerID = txtCustomerID.Text; cus.Name= txtFullName.Text; cus.Address =txtAddress.Text; cus.Phone = txtFullName.Text; bool sameID = false; var rows = dt.Rows; foreach (DataRow datarow in rows) { if (datarow["CustomerID"].ToString().Equals(cus.CustomerID)) { sameID = true; break; } } if (!sameID) { CustomerBLL.AddCustomer(cus); System.Windows.Forms.MessageBox.Show("Successfully"); if (AddFinished != null) { AddFinished(cus); } } else { System.Windows.Forms.MessageBox.Show("This ID was existed!!"); } } catch (Exception g) { System.Windows.Forms.MessageBox.Show("Error: " + g.Message); } finally { this.Close(); } }
public static List<Customer> SelectAll() { List<Customer> cusList = new List<Customer>(); string SelectAllCus = "spGetAllCustomer"; SqlDataReader rd = DataProvider.ExecuteQueryWithDataReader(SelectAllCus, CommandType.StoredProcedure); if (rd.HasRows) { while (rd.Read()) { Customer r = new Customer() { CustomerID = rd.GetString(0), Name = rd.GetString(1), Address = rd.GetString(2), Phone = rd.GetString(3), Active = rd.GetBoolean(4) }; cusList.Add(r); } } return cusList.OrderBy(p => p.CustomerID).ToList(); }
public static bool AddCustomer(Customer cus) { return CustomerData.InsertCustomer(cus); }