Exemple #1
0
 /// <summary>СОБЫТИЕ Переходим на верхний вопрос (или на последний, если был первый)</summary>
 private void PART_ButtonUp_Click(object sender, RoutedEventArgs e)
 {
     PRI_Shablon = PRI_Document.PROP_Shablon.Find(x => PRI_Document.PROP_Shablon.Min(i => i.PROP_Nomer) == PRI_Shablon.PROP_Nomer
         ? x.PROP_Nomer == PRI_Document.PROP_Shablon.Max(i => i.PROP_Nomer)
             : x.PROP_Nomer == PRI_Shablon.PROP_Nomer - 1);
     MET_SelectedShablon();
     PART_RadListBox.SelectedValue = PRI_Shablon;
 }
Exemple #2
0
        /// <summary>КОНСТРУКТОР</summary>
        /// <param name="pPole">Поле с которым работаем</param>
        public UserWindow_Lua(VirtualPole pPole)
        {
            InitializeComponent();

            PART_Log.PART_TextBox.MaxHeight = 80;
            PART_Log.VerticalAlignment      = VerticalAlignment.Stretch;
            // Родительское окно
            if (Owner == null)
            {
                Owner = Application.Current.MainWindow;
            }
            // Настраиваем положение окна
            Left = 0;
            if (Owner != null)
            {
                Top        = 15;
                Height     = Owner.Height + Owner.Top - 15;
                Owner.Left = Width - 15;
#if DEBUG
                //   Left = Owner.Left + Owner.Width + 500;
#endif
            }

            // Находим вопрос шаблона
            PRI_Pole         = pPole;
            PRI_Document     = pPole.PROP_Docum;
            PRI_Shablon      = PRI_Document.PROP_Shablon.Find(x => x.PROP_VarId == pPole.PROP_VarId);
            this.DataContext = PRI_Shablon;

            // Настраиваем Lua поле
            PRI_Regular  = @"(lPole|Pole|lMessage|lKbolInfoAdd|lKbolInfoDel|lPolePDate|";
            PRI_Regular += "lOperInfo|lOperInfoDel|lRead|lNew|lDateIf|lTimeGosp|lSqlToStr|";
            PRI_Regular += "lKbolInfoOms|lLog|lVisiblOn|lVisiblOff|lNecesOn|lNecesOf|";
            PRI_Regular += "lTextClear|";
            PRI_Regular += "gKorpus|gKL|gFIO|gDR|gUser|gUserName|gPol|gLpu|gOtd|gCodApstac|";
            PRI_Regular += "OnCreat|OnChange|OnBeforeSave|OnSave|";
            PRI_Regular += "PROP_Text|OnChange|OnBeforeSave|OnSave)";

            PART_FCTextBox                  = new FastColoredTextBox();
            PART_FCTextBox.Language         = FastColoredTextBoxNS.Language.Lua;
            PART_FCTextBox.TextChanged     += Ts_TextChanged;
            PART_FCTextBox.WordWrap         = true;
            PART_WindowsFormsHostFCTB.Child = PART_FCTextBox;

            // Заполняем список вопросов шаблона боковой панели
            PART_RadListBox.ItemsSource   = PRI_Document.PROP_Shablon;
            PART_RadListBox.SelectedValue = PRI_Shablon;

            // Делегаты для функции lLog
            MyGlo.Event_sLuaLog = MET_LogAdd;
        }
