public void FillInfo() { Customer customer = new Customer(); cDal = new CallerIDDAL(); try { customer = cDal.selectCustomer(info.phoneNumber); } catch (Exception e) { MessageBox.Show(e.ToString()); } if (info != null) { txtPhoneLine1.Text = info.phoneNumber; if (customer != null) { txtNameLine1.Text = customer.Name; txtLastNameLine1.Text = customer.LastName; addressLine1.Text = customer.Address; if (!string.IsNullOrEmpty(customer.Region)) txtRegionLine1.Text = customer.Region; if (string.IsNullOrEmpty(customer.CustomerNote)) txtNoteLine1.Text = customer.CustomerNote; } } }
public void insertCustomer() { cDal = new CallerIDDAL(); Customer customer = new Customer(); bool inserted = false; customer.Name = txtNameLine1.Text; customer.LastName = txtLastNameLine1.Text; customer.Address = addressLine1.Text; customer.Phone = txtPhoneLine1.Text; customer.Region = txtRegionLine1.Text; customer.CustomerNote = txtNoteLine1.Text; if (customer != null) { inserted = cDal.insertNewCustomer(customer); } if (!inserted) MessageBox.Show("Müşteri ad, soyad ve adres bilgilerini lütfen eksiksiz bir şekilde doldurunuz."); }
public List<int> sonSiparisler(string phone) { try { List<int> orders = new List<int>(); Customer customer = new Customer(); SqlCommand cmd = SQLBaglantisi.getCommand("Select OrderId from CustomerOrders Where Phone=@phone"); cmd.Parameters.AddWithValue("@phone", phone); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { orders.Add(dr.GetInt32(0)); } return orders; } catch (Exception) { return null; } }
/// <summary> /// Gets the customer information from the database by phone number. /// </summary> /// <param name="phone">Phone is the unique key for each customer.</param> /// <returns></returns> public Customer selectCustomer(string phone) { try { Customer customer = new Customer(); SqlCommand cmd = SQLBaglantisi.getCommand("Select Phone, Name, LastName, Address, Region, CustomerNote from Customers Where Phone=@phone"); cmd.Parameters.AddWithValue("@phone", phone); SqlDataReader dr = cmd.ExecuteReader(); dr.Read(); customer.Phone = dr.GetString(0); customer.Name = dr.GetString(1); customer.LastName = dr.GetString(2); customer.Address = dr.GetString(3); customer.Region = dr.GetString(4); customer.CustomerNote = dr.GetString(5); return customer; } catch (Exception) { return null; } }
public bool insertNewCustomer(Customer customer) { try { SqlCommand cmd = SQLBaglantisi.getCommand("Insert into Customers Values(@phone,@name,@lastName,@address,@region,@customerNote)"); cmd.Parameters.AddWithValue("@phone", customer.Phone); cmd.Parameters.AddWithValue("@name", customer.Name); cmd.Parameters.AddWithValue("@lastName", customer.LastName); cmd.Parameters.AddWithValue("@address", customer.Address); cmd.Parameters.AddWithValue("@region", customer.Region); cmd.Parameters.AddWithValue("@customerNote", customer.CustomerNote); cmd.ExecuteNonQuery(); cmd.Connection.Close(); cmd.Connection.Dispose(); return true; } catch (Exception e) { return false; } }