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 ShopPurchase : Form { SqlConnection cn; SqlDataReader dr; SqlCommand cm; DatabaseConn conn = new DatabaseConn(); string customerID,receiptID; public ShopPurchase(string customerID) { InitializeComponent(); cn = new SqlConnection(conn.MyConnection()); this.customerID = customerID; holding.Left = (ClientSize.Width - holding.Width) / 2; holding.Top = (ClientSize.Height - holding.Height) / 2; } public int loadPurchases() { try { dataGridView1.Invoke(new Action(() => { int i = 1; dataGridView1.Rows.Clear(); cn.Open(); cm = new SqlCommand("Select tc.date,cp.transactionID,SUM(tc.quantity),SUM(tc.total),tc.status from tblCustomerPurchases cp Inner Join " + "tblCart tc on tc.transno = cp.transactionID where cp.customerID = @customerID and tc.status <> 'CANCELLED' and tc.branchID = @branch " + "group by tc.date, cp.transactionID,tc.status", cn); cm.Parameters.AddWithValue("@customerID", this.customerID); cm.Parameters.AddWithValue("@branch", Settings.Default.BranchID); cm.ExecuteNonQuery(); dr = cm.ExecuteReader(); while (dr.Read()) { dataGridView1.Rows.Add(i, Convert.ToDateTime(dr[0].ToString()).ToLongDateString()+ " "+ Convert.ToDateTime(dr[0].ToString()).ToLongTimeString(), dr[1].ToString(), dr[2].ToString(),Settings.Default.currrencyCode +" "+ dr[3].ToString(), dr[4].ToString()); i ++; } dr.Close(); cn.Close(); })); return 1; }catch(Exception ex) { cn.Close(); ErrorLogging.WriteToFile(ex.ToString()); return 0; } } private async void ShopPurchase_Load(object sender, EventArgs e) { Task task = new Task(loadPurchases); holding.Visible = true; task.Start(); int result = await task; if (result == 0) { string title = "Error Occurred"; string message = "An error occurred while getting customer purchase history, please try again later."; NoAction noAction = new NoAction(title,message); noAction.BringToFront(); noAction.ShowDialog(); } holding.Visible = false; } private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { if(e.RowIndex != -1) { receiptID = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString(); ViewCustomerSales customerSales = new ViewCustomerSales(receiptID,customerID); customerSales.BringToFront(); customerSales.ShowDialog(); } } } }