//Use schema private void button5_Click(object sender, EventArgs e) { if (comboBox1.SelectedIndex == -1) return; UserSchema sch = new UserSchema(); string[] sMas = Directory.GetFiles(AppConfig.Path_Schemes + "\\", "*.mst"); FileStream fs = null; for (int i = 0; i < sMas.Length; i++) { fs = new FileStream(sMas[i], FileMode.Open); sch = (UserSchema)binF.Deserialize(fs); fs.Close(); fs.Dispose(); if (sch.SchemaName == comboBox1.Text) { for (int j = 0; j < sch.SchemaTable.Length; j++) userProperties.SetItemChecked(j, sch.SchemaTable[j]); //SaveUser(treeView1.SelectedNode.Index); SaveUser(listBox1.SelectedIndex); } } }
private void saveToolStripButton1_Click(object sender, EventArgs e) { UserSchema sh = new UserSchema(); string oldName = string.Empty; if (toolStripComboBox1.Items.Count != 0) oldName = toolStripComboBox1.SelectedItem.ToString(); sh.SchemaName = toolStripTextBox1.Text; if (!isNewSch && oldName != sh.SchemaName) { DialogResult rez = MMessageBox.Show("Обновити схему \"" + oldName + "\" ?", "Сервіс", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (rez == DialogResult.No) { toolStripTextBox1.Focus(); toolStripTextBox1.SelectAll(); return; } File.Delete(AppConfig.Path_Schemes + "\\" + oldName + ".mst"); } FileStream fs = new FileStream(AppConfig.Path_Schemes + "\\" + sh.SchemaName + ".mst", FileMode.Create, FileAccess.Write); sh.SchemaTable = new bool[checkedListBox1.Items.Count]; for (int i = 0; i < UserSchema.ItemsCount; i++) sh.SchemaTable[i] = checkedListBox1.GetItemChecked(i); System.Runtime.Serialization.Formatters.Binary.BinaryFormatter binF = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); binF.Serialize(fs, sh); fs.Close(); if (isNewSch) { toolStripComboBox1.Items.Add(sh.SchemaName); toolStripComboBox1.SelectedItem = sh.SchemaName; comboBox1.Items.Add(sh.SchemaName); } else if (sh.SchemaName != oldName) { toolStripComboBox1.Items.RemoveAt(toolStripComboBox1.Items.IndexOf(oldName)); toolStripComboBox1.Items.Add(sh.SchemaName); comboBox1.Items.RemoveAt(comboBox1.Items.IndexOf(oldName)); comboBox1.Items.Add(sh.SchemaName); toolStripComboBox1.SelectedItem = sh.SchemaName; comboBox1.SelectedIndex = 0; } toolStripTextBox1.Text = ""; toolStripTextBox1.Enabled = false; ClearCheckedBox(ref checkedListBox1); AutoEnableToolBar(); isNewSch = false; }
/// <summary> /// Перевірка параметрів користувача з існуючими схемами /// </summary> /// <param name="schema">Список існуючих схем</param> /// <returns>Назва схеми, яка співападає з параметрами користувачів</returns> private string RecognizeSchema(bool[] schema) { UserSchema sch = new UserSchema(); int j = 0; string[] sMas = Directory.GetFiles(AppConfig.Path_Schemes + "\\", "*.mst"); bool match = true; FileStream fs = null; for (int i = 0; i < sMas.Length; i++) { fs = new FileStream(sMas[i], FileMode.Open); try { sch = (UserSchema)binF.Deserialize(fs); } catch { } fs.Close(); fs.Dispose(); for (j = 0; j < UserSchema.ItemsCount - 1; j++) if (schema[j] != sch.SchemaTable[j]) { match = false; break; } if (match) return sch.SchemaName; else match = true; } return ""; }
//Methods for administration of schemas private void LoadSchemesList() { if (!Directory.Exists(AppConfig.Path_Schemes)) Directory.CreateDirectory(AppConfig.Path_Schemes); UserSchema sch = new UserSchema(); checkedListBox1.Items.AddRange(sch.SchemaItems); userProperties.Items.AddRange(sch.SchemaItems); string[] sMas = Directory.GetFiles(AppConfig.Path_Schemes + "\\", "*.mst"); for (int i = 0; i < sMas.Length; i++) { try { System.Runtime.Serialization.Formatters.Binary.BinaryFormatter binF = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); sch = (UserSchema)binF.Deserialize(new FileStream(sMas[i], FileMode.Open)); toolStripComboBox1.Items.Add(sch.SchemaName); comboBox1.Items.Add(sch.SchemaName); } catch { } } if (toolStripComboBox1.Items.Count != 0) { toolStripComboBox1.SelectedIndex = 0; comboBox1.SelectedIndex = 0; } AutoEnableToolBar(); }
private void editToolStripButton5_Click(object sender, EventArgs e) { ToolBarItemsEnable(false); saveToolStripButton1.Enabled = true; cancelToolStripButton1.Enabled = true; toolStripTextBox1.Enabled = true; UserSchema sch = new UserSchema(); string[] sMas = Directory.GetFiles(AppConfig.Path_Schemes + "\\", "*.mst"); FileStream fs = null; for (int i = 0; i < sMas.Length; i++) { fs = new FileStream(sMas[i], FileMode.Open); System.Runtime.Serialization.Formatters.Binary.BinaryFormatter binF = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); sch = (UserSchema)binF.Deserialize(fs); if (sch.SchemaName == toolStripComboBox1.SelectedItem.ToString()) { for (int j = 0; j < UserSchema.ItemsCount; j++) checkedListBox1.SetItemChecked(j, sch.SchemaTable[j]); fs.Close(); break; } fs.Close(); } toolStripTextBox1.Text = sch.SchemaName; checkedListBox1.Enabled = true; }
/// <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); } }