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 DeliveryLogs : Form { SqlConnection cn; SqlDataReader dr; SqlCommand cm; DatabaseConn conn = new DatabaseConn(); string customerID; public DeliveryLogs(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 dh.dateCompleted,dh.deliveryID,Sum(dd.quantity),dh.totalCost,dh.status from tblDeliveryHead dh Inner Join " + "tblDeliveryDetails dd on dd.deliveryID = dh.deliveryID where dh.customerID = @customerID " + "and dh.branchID = @branch group by dh.dateCompleted,dh.deliveryID,dh.totalCost,dh.status", cn); cm.Parameters.AddWithValue("@customerID", this.customerID); cm.Parameters.AddWithValue("@branch", Settings.Default.BranchID); cm.ExecuteNonQuery(); dr = cm.ExecuteReader(); while (dr.Read()) { if (dr[4].ToString().Equals("DELIVERED")) { 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()); i++; } else { dataGridView1.Rows.Add(i, "PENDING DELIVERY",dr[1].ToString(), dr[2].ToString(), Settings.Default.currrencyCode + " " + dr[3].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; } } }