using BiskLog_Point_Of_Sale.Classes; using BiskLog_Point_Of_Sale.Multiple_Login; 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.Customer { public partial class ViewCustomerSales : Form { SqlConnection cn; SqlDataReader dr; SqlCommand cm; DatabaseConn conn = new DatabaseConn(); string receiptID, customerID; public ViewCustomerSales(string receiptID, string customerID) { InitializeComponent(); holding.Left = (ClientSize.Width - holding.Width) / 2; holding.Top = (ClientSize.Height - holding.Height) / 2; cn = new SqlConnection(conn.MyConnection()); this.receiptID = receiptID; this.customerID = customerID; } private void CLOSE_Click(object sender, EventArgs e) { this.Close(); } private void CLOSE_MouseEnter(object sender, EventArgs e) { CLOSE.BackColor = Color.Crimson; } private void CLOSE_MouseLeave(object sender, EventArgs e) { CLOSE.BackColor = Color.Transparent; } private async void ViewCustomerSales_Load(object sender, EventArgs e) { Task task = new Task(LoadReceipt); holding.Visible = true; task.Start(); int result = await task; if (result == 0) { string title = "Error Occurred"; string message = "An error occurred while trying to load sales please try again later."; NoAction noAction = new NoAction(title, message); noAction.BringToFront(); noAction.ShowDialog(); } holding.Visible = false; } public int LoadReceipt() { try { dataGridView1.Invoke(new Action(() => { int i = 1; cn.Open(); cm = new SqlCommand("Select tc.date,tp.product_name,CAST(tc.total/tc.price AS INT) as quantity ,tc.total,u.unitname " + "from tblCustomerPurchases cp Inner Join tblCart tc on tc.transno = cp.transactionID " + "Inner Join tblProduct tp On tp.pcode = tc.id Inner Join UnitOfMeasure u On u.unitCode = tc.unit " + "where cp.customerID = @customerID and tc.status <> 'CANCELLED' and tc.branchID = @branch and tc.transno = @transactionID " + "group by tc.date, tp.product_name, tc.total, tc.price, u.unitname", cn); cm.Parameters.AddWithValue("@transactionID", receiptID); cm.Parameters.AddWithValue("@customerID", customerID); cm.Parameters.AddWithValue("@branch", Settings.Default.BranchID); cm.ExecuteNonQuery(); dr = cm.ExecuteReader(); while (dr.Read()) { dataGridView1.Rows.Add(i, dr[0].ToString(), dr[1].ToString(), dr[2].ToString(), dr[4].ToString(),Settings.Default.currrencyCode + " " + dr[3].ToString() ); i++; } dr.Close(); cn.Close(); })); return 1; } catch (Exception ex) { ErrorLogging.WriteToFile(ex.ToString()); cn.Close(); return 0; } } } }