/// <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); } }