mamamaria

ChangeGoodInOrderForm

Apr 25th, 2022 (edited)
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.35 KB | None | 0 0
  1. using Npgsql;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Data.SqlClient;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12.  
  13. namespace WindowsFormsApp2
  14. {
  15.     public partial class ChangeGoodInOrderForm : Form
  16.     {
  17.         NpgsqlConnection con;
  18.         private DataSet ds = new DataSet();
  19.         private DataTable dt = new DataTable();
  20.         SqlDataReader dr;
  21.         NpgsqlDataAdapter da;
  22.         int id;
  23.         int goodID, orderID;
  24.         private void Update()
  25.         {
  26.             string sql = "Select * from goods";
  27.             da = new NpgsqlDataAdapter(sql, con);
  28.             ds.Reset();
  29.             da.Fill(ds);
  30.             dt = ds.Tables[0];
  31.             comboBoxGood.DataSource = dt;
  32.             comboBoxGood.DisplayMember = "name";
  33.             comboBoxGood.ValueMember = "goodID";
  34.             comboBoxGood.SelectedValue = goodID.ToString();
  35.  
  36.         }
  37.         public ChangeGoodInOrderForm(NpgsqlConnection con, int id, int orderID, int goodID, int amount)
  38.         {
  39.             InitializeComponent();
  40.             this.con = con;
  41.             this.id = id;
  42.             this.orderID = orderID;
  43.             this.goodID = goodID;
  44.             textBoxAmount.Text = amount.ToString();
  45.  
  46.         }
  47.  
  48.         private void buttonSave_Click(object sender, EventArgs e)
  49.         {
  50.             //try
  51.             //{
  52.                 NpgsqlCommand command = new NpgsqlCommand("UPDATE orderEntries SET orderID = :orderID, goodID = :goodID, " +
  53.                     "amount = :amount WHERE orderEntriesID = :id", con);
  54.                 command.Parameters.AddWithValue("id", id);
  55.                 command.Parameters.AddWithValue("orderID", orderID);
  56.                 command.Parameters.AddWithValue("goodID", comboBoxGood.SelectedValue);
  57.                 command.Parameters.AddWithValue("amount", Convert.ToInt32(textBoxAmount.Text));
  58.                 command.ExecuteNonQuery();
  59.                 Close();
  60.             //}
  61.             //catch { }
  62.         }
  63.  
  64.         private void ChangeGoodInOrderForm_Load(object sender, EventArgs e)
  65.         {
  66.             Update();
  67.         }
  68.  
  69.         private void ChangeGoodInOrderForm_FormClosed(object sender, FormClosedEventArgs e)
  70.         {
  71.             Close();
  72.         }
  73.     }
  74. }
  75.  
Add Comment
Please, Sign In to add comment