Exemple #1
0
        private bool introducedPunctuation;         //Флажок показывающий - введена ли запятая или точка в поле с ценой

        public MainForm()
        {
            InitializeComponent();
            PortConfigForm           = null;
            ChangePasswordDUForm     = null;
            CurrentComPortObject     = null;
            AboutProgrammForm        = null;
            PassToGlobalSettingsForm = null;
            GlobalSettingForm        = null;
            NameOfCurrentComPort     = Properties.Settings.Default.PortName;         //По умолчанию при запуске будем подключаться к этому порту;
            BaudRate = Properties.Settings.Default.BaudRates;
            introducedPunctuation = false;
            //Keys[] keypressed = { 8, 13, 44, 46, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 127 };
            //ValidKeyMainForm = new List<Keys>(keypressed);
        }
Exemple #2
0
        //Обработчик нажатия пункта меню "О программе"
        private void AboutProgramm_Click(object sender, EventArgs e)
        {
            #region Открытие вспомогательных окон до начала настройки
            if (AboutProgrammForm == null)
            {
                AboutProgrammForm = new FAboutProgramm(this);
                AboutProgrammForm.ShowDialog();
            }
            else
            {
                AboutProgrammForm.ShowDialog();
            }

            if (AboutProgrammForm.DialogResult == DialogResult.OK)
            {
                if (PassToGlobalSettingsForm == null)
                {
                    PassToGlobalSettingsForm = new FPassToGlobalSettings(this);
                    PassToGlobalSettingsForm.ShowDialog();
                }
                else
                {
                    PassToGlobalSettingsForm.ShowDialog();
                }
            }
            else
            {
                return;
            }

            if (PassToGlobalSettingsForm.DialogResult == DialogResult.OK)
            {
                if (GlobalSettingForm == null)
                {
                    GlobalSettingForm = new FGlobalSetting(CurrentComPortObject);
                    //CurrentComPortObject.Close(NameOfCurrentComPort);
                    GlobalSettingForm.ShowDialog();
                }
                else
                {
                    CurrentComPortObject.Close(NameOfCurrentComPort);
                    GlobalSettingForm.ShowDialog();
                }
            }
            else
            {
                return;
            }
            #endregion

            if (GlobalSettingForm.DialogResult == DialogResult.OK)
            {
                panelForPriceDisplay.Controls.Clear();

                int rowCount = GlobalSettingForm.CustomVisibleInfoTable.Rows.Count;
                if (rowCount > 0)
                {
                    #region Подготовка XML документа и очистка секций UserTableViewSection, Aliases
                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.Load("settings.xml");

                    XmlNodeList nodelist = xmlDoc.SelectNodes("allsettings/UserTableViewSection");
                    if (nodelist.Count > 0)
                    {
                        foreach (XmlNode item in nodelist)
                        {
                            xmlDoc.DocumentElement.RemoveChild(item);
                        }
                        xmlDoc.Save("settings.xml");
                    }

                    nodelist = xmlDoc.SelectNodes("allsettings/Aliases");
                    if (nodelist.Count > 0)
                    {
                        foreach (XmlNode item in nodelist)
                        {
                            xmlDoc.DocumentElement.RemoveChild(item);
                        }
                        xmlDoc.Save("settings.xml");
                    }
                    XmlElement UserTableViewSection = xmlDoc.CreateElement("UserTableViewSection");
                    XmlElement AliasSection         = xmlDoc.CreateElement("Aliases");
                    xmlDoc.DocumentElement.AppendChild(UserTableViewSection);
                    xmlDoc.DocumentElement.AppendChild(AliasSection);
                    xmlDoc.Save("settings.xml");
                    #endregion


                    int j = 0;
                    for (int i = 0; i < rowCount; i++)
                    {
                        #region Формирование лейблов и эдитов по данным таблицы
                        if ((bool)GlobalSettingForm.CustomVisibleInfoTable[1, i].Value)
                        {
                            string labeltext = null;
                            if (GlobalSettingForm.CustomVisibleInfoTable[2, i].Value.ToString() == "")
                            {
                                labeltext = GlobalSettingForm.CustomVisibleInfoTable[5, i].Value.ToString();
                            }
                            else
                            {
                                labeltext = GlobalSettingForm.CustomVisibleInfoTable[2, i].Value.ToString();
                            }
                            string  fueltext    = GlobalSettingForm.CustomVisibleInfoTable[4, i].Value.ToString();
                            Label   NameOfFuel  = new Label();
                            TextBox PriceOfFuel = new TextBox();
                            panelForPriceDisplay.Controls.Add(NameOfFuel);
                            panelForPriceDisplay.Controls.Add(PriceOfFuel);
                            NameOfFuel.Text          = labeltext;
                            NameOfFuel.Enabled       = true;
                            NameOfFuel.Width         = 130;
                            NameOfFuel.Font          = new Font(new FontFamily("Arial"), 10);
                            PriceOfFuel.Text         = fueltext;
                            PriceOfFuel.Enabled      = true;
                            PriceOfFuel.Width        = 100;
                            PriceOfFuel.MaxLength    = 5;
                            PriceOfFuel.Tag          = GlobalSettingForm.CustomVisibleInfoTable[5, i].Value.ToString();
                            PriceOfFuel.Font         = new Font(new FontFamily("Arial"), 10);
                            NameOfFuel.Location      = new Point(20, j * PriceOfFuel.Height + 40);
                            PriceOfFuel.Location     = new Point(170, j * PriceOfFuel.Height + 40);
                            PriceOfFuel.Enter       += PriceOfFuel_Enter;
                            PriceOfFuel.KeyPress    += new KeyPressEventHandler(EditPrice_KeyPress);
                            PriceOfFuel.TextChanged += new EventHandler(EditPrice_TextChanged);
                            PriceOfFuel.MouseEnter  += PriceOfFuel_MouseEnter;
                            j = j + 1;
                        }
                        else
                        {
                            continue;
                        }
                        #endregion

                        #region Занесение данных из таблицы CustomVisibleInfoTable в XML файл
                        XmlElement CurrentUserTableViewRow = xmlDoc.CreateElement("Row");
                        CurrentUserTableViewRow.SetAttribute("number", (i + 1).ToString());                                    // Порядковый номер строки
                        CurrentUserTableViewRow.SetAttribute("visible",
                                                             GlobalSettingForm.CustomVisibleInfoTable[1, i].Value.ToString()); // Значение из 2 ячейки строки
                        CurrentUserTableViewRow.SetAttribute("label",
                                                             GlobalSettingForm.CustomVisibleInfoTable[2, i].Value.ToString()); // Значение из 3 ячейки строки
                        CurrentUserTableViewRow.SetAttribute("device",
                                                             GlobalSettingForm.CustomVisibleInfoTable[3, i].Value.ToString()); // Значение из 4 ячейки строки
                        CurrentUserTableViewRow.SetAttribute("value",
                                                             GlobalSettingForm.CustomVisibleInfoTable[4, i].Value.ToString()); // Значение из 5 ячейки строки
                        CurrentUserTableViewRow.SetAttribute("adress",
                                                             GlobalSettingForm.CustomVisibleInfoTable[5, i].Value.ToString()); // Значение из 6 ячейки строки
                        UserTableViewSection.AppendChild(CurrentUserTableViewRow);
                        #endregion

                        #region Формирование дополнительной секции Aliases
                        string     userNameElement   = GlobalSettingForm.CustomVisibleInfoTable[2, i].Value.ToString();
                        string     adressNameElement = GlobalSettingForm.CustomVisibleInfoTable[5, i].Value.ToString();
                        XmlElement AliasElement      = null;
                        if (userNameElement == "")
                        {
                            AliasElement = xmlDoc.CreateElement(adressNameElement);
                        }
                        else
                        {
                            AliasElement = xmlDoc.CreateElement(userNameElement);
                        }
                        AliasElement.InnerText = adressNameElement;
                        AliasSection.AppendChild(AliasElement);
                        #endregion
                    }
                    xmlDoc.Save("settings.xml");
                }

                Properties.Settings.Default.DigitCapacity = Convert.ToInt32(GlobalSettingForm.DigitCapacity);
                Properties.Settings.Default.PortName      = GlobalSettingForm.portName;
                Properties.Settings.Default.BaudRates     = GlobalSettingForm.baudRate;
                Properties.Settings.Default.Save();
                NameOfCurrentComPort = GlobalSettingForm.portName;
                BaudRate             = GlobalSettingForm.baudRate;
                CurrentComPortObject.Open(NameOfCurrentComPort, BaudRate);
                MessageBox.Show("Текущий порт " + NameOfCurrentComPort + "\n"
                                + "Текущая скорость " + BaudRate, "Изменение настроек порта");
            }
            else             // if (GlobalSettingForm.DialogResult == DialogResult.OK)
            {
                //Если ты просто закрыл окно настроек;
                CurrentComPortObject.Open(NameOfCurrentComPort, BaudRate);
            }
        }