private void DeleteTemplate(int rowIndex)
        {
            try
            {
                if (dataTableTemplate.Rows.Count == 0)
                {
                    return;
                }

                if (DialogResult.No == MessageBox.Show(string.Format("Verrà eliminato il template selezionato." + Environment.NewLine + "Vuoi proseguire?", ""), "Cancellazione File", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                {
                    return;
                }

                string strPathFile = this.dataGridView2.Rows[rowIndex].Cells[1].Value.ToString();

                if (!File.Exists(strPathFile))
                {
                    throw new FileNotFoundException("Impossibile trovare il file nella posizione indicata.");
                }

                TemplateDB.DeleteTemplate(rowIndex);

                this.LoadGridTemplate();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Errore: " + ex.Message, "File inesistente", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
예제 #2
0
        // Reloads the templates and sets the index to the first item.
        private void reloadTemplateList()
        {
            templateRichTextBox.Text = "";
            templateSelectorComboBox.Items.Clear();

            Template blank = new Template
            {
                Subject = "",
                Message = ""
            };

            templateSelectorComboBox.Items.Add(blank);

            if (!TemplateDB.Load(ref templates))
            {
                MessageBox.Show("Unable to retrieve templates from the database. Now closing program.", "Error!");
                Close();
            }

            foreach (Template template in templates)
            {
                templateSelectorComboBox.Items.Add(template);
            }

            templateSelectorComboBox.SelectedIndex = 0;
        }
예제 #3
0
 // Updates the currently selected template with whatever is in the RTB.
 private void updateTemplate(string subject)
 {
     if (!IsNullOrBlank(templateSelectorComboBox))
     {
         Template myTemplate = new Template
         {
             Subject          = subject,
             Message          = templateRichTextBox.Text,
             CreatedAccountId = LoginedEmployee.AccountId,
             CreatedDate      = DateTime.Now
         };
         TemplateDB.Update(myTemplate);
         reloadTemplateList();
     }
 }
예제 #4
0
        /// <summary>
        /// Initialize and load items of templateComboBox.
        /// </summary>
        private void InitializeTemplateComboBox()
        {
            // set the default option to be "None"
            templateComboBox.Items.Clear();
            templateComboBox.Items.Add(NoneOption);
            templateComboBox.SelectedIndex = 0;

            // load templates
            if (TemplateDB.Load(ref templates))
            {
                templateComboBox.Items.AddRange(templates.ToArray());
            }
            else
            {
                ShowErrorMessageBox(DatabaseError, "Loading templates failed!");
            }
        }
예제 #5
0
        // Saves the template to the database with the subject being the name for the template.
        // If the template has the same subject as one already in the DB, prompts user to make sure they want to overwrite.
        // Then, updates the template in the database.
        private void saveAsButton_Click(object sender, EventArgs e)
        {
            templateErrorProvider.Clear();

            // If the template RTB is blank, it will not save the template.
            if (templateRichTextBox.Text == "")
            {
                templateErrorProvider.SetError(templateRichTextBox, "Cannot save a blank template! Please try again.");
                return;
            }

            using (Form3 form3 = new Form3())
            {
                if (form3.ShowDialog() == DialogResult.OK)
                {
                    string subject = form3.SelectedText;
                    int    index   = templateSelectorComboBox.FindStringExact(subject);

                    // if index is anything but -1 (that means it's found a template with that name), then it selects that template and saves over the current text.
                    if (index != -1)
                    {
                        updateTemplate(subject);
                        reloadTemplateList();
                    }

                    // If the previous statements return false, then it saves the template as a new template.
                    else if (subject != "" || subject != null)
                    {
                        Template myTemplate = new Template
                        {
                            Subject          = subject,
                            Message          = templateRichTextBox.Text,
                            CreatedAccountId = LoginedEmployee.AccountId,
                            CreatedDate      = DateTime.Now
                        };
                        TemplateDB.Add(myTemplate);
                        reloadTemplateList();
                    }
                }
            }
        }
예제 #6
0
        // Loads the templateCreator, adds all of the tags to the tag combo box from the db.
        private void templateCreator_Load(object sender, EventArgs e)
        {
            //this.MinimumSize = new Size(this.Width, this.Height);
            //this.MaximumSize = new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);

            //this.AutoSize = true;
            //this.AutoSizeMode = AutoSizeMode.GrowAndShrink;

            templateSelectorComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
            customTagComboBox.DropDownStyle        = ComboBoxStyle.DropDownList;

            TemplateDB.Load(ref templates);
            TagDB.Load(ref tags);

            foreach (Tag myTag in tags)
            {
                customTagComboBox.Items.Add(myTag.Name);
            }

            reloadTemplateList();
        }
예제 #7
0
        // Determines whether or not the user wants to delete the selected template, and does so if they click yes.
        private void deleteButton_Click(object sender, EventArgs e)
        {
            if (!IsNullOrBlank(templateSelectorComboBox))
            {
                Template template = (Template)templateSelectorComboBox.SelectedItem;

                // it will delete the template from the DB if the user clicks yes.
                DialogResult delete = MessageBox.Show(
                    "The template \"" + template.Subject + "\" is about to be deleted!\n" +
                    "Are you sure you want to delete the template?\nTHE TEMPLATE CANNOT BE RECOVERED.",
                    "Warning!",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Asterisk,
                    MessageBoxDefaultButton.Button2
                    );
                if (delete == DialogResult.Yes)
                {
                    TemplateDB.Delete(template);
                    reloadTemplateList();
                }
            }
        }
예제 #8
0
        public static void ImportaTemplate(string filePath)
        {
            FileNameParser parser = new FileNameParser(filePath);

            Template template = new Template
            {
                DTINS = DateTime.Now,
                DESCR = parser.DESCR,
                PATH  = parser.PATH,
            };

            TemplateDB.SaveTemplate(template);

            TemplateDB.RunScriptTemplate(template.KEY_TEMPL, template.DESCR);

            List <PdfAssociation> pdfAssociations = PdfAssociationDB.LoadPdfAssociation(template.KEY_TEMPL); // chiave template

            if (pdfAssociations == null)
            {
                throw new Exception("Associazioni field/pdf non valorizzate");
            }
        }
예제 #9
0
        private void deletePermessi_Click(object sender, EventArgs e)
        {
            if (dataTableTemplate.Rows.Count == 0)
            {
                return;
            }

            DataRow row = dataTableTemplate.Rows[rowIndex];

            if (row == null)
            {
                return;
            }

            if (DialogResult.No == MessageBox.Show(string.Format("Verrà eliminato il template selezionato." + Environment.NewLine + "Vuoi proseguire?", ""), "Acquisizione File", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
            {
                return;
            }

            TemplateDB.DeleteTemplate(1);// row.ItemArray[0].ToString());

            this.LoadTemplate();
        }