using BiskLog_Point_Of_Sale.Classes; using BiskLog_Point_Of_Sale.Properties; using Point_Of_Sale_Managment; 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 BiskLog_Point_Of_Sale.Products_Module { public partial class InfoWindow : Form { SqlConnection cn; SqlCommand cm; SqlDataReader dr; DatabaseConn conn = new DatabaseConn(); string currency; public InfoWindow(string ID, string name) { InitializeComponent(); cn = new SqlConnection(conn.MyConnection()); currency = Settings.Default.currrencyCode + " "; productIDlbl.Text = ID; productNamelbl.Text = name; } private void exitBTN_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Abort; this.Close(); } public int LoadDetails() { try { dataGridView1.Invoke(new Action(() => { cn.Open(); cm = new SqlCommand("Select u.unitname,I.quantity,p.price from tblProduct p Inner Join UnitOfMeasure u On u.unitCode = p.baseUnit Inner Join tblInventory I On I.pcode = p.pcode " + "where p.branchID = @branchID and p.pcode = @pcode " + "Select u.unitname, I.quantity / PAU.[quantity/unit] as quantity, PAU.[price/unit] from tblProduct p Inner Join ProductAltUnit PAU On PAU.pcode = p.pcode " + "Inner Join UnitOfMeasure u On u.unitCode = PAU.unitCode Inner Join tblInventory I On I.pcode = p.pcode where p.branchID = @branchID and p.pcode = @pcode", cn); cm.Parameters.AddWithValue("@branchID", Settings.Default.BranchID); cm.Parameters.AddWithValue("@pcode", productIDlbl.Text); cm.ExecuteNonQuery(); dr = cm.ExecuteReader(); dr.Read(); if (dr.HasRows) { dataGridView1.Rows.Add(dr[0].ToString(),dr[1].ToString(),currency + dr[2].ToString()); } dr.NextResult(); while (dr.Read()) { dataGridView1.Rows.Add(dr[0].ToString(), dr[1].ToString(), currency + dr[2].ToString()); } dr.Close(); cn.Close(); })); return 1; } catch (Exception ex) { ErrorLogging.WriteToFile(ex.ToString()); cn.Close(); return 0; } } private async void InfoWindow_Load(object sender, EventArgs e) { Task task = new Task(LoadDetails); task.Start(); await task; } } }