Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Npgsql;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Data.SqlClient;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace WindowsFormsApp2
- {
- public partial class ChangeOrderForm : Form
- {
- NpgsqlConnection con;
- int id;
- int clientID;
- private void Update()
- {
- DataSet ds = new DataSet();
- DataTable dt = new DataTable();
- SqlDataReader dr;
- NpgsqlDataAdapter da;
- string sql = "Select * from clients";
- da = new NpgsqlDataAdapter(sql, con);
- ds.Reset();
- da.Fill(ds);
- dt = ds.Tables[0];
- comboBoxClientName.DataSource = dt;
- comboBoxClientName.DisplayMember = "name";
- comboBoxClientName.ValueMember = "clientID";
- comboBoxClientName.SelectedValue = clientID.ToString();
- }
- private void UpdateorderEntries()
- {
- DataSet ds = new DataSet();
- DataTable dt = new DataTable();
- SqlDataReader dr;
- NpgsqlDataAdapter da;
- string sqlorderEntries = "Select orderEntriesID, orderEntries.orderID, orderEntries.goodID, name, amount FROM orderEntries JOIN goods on orderID = :id AND orderEntries.goodID = goods.goodID";
- NpgsqlCommand command = new NpgsqlCommand(sqlorderEntries, con);
- command.Parameters.AddWithValue("id", id);
- da = new NpgsqlDataAdapter(command);
- ds.Reset();
- da.Fill(ds);
- dt = ds.Tables[0];
- dataGridView1.DataSource = dt;
- }
- public ChangeOrderForm(NpgsqlConnection con, int id, int clientID, DateTime orderdate, bool delivered)
- {
- InitializeComponent();
- //comboBoxClientName.SelectedValue = clientID.ToString();
- dateTimePicker.Value = orderdate;
- checkBoxDelivered.Checked = delivered;
- this.con = con;
- this.id = id;
- this.clientID = clientID;
- }
- private void ChangeOrderForm_Load(object sender, EventArgs e)
- {
- Update();
- UpdateorderEntries();
- }
- private void ChangeOrderForm_FormClosed(object sender, FormClosedEventArgs e)
- {
- Close();
- }
- private void buttonSave_Click(object sender, EventArgs e)
- {
- try
- {
- NpgsqlCommand command = new NpgsqlCommand("UPDATE orders SET clientID = :clientID, orderdate =:orderdate, delivered = :delivered WHERE orderID = :id", con);
- command.Parameters.AddWithValue("id", id);
- command.Parameters.AddWithValue("clientID", comboBoxClientName.SelectedValue);
- command.Parameters.AddWithValue("orderdate", dateTimePicker.Value);
- command.Parameters.AddWithValue("delivered", checkBoxDelivered.Checked);
- command.ExecuteNonQuery();
- Close();
- }
- catch { }
- }
- private void buttonChange_Click(object sender, EventArgs e)
- {
- try
- {
- int orderEntriesID = (int)dataGridView1.CurrentRow.Cells["orderEntriesID"].Value;
- int orderID = (int)dataGridView1.CurrentRow.Cells["orderID"].Value;
- int goodID = (int)dataGridView1.CurrentRow.Cells["goodID"].Value;
- int amount = (int)dataGridView1.CurrentRow.Cells["amount"].Value;
- ChangeGoodInOrderForm f = new ChangeGoodInOrderForm(con, orderEntriesID, orderID, goodID, amount);
- f.ShowDialog();
- Update();
- }
- catch { }
- }
- private void buttonAdd_Click(object sender, EventArgs e)
- {
- AddGoodInOrderForm f = new AddGoodInOrderForm(con, id);
- f.ShowDialog();
- Update();
- UpdateorderEntries();
- }
- }
- }
Add Comment
Please, Sign In to add comment