private void btnUseTemplate_Click(object sender, EventArgs e) { string file = (string)lstTemplates.SelectedItem; if (string.IsNullOrEmpty(file)) { MessageBox.Show("Please choose a template."); return; } XmlSerializer serializer = new XmlSerializer(typeof(RTEmail)); RTEmail email; using (TextReader textReader = new StreamReader(Path.Combine(RTSettings.GetTemplateDirectory(), file + RTSettings.TemplateFileType))) { using (XmlReader xmlReader = XmlReader.Create(textReader)) { email = (RTEmail)serializer.Deserialize(xmlReader); } } using (TicketForm frm = new TicketForm()) { frm.LoadTicket(email); if (frm.CreatedTemplates) { LoadTemplateList(); } } }
public MainForm() { InitializeComponent(); RTActiveDirectory.LoadInBackground(); LoadTemplateList(); lblTemplates.Text = "Select Template (from " + RTSettings.GetTemplateDirectory() + ")"; }
private void LoadTemplateList() { lstTemplates.Items.Clear(); if (!Directory.Exists(RTSettings.GetTemplateDirectory())) { Directory.CreateDirectory(RTSettings.GetTemplateDirectory()); } else { foreach (string file in Directory.EnumerateFiles(RTSettings.GetTemplateDirectory(), "*" + RTSettings.TemplateFileType)) { lstTemplates.Items.Add(Path.GetFileNameWithoutExtension(file)); } } }
private void btnMakeTemplate_Click(object sender, EventArgs e) { using (AskTemplateNameForm frm = new AskTemplateNameForm()) { if (frm.ShowDialog() == DialogResult.OK) { string fullPath = Path.Combine(RTSettings.GetTemplateDirectory(), frm.TemplateName + RTSettings.TemplateFileType); XmlSerializer serializer = new XmlSerializer(typeof(RTEmail)); StringBuilder sb = new StringBuilder(); XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); ns.Add("", ""); XmlWriterSettings xmlSettings = new XmlWriterSettings(); xmlSettings.Indent = true; xmlSettings.OmitXmlDeclaration = true; using (XmlWriter xmlWriter = XmlWriter.Create(fullPath, xmlSettings)) { serializer.Serialize(xmlWriter, grdValues.SelectedObject, ns); } MessageBox.Show("Saved as template."); CreatedTemplates = true; } } }
private void btnOkay_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtName.Text)) { MessageBox.Show("Enter a template name."); return; } if (txtName.Text.Contains("\\") || txtName.Text.Contains(".") || txtName.Text.Contains("?") || txtName.Text.Contains("*") || txtName.Text.Contains("/")) { MessageBox.Show("Name contains invalid character."); return; } if (System.IO.File.Exists(System.IO.Path.Combine(RTSettings.GetTemplateDirectory(), txtName.Text + RTSettings.TemplateFileType))) { DialogResult response = MessageBox.Show("There is already a template by that name. Do you want to replace it?", "Confirm", MessageBoxButtons.OKCancel); if (response != DialogResult.OK) { return; } } TemplateName = txtName.Text; this.DialogResult = DialogResult.OK; this.Close(); }