Exemple #3
0
 /// <summary>СОБЫТИЕ  Выбор нового вопроса из боковой панели</summary>
 private void PART_RadListBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
 {
     PRI_Shablon = (UserShablon)PART_RadListBox.SelectedValue;
     MET_SelectedShablon();
 }
        /// <summary>СОБЫТИЕ Нажали на кнопку "Загрузка шаблона из Excel"</summary>
        protected virtual void PRI_ButtonFromExcel_1_Click(object sender, RoutedEventArgs e)
        {
            DataRowView _DataRowView = (DataRowView)PART_DataGrid.SelectedItem;
            int         _CodShablon  = Convert.ToInt16(_DataRowView.Row["Cod"]);
            string      _TipDoc      = PRI_ComboBox_1.SelectedValue.ToString();
            eTipDocum   _eTip        = eTipDocum.Null;

            switch (_TipDoc)
            {
            case "apaN":
                _eTip = eTipDocum.Pol;
                break;

            case "ast":
                _eTip = eTipDocum.Stac;
                break;

            case "par":
                _eTip = eTipDocum.Paracl;
                break;

            case "kdl":
                _eTip = eTipDocum.Kdl;
                break;
            }
            var    _TipProtokol = new MyTipProtokol(_eTip);
            string _NameFile    = $"{_TipDoc}_{_CodShablon}";
            string _PathFile    = $@"C:\Shablons\{_NameFile}.xlsx";

            Excel.Workbook    _WorkBook;
            Excel.Application _ExcelApp;
            _ExcelApp = new Excel.Application();
            FileInfo _FileInfo = new FileInfo(_PathFile);

            // Если нашли файл с текущим шаблоном
            if (!_FileInfo.Exists)
            {
                MessageBox.Show($"Не найден файл: {_PathFile}", "Алё, чо грузить то?!");
                return;
            }
            _WorkBook = _ExcelApp.Workbooks.Open(_PathFile);
            Excel.Worksheet _Sheet = (Excel.Worksheet)_WorkBook.Worksheets.Item[1];

            // Заполняем данные
            List <UserShablon> _ListShablons = new List <UserShablon>();
            int _y = 2;
            int _x = 1;

            try
            {
                while (_Sheet.Cells[_y, 1].Value2 is double)
                {
                    _x = 1;
                    UserShablon _Shablon = new UserShablon();
                    _Shablon.PROP_Cod         = (int)_Sheet.Cells[_y, _x++].Value2;
                    _Shablon.PROP_ID          = (int)_Sheet.Cells[_y, _x++].Value2;
                    _Shablon.PROP_Nomer       = (byte)_Sheet.Cells[_y, _x++].Value2;
                    _Shablon.PROP_VarId       = (int)_Sheet.Cells[_y, _x++].Value2;
                    _Shablon.PROP_Maska       = _Sheet.Cells[_y, _x++].Text ?? "";
                    _Shablon.PROP_Type        = (byte)_Sheet.Cells[_y, _x++].Value2;
                    _Shablon.PROP_Razdel      = _Sheet.Cells[_y, _x++].Value2 ?? "";
                    _Shablon.PROP_Name        = _Sheet.Cells[_y, _x++].Value2 ?? "";
                    _Shablon.PROP_ValueStart  = _Sheet.Cells[_y, _x++].Value2 ?? "";
                    _Shablon.PROP_OutText     = _Sheet.Cells[_y, _x++].Value2 ?? "";
                    _Shablon.PROP_InText      = _Sheet.Cells[_y, _x++].Value2 ?? "";
                    _Shablon.PROP_xFormat     = _Sheet.Cells[_y, _x++].Value2 ?? "";
                    _Shablon.PROP_xLua        = _Sheet.Cells[_y, _x++].Value2 ?? "";
                    _Shablon.PROP_xInfo       = _Sheet.Cells[_y, _x].Value2 ?? "";
                    _Shablon.PROP_TipProtokol = _TipProtokol;
                    _Shablon.PROP_FlagEdit    = false;
                    _y++;
                    _ListShablons.Add(_Shablon);
                }
            }
            catch (Exception)
            {
                _WorkBook.Close();
                _ExcelApp.Quit();
                MessageBox.Show($"Ошибка загрузки в строке: {_y}, в столбце: {--_x}", "Ошибка");
                return;
            }
            UserShablon.MET_FactoryListShablon(_eTip, _CodShablon);
            int _Remov = ((VirtualModul)MyGlo.Modul).PUB_Shablon.RemoveAll(p => p.PROP_ID == _CodShablon);

            ((VirtualModul)MyGlo.Modul).PUB_Shablon.AddRange(_ListShablons);
            _WorkBook.Close();
            _ExcelApp.Quit();

            // Если загружаем в SQL
            if (PRI_CheckBox_1.IsChecked == true)
            {
                UserShablon.MET_SaveExcelToSQL(_eTip, _CodShablon);
                MessageBox.Show($"Удалено: {_Remov} строк. Загружено {_ListShablons.Count} строк!", "Загружено в SQL");
            }
            else
            {
                MessageBox.Show($"Удалено: {_Remov} строк. Загружено {_ListShablons.Count} строк!", "Загружено в Память");
            }
        }
        /// <summary>СОБЫТИЕ Нажали на кнопку "Выгрузка шаблона в Excel"</summary>
        protected virtual void PRI_ButtonToExcel_1_Click(object sender, RoutedEventArgs e)
        {
            DataRowView _DataRowView = (DataRowView)PART_DataGrid.SelectedItem;
            int         _CodShablon  = Convert.ToInt16(_DataRowView.Row["Cod"]);
            string      _TipDoc      = PRI_ComboBox_1.SelectedValue.ToString();
            eTipDocum   _eTip        = eTipDocum.Null;

            switch (_TipDoc)
            {
            case "apaN":
                _eTip = eTipDocum.Pol;
                break;

            case "ast":
                _eTip = eTipDocum.Stac;
                break;

            case "par":
                _eTip = eTipDocum.Paracl;
                break;

            case "kdl":
                _eTip = eTipDocum.Kdl;
                break;
            }
            string _NameFile = $"{_TipDoc}_{_CodShablon}";
            string _PathFile = $@"C:\Shablons\{_NameFile}.xlsx";

            Excel.Workbook    _WorkBook;
            Excel.Application _ExcelApp;
            Process[]         _Processes = Process.GetProcesses();
            // Выбираем только наши
            IEnumerable <Process> _ProcsBazis = _Processes.Where(p => p.ProcessName == "EXCEL" && p.MainWindowTitle == $"{_NameFile}.xlsx - Excel");

            foreach (var _Process in _ProcsBazis)
            {
                // Активирует окно процесса
                SetForegroundWindow(_Process.MainWindowHandle);
                // Отображает данное окно на перед, даже если было свернуто
                ShowWindow(_Process.MainWindowHandle, 1);
                return;
            }
            _ExcelApp = new Excel.Application();

            bool     _FileNew;
            FileInfo _FileInfo = new FileInfo(_PathFile);

            // Если нашли файл с текущим шаблоном
            if (_FileInfo.Exists)
            {
                _ExcelApp.Workbooks.Open(_PathFile);
                _FileNew = false;
            }
            else
            {
                _ExcelApp.SheetsInNewWorkbook = 1;
                _ExcelApp.Workbooks.Add(Type.Missing);
                _FileNew = true;
            }
            PRI_Shablons    = UserShablon.MET_FactoryListShablon(_eTip, _CodShablon);
            _WorkBook       = _ExcelApp.Workbooks[1];
            _WorkBook.Saved = true;
            Excel.Worksheet _Sheet = (Excel.Worksheet)_WorkBook.Worksheets.Item[1];
            // Рисуем заголовки
            int _y = 1;
            int _x = 1;

            _Sheet.Cells[_y, _x++].Value   = "Cod";
            _Sheet.Columns[_x].ColumnWidth = 6;
            _Sheet.Cells[_y, _x++].Value   = "ID";
            _Sheet.Columns[_x].ColumnWidth = 7;
            _Sheet.Cells[_y, _x++].Value   = "Nomer";
            _Sheet.Columns[_x].ColumnWidth = 5;
            _Sheet.Cells[_y, _x++].Value   = "VarId";
            _Sheet.Columns[_x].ColumnWidth = 6;
            _Sheet.Cells[_y, _x++].Value   = "Maska";
            _Sheet.Columns[_x].ColumnWidth = 5;
            _Sheet.Cells[_y, _x++].Value   = "Type";
            _Sheet.Columns[_x].ColumnWidth = 20;
            _Sheet.Cells[_y, _x++].Value   = "Razdel";
            _Sheet.Columns[_x].ColumnWidth = 24;
            _Sheet.Cells[_y, _x++].Value   = "Name";
            _Sheet.Columns[_x].ColumnWidth = 28;
            _Sheet.Cells[_y, _x++].Value   = "ValueStart";
            _Sheet.Columns[_x].ColumnWidth = 19;
            _Sheet.Cells[_y, _x++].Value   = "OutText";
            _Sheet.Cells[_y, _x++].Value   = "InText";
            _Sheet.Columns[_x].ColumnWidth = 27;
            _Sheet.Cells[_y, _x++].Value   = "xFormat";
            _Sheet.Columns[_x].ColumnWidth = 45;
            _Sheet.Cells[_y, _x++].Value   = "xLua";
            _Sheet.Columns[_x].ColumnWidth = 22;
            _Sheet.Cells[_y, _x].Value     = "xInfo";
            // Заполняем данные
            _y = 2;
            foreach (var _Shablon in PRI_Shablons)
            {
                _x = 1;
                _Sheet.Cells[_y, _x++].Value = _Shablon.PROP_Cod;
                _Sheet.Cells[_y, _x++].Value = _Shablon.PROP_ID;
                _Sheet.Cells[_y, _x++].Value = _Shablon.PROP_Nomer;
                _Sheet.Cells[_y, _x++].Value = _Shablon.PROP_VarId;
                _Sheet.Cells[_y, _x++].Value = _Shablon.PROP_Maska;
                _Sheet.Cells[_y, _x++].Value = _Shablon.PROP_Type;
                _Sheet.Cells[_y, _x++].Value = _Shablon.PROP_Razdel;
                _Sheet.Cells[_y, _x++].Value = _Shablon.PROP_Name;
                _Sheet.Cells[_y, _x++].Value = _Shablon.PROP_ValueStart;
                _Sheet.Cells[_y, _x++].Value = _Shablon.PROP_OutText;
                _Sheet.Cells[_y, _x++].Value = _Shablon.PROP_InText;
                _Sheet.Cells[_y, _x++].Value = _Shablon.PROP_xFormat;
                _Sheet.Cells[_y, _x++].Value = _Shablon.PROP_xLua;
                _Sheet.Cells[_y, _x].Value   = _Shablon.PROP_xInfo;
                if (_Shablon.PROP_xLua != "")
                {
                    _Sheet.Cells[_y, _x].Rows.RowHeight = 100;
                }
                _y++;
            }
            _Sheet.Name = DateTime.Now.ToString().Replace(':', '.');
            _Sheet.Copy(Before: _WorkBook.Worksheets[1]);
            _Sheet                  = (Excel.Worksheet)_WorkBook.Worksheets.Item[1];
            _Sheet.Name             = "Текущий";
            _ExcelApp.DisplayAlerts = true;
            if (_FileNew)
            {
                _WorkBook.SaveAs(_PathFile);
            }
            else
            {
                _WorkBook.Save();
            }
            _WorkBook.Activate();
            IntPtr _Handler1 = FindWindow(null, _ExcelApp.Caption);

            SetForegroundWindow(_Handler1);
            _ExcelApp.Visible = true;
        }