using BiskLog_Point_Of_Sale.Classes; using BiskLog_Point_Of_Sale.Multiple_Login; using BiskLog_Point_Of_Sale.Properties; using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace BiskLog_Point_Of_Sale.Invoice { public partial class InvoiceRecheck : Form { List list; public List vetted = new List(); List changed = new List(); List unchanged = new List(); public InvoiceRecheck(List list) { InitializeComponent(); this.list = list; } private void InvoiceRecheck_Load(object sender, System.EventArgs e) { invoiceList.Columns["bqty"].ReadOnly = false; invoiceList.Columns[0].ReadOnly = true; invoiceList.Columns[1].ReadOnly = true; invoiceList.Columns[2].ReadOnly = true; invoiceList.Columns[4].ReadOnly = true; invoiceList.Columns[5].ReadOnly = true; invoiceList.Columns[6].ReadOnly = true; invoiceList.Columns[7].ReadOnly = true; invoiceList.Columns[8].ReadOnly = true; invoiceList.Columns[9].ReadOnly = true; string currency = Settings.Default.currrencyCode + " "; int i = 1; foreach (OldAndNew pos in list) { invoiceList.Rows.Add(i, pos.productCode, pos.productname, pos.old_quantity, pos.unitName, pos.new_quantity, currency + pos.old_price, currency + pos.new_price, pos.unitCode, pos.distinctiveCode); invoiceList.Rows[i - 1].Cells[3].Style.BackColor = Color.FromArgb(10, 10, 120); if (pos.old_quantity > pos.new_quantity) { invoiceList.Rows[i - 1].Cells[3].Style.BackColor = Color.DarkRed; invoiceList.Rows[i - 1].Cells[3].Style.ForeColor = Color.White; invoiceList.Rows[i - 1].Cells[3].Style.Alignment = DataGridViewContentAlignment.MiddleCenter; invoiceList.Rows[i - 1].Cells[3].Style.Font = new Font("Segoe UI", 12, style: FontStyle.Bold); } else { invoiceList.Rows[i - 1].Cells[3].Style.BackColor = Color.DarkGreen; invoiceList.Rows[i - 1].Cells[3].Style.ForeColor = Color.White; invoiceList.Rows[i - 1].Cells[3].Style.Alignment = DataGridViewContentAlignment.MiddleCenter; invoiceList.Rows[i - 1].Cells[3].Style.Font = new Font("Segoe UI", 12, style: FontStyle.Bold); } i++; } } private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { e.Control.KeyPress -= new KeyPressEventHandler(Column1_KeyPress); if (invoiceList.CurrentCell.ColumnIndex == 3) //Desired Column { TextBox tb = e.Control as TextBox; if (tb != null) { tb.KeyPress += new KeyPressEventHandler(Column1_KeyPress); } } } private void Column1_KeyPress(object sender, KeyPressEventArgs e) { if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar)) { e.Handled = true; } } public int checkAvailabilty() { int priceChanges = 0; bool outOfOrder = false; try { foreach (DataGridViewRow rows in invoiceList.Rows) { string code = rows.Cells[1].Value.ToString(); string name = rows.Cells[2].Value.ToString(); string unitName = rows.Cells[4].Value.ToString(); string unitCode = rows.Cells[8].Value.ToString(); string distinctiveCode = rows.Cells[9].Value.ToString(); int quantity = int.Parse(rows.Cells[3].Value.ToString().TrimStart('0')); int available = int.Parse(rows.Cells[5].Value.ToString()); decimal perUnit = decimal.Parse(rows.Cells[7].Value.ToString().Substring(Settings.Default.currrencyCode.Length)); // decimal price = (quantity * perUnit); decimal oldprice = decimal.Parse(rows.Cells[6].Value.ToString().Substring(Settings.Default.currrencyCode.Length)); if (quantity > available) { rows.Cells[3].Style.BackColor = Color.DarkRed; rows.Cells[3].Style.ForeColor = Color.White; rows.Cells[3].Style.Alignment = DataGridViewContentAlignment.MiddleCenter; rows.Cells[3].Style.Font = new Font("Segoe UI", 12, style: FontStyle.Bold); outOfOrder = true; } else { rows.Cells[3].Style.BackColor = Color.DarkGreen; rows.Cells[3].Style.ForeColor = Color.White; rows.Cells[3].Style.Alignment = DataGridViewContentAlignment.MiddleCenter; rows.Cells[3].Style.Font = new Font("Segoe UI", 12, style: FontStyle.Bold); } if (oldprice != perUnit) priceChanges++; InvoicePOS POSold = new InvoicePOS( productCode: code, quantity: quantity, totalprice: oldprice * quantity, unitprice: oldprice, productname: name, distinctiveCode: distinctiveCode, unitCode: unitCode, unitName: unitName ); InvoicePOS POSnew = new InvoicePOS( productCode: code, quantity: quantity, totalprice: perUnit * quantity, unitprice: perUnit, productname: name, distinctiveCode: distinctiveCode, unitCode: unitCode, unitName: unitName ); changed.Add(POSnew); unchanged.Add(POSold); invoiceList.ClearSelection(); } } catch (Exception ex) { ErrorLogging.WriteToFile(ex.ToString()); } if (!outOfOrder && (priceChanges == 0)) { return 1; } else if (!outOfOrder && (priceChanges != 0)) { return 2; } else { return 3; } } private void Exit_Click(object sender, System.EventArgs e) { this.DialogResult = DialogResult.Abort; this.Close(); } private void Exit_MouseEnter(object sender, System.EventArgs e) { exit.BackColor = Color.Crimson; } private void Exit_MouseLeave(object sender, System.EventArgs e) { exit.BackColor = Color.Transparent; } private void InvoiceList_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) { if (e.ColumnIndex == 3 && e.RowIndex != -1) { e.AdvancedBorderStyle.All = DataGridViewAdvancedCellBorderStyle.Single; } else { e.AdvancedBorderStyle.All = DataGridViewAdvancedCellBorderStyle.None; } } private void Button1_Click(object sender, System.EventArgs e) { string title = ""; string message = ""; int result = checkAvailabilty(); switch (result) { case 1: title = "Continue"; message = "Would you like to continue with the new changes ?"; Confirmation confirmation = new Confirmation(title, message); confirmation.BringToFront(); confirmation.ShowDialog(); if (confirmation.DialogResult == DialogResult.Yes) { vetted = unchanged; this.DialogResult = DialogResult.OK; this.Close(); } break; case 2: title = "Confirm"; message = "Prices of some products might have been altered since the generation of this invoice, would you like to continue " + "with the latest pricings ?"; Confirmation confirmatioon = new Confirmation(title, message); confirmatioon.BringToFront(); confirmatioon.ShowDialog(); if (confirmatioon.DialogResult == DialogResult.Yes) { vetted = changed; this.DialogResult = DialogResult.OK; this.Close(); } else { vetted = unchanged; this.DialogResult = DialogResult.OK; this.Close(); } break; case 3: title = "Attention"; message = "The quantity of some selected products may not been available please check and try again"; NoAction confirmatiooned = new NoAction(title, message); confirmatiooned.BringToFront(); confirmatiooned.ShowDialog(); break; default: break; } } } }