Ejemplo n.º 1
0
        public CheckList()
        {
            InitializeComponent();

            DirectoryInfo localFolder   = new DirectoryInfo(Path.Combine(Application.StartupPath, "checklists"));
            DirectoryInfo networkFolder = new DirectoryInfo(Path.Combine(Settings.Default.DataFolder, "checklists"));

            foreach (FileInfo configurationFile in localFolder.GetFiles())
            {
                if (configurationFile.Extension == ".xml")
                {
                    ChecklistFile newChecklist = new ChecklistFile(configurationFile.Name, configurationFile, true);
                    CBChecklistSelector.Items.Add(newChecklist);
                }
            }

            foreach (FileInfo configurationFile in networkFolder.GetFiles())
            {
                if (configurationFile.Extension == ".xml")
                {
                    ChecklistFile newChecklist = new ChecklistFile(configurationFile.Name, configurationFile, false);
                    CBChecklistSelector.Items.Add(newChecklist);
                }
            }

            SetGridStyle();
        }
Ejemplo n.º 2
0
        private void loadSelectedXMLFile()
        {
            if (CBChecklistSelector.SelectedItem is ChecklistFile)
            {
                ChecklistFile selectedChecklist = (ChecklistFile)CBChecklistSelector.SelectedItem;
                checklistBindingSource.DataSource = SortableBindingListHelper.GetBindingListFromXmlFile <ChecklistItem>(selectedChecklist.File.FullName);
                foreach (DataGridViewRow row in dataGridViewChecklist.Rows)
                {
                    ChecklistItem item3 = (ChecklistItem)row.DataBoundItem;
                    if (item3.Versteckt)
                    {
                        row.Visible = false;
                    }
                }

                templateList    = new List <string>();
                currentTemplate = null;
                tcTemplates.TabPages.Clear();
                TabPage happyPathPage = null;
                foreach (FileInfo template in selectedChecklist.DirectoryWithFiles.GetFiles("*.txt"))
                {
                    templateList.Add(template.Name);
                    RichTextBox richTextBox = new RichTextBox();
                    TabPage     tabpage     = new TabPage();
                    tabpage.Text = template.Name;
                    tabpage.Controls.Add(richTextBox);
                    tcTemplates.TabPages.Add(tabpage);
                    richTextBox.Dock        = DockStyle.Fill;
                    richTextBox.BorderStyle = BorderStyle.None;
                    if (template.Name == selectedChecklist.HappyPathTemplateName)
                    {
                        FileInfo happyPathTemplate = selectedChecklist.GetHappyPathTemplate();
                        currentTemplate    = System.IO.File.ReadAllText(happyPathTemplate.FullName);
                        currentRichTextBox = richTextBox;
                        happyPathPage      = tabpage;
                    }
                }

                if (happyPathPage != null)
                {
                    tcTemplates.SelectedTab = happyPathPage;
                    renderEmail();
                }
            }
        }
Ejemplo n.º 3
0
        private void tcTemplates_SelectedIndexChanged(object sender, EventArgs e)
        {
            TabPage selectedPage = tcTemplates.SelectedTab;

            if (selectedPage != null)
            {
                foreach (Control control in selectedPage.Controls)
                {
                    if (control is RichTextBox)
                    {
                        ChecklistFile selectedChecklist = (ChecklistFile)CBChecklistSelector.SelectedItem;
                        currentRichTextBox = (RichTextBox)control;
                        currentTemplate    = System.IO.File.ReadAllText(selectedChecklist.DirectoryWithFiles.FullName + @"\" + selectedPage.Text);
                        renderEmail();
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private void dataGridViewChecklist_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
        {
            ChecklistFile selectedChecklist = (ChecklistFile)CBChecklistSelector.SelectedItem;
            var           senderGrid        = (DataGridView)sender;

            if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn &&
                e.RowIndex >= 0)
            {
                int           index = e.RowIndex;
                ChecklistItem item  = (ChecklistItem)senderGrid.Rows[index].DataBoundItem;
                if (e.ColumnIndex == 4)
                {
                    if (item.Hilfe.Programm != null && item.Hilfe.Programm.Length > 0)
                    {
                        ProcessStartInfo processInfo;
                        processInfo = new ProcessStartInfo(item.Hilfe.Programm, item.Hilfe.Parameter);
                        processInfo.UseShellExecute = true;
                        Process.Start(processInfo);
                    }
                }
                else
                {
                    string filename = item.Funktion.Programm;
                    if (selectedChecklist != null)
                    {
                        FileInfo batchFile = new FileInfo(selectedChecklist.DirectoryWithFiles.FullName + @"\" + filename);
                        if (batchFile.Exists)
                        {
                            int exitCode;
                            ProcessStartInfo processInfo;
                            Process          process;
                            string           parameters = "";
                            if (item.Parameter != null)
                            {
                                parameters = item.Parameter.Replace(';', ' ');
                            }


                            Template parameterTemplate  = initXMLFileTemplate(parameters);
                            string   gerendeteparameter = parameterTemplate.Render();
                            processInfo = new ProcessStartInfo("cmd.exe", "/c " + batchFile.FullName + " " + gerendeteparameter);
                            processInfo.CreateNoWindow  = false;
                            processInfo.UseShellExecute = false;
                            // *** Redirect the output ***
                            processInfo.RedirectStandardError  = true;
                            processInfo.RedirectStandardOutput = true;

                            process = Process.Start(processInfo);
                            process.WaitForExit();

                            // *** Read the streams ***
                            // Warning: This approach can lead to deadlocks, see Edit #2
                            string output = process.StandardOutput.ReadToEnd();
                            string error  = process.StandardError.ReadToEnd();

                            exitCode      = process.ExitCode;
                            item.Resultat = exitCode.ToString();
                            //item.Funktion = "Pressed";
                            richTextBoxLog.BeginInvoke((MethodInvoker) delegate
                            {
                                AppendLogText(string.Format("Punkt '{0}', Funktion '{2}', Parameter '{1}'", item.Nummer, gerendeteparameter, item.Funktion.Programm), Color.FromArgb(128, 207, 240));
                                //AppendLogText(output, Color.Black);
                                if (error.Length > 0)
                                {
                                    AppendLogText("Error: " + error + "\r\n\r\n", Color.Red);
                                }
                                if (exitCode > 0)
                                {
                                    AppendLogText("Exit Code: " + exitCode + "\r\n\r\n", Color.Green);
                                }
                            });
                            foreach (Resultat resultat in item.Funktion.ResultatList)
                            {
                                if (item.Resultat == resultat.ResultatCode)
                                {
                                    ProcessResultat(resultat, false);
                                }
                            }
                        }
                    }
                }
            }
            dataGridViewChecklist.Refresh();
            richTextBoxLog.SelectionStart = richTextBoxLog.Text.Length; //Set the current caret position at the end
            richTextBoxLog.ScrollToCaret();
        }