private void saveButton_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.CheckPathExists = true; saveFileDialog.Title = languageSupportManager.GetStringValue("SaveDialogTitle"); saveFileDialog.Filter = languageSupportManager.GetStringValue("Configuration_SaveButton_Filter_etmp") + "|*.etmp|" + languageSupportManager.GetStringValue("Configuration_SaveButton_Filter_estm") + "|*.estm"; saveFileDialog.FileName = languageSupportManager.GetStringValue("Configuration_SaveButton_DefaultFileName") + $".{DateTime.Now.ToString("yyyyMMdd")}"; saveFileDialog.InitialDirectory = Environment.CurrentDirectory; Message(true, languageSupportManager.GetStringValue("Configuration_SaveButton_AsyncSavingMessage")); if (saveFileDialog.ShowDialog(this) == DialogResult.OK) { gridTemplateControls.EndEdit(DataGridViewDataErrorContexts.Commit); Template template = new Template(); template.Base = 0; if (Regex.IsMatch(baseHoursTextBox.Text, @"^\d{1,2}$")) { template.Base = int.Parse(baseHoursTextBox.Text); } if (Regex.IsMatch(priceHourTextBox.Text, @"^\d{1,4}$")) { template.PriceHour = double.Parse(priceHourTextBox.Text); } template.CustomControls = new List <CustomControl>(); foreach (DataGridViewRow row in gridTemplateControls.Rows) { if (!row.IsNewRow) { CustomControl customControl = new CustomControl(); customControl.Category = (string)row.Cells[0].Value; customControl.Description = (string)row.Cells[1].Value; customControl.ControlType = (string)row.Cells[2].Value; customControl.Weight = (row.Cells[3].Value == null ? double.Parse("0") : double.Parse(row.Cells[3].Value.ToString())); customControl.DefaultValue = (row.Cells[4].Value == null ? string.Empty : row.Cells[4].Value.ToString()); customControl.Effort = bool.Parse((string)row.Cells[5].Value); template.CustomControls.Add(customControl); } } templateBO.SaveTemplate(template, saveFileDialog.FileName); Message(true, languageSupportManager.GetStringValue("Configuration_SaveButton_AsyncSavedMessage")); } else { Message(true, languageSupportManager.GetStringValue("Configuration_SaveButton_AsyncCenceledMessage")); } }
private void saveButton_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.CheckPathExists = true; saveFileDialog.Filter = languageSupportManager.GetStringValue("Main_SaveButton_Filter_estm") + "|*.estm"; saveFileDialog.FileName = languageSupportManager.GetStringValue("Main_SaveButton_DefaultFileNameTemplate") + $".{DateTime.Now.ToString("yyyyMMdd")}"; saveFileDialog.Title = languageSupportManager.GetStringValue("SaveDialogTitle"); saveFileDialog.InitialDirectory = Environment.CurrentDirectory; if (saveFileDialog.ShowDialog(this) == DialogResult.OK) { Template usedTemplate = new Template(); usedTemplate.Base = template.Base; usedTemplate.PriceHour = template.PriceHour; usedTemplate.CustomControls = new List <CustomControl>(); foreach (ICustomControl usedControl in controlContainer.Controls) { CustomControl customControl = new CustomControl(); customControl.Category = usedControl.Category; customControl.Description = usedControl.Description; customControl.ControlType = usedControl.ControlType; customControl.Effort = usedControl.Effort; customControl.Weight = usedControl.Weight; if (usedControl.GetType() == typeof(NumberControl)) { NumberControl numberControl = (NumberControl)usedControl; customControl.DefaultValue = numberControl.SelectedNumber.ToString(); } else if (usedControl.GetType() == typeof(OptionBoolControl)) { OptionBoolControl optionBoolControl = (OptionBoolControl)usedControl; customControl.DefaultValue = optionBoolControl.SelectedOption.ToString(); } else if (usedControl.GetType() == typeof(PercentControl)) { PercentControl percentControl = (PercentControl)usedControl; int percent = Convert.ToInt32(percentControl.EstimatedWeight * 100); customControl.DefaultValue = percent.ToString(); } usedTemplate.CustomControls.Add(customControl); } templateBO.SaveTemplate(usedTemplate, saveFileDialog.FileName); } }