public static void Create(Customer _customer)
 {
     connection.Open();
     try
     {
         SqlCommand cmd = new SqlCommand(@"INSERT INTO Customers (FIRSTNAME, LASTNAME, TELEPHONE, ADDRESS) VALUES (@fname, @lname, @tel, @address)", connection);
         cmd.Parameters.AddWithValue("@fname", _customer.FirstName);
         cmd.Parameters.AddWithValue("@lname", _customer.LastName);
         cmd.Parameters.AddWithValue("@tel", _customer.Telephone);
         cmd.Parameters.AddWithValue("@address", _customer.Address);
         cmd.ExecuteNonQuery();
     }
     catch (SqlException e)
     {
         MessageBox.Show(e.ToString());
     }
     catch (Exception exception)
     {
         MessageBox.Show(exception.Message);
     }
     finally
     {
         connection.Close();
     }
 }
 private Customer ParsedCustomer()
 {
     var cust = new Customer();
     cust.FirstName = textBox1.Text;
     cust.LastName = textBox2.Text;
     cust.Telephone = textBox3.Text;
     cust.Address = textBox4.Text;
     return cust;
 }
 public UpdateFormCustomer(Customer _existcustomer)
 {
     InitializeComponent();
     IdLabel.Text = "ID Πελάτη : ";
     IDBox.Text = _existcustomer.ID.ToString();
     ExistFNameBox.Text = _existcustomer.FirstName;
     ExistLNameBox.Text = _existcustomer.LastName;
     ExistTelBox.Text = _existcustomer.Telephone;
     ExistAddressBox.Text = _existcustomer.Address;
 }
 public OrdersCustomerForm(Customer _customer)
 {
     InitializeComponent();
     label1.Text = _customer.ID.ToString();
     label2.Text = _customer.FirstName;
     label2.Dock = DockStyle.Left | DockStyle.Top;
     label3.Text = _customer.LastName;
     label3.Dock = DockStyle.Left | DockStyle.Top;
     label4.Text = _customer.Telephone;
     label6.Text = _customer.Address;
 }
 private Customer ParsedCustomer()
 {
     int id = Convert.ToInt32(label1.Text);
     string firstname = label2.Text;
     string lastname = label3.Text;
     string telephone = label4.Text;
     string address = label6.Text;
     var Cust = new Customer();
     Cust.ID = id;
     Cust.FirstName = firstname;
     Cust.LastName = lastname;
     Cust.Telephone = telephone;
     Cust.Address = address;
     return Cust;
 }
 public static void Delete(Customer _customer)
 {
     connection.Open();
     try
     {
         string query = "DELETE FROM Customers where ID LIKE @CODE";
         SqlCommand cmd = new SqlCommand(query, connection);
         cmd.Parameters.AddWithValue("@CODE", _customer.ID);
         cmd.ExecuteNonQuery();
     }
     catch (SqlException exception)
     {
         MessageBox.Show(exception.ToString());
     }
     finally
     {
         connection.Close();
     }
 }
 private Customer ParsedCustomer()
 {
     var cust = new Customer();
     cust.ID = Convert.ToInt32(IDBox.Text);
     if (ReplaceFNameBox.Text == string.Empty || ReplaceFNameBox == null)
     {
         ReplaceFNameBox.Text = ExistFNameBox.Text;
         cust.FirstName = ReplaceFNameBox.Text;
     }
     else
     {
         cust.FirstName = ReplaceFNameBox.Text;
     }
     if (ReplaceLNameBox.Text == string.Empty || ReplaceLNameBox == null)
     {
         ReplaceLNameBox.Text = ExistLNameBox.Text;
         cust.LastName = ReplaceLNameBox.Text;
     }
     else
     {
         cust.LastName = ReplaceLNameBox.Text;
     }
     if (ReplaceTelBox.Text == string.Empty || ReplaceTelBox == null)
     {
         ReplaceTelBox.Text = ExistTelBox.Text;
         cust.Telephone = ReplaceTelBox.Text;
     }
     else
     {
         cust.Telephone = ReplaceTelBox.Text;
     }
     if (ReplaceAddressBox.Text == string.Empty || ReplaceAddressBox == null)
     {
         ReplaceAddressBox.Text = ExistAddressBox.Text;
         cust.Address = ReplaceAddressBox.Text;
     }
     else
     {
         cust.Address = ReplaceAddressBox.Text;
     }
     return cust;
 }
        public static void Create(Customer _customer, Order _order)
        {
            connection.Open();
            try
            {
                string query = "INSERT INTO Orders (IDCUSTOMER, DΕSCRIPTION) VALUES (@idcustomer,@description)";
                SqlCommand cmd = new SqlCommand(query, connection);
                cmd.Parameters.AddWithValue("@idcustomer", _customer.ID);
                cmd.Parameters.AddWithValue("@description", _order.Description);
                cmd.ExecuteNonQuery();

            }
            catch (SqlException e)
            {
                MessageBox.Show(e.ToString());
            }
            finally
            {
                connection.Close();
            }
        }
 public static void Update(Customer _customer)
 {
     connection.Open();
     try
     {
         SqlCommand cmd = new SqlCommand(@"UPDATE Customers SET FIRSTNAME = @fname, LASTNAME = @lname, TELEPHONE = @telephone, ADDRESS = @address WHERE ID LIKE @ID", connection);
         cmd.Parameters.AddWithValue("@ID", _customer.ID);
         cmd.Parameters.AddWithValue("@fname", _customer.FirstName);
         cmd.Parameters.AddWithValue("@lname", _customer.LastName);
         cmd.Parameters.AddWithValue("@telephone", _customer.Telephone);
         cmd.Parameters.AddWithValue("@address", _customer.Address);
         cmd.ExecuteNonQuery();
     }
     catch (SqlException e)
     {
         MessageBox.Show(e.ToString());
     }
     finally
     {
         connection.Close();
     }
 }
Example #10
0
 private Customer ParsedCustomer()
 {
     DataGridViewRow row = dataGridView1.CurrentCell.OwningRow;
     int id = Convert.ToInt32(row.Cells[0].Value.ToString());
     string firstname = row.Cells[1].Value.ToString();
     string lastname = row.Cells[2].Value.ToString();
     string telephone = row.Cells[3].Value.ToString();
     string address = row.Cells[4].Value.ToString();
     var Cust = new Customer();
     Cust.ID = id;
     Cust.FirstName = firstname;
     Cust.LastName = lastname;
     Cust.Telephone = telephone;
     Cust.Address = address;
     return Cust;
 }
 /// <summary>
 /// Επιστρέφει στο DataGridView τα στοιχεία του πίνακα που ανήκουν στον συγκεκριμένο Πελάτη _customer
 /// </summary>
 /// <param name="_datagridview"></param>
 /// <param name="_customer"></param>
 public static void Read(DataGridView _datagridview, Customer _customer)
 {
     connection.Open();
     try
     {
         string query = "SELECT * FROM Orders WHERE IDCUSTOMER =" + _customer.ID.ToString();
         SqlDataAdapter DA = new SqlDataAdapter(query, connection);
         DataTable DT = new DataTable();
         DA.Fill(DT);
         _datagridview.DataSource = DT;
         _datagridview.Columns[0].HeaderText = "Νούμερο Παραγγελίας";
         _datagridview.Columns[1].HeaderText = "Κωδικός Πελάτη";
         _datagridview.Columns[2].HeaderText = "Περιγραφή";
     }
     catch (SqlException e)
     {
         MessageBox.Show(e.ToString());
     }
     finally
     {
         connection.Close();
     }
 }