Beispiel #1
0
        /// <summary>
        /// Save the current listing as a template
        /// </summary>
        private void SaveTemplate()
        {
            if (txtTemplateName.Text.Equals(cboTemplates.Text))
            {
                MessageBox.Show("This template name already exists! If you want to persist the changes just press the Save button and leave the Name field empty.", "WinStruct", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtTemplateName.Clear();
                return;
            }

            if (txtTemplateName.Text.Length == 0 && cboTemplates.SelectedIndex == 0)
            {
                MessageBox.Show("Please provide a name for this template!", "WinStruct", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtTemplateName.Focus();
                return;
            }

            if (txtStructure.Text.Length == 0 && cboTemplates.SelectedIndex == 0)
            {
                MessageBox.Show("Please provide some content for this template!", "WinStruct", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtStructure.Focus();
                return;
            }

            try
            {
                ProjectTemplate tpl = new ProjectTemplate();
                string oldTemplate = cboTemplates.Text;

                if (cboTemplates.SelectedIndex > 0 && txtTemplateName.Text.Length > 0 && txtTemplateName.Text.Equals(oldTemplate) == false && tpl.add(txtTemplateName.Text, txtStructure.Text))
                {
                    MessageBox.Show("Template '" + txtTemplateName.Text + "' was successfully created.", "WinStruct", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    FillTemplatesCombo();
                    cboTemplates.SelectedItem = txtTemplateName.Text;
                }
                else if (cboTemplates.Text.Length > 0 && txtTemplateName.Text.Length == 0 && tpl.edit(cboTemplates.Text, txtStructure.Text))
                {
                    MessageBox.Show("Template '" + cboTemplates.Text + "' was successfully updated.", "WinStruct", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    FillTemplatesCombo();
                    cboTemplates.SelectedItem = oldTemplate;
                }
                else if (cboTemplates.SelectedIndex == 0 && txtTemplateName.Text.Length > 0 && tpl.add(txtTemplateName.Text, txtStructure.Text))
                {
                    MessageBox.Show("Template '" + txtTemplateName.Text + "' was successfully created.", "WinStruct", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    FillTemplatesCombo();
                    cboTemplates.SelectedItem = txtTemplateName.Text;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error while creating template '" + txtTemplateName.Text + "': " + ex.Message, "WinStruct", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cboTemplates_SelectedIndexChanged(object sender, EventArgs e)
        {
            txtTemplateName.Clear();

                ProjectTemplate tpl = new ProjectTemplate();
                txtStructure.Text = tpl.get(cboTemplates.Text);

                if (cboTemplates.SelectedIndex > 0 || txtStructure.Text.Length > 0)
                {
                    btnDeleteTemplate.Enabled = true;
                    btnCreate.Enabled = true;
                    mnuCreateProject.Enabled = true;
                }
                else
                {
                    btnDeleteTemplate.Enabled = false;
                    btnCreate.Enabled = false;
                    mnuCreateProject.Enabled = false;
                }
        }
Beispiel #3
0
        /// <summary>
        /// Get all templates from database and fill the combo
        /// </summary>
        private void FillTemplatesCombo()
        {
            ProjectTemplate tpl = new ProjectTemplate();

            txtTemplateName.Clear();
            cboTemplates.Items.Clear();
            cboTemplates.Items.Add("Custom");

            Dictionary<int, string> items = tpl.get();
            foreach (KeyValuePair<int, string> item in items)
            {
                cboTemplates.Items.Add(item.Value);
            }

            cboTemplates.SelectedIndex = 0;
        }
Beispiel #4
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnDeleteTemplate_Click(object sender, EventArgs e)
 {
     try
         {
             ProjectTemplate tpl = new ProjectTemplate();
             if (tpl.delete(cboTemplates.SelectedItem.ToString()))
             {
                 FillTemplatesCombo();
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show("Error while deleting template '" + txtTemplateName.Text + "': " + ex.Message, "WinStruct", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
 }