/// <summary> /// Перевизначений метод обробки повідомлень. /// </summary> /// <param name="m">Повідомлення</param> protected override void WndProc(ref Message m) { base.WndProc(ref m); //winapi.WinAPI.OutputDebugString(m.ToString()); if (m.Msg == (int)AppFunc.MyMsgs.WM_HOTKEY) { //winapi.Funcs.OutputDebugString("Q"); #region hot key control switch (m.WParam.ToInt32()) { case 0x10: #region CONTROL + DELETE { if (Cheque.Rows.Count == 0) return; if (!(ADMIN_STATE || UserStruct.Properties[24])) if (admin.ShowDialog() != DialogResult.OK) return; try { int index = chequeDGV.CurrentRow.Index; Cheque.Rows.RemoveAt(index); //AppFunc.OutputDebugString("k"); RowsRemoved_MyEvent(true); index--; if (index < 0) if (Cheque.Rows.Count != 0) index = 0; else return; chequeDGV.CurrentCell = chequeDGV.Rows[index].Cells[chequeDGV.Columns.GetFirstColumn(DataGridViewElementStates.Visible).Name]; chequeDGV.Rows[index].Selected = true; } catch { } break; } #endregion case 0x11: #region CONTROL + SHIFT + DELETE { if (Cheque.Rows.Count == 0) return; if (!(ADMIN_STATE || UserStruct.Properties[24])) if (admin.ShowDialog() != DialogResult.OK) return; Cheque.Rows.Clear(); RowsRemoved_MyEvent(true); break; } #endregion case 0x12: #region CONTROL + PageDown { if (inventChq) return; if (!(ADMIN_STATE || UserStruct.Properties[3])) if (admin.ShowDialog() != DialogResult.OK) return; double discSUMA = 0.0; try { discSUMA = (double)Cheque.Compute("Sum(SUM)", "USEDDISC = " + Boolean.TrueString); } catch { } DiscountRequest d = new DiscountRequest(discSUMA, true); d.SetDiscount(ref discArrPercent, ref discArrCash); d.Dispose(); if (discArrPercent[0] == 0.0 && discArrPercent[1] == 0.0 && discArrCash[0] == 0.0 && discArrCash[1] == 0.0) ResetDiscount(); else { відмінитиЗнижкунадбавкуToolStripMenuItem.Enabled = true; if (AppConfig.APP_OnlyDiscount) відмінитиЗнижкунадбавкуToolStripMenuItem.Text = "Скасувати знижку"; else { if ((discArrPercent[0] != 0.0 && discArrPercent[1] != 0.0) || (discArrCash[0] != 0.0 && discArrCash[1] != 0.0)) відмінитиЗнижкунадбавкуToolStripMenuItem.Text = "Скасувати знижку і націнку"; if ((discArrPercent[0] == 0.0 && discArrPercent[1] != 0.0) || (discArrCash[0] == 0.0 && discArrCash[1] != 0.0)) відмінитиЗнижкунадбавкуToolStripMenuItem.Text = "Скасувати націнку"; if ((discArrPercent[0] != 0.0 && discArrPercent[1] == 0.0) || (discArrCash[0] != 0.0 && discArrCash[1] == 0.0)) відмінитиЗнижкунадбавкуToolStripMenuItem.Text = "Скасувати знижку"; } } UpdateSumInfo(true); break; } #endregion case 0x13: #region CONTROL + PageUp { if (inventChq) return; if (!(ADMIN_STATE || UserStruct.Properties[3])) if (admin.ShowDialog() != DialogResult.OK) return; double discSUMA = 0; try { discSUMA = (double)Cheque.Compute("Sum(SUM)", "USEDDISC = " + Boolean.TrueString); } catch { } DiscountRequest d = new DiscountRequest(discSUMA, false); d.SetDiscount(ref discArrPercent, ref discArrCash); d.Dispose(); if (discArrPercent[0] == 0.0 && discArrPercent[1] == 0.0 && discArrCash[0] == 0.0 && discArrCash[1] == 0.0) ResetDiscount(); else { відмінитиЗнижкунадбавкуToolStripMenuItem.Enabled = true; if (AppConfig.APP_OnlyDiscount) відмінитиЗнижкунадбавкуToolStripMenuItem.Text = "Скасувати націнку"; else { if ((discArrPercent[0] != 0.0 && discArrPercent[1] != 0.0) || (discArrCash[0] != 0.0 && discArrCash[1] != 0.0)) відмінитиЗнижкунадбавкуToolStripMenuItem.Text = "Скасувати знижку і націнку"; if ((discArrPercent[0] == 0.0 && discArrPercent[1] != 0.0) || (discArrCash[0] == 0.0 && discArrCash[1] != 0.0)) відмінитиЗнижкунадбавкуToolStripMenuItem.Text = "Скасувати націнку"; if ((discArrPercent[0] != 0.0 && discArrPercent[1] == 0.0) || (discArrCash[0] != 0.0 && discArrCash[1] == 0.0)) відмінитиЗнижкунадбавкуToolStripMenuItem.Text = "Скасувати знижку"; } } UpdateSumInfo(true); break; } #endregion case 0x14: #region SHIFT + DELETE { if (inventChq) return; ResetDiscount(); UpdateSumInfo(true); break; } #endregion case 0x15: #region ENTER { //for (int i = 0x10; i < 0x20; i++) //AppFunc.UnregisterHotKey(this, i); bool editWasClosed = false; //winapi.WinAPI.OutputDebugString("Enter"); if (!UserStruct.Properties[22]) if (lastInputChar.AddMilliseconds(130) > DateTime.Now && chararray != null && chararray.Length != 0) { //if (chequeDGV.CurrentCell != null && chequeDGV.CurrentCell.IsInEditMode) //{ // if (chequeDGV.CurrentCell.EditedFormattedValue.ToString().Contains(chararray)) // { // string val = chequeDGV.CurrentCell.EditedFormattedValue.ToString(); // int bcidx = val.IndexOf(chararray); // val = val.Substring(0, bcidx); // if (val == string.Empty) // val = "0"; // chequeDGV.CurrentCell.Value = Convert.ToDouble(val); // } // chequeDGV.EndEdit(); // editWasClosed = true; //} //winapi.WinAPI.OutputDebugString("srch: " + chararray); SearchFilter(false, 2, true); SrchTbox.Text = chararray; SrchTbox.Select(); chararray = string.Empty; } //close edit if (chequeDGV.CurrentCell != null && chequeDGV.CurrentCell.IsInEditMode) { chequeDGV.EndEdit(); editWasClosed = true; } //lastInputChar = DateTime.Now; //launch article property if (chequeDGV.Focused && chequeDGV.RowCount != 0) { if (!(ADMIN_STATE || UserStruct.Properties[24])) if (admin.ShowDialog() != DialogResult.OK) return; DataRow dRow = Cheque.Rows.Find(chequeDGV.CurrentRow.Cells["C"].Value); Request req = new Request(dRow, AppFunc.GetDouble(dRow["TOT"])); req.UpdateRowSource(); req.Dispose(); UpdateSumInfo(true); return; } //Adding article to Cheque if (articleDGV.Focused && articleDGV.RowCount != 0) { DataRow article = Articles.Rows.Find(articleDGV.CurrentRow.Cells["C"].Value); if (article != null) AppFunc.AddArticleToCheque(chequeDGV, articleDGV, article, AppConfig.APP_StartTotal, Articles); return; } //winapi.WinAPI.OutputDebugString("srch: " + SrchTbox.Text); //Searching if (!editWasClosed && SrchTbox.Focused && SrchTbox.Text != string.Empty) { DataTable sTable = Articles.Clone(); bool allowToShow = false; int i = 0; //Debug.Write("BeginAdd"); #region search box if (SrchTbox.Text != "") { switch (currSrchType) { case 0: { #region by name string[] words = SrchTbox.Text.Trim().Split(' '); DataRow[] dr1 = new DataRow[0]; DataRow[] dr2 = new DataRow[0]; DataTable dTable = (DataTable)articleDGV.DataSource; //string srchString = string.Empty; SrchTbox.Text = string.Empty; for (int l = 0; l < words.Length; l++) { try { dr1 = dTable.Select("NAME Like '%" + words[l] + "%'"); dr2 = dTable.Select("DESC Like '%" + words[l] + "%'"); } catch { } sTable.Clear(); sTable.BeginLoadData(); if (dr1.Length > dr2.Length) { for (i = 0; i < dr1.Length; i++) sTable.Rows.Add(dr1[i].ItemArray); } else { for (i = 0; i < dr2.Length; i++) sTable.Rows.Add(dr2[i].ItemArray); } sTable.EndLoadData(); dTable = sTable.Copy(); if (dTable.Rows.Count > 0) { articleDGV.DataSource = dTable; articleDGV.Select(); allowToShow = true; SrchTbox.Text += words[l] + " "; //SrchTbox.Select(0, srchString.Length); } } if (SrchTbox.Text == string.Empty) //if (SrchTbox.SelectedText == string.Empty) { MMessageBox.Show(this, "Нажаль нічого не вдалось знайти", "Результат пошуку", MessageBoxButtons.OK, MessageBoxIcon.Information); SearchFilter(false, AppConfig.APP_SearchType, true); } #endregion break; } case 1: { #region by id try { DataRow[] dr = Articles.Select("ID Like \'" + SrchTbox.Text + "%\'"); if (dr.Length == 0) { MMessageBox.Show(this, "Нажаль нічого не вдалось знайти", "Результат пошуку", MessageBoxButtons.OK, MessageBoxIcon.Information); SearchFilter(false, AppConfig.APP_SearchType, true); break; } if (dr.Length == 1) { SearchFilter(false, currSrchType, true); AppFunc.AddArticleToCheque(chequeDGV, articleDGV, dr[0], AppConfig.APP_StartTotal, Articles); allowToShow = false; break; } else { sTable.Clear(); sTable.BeginLoadData(); for (i = 0; i < dr.Length; i++) sTable.Rows.Add(dr[i].ItemArray); sTable.EndLoadData(); articleDGV.DataSource = sTable; articleDGV.Select(); allowToShow = true; } } catch { SrchTbox.Focus(); SrchTbox.SelectAll(); } #endregion break; } case 2: { #region by bc try { allowToShow = BCSearcher(SrchTbox.Text, true); } catch (FormatException) { SrchTbox.Focus(); SrchTbox.SelectAll(); } #endregion break; } } } #endregion if (splitContainer1.Panel2Collapsed && allowToShow) { вікноТоварівToolStripMenuItem.PerformClick(); splitContainer1.Panel2.Tag = new object(); articleDGV.Select(); } articleDGV.Update(); //Debug.Write("EndAdd"); } break; } #endregion case 0x16: #region CONTROL + ENTER { if (inventChq || Cheque.Rows.Count == 0) return; if (!(ADMIN_STATE || UserStruct.Properties[23])) if (admin.ShowDialog() != DialogResult.OK) return; CloseCheque(Program.Service.UseEKKR); break; } #endregion case 0x17: #region CONTROL + SHIFT + ENTER { if (inventChq) return; if (Cheque.Rows.Count == 0 && UserStruct.Properties[12]) { string nextChqNom = ""; object[] localData = AppFunc.NonFxChqsInfo(0, ref nextChqNom); DDM_Status.Text = string.Format("За {1} продано {0} чек(ів) на суму {2:F" + AppConfig.APP_MoneyDecimals + "}", localData[0], localData[1], double.Parse(localData[2].ToString())); return; } if (Cheque.Rows.Count == 0/* || !Program.Service.UseEKKR*/) return; if (AppConfig.APP_IllegalMsgPrompt && DialogResult.Yes != MMessageBox.Show(this, "Закрити чек без фіксації оплати", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)) return; if (!(ADMIN_STATE || (UserStruct.Properties[23] && UserStruct.Properties[6]))) if (admin.ShowDialog() != DialogResult.OK) return; CloseCheque(false); break; } #endregion case 0x18: #region F5 { if (!AppConfig.APP_SrchTypesAccess[0]) { MMessageBox.Show(this, "Пошук по назві не дозволений", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (currSrchType != 0) SearchFilter(false, 0, true); else { SrchTbox.Focus(); SrchTbox.Select(SrchTbox.Text.Length, 0); } break; } #endregion case 0x19: #region F6 { if (!AppConfig.APP_SrchTypesAccess[1]) { MMessageBox.Show(this, "Пошук по коду не дозволений", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (currSrchType != 1) SearchFilter(false, 1, true); else { SrchTbox.Focus(); SrchTbox.Select(SrchTbox.Text.Length, 0); } break; } #endregion case 0x1A: #region F7 { //winapi.WinAPI.OutputDebugString("F7"); if (!AppConfig.APP_SrchTypesAccess[2]) { MMessageBox.Show(this, "Пошук по штрих-коду не дозволений", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (currSrchType != 2) SearchFilter(false, 2, true); else { SrchTbox.Focus(); SrchTbox.Select(0, SrchTbox.Text.Length); } break; } #endregion case 0x1B: #region F8 { if (Cheque.ExtendedProperties.Contains("BILL")) MMessageBox.Show(this, "Відкритий рахунок №" + " " + Cheque.ExtendedProperties["NOM"], Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); break; } #endregion case 0x1C: #region F9 { string infoText = string.Empty; UserSchema us = new UserSchema(); infoText += UserStruct.UserID; infoText += "\r\n\r\n--------------------------------------------------\r\n\r\n"; for (int i = 0; i < UserSchema.ItemsCount; i++) infoText += us.SchemaItems[i] + " : " + (UserStruct.Properties[i] ? "Так" : "Ні") + "\r\n"; MMessageBox.Show(infoText, UserStruct.UserID); break; } #endregion case 0x1D: #region ESCAPE { SearchFilter(false, AppConfig.APP_SearchType, true); break; } #endregion case 0x1E: #region CONTROL + Q { if (inventChq) return; nakladna = !nakladna; if (nakladna) CashLbl.Image = Properties.Resources.naklad; else CashLbl.Image = null; break; } #endregion case 0x1F: #region CONTROL { if (chequeDGV.CurrentCell != null && chequeDGV.CurrentCell.IsInEditMode) chequeDGV.EndEdit(); break; } #endregion } #endregion //winapi.Funcs.OutputDebugString("W"); } if (m.Msg == (int)AppFunc.MyMsgs.WM_UPDATE) { if (_fl_canUpdate) this.timer1_Tick(this.timer1, EventArgs.Empty); } }
/// <summary> /// Додавання товарк в чек або зміна кількості товару в чеку /// </summary> /// <param name="chqDGW">Таблиця чеку</param> /// <param name="artDGW">Таблиця товарів (можливе застосування фільтру до записів)</param> /// <param name="article">Запис з товаром</param> /// <param name="startTotal">Стартова кількість</param> /// <param name="artsTable">Оригінальна таблиця товарів (без затстосування фільтру до записів)</param> public static void AddArticleToCheque(DataGridView chqDGW, DataGridView artDGW, DataRow article, double startTotal, DataTable artsTable) { //winapi.Funcs.OutputDebugString("A"); if (AppConfig.TAX_AppTaxChar == null || AppConfig.TAX_AppTaxChar.Length == 0) { MMessageBox.Show("Немає податкових ставок", "InTech PayDesk", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if ((double)article["PRICE"] == 0) { MMessageBox.Show("Нульова ціна товару", "InTech PayDesk", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } /* * 1) If article exist * a) CTOT=TOT * b) TOT=startValue */ //winapi.Funcs.OutputDebugString("G"); int index = 0; bool rowIsUpdated = false; DataRow dRow = null; bool funcRezult = false; DataTable cheque = chqDGW.DataSource as DataTable; if (UserStruct.Properties[9] && startTotal == AppConfig.APP_StartTotal) startTotal = CheckByMask(article["UNIT"], startTotal); //Update existed rows //winapi.Funcs.OutputDebugString("H"); if (UserStruct.Properties[7] && cheque.Rows.Count != 0) { DataRow[] dRows = cheque.Select("ID='" + article["ID"] + "'"); if (dRows.Length != 0 && dRows[0] != null) try { dRow = dRows[0]; dRow["TMPTOT"] = dRow["TOT"]; if (UserStruct.Properties[17] || startTotal == 0.0) { Request req = new Request(dRow, startTotal); funcRezult = req.UpdateRowSource(); req.Dispose(); //winapi.Funcs.OutputDebugString("U"); if (!funcRezult) return; } else {/* int pack = 0; int.TryParse(dRow["PACK"].ToString(), out pack); if (pack == 0) pack = 1; if (AppConfig.APP_AddTotal == "type1") startTotal = GetRoundedDose(startTotal / pack); if (AppConfig.APP_AddTotal == "type2") startTotal = GetRoundedDose(startTotal * pack);*/ dRow["TOT"] = startTotal; } index = cheque.Rows.IndexOf(dRow); rowIsUpdated = true; } catch (Exception ex) { WriteLog(ex, MethodInfo.GetCurrentMethod().Name); } } //Add new row if (!rowIsUpdated) { //winapi.Funcs.OutputDebugString("J"); dRow = cheque.NewRow(); dRow["ORIGPRICE"] = article["PRICE"]; //C string c = dRow["C"].ToString(); dRow.ItemArray = article.ItemArray; dRow["C"] = long.Parse(c); //TAX try { index = Array.IndexOf<char>(AppConfig.TAX_MarketColumn, dRow["VG"].ToString()[0]); } catch { index = 0; } if (index < 0) index = 0; char pch = AppConfig.TAX_AppColumn[index]; index = Array.IndexOf<char>(AppConfig.TAX_AppTaxChar, pch); if (index >= 0) { dRow["VG"] = pch; dRow["TAX_VAL"] = AppConfig.TAX_AppTaxRates[index]; dRow["USEDDISC"] = AppConfig.TAX_AppTaxDisc[index]; } if (UserStruct.Properties[17] || startTotal == 0.0) { Request req = new Request(dRow, startTotal); funcRezult = req.UpdateRowSource(); req.Dispose(); if (!funcRezult) return; } else {/* int pack = 1; int.TryParse(dRow["PACK"].ToString(), out pack); if (pack == 0) pack = 1; if (AppConfig.APP_AddTotal == "type1") startTotal = GetRoundedDose(startTotal / pack); if (AppConfig.APP_AddTotal == "type2") startTotal = GetRoundedDose(startTotal * pack);*/ dRow["TOT"] = startTotal; } #region Sorting article by ID and adding if (UserStruct.Properties[14] && cheque.Rows.Count != 0) { index = 0; do { if (GetIDCode(cheque.Rows[index]["ID"]) < GetIDCode(dRow["ID"])) index++; else break; } while (cheque.Rows.Count > index); cheque.Rows.InsertAt(dRow, index); } else { cheque.Rows.Add(dRow); index = cheque.Rows.Count - 1; } #endregion } //winapi.Funcs.OutputDebugString("K"); if (rowIsUpdated) index = dRow.Table.Rows.IndexOf(dRow); chqDGW.CurrentCell = chqDGW.Rows[index].Cells["TOT"]; try { object uniqueKey = article["C"]; article = (artDGW.DataSource as DataTable).Rows.Find(uniqueKey); if (article != null) index = (artDGW.DataSource as DataTable).Rows.IndexOf(article); else { artDGW.DataSource = artsTable; article = artsTable.Rows.Find(uniqueKey); index = artsTable.Rows.IndexOf(article); } artDGW.CurrentCell = artDGW.Rows[index].Cells[artDGW.Columns.GetFirstColumn(DataGridViewElementStates.Visible).Name]; } catch { } chqDGW.BeginEdit(true); if (!UserStruct.Properties[22]) chqDGW.EndEdit(); //winapi.Funcs.OutputDebugString("E"); }