void lbKeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { frmSingleInputBox fsiGetName = new frmSingleInputBox("Enter the name of staff member " + lbNumbers.Items[((ListBox)sender).SelectedIndex].ToString(), ref sEngine); fsiGetName.tbResponse.Text = lbStaff.Items[((ListBox)sender).SelectedIndex].ToString(); fsiGetName.ShowDialog(); if (fsiGetName.Response != "$NONE") { lbStaff.Items[((ListBox)sender).SelectedIndex] = fsiGetName.Response; } } else if (e.KeyCode == Keys.Escape) { if (MessageBox.Show("Would you like to save the changes?", "Save Changes?", MessageBoxButtons.YesNo) == DialogResult.Yes) { string[] sToAdd = new string[lbStaff.Items.Count]; for (int i = 0; i < sToAdd.Length; i++) { sToAdd[i] = lbStaff.Items[i].ToString(); } sEngine.SaveListOfStaffMembers(sToAdd, sShopCode); if (MessageBox.Show("Upload changes to all tills now?", "Upload?", MessageBoxButtons.YesNo) == DialogResult.Yes) { sEngine.CopyWaitingFilesToTills(); } this.Close(); } else { this.Close(); } } }
public frmPayForCommissionItem(ref StockEngine sEngine) { // Get the barcode of the commission item frmSingleInputBox fsfiGetCode = new frmSingleInputBox("Enter the Barcode of the commission item. Press F5 to look up:", ref sEngine); fsfiGetCode.ShowDialog(); if (fsfiGetCode.Response != "$NONE") { frmSingleInputBox fsfiGetQtySold = new frmSingleInputBox("Enter the quantity of items that you are paying for:", ref sEngine); fsfiGetQtySold.ShowDialog(); if (fsfiGetQtySold.Response != "$NONE") { decimal dQtyPaid = -1; try { dQtyPaid = Convert.ToDecimal(fsfiGetQtySold.Response); } catch { System.Windows.Forms.MessageBox.Show("Invalid number entered."); return; } frmSingleInputBox fGetAmount = new frmSingleInputBox("Enter the total amount that you paid for the items:", ref sEngine); fGetAmount.ShowDialog(); if (fGetAmount.Response != "$NONE") { decimal dAmountPaid = -1; try { dAmountPaid = Convert.ToDecimal(fGetAmount.Response); } catch { System.Windows.Forms.MessageBox.Show("Invalid amount entered."); return; } frmListOfShops flos = new frmListOfShops(ref sEngine); flos.ShowDialog(); if (flos.SelectedShopCode != "$NONE") { // Code here to straighten out the stock files if (sEngine.MarkCommissionItemAsPaid(fsfiGetCode.Response, dQtyPaid, dAmountPaid, flos.SelectedShopCode)) { System.Windows.Forms.MessageBox.Show(dQtyPaid.ToString() + " " + sEngine.GetMainStockInfo(fsfiGetCode.Response)[1] + " paid for at a total of " + dAmountPaid.ToString()); } else { System.Windows.Forms.MessageBox.Show("Unfortunately the items couldn't be paid for. This could be because the total you've ever received is less than the total you're trying to pay for"); } } else { return; } } } } }
void lbListOfCatGroups_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { lbListOfCatsInGroup.Focus(); if (lbListOfCatsInGroup.Items.Count > 0) { lbListOfCatsInGroup.SelectedIndex = 0; } } else if (e.KeyCode == Keys.Insert) { // Add New Item frmSingleInputBox fGetDesc = new frmSingleInputBox("Please enter the description of the category group :", ref sEngine); fGetDesc.ShowDialog(); lbListOfCatsInGroup.Items.Clear(); string sDesc = ""; if (fGetDesc.Response != "$NONE") { sDesc = fGetDesc.Response; frmSingleInputBox fGetCats = new frmSingleInputBox("Enter the category code, or press F5 to choose a category. Leave blank to finish.", ref sEngine); fGetCats.GettingCategory = true; fGetCats.ShowDialog(); string[] sCats = new string[0]; while (fGetCats.Response != "$NONE") { Array.Resize <string>(ref sCats, sCats.Length + 1); sCats[sCats.Length - 1] = fGetCats.Response; lbListOfCatsInGroup.Items.Add(sEngine.GetCategoryDesc(fGetCats.Response)); fGetCats.Response = "$NONE"; fGetCats.tbResponse.Text = ""; fGetCats.ShowDialog(); } if (MessageBox.Show("Save category group?", "Save", MessageBoxButtons.YesNo) == DialogResult.Yes) { sEngine.AddEditCategoryGroup(sDesc, sCats); lbListOfCatGroups.Items.Add(sDesc); lbListOfCatsInGroup.SelectedIndex = lbListOfCatsInGroup.Items.Count - 1; } else { lbListOfCatGroups.SelectedIndex = 0; } } } else if (e.KeyCode == Keys.Delete && e.Shift) { sEngine.DeleteCategoryGroup(lbListOfCatGroups.Items[lbListOfCatGroups.SelectedIndex].ToString()); lbListOfCatGroups.Items.RemoveAt(lbListOfCatGroups.SelectedIndex); lbListOfCatGroups.SelectedIndex = 0; } else if (e.KeyCode == Keys.Escape) { this.Close(); } }
void AddVATCode() { frmSingleInputBox fsiGetCode = new frmSingleInputBox("Enter the 2 character code to use :", ref sEngine); fsiGetCode.ShowDialog(); if (fsiGetCode.Response != "$NONE") { frmSingleInputBox fsiGetName = new frmSingleInputBox("Enter a description of the new rate :", ref sEngine); fsiGetName.ShowDialog(); if (fsiGetName.Response != "$NONE") { frmSingleInputBox fsiGetRate = new frmSingleInputBox("Enter the new rate (%):", ref sEngine); fsiGetRate.ShowDialog(); if (fsiGetRate.Response != "$NONE") { bool bOk = false; try { Convert.ToDecimal(fsiGetRate.Response); bOk = true; } catch { ; } if (bOk) { Array.Resize <TextBox>(ref tbCodes, tbCodes.Length + 1); Array.Resize <TextBox>(ref tbNames, tbNames.Length + 1); Array.Resize <TextBox>(ref tbRates, tbRates.Length + 1); tbCodes[tbCodes.Length - 1] = new TextBox(); tbNames[tbNames.Length - 1] = new TextBox(); tbRates[tbRates.Length - 1] = new TextBox(); this.Controls.Add(tbCodes[tbRates.Length - 1]); this.Controls.Add(tbNames[tbRates.Length - 1]); this.Controls.Add(tbRates[tbRates.Length - 1]); tbCodes[tbCodes.Length - 1].Width = 50; tbNames[tbNames.Length - 1].Width = 200; tbRates[tbRates.Length - 1].Width = 100; tbCodes[tbCodes.Length - 1].Location = new System.Drawing.Point(10, tbCodes[tbCodes.Length - 2].Top + tbCodes[tbCodes.Length - 2].Height + 10); tbNames[tbNames.Length - 1].Location = new System.Drawing.Point(tbCodes[tbCodes.Length - 1].Width + tbCodes[tbCodes.Length - 1].Left + 10, tbCodes[tbCodes.Length - 1].Top); tbRates[tbRates.Length - 1].Location = new System.Drawing.Point(tbNames[tbNames.Length - 1].Left + tbNames[tbNames.Length - 1].Width + 10, tbNames[tbNames.Length - 1].Top); this.Height += tbCodes[0].Height; tbCodes[tbCodes.Length - 1].Text = fsiGetCode.Response; tbNames[tbNames.Length - 1].Text = fsiGetName.Response; tbRates[tbRates.Length - 1].Text = fsiGetRate.Response; } } } } }
public AddMultiBarcodeItem(ref StockEngine sEngine) { frmSingleInputBox fsiGetBarcode = new frmSingleInputBox("Enter the barcode for the new multi-barcode item", ref sEngine); fsiGetBarcode.ShowDialog(); if (fsiGetBarcode.Response != "$NONE") { Barcode = fsiGetBarcode.Response; frmSingleInputBox fsiGetDesc = new frmSingleInputBox("Enter the description for the new multi-barcode item", ref sEngine); fsiGetDesc.ShowDialog(); if (fsiGetDesc.Response != "$NONE") { frmListOfShops flos = new frmListOfShops(ref sEngine); flos.ShowDialog(); frmListOfTills flot = new frmListOfTills(ref sEngine, flos.SelectedShopCode); flot.ShowDialog(); System.Windows.Forms.MessageBox.Show("When the till is free, it will temporarily move to this computer. Enter the number 0 as your ID, and enter the transaction as you would like it to appear when you enter " + fsiGetBarcode.Response + " at the till. Then press the space bar and the till program will quit back to this", "Instructions", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information); sEngine.RunTillSoftware(); string[] sData = sEngine.GetStoredTransactionFromTill(Convert.ToInt32(flot.sSelectedTillCode)); int nOfLines = 0; foreach (string line in sData) { if (line.Contains(',')) { nOfLines++; } } string[] sBarcodes = new string[nOfLines]; decimal[] dQuantities = new decimal[nOfLines]; decimal[] dAmountPerItem = new decimal[nOfLines]; for (int i = 0; i < nOfLines; i++) { string[] sTemp = sData[i].Split(','); sBarcodes[i] = sTemp[0]; dQuantities[i] = Convert.ToDecimal(sTemp[1]); dAmountPerItem[i] = Convert.ToDecimal(sTemp[2]) / dQuantities[i]; } sEngine.AddMultiItemItem(fsiGetBarcode.Response, fsiGetDesc.Response, flos.SelectedShopCode, sBarcodes, dQuantities, dAmountPerItem); if (System.Windows.Forms.MessageBox.Show("Upload changes to all tills now?", "Upload?", System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { sEngine.CopyWaitingFilesToTills(); } } else { Barcode = "$NULL"; } } else { Barcode = "$NULL"; } }
void DeleteVATCode(string sCode) { if (MessageBox.Show("To delete a VAT code, you must have another code that items belonging to the old code can use. Also, any other changes will first be saved. Continue?", "VAT Code Delete", MessageBoxButtons.YesNo) == DialogResult.Yes) { Save(); frmSingleInputBox fsiGetNewCode = new frmSingleInputBox("Enter the code of the VAT rate replacing " + sCode, ref sEngine); fsiGetNewCode.ShowDialog(); if (fsiGetNewCode.Response != "$NONE") { if (sCode != fsiGetNewCode.Response) { bool bFound = false; for (int i = 0; i < tbCodes.Length; i++) { if (fsiGetNewCode.Response.ToUpper() == tbCodes[i].Text.ToUpper()) { bFound = true; break; } } if (bFound) { sEngine.ChangeItemsVATCodes(sCode, fsiGetNewCode.Response); int nCodeLoc = -1; for (int i = 0; i < tbCodes.Length; i++) { if (tbCodes[i].Text.ToUpper() == sCode) { nCodeLoc = i; break; } } if (nCodeLoc != -1) { for (int i = nCodeLoc; i < tbCodes.Length - 1; i++) { tbCodes[i].Text = tbCodes[i + 1].Text; tbNames[i].Text = tbNames[i + 1].Text; tbRates[i].Text = tbRates[i + 1].Text; } this.Controls.Remove(tbCodes[tbCodes.Length - 1]); this.Controls.Remove(tbNames[tbNames.Length - 1]); this.Controls.Remove(tbRates[tbRates.Length - 1]); Array.Resize <TextBox>(ref tbCodes, tbCodes.Length - 1); Array.Resize <TextBox>(ref tbNames, tbNames.Length - 1); Array.Resize <TextBox>(ref tbRates, tbRates.Length - 1); this.Height -= tbCodes[0].Height; } } } } } }
void mAveCost_Click(object sender, EventArgs e) { frmSingleInputBox fsAvecost = new frmSingleInputBox("Enter the new average cost...", ref sEngine); fsAvecost.ShowDialog(); if (fsAvecost.Response != "$NONE") { sEngine.EditAverageCostOfItem(sBarcode, sShopCode, fsAvecost.Response); ShowStatsAboutProduct(); } }
void GetPassword() { if (!bGotPassword) { frmSingleInputBox fGetPassword = new frmSingleInputBox("Enter the administrator password : "******"$NONE" && fGetPassword.Response.ToUpper() == sEngine.GetPasswords(2).ToUpper()) { bGotPassword = true; } } }
/// <summary> /// Gets the settlement discount amount to apply at the end, if any /// </summary> private void EnterSettlementDiscount() { frmSingleInputBox fsiGetSettlement = new frmSingleInputBox("Enter the settlement discount percentage, if any:", ref sEngine); fsiGetSettlement.tbResponse.Text = "0.00"; fsiGetSettlement.ShowDialog(); try { dSettlementDiscount = Convert.ToDecimal(fsiGetSettlement.Response); } catch { dSettlementDiscount = 0; } }
void MoveToLine() { frmSingleInputBox fsi = new frmSingleInputBox("Which line would you like to go to?", ref sEngine); fsi.ShowDialog(); if (fsi.Response != "$NONE") { try { tbBarcode[Convert.ToInt32(fsi.Response) - 1].Focus(); } catch { return; } } }
private void EditOffer(string sBarcode) { frmSingleInputBox fsiGetDesc = new frmSingleInputBox("Enter a description of the offer [30 characters maximum]", ref sEngine); fsiGetDesc.tbResponse.Text = sEngine.GetDetailsOfOffer(sBarcode)[1]; fsiGetDesc.ShowDialog(); if (fsiGetDesc.Response != "$NONE") { frmOffersReceptDesigner ford = new frmOffersReceptDesigner(sBarcode, ref sEngine); ford.ShowDialog(); sEngine.CreateAnOffer(sBarcode, fsiGetDesc.Response, "", sBarcode + ".txt"); } LoadOffers(); sEngine.GenerateOffersForAllTills(); }
void lbKeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { frmSingleInputBox fGetCost = new frmSingleInputBox("Enter the invoice cost :", ref sEngine); fGetCost.tbResponse.Text = lbCost.Items[((ListBox)sender).SelectedIndex].ToString(); fGetCost.ShowDialog(); if (fGetCost.Response != "$NONE") { frmSingleInputBox fGetQuantity = new frmSingleInputBox("Enter the quantity of items that this cost represents :", ref sEngine); fGetQuantity.tbResponse.Text = "1.00"; fGetQuantity.ShowDialog(); if (fGetQuantity.Response != "$NONE") { decimal dQuantity = Convert.ToDecimal(fGetQuantity.Response); frmSingleInputBox fGetDiscount = new frmSingleInputBox("Enter the discount in percentage (excluding settlement), if any :", ref sEngine); fGetDiscount.tbResponse.Text = "0.00"; fGetDiscount.ShowDialog(); if (fGetDiscount.Response != "$NONE") { decimal dInvoicePrice = Convert.ToDecimal(fGetCost.Response); dInvoicePrice /= dQuantity; dInvoicePrice -= (dInvoicePrice * (Convert.ToDecimal(fGetDiscount.Response) / 100)); bCostChanged[((ListBox)sender).SelectedIndex] = true; lbCost.Items[((ListBox)sender).SelectedIndex] = FormatMoneyForDisplay(dInvoicePrice); } } } if (((ListBox)sender).SelectedIndex + 1 < ((ListBox)sender).Items.Count) { ((ListBox)sender).SelectedIndex = ((ListBox)sender).SelectedIndex + 1; } } else if (e.KeyCode == Keys.Escape) { if (MessageBox.Show("Save Changes?", "Save Changes?", MessageBoxButtons.YesNo) == DialogResult.Yes) { SaveChanges(); } bSaved = true; this.Close(); } }
public frmMenu(string shortcutString) { this.Disposed += new EventHandler(frmMenu_Disposed); sEngine = new StockEngine(); if (!sEngine.GotEmailSupportAddress()) { frmSingleInputBox fsfiGetEmail = new frmSingleInputBox("Please enter an e-mail address. Leave blank if you like.", ref sEngine); fsfiGetEmail.ShowDialog(); if (fsfiGetEmail.Response != "$NONE") { sEngine.SetEmailSupportAddress(fsfiGetEmail.Response); } } ScalableForm.TitleAddition = sEngine.CompanyName; SetupMenu(); this.Text = "Main Menu"; this.Focus(); this.VisibleChanged += frmMenu_VisibleChanged; this.shortcutString = shortcutString; }
private void AddOffer() { frmSingleInputBox fsiGetCode = new frmSingleInputBox("Enter an 8 digit numerical code for the offer F6 to auto-generate one", ref sEngine); fsiGetCode.tbResponse.KeyDown += new KeyEventHandler(tbResponse_KeyDown); fsiGetCode.ShowDialog(); if (fsiGetCode.Response != "$NONE") { frmSingleInputBox fsiGetDesc = new frmSingleInputBox("Enter a description of the offer [30 characters maximum]", ref sEngine); fsiGetDesc.ShowDialog(); if (fsiGetDesc.Response != "$NONE") { frmOffersReceptDesigner ford = new frmOffersReceptDesigner(fsiGetCode.tbResponse.Text, ref sEngine); ford.ShowDialog(); sEngine.CreateAnOffer(fsiGetCode.Response, fsiGetDesc.Response, "", fsiGetCode.Response + ".txt"); } } LoadOffers(); sEngine.GenerateOffersForAllTills(); }
void lbListOfCatsInGroup_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Delete && e.Shift) { for (int i = lbListOfCatsInGroup.SelectedIndex; i < sCodesOnDisplay.Length - 1; i++) { sCodesOnDisplay[i] = sCodesOnDisplay[i + 1]; } Array.Resize <string>(ref sCodesOnDisplay, sCodesOnDisplay.Length - 1); lbListOfCatsInGroup.Items.RemoveAt(lbListOfCatsInGroup.SelectedIndex); if (lbListOfCatGroups.Items.Count > 0) { lbListOfCatGroups.SelectedIndex = 0; } else { sEngine.DeleteCategoryGroup(lbListOfCatGroups.Items[lbListOfCatGroups.SelectedIndex].ToString()); lbListOfCatGroups.Items.RemoveAt(lbListOfCatGroups.SelectedIndex); lbListOfCatGroups.SelectedIndex = 0; lbListOfCatGroups.Focus(); } sEngine.AddEditCategoryGroup(lbListOfCatGroups.Items[lbListOfCatGroups.SelectedIndex].ToString(), sCodesOnDisplay); } else if (e.KeyCode == Keys.Insert) { frmSingleInputBox fGetCat = new frmSingleInputBox("Enter the category code, of press F5 to choose a category. Leave blank to cancel.", ref sEngine); fGetCat.GettingCategory = true; if (fGetCat.Response != "$NONE") { Array.Resize <string>(ref sCodesOnDisplay, sCodesOnDisplay.Length + 1); sCodesOnDisplay[sCodesOnDisplay.Length - 1] = fGetCat.Response; sEngine.AddEditCategoryGroup(lbListOfCatGroups.Items[lbListOfCatGroups.SelectedIndex].ToString(), sCodesOnDisplay); } } else if (e.KeyCode == Keys.Escape) { lbListOfCatGroups.Focus(); } }
void QtyKeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { frmSingleInputBox fGetPassword = new frmSingleInputBox("Please enter the administrator password :"******"$NONE" || fGetPassword.Response.ToUpper() != sEngine.GetPasswords(2).ToUpper()) { MessageBox.Show("Incorrect password"); this.Close(); } else { sEngine.TransferStockItem(InputTextBox("FROM").Text, InputTextBox("TO").Text, InputTextBox("BARCODE").Text, Convert.ToDecimal(InputTextBox("QTY").Text), false); if (MessageBox.Show("Would you like to upload all changes to tills?", "Upload?", MessageBoxButtons.YesNo) == DialogResult.Yes) { sEngine.CopyWaitingFilesToTills(); } this.Close(); } } }
void mEditLastCost_Click(object sender, EventArgs e) { decimal dLastCost = Convert.ToDecimal(sEngine.GetMainStockInfo(sBarcode)[8]); frmSingleInputBox fsiGetLastCost = new frmSingleInputBox("Enter the last cost :", ref sEngine); fsiGetLastCost.tbResponse.Text = FormatMoneyForDisplay(dLastCost); fsiGetLastCost.ShowDialog(); if (fsiGetLastCost.Response != "$NONE") { bool bOk = false; try { Convert.ToDecimal(fsiGetLastCost.Response); bOk = true; } catch {; } if (bOk) { sEngine.ChangeLastCostOfItem(sBarcode, Convert.ToDecimal(fsiGetLastCost.Response)); ShowStatsAboutProduct(); } } }
void mEditStock_Click(object sender, EventArgs e) { decimal dCurrentStockLevel = Convert.ToDecimal(sEngine.GetItemStockStaRecord(sBarcode, sShopCode)[36]); frmSingleInputBox fsGetNewStocklevel = new frmSingleInputBox("Enter the new stock level :", ref sEngine); fsGetNewStocklevel.ShowDialog(); if (fsGetNewStocklevel.Response != "$NONE") { frmSingleInputBox fGetPassword = new frmSingleInputBox("Enter the administrator password : "******"$NONE" && fGetPassword.Response.ToUpper() == sEngine.GetPasswords(2).ToUpper()) { if (sEngine.GetMainStockInfo(sBarcode)[5] == "1") { if (Convert.ToDecimal(fsGetNewStocklevel.Response) > dCurrentStockLevel) { sEngine.TransferStockItem("BH", sShopCode, sBarcode, Convert.ToDecimal(fsGetNewStocklevel.Response) - dCurrentStockLevel, false); } else { sEngine.TransferStockItem(sShopCode, "BH", sBarcode, dCurrentStockLevel - Convert.ToDecimal(fsGetNewStocklevel.Response), false); } } else if (sEngine.GetMainStockInfo(sBarcode)[5] == "6") { sEngine.ReceiveComissionItem(sBarcode, (Convert.ToDecimal(fsGetNewStocklevel.Response) - dCurrentStockLevel).ToString(), sShopCode); } ShowStatsAboutProduct(); if (MessageBox.Show("Would you like to upload the stock level change to all tills?", "Upload now?", MessageBoxButtons.YesNo) == DialogResult.Yes) { sEngine.CopyWaitingFilesToTills(); } } } }
void EditStatsClick(object sender, EventArgs e) { MenuItem s = (MenuItem)sender; int nX = Convert.ToInt32(s.Name.Split(',')[0]); int nY = Convert.ToInt32(s.Name.Split(',')[1]); string sDBaseFieldName = sTopFNames[nX] + sSideFNames[nY]; frmSingleInputBox fsiGetNewData = new frmSingleInputBox("Enter the new data (field " + sDBaseFieldName + "):", ref sEngine); fsiGetNewData.ShowDialog(); if (fsiGetNewData.Response != "$NONE") { try { Convert.ToDecimal(fsiGetNewData.Response); sEngine.ChangeStockStaField(sBarcode, sDBaseFieldName, fsiGetNewData.Response, sShopCode); ShowStatsAboutProduct(); } catch { MessageBox.Show("Invalid data entered. The record has not had its data changed."); } } }
void dGrid_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.F3 && !bF3Registered) { bF5Registered = false; bEscapeRegistered = false; bF3Registered = true; frmSingleInputBox fsfiGetOriginal = new frmSingleInputBox("Where the " + dGrid.Columns[dGrid.SelectedCells[0].ColumnIndex].Name + " is currently...", ref sEngine); fsfiGetOriginal.tbResponse.Text = dGrid.CurrentCell.Value.ToString(); fsfiGetOriginal.ShowDialog(); if (fsfiGetOriginal.Response != "$NONE") { frmSingleInputBox fsfiGetNew = new frmSingleInputBox("Change the " + dGrid.Columns[dGrid.SelectedCells[0].ColumnIndex].Name + " from " + fsfiGetOriginal.Response + " to...", ref sEngine); fsfiGetNew.ShowDialog(); if (fsfiGetNew.Response != "$NONE") { bool bNoneConverted = false; while (!bNoneConverted) // Has to be done otherwise the grid sorts elements as it's changing them and ends up missing some { bNoneConverted = true; for (int i = 0; i < dGrid.Rows.Count; i++) { if (dGrid.SelectedCells[0].ColumnIndex != 4 && dGrid.SelectedCells[0].ColumnIndex != 8 && dGrid.Rows[i].Cells[dGrid.SelectedCells[0].ColumnIndex].FormattedValue.ToString() == fsfiGetOriginal.Response) { dGrid.Rows[i].Cells[dGrid.SelectedCells[0].ColumnIndex].Value = fsfiGetNew.Response; bNoneConverted = false; //i = 0; } else if ((dGrid.SelectedCells[0].ColumnIndex == 4 || dGrid.SelectedCells[0].ColumnIndex == 8) && dGrid.Rows[i].Cells[dGrid.SelectedCells[0].ColumnIndex].FormattedValue.ToString() != "" && Convert.ToDecimal(dGrid.Rows[i].Cells[dGrid.SelectedCells[0].ColumnIndex].FormattedValue.ToString()).Equals(Convert.ToDecimal(fsfiGetOriginal.Response))) { dGrid.Rows[i].Cells[dGrid.SelectedCells[0].ColumnIndex].Value = ScalableForm.FormatMoneyForDisplay(fsfiGetNew.Response); bNoneConverted = false; //i = 0; } } } } } } else if (e.KeyCode == Keys.Escape && ((dGrid.CurrentCell != null && !dGrid.CurrentCell.IsInEditMode && !bEscapeRegistered) || (bEscapeRegistered && (nRowEscRegistered != dGrid.CurrentCell.RowIndex) || (nColumnEscRegistered != dGrid.CurrentCell.ColumnIndex))))// && lastKey != Keys.Escape) { bEscapeRegistered = true; nColumnEscRegistered = dGrid.CurrentCell.ColumnIndex; nRowEscRegistered = dGrid.CurrentCell.RowIndex; bF5Registered = false; bF3Registered = false; AskToSave(); } else if (dGrid.CurrentCell.ColumnIndex == 2 && e.KeyCode == Keys.F5 && !bShowingType && !bF5Registered) { bEscapeRegistered = false; bF5Registered = true; bF3Registered = false; bShowingType = true; frmListOfItemTypes flot = new frmListOfItemTypes(); flot.SelectedItemType = Convert.ToInt32(dGrid.CurrentCell.Value.ToString()); flot.ShowDialog(); if (flot.SelectedItemType != -1) { dGrid.CurrentCell.Value = flot.SelectedItemType.ToString(); } bShowingType = false; e.Handled = true; } else if (dGrid.CurrentCell.ColumnIndex == 3 && e.KeyCode == Keys.F5 && !bF5Registered) { bEscapeRegistered = false; bF5Registered = true; bF3Registered = false; frmCategorySelect fcs = new frmCategorySelect(ref sEngine); fcs.ShowDialog(); if (fcs.SelectedItemCategory != "$NULL") { dGrid.CurrentCell.Value = fcs.SelectedItemCategory; } } else if (dGrid.CurrentCell.ColumnIndex == 5 && e.KeyCode == Keys.F5 && !bF5Registered) { bEscapeRegistered = false; bF5Registered = true; bF3Registered = false; frmListOfVATRates flov = new frmListOfVATRates(ref sEngine); flov.ShowDialog(); if (flov.sSelectedVATCode != "NULL") { dGrid.CurrentCell.Value = flov.sSelectedVATCode; } } else if (dGrid.CurrentCell.ColumnIndex == 7 && e.KeyCode == Keys.F5 && !bF5Registered) { bEscapeRegistered = false; bF5Registered = true; bF3Registered = false; frmListOfSuppliers flos = new frmListOfSuppliers(ref sEngine); flos.ShowDialog(); if (flos.sSelectedSupplierCode != "NULL") { dGrid.CurrentCell.Value = flos.sSelectedSupplierCode; } } else if (dGrid.CurrentCell.ColumnIndex == 10 && e.KeyCode == Keys.F5 && !bF5Registered) { bEscapeRegistered = false; bF5Registered = true; bF3Registered = false; frmSearchForItemV2 fsfi = new frmSearchForItemV2(ref sEngine); fsfi.ShowDialog(); if (fsfi.GetItemBarcode() != "NONE_SELECTED") { dGrid.CurrentCell.Value = fsfi.GetItemBarcode(); } } else if (e.KeyCode == Keys.Down || e.KeyCode == Keys.Right || e.KeyCode == Keys.Up || e.KeyCode == Keys.Left) { bF3Registered = false; bF5Registered = false; bEscapeRegistered = false; } else if (e.KeyCode == Keys.Enter) { e.Handled = true; } }
void lbListOfCodes_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { frmSingleInputBox fGetCode = new frmSingleInputBox("Please enter the code", ref sEngine); string sOriginalCode = lbListOfCodes.Items[lbListOfCodes.SelectedIndex].ToString(); string sNewCode = ""; string sDesc = ""; fGetCode.tbResponse.Text = lbListOfCodes.Items[lbListOfCodes.SelectedIndex].ToString(); fGetCode.ShowDialog(); if (fGetCode.Response != "$NONE") { sNewCode = fGetCode.Response; frmSingleInputBox fGetDesc = new frmSingleInputBox("Please enter the description", ref sEngine); fGetDesc.tbResponse.Text = lbListOfCategories.Items[lbListOfCodes.SelectedIndex].ToString().TrimStart(' '); fGetDesc.ShowDialog(); if (fGetDesc.Response != "$NONE") { sDesc = fGetDesc.Response; sEngine.EditCategoryDetails(sOriginalCode, sNewCode, sDesc); ListAllCategories(); lbListOfCodes.SelectedIndex = 0; for (int i = 0; i < lbListOfCodes.Items.Count; i++) { if (lbListOfCodes.Items[i].ToString() == fGetCode.Response) { lbListOfCodes.SelectedIndex = i; } } } } } else if (e.KeyCode == Keys.Escape) { this.Close(); } else if (e.KeyCode == Keys.Insert) { frmSingleInputBox fGetCode = new frmSingleInputBox("Enter the code for the new category:", ref sEngine); fGetCode.ShowDialog(); if (fGetCode.Response != "$NONE") { frmSingleInputBox fGetDesc = new frmSingleInputBox("Enter the description for the new category:", ref sEngine); fGetDesc.ShowDialog(); if (fGetDesc.Response != "$NONE") { sEngine.AddCategory(fGetCode.Response, fGetDesc.Response); ListAllCategories(); lbListOfCodes.SelectedIndex = 0; for (int i = 0; i < lbListOfCodes.Items.Count; i++) { if (lbListOfCodes.Items[i].ToString() == fGetCode.Response) { lbListOfCodes.SelectedIndex = i; } } } } } }
void GetInfoAndCalculatePrices() { RemoveRow(tbBarcode.Length - 1); bool bAllEmpty = true; int nNotEmpty = 0; for (int i = 0; i < tbTargetMargin.Length; i++) { if (tbTargetMargin[i].Text.Length > 0) { bAllEmpty = false; nNotEmpty++; } } bool bAllFilledIn = false; if (nNotEmpty == tbTargetMargin.Length) { bAllFilledIn = true; } frmSingleInputBox fGetFinalPrice = new frmSingleInputBox("What is the total price?", ref sEngine); decimal dTotal = 0; for (int i = 0; i < lblRRPEach.Length; i++) { if (tbMarginOrRRP[i].Text != "R") { dTotal += (Convert.ToDecimal(lblRRPEach[i].Text) * Convert.ToDecimal(tbQty[i].Text)); } else { if (tbTargetMargin[i].Text.Length != 0) { dTotal += (Convert.ToDecimal(tbTargetMargin[i].Text) * Convert.ToDecimal(tbQty[i].Text)); } else { dTotal += (Convert.ToDecimal(lblRRPEach[i].Text) * Convert.ToDecimal(tbQty[i].Text)); } } } fGetFinalPrice.tbResponse.Text = FormatMoneyForDisplay(dTotal); decimal dTargetPrice = 0; if (!bAllFilledIn) { fGetFinalPrice.ShowDialog(); try { dTargetPrice = Convert.ToDecimal(fGetFinalPrice.Response); } catch { MessageBox.Show("Invalid Price Entered"); return; } } else { dTargetPrice = dTotal; } bool[] bPriceCalculated = new bool[tbBarcode.Length]; for (int i = 0; i < bPriceCalculated.Length; i++) { bPriceCalculated[i] = false; } decimal dPriceLeft = dTargetPrice; decimal dFullRRPTotal = 0; for (int i = 0; i < tbTargetMargin.Length; i++) { dFullRRPTotal += (Convert.ToDecimal(lblRRPEach[i].Text) * Convert.ToDecimal(tbQty[i].Text)); if (tbTargetMargin[i].Text != "") { string[] sStockStatInfo = sEngine.GetItemStockStaRecord(tbBarcode[i].Text, InputTextBox("SHOPCODEINPUT").Text); string[] sMainStockInfo = sEngine.GetMainStockInfo(tbBarcode[i].Text); if (tbMarginOrRRP[i].Text.ToUpper() == "M") { decimal dCost = Convert.ToDecimal(sStockStatInfo[1]); decimal dTargetMarginPercent = Convert.ToDecimal(tbTargetMargin[i].Text); decimal dVATRate = 1 + (sEngine.GetVATRateFromCode(tbBarcode[0].Text) / 100); decimal dProfitReq = 0; if (dCost != 0) { dProfitReq = dTargetMarginPercent / (100 / dCost); } else { dProfitReq = Convert.ToDecimal(lblRRPEach[i].Text) / dVATRate; } decimal dFinalPrice = Math.Round((dCost + dProfitReq) * dVATRate, 2); decimal dQuantity = Convert.ToDecimal(tbQty[i].Text); lblFinalLinePrice[i].Text = FormatMoneyForDisplay(Math.Round(dFinalPrice, 2)); if (dCost == 0) { lblFinalLineMargin[i].Text = "100%"; } else { lblFinalLineMargin[i].Text = FormatMoneyForDisplay((100 / dCost) * dProfitReq) + "%"; } bPriceCalculated[i] = true; dPriceLeft -= (dFinalPrice * dQuantity); } else { decimal dCost = Convert.ToDecimal(sStockStatInfo[1]); decimal dVATRate = 1 + (sEngine.GetVATRateFromCode(tbBarcode[0].Text) / 100); decimal dRRP = Convert.ToDecimal(tbTargetMargin[i].Text); decimal dNet = dRRP / dVATRate; decimal dProfit = dNet - dCost; lblFinalLinePrice[i].Text = FormatMoneyForDisplay(dRRP); if (dCost != 0) { lblFinalLineMargin[i].Text = FormatMoneyForDisplay((100 / dCost) * dProfit) + "%"; } else { lblFinalLineMargin[i].Text = "100%"; } bPriceCalculated[i] = true; dPriceLeft -= (dRRP * Convert.ToDecimal(tbQty[i].Text)); } } } decimal dTotalRRPLeft = 0; for (int i = 0; i < tbTargetMargin.Length; i++) { if (!bPriceCalculated[i]) { dTotalRRPLeft += (Convert.ToDecimal(lblRRPEach[i].Text) * Convert.ToDecimal(tbQty[i].Text)); } } for (int i = 0; i < tbTargetMargin.Length; i++) { if (!bPriceCalculated[i]) { string[] sStockStaInfo = sEngine.GetItemStockStaRecord(tbBarcode[i].Text, InputTextBox("SHOPCODEINPUT").Text); decimal dTotalValueOfItem = Convert.ToDecimal(lblRRPEach[i].Text) * Convert.ToDecimal(tbQty[i].Text); decimal dTotalValueOfTransaction = dTotalRRPLeft; decimal dAmountThatNeedsDiscounting = dTotalRRPLeft - dPriceLeft; decimal dAmountToDiscount = (dTotalValueOfItem / dTotalValueOfTransaction) * dAmountThatNeedsDiscounting; decimal dNewPrice = (dTotalValueOfItem - dAmountToDiscount); dNewPrice /= Convert.ToDecimal(tbQty[i].Text); decimal dVATRate = 1 + (sEngine.GetVATRateFromCode(tbBarcode[0].Text) / 100); decimal dProfit = (dNewPrice / dVATRate) - Convert.ToDecimal(sStockStaInfo[1]); decimal dCost = Convert.ToDecimal(sStockStaInfo[1]); if (dCost == 0) { lblFinalLineMargin[i].Text = "100%"; } else { lblFinalLineMargin[i].Text = FormatMoneyForDisplay((100 / dCost) * dProfit) + "%"; } lblFinalLinePrice[i].Text = FormatMoneyForDisplay(dNewPrice); } } decimal dSumPrice = 0; for (int i = 0; i < lblFinalLinePrice.Length; i++) { dSumPrice += (Convert.ToDecimal(lblFinalLinePrice[i].Text) * Convert.ToDecimal(tbQty[i].Text)); } if (dSumPrice != dTargetPrice) { lblFinalLinePrice[lblFinalLinePrice.Length - 1].Text = FormatMoneyForDisplay(Convert.ToDecimal(lblFinalLinePrice[lblFinalLinePrice.Length - 1].Text) + (dTargetPrice - dSumPrice)); } dSumPrice = 0; for (int i = 0; i < lblFinalLinePrice.Length; i++) { dSumPrice += (Convert.ToDecimal(lblFinalLinePrice[i].Text) * Convert.ToDecimal(tbQty[i].Text)); } RemoveInputTextBox("ACCEPT"); AddInputControl("ACCEPT", "Total is " + FormatMoneyForDisplay(dSumPrice) + ". Do you want to accept the above and save?", new Point(10, tbBarcode[tbBarcode.Length - 1].Top + 100), 450, "Enter Y to save, N to restart, Q to Quit. F2 to edit."); InputTextBox("ACCEPT").KeyDown += new KeyEventHandler(AcceptKeyDown); InputTextBox("ACCEPT").Focus(); }