protected virtual void Save() { if (!_saveChangesToDatabase) { return; } try { foreach (Control control in flowLayoutPanel1.Controls) { if (control is AttachedFileControl) { PropertyInfo propertyInfo = control.Tag as PropertyInfo; if (propertyInfo == null) { continue; } AttachedFileControl attachedFileControl = ((AttachedFileControl)control); attachedFileControl.Save(); AttachedFile val = (AttachedFile)propertyInfo.GetValue(_typeToImport, null); AttachedFile controlVal = ((AttachedFileControl)control).AttachedFile; if (val != controlVal) { propertyInfo.SetValue(_typeToImport, controlVal, null); } } } //GlobalObjects.CasEnvironment.Manipulator.Save(_typeToImport); } catch (Exception ex) { Program.Provider.Logger.Log("Error while save smsEventType", ex); } }
private void InitializeComponent() { labelComponent = new Label(); labelFrom = new Label(); labelFromAdditional = new Label(); labelDate = new Label(); labelTo = new Label(); labelToAdditional = new Label(); labelRemarks = new Label(); textBoxSerialNumber = new TextBox(); textBoxPartNumber = new TextBox(); textBoxFrom = new TextBox(); textBoxFromAdditional = new TextBox(); textBoxDate = new TextBox(); textBoxTo = new TextBox(); textBoxToAdditional = new TextBox(); textBoxRemarks = new TextBox(); fileControl = new AttachedFileControl() { Filter = "Adobe PDF Files|*.pdf", Description1 = "This record does not contain a file proving the compliance. Enclose PDF file to prove the compliance.", Description2 = "Attached file proves the compliance.", Icon = icons.PDFSmall }; buttonOK = new Button(); buttonApply = new Button(); buttonCancel = new Button(); tabControl = new TabControl(); tabPageGeneral = new TabPage(); labelSeparator = new Label(); labelSeparator2 = new Label(); labelSeparator3 = new Label(); labelSeparator4 = new Label(); // // tabControl // tabControl.Controls.Add(tabPageGeneral); tabControl.Location = new Point(Css.WindowsForm.Constants.LEFT_MARGIN, Css.WindowsForm.Constants.TOP_MARGIN); // // tabPageGeneral // tabPageGeneral.BackColor = Css.WindowsForm.Colors.TabBackColor; tabPageGeneral.Text = "General"; tabPageGeneral.Controls.Add(labelComponent); tabPageGeneral.Controls.Add(textBoxSerialNumber); tabPageGeneral.Controls.Add(textBoxPartNumber); tabPageGeneral.Controls.Add(labelDate); tabPageGeneral.Controls.Add(textBoxDate); tabPageGeneral.Controls.Add(labelSeparator); tabPageGeneral.Controls.Add(labelFrom); tabPageGeneral.Controls.Add(textBoxFrom); tabPageGeneral.Controls.Add(labelFromAdditional); tabPageGeneral.Controls.Add(textBoxFromAdditional); tabPageGeneral.Controls.Add(labelSeparator2); tabPageGeneral.Controls.Add(labelTo); tabPageGeneral.Controls.Add(textBoxTo); tabPageGeneral.Controls.Add(labelToAdditional); tabPageGeneral.Controls.Add(textBoxToAdditional); tabPageGeneral.Controls.Add(labelSeparator3); tabPageGeneral.Controls.Add(labelRemarks); tabPageGeneral.Controls.Add(textBoxRemarks); tabPageGeneral.Controls.Add(labelSeparator4); tabPageGeneral.Controls.Add(fileControl); // // labelComponent // labelComponent.Font = Css.WindowsForm.Fonts.RegularFont; labelComponent.ForeColor = Css.WindowsForm.Colors.ForeColor; labelComponent.Location = new Point(Css.WindowsForm.Constants.TAB_LEFT_MARGIN, Css.WindowsForm.Constants.TAB_TOP_MARGIN); labelComponent.Size = Css.WindowsForm.Constants.DefaultLabelSize; labelComponent.Text = "Component:"; labelComponent.TextAlign = ContentAlignment.MiddleLeft; // // textBoxSerialNumber // textBoxSerialNumber.Font = Css.WindowsForm.Fonts.RegularFont; textBoxSerialNumber.ForeColor = Css.WindowsForm.Colors.ForeColor; textBoxSerialNumber.Location = new Point(labelComponent.Right, Css.WindowsForm.Constants.TAB_TOP_MARGIN); textBoxSerialNumber.ReadOnly = true; // // textBoxPartNumber // textBoxPartNumber.Font = Css.WindowsForm.Fonts.RegularFont; textBoxPartNumber.ForeColor = Css.WindowsForm.Colors.ForeColor; textBoxPartNumber.Location = new Point(labelComponent.Right, labelComponent.Bottom + Css.WindowsForm.Constants.HEIGHT_INTERVAL); textBoxPartNumber.ReadOnly = true; // // labelDate // labelDate.Font = Css.WindowsForm.Fonts.RegularFont; labelDate.ForeColor = Css.WindowsForm.Colors.ForeColor; labelDate.Location = new Point(Css.WindowsForm.Constants.TAB_LEFT_MARGIN, textBoxPartNumber.Bottom + Css.WindowsForm.Constants.HEIGHT_INTERVAL); labelDate.Size = Css.WindowsForm.Constants.DefaultLabelSize; labelDate.Text = "Date:"; labelDate.TextAlign = ContentAlignment.MiddleLeft; // // textBoxDate // textBoxDate.Font = Css.WindowsForm.Fonts.RegularFont; textBoxDate.ForeColor = Css.WindowsForm.Colors.ForeColor; textBoxDate.Location = new Point(labelDate.Right, textBoxPartNumber.Bottom + Css.WindowsForm.Constants.HEIGHT_INTERVAL); textBoxDate.ReadOnly = true; // // labelSeparator // labelSeparator.AutoSize = false; labelSeparator.Location = new Point(Css.WindowsForm.Constants.TAB_SEPARATOR_LEFT_MARGIN, textBoxDate.Bottom + Css.WindowsForm.Constants.SEPARATOR_INTERVAL); labelSeparator.Height = 2; labelSeparator.BorderStyle = BorderStyle.Fixed3D; // // labelFrom // labelFrom.Font = Css.WindowsForm.Fonts.RegularFont; labelFrom.ForeColor = Css.WindowsForm.Colors.ForeColor; labelFrom.Location = new Point(Css.WindowsForm.Constants.TAB_LEFT_MARGIN, labelSeparator.Bottom + Css.WindowsForm.Constants.SEPARATOR_INTERVAL); labelFrom.Size = Css.WindowsForm.Constants.DefaultLabelSize; labelFrom.Text = "From:"; labelFrom.TextAlign = ContentAlignment.MiddleLeft; // // textBoxFrom // textBoxFrom.Font = Css.WindowsForm.Fonts.RegularFont; textBoxFrom.ForeColor = Css.WindowsForm.Colors.ForeColor; textBoxFrom.Location = new Point(labelFrom.Right, labelSeparator.Bottom + Css.WindowsForm.Constants.SEPARATOR_INTERVAL); textBoxFrom.ReadOnly = true; // // labelFromAdditional // labelFromAdditional.Font = Css.WindowsForm.Fonts.RegularFont; labelFromAdditional.ForeColor = Css.WindowsForm.Colors.ForeColor; labelFromAdditional.Location = new Point(Css.WindowsForm.Constants.TAB_LEFT_MARGIN, textBoxFrom.Bottom + Css.WindowsForm.Constants.HEIGHT_INTERVAL); labelFromAdditional.Size = Css.WindowsForm.Constants.DefaultLabelSize; labelFromAdditional.TextAlign = ContentAlignment.MiddleLeft; // // textBoxFromAdditional // textBoxFromAdditional.Font = Css.WindowsForm.Fonts.RegularFont; textBoxFromAdditional.ForeColor = Css.WindowsForm.Colors.ForeColor; textBoxFromAdditional.Location = new Point(labelFromAdditional.Right, textBoxFrom.Bottom + Css.WindowsForm.Constants.HEIGHT_INTERVAL); textBoxFromAdditional.ReadOnly = true; // // labelSeparator2 // labelSeparator2.AutoSize = false; labelSeparator2.Height = 2; labelSeparator2.Location = new Point(Css.WindowsForm.Constants.TAB_SEPARATOR_LEFT_MARGIN, textBoxFromAdditional.Bottom + Css.WindowsForm.Constants.SEPARATOR_INTERVAL); labelSeparator2.BorderStyle = BorderStyle.Fixed3D; // // labelTo // labelTo.Font = Css.WindowsForm.Fonts.RegularFont; labelTo.ForeColor = Css.WindowsForm.Colors.ForeColor; labelTo.Location = new Point(Css.WindowsForm.Constants.TAB_LEFT_MARGIN, labelSeparator2.Bottom + Css.WindowsForm.Constants.SEPARATOR_INTERVAL); labelTo.Size = Css.WindowsForm.Constants.DefaultLabelSize; labelTo.Text = "To:"; labelTo.TextAlign = ContentAlignment.MiddleLeft; // // textBoxTo // textBoxTo.Font = Css.WindowsForm.Fonts.RegularFont; textBoxTo.ForeColor = Css.WindowsForm.Colors.ForeColor; textBoxTo.Location = new Point(labelTo.Right, labelSeparator2.Bottom + Css.WindowsForm.Constants.SEPARATOR_INTERVAL); textBoxTo.ReadOnly = true; // // labelToAdditional // labelToAdditional.Font = Css.WindowsForm.Fonts.RegularFont; labelToAdditional.ForeColor = Css.WindowsForm.Colors.ForeColor; labelToAdditional.Location = new Point(Css.WindowsForm.Constants.TAB_LEFT_MARGIN, textBoxTo.Bottom + Css.WindowsForm.Constants.HEIGHT_INTERVAL); labelToAdditional.Size = Css.WindowsForm.Constants.DefaultLabelSize; labelToAdditional.TextAlign = ContentAlignment.MiddleLeft; // // textBoxToAdditional // textBoxToAdditional.Font = Css.WindowsForm.Fonts.RegularFont; textBoxToAdditional.ForeColor = Css.WindowsForm.Colors.ForeColor; textBoxToAdditional.Location = new Point(labelTo.Right, textBoxTo.Bottom + Css.WindowsForm.Constants.HEIGHT_INTERVAL); //textBoxToAdditional.ReadOnly = true; // // labelSeparator3 // labelSeparator3.AutoSize = false; labelSeparator3.Height = 2; labelSeparator3.BorderStyle = BorderStyle.Fixed3D; labelSeparator3.Location = new Point(Css.WindowsForm.Constants.TAB_SEPARATOR_LEFT_MARGIN, textBoxToAdditional.Bottom + Css.WindowsForm.Constants.SEPARATOR_INTERVAL); // // labelRemarks // labelRemarks.Font = Css.WindowsForm.Fonts.RegularFont; labelRemarks.ForeColor = Css.WindowsForm.Colors.ForeColor; labelRemarks.Location = new Point(Css.WindowsForm.Constants.TAB_LEFT_MARGIN, labelSeparator3.Bottom + Css.WindowsForm.Constants.SEPARATOR_INTERVAL); labelRemarks.Size = Css.WindowsForm.Constants.DefaultLabelSize; labelRemarks.Text = "Remarks:"; labelRemarks.TextAlign = ContentAlignment.MiddleLeft; // // textBoxRemarks // textBoxRemarks.Font = Css.WindowsForm.Fonts.RegularFont; textBoxRemarks.ForeColor = Css.WindowsForm.Colors.ForeColor; textBoxRemarks.BackColor = Color.White; textBoxRemarks.Multiline = true; textBoxRemarks.Height = Css.WindowsForm.Constants.BIG_TEXT_BOX_HEIGHT; textBoxRemarks.Location = new Point(labelRemarks.Right, labelSeparator3.Bottom + Css.WindowsForm.Constants.SEPARATOR_INTERVAL); // // labelSeparator4 // labelSeparator4.AutoSize = false; labelSeparator4.Height = 2; labelSeparator4.BorderStyle = BorderStyle.Fixed3D; labelSeparator4.Location = new Point(Css.WindowsForm.Constants.TAB_SEPARATOR_LEFT_MARGIN, textBoxRemarks.Bottom + Css.WindowsForm.Constants.SEPARATOR_INTERVAL); // // fileControl // fileControl.Location = new Point(Css.WindowsForm.Constants.TAB_LEFT_MARGIN, labelSeparator4.Bottom + Css.WindowsForm.Constants.SEPARATOR_INTERVAL); // // buttonOK // buttonOK.Font = Css.WindowsForm.Fonts.RegularFont; buttonOK.ForeColor = Css.WindowsForm.Colors.ForeColor; buttonOK.Size = new Size(Css.WindowsForm.Constants.BUTTON_WIDTH, Css.WindowsForm.Constants.BUTTON_HEIGHT); buttonOK.Text = "OK"; buttonOK.Click += ButtonOkClick; // // buttonApply // buttonApply.Font = Css.WindowsForm.Fonts.RegularFont; buttonApply.ForeColor = Css.WindowsForm.Colors.ForeColor; buttonApply.Size = new Size(Css.WindowsForm.Constants.BUTTON_WIDTH, Css.WindowsForm.Constants.BUTTON_HEIGHT); buttonApply.Text = "Apply"; buttonApply.Click += ButtonApplyClick; // // buttonCancel // buttonCancel.Font = Css.WindowsForm.Fonts.RegularFont; buttonCancel.ForeColor = Css.WindowsForm.Colors.ForeColor; buttonCancel.Size = new Size(Css.WindowsForm.Constants.BUTTON_WIDTH, Css.WindowsForm.Constants.BUTTON_HEIGHT); buttonCancel.Text = "Cancel"; buttonCancel.Click += ButtonCancelClick; Text = "SN " + _currentComponent.SerialNumber + ". Transfer record"; AcceptButton = buttonOK; CancelButton = buttonCancel; FormBorderStyle = FormBorderStyle.FixedDialog; MaximizeBox = false; MinimizeBox = false; ClientSize = Css.WindowsForm.Constants.DefaultFormSize; StartPosition = FormStartPosition.CenterScreen; Controls.Add(tabControl); Controls.Add(buttonOK); Controls.Add(buttonApply); Controls.Add(buttonCancel); }
/// <summary> /// Применить к объекту сделанные изменения на контроле. /// Если не все данные удовлетворяют формату ввода (например при вводе чисел), свойства объекта не изменяются, возвращается false /// Вызов base.ApplyChanges() обязателен /// </summary> /// <returns></returns> protected virtual void ApplyChanges() { foreach (Control control in flowLayoutPanel1.Controls) { if (control is TextBox) { PropertyInfo propertyInfo = control.Tag as PropertyInfo; if (propertyInfo == null) { continue; } if (propertyInfo.PropertyType.Name.ToLower() != "string") { continue; } string val = (string)propertyInfo.GetValue(_typeToImport, null); string controlVal = control.Text; if (val != controlVal) { propertyInfo.SetValue(_typeToImport, controlVal, null); } } if (control is RichTextBox) { PropertyInfo propertyInfo = control.Tag as PropertyInfo; if (propertyInfo == null) { continue; } if (propertyInfo.PropertyType.Name.ToLower() != "string") { continue; } string val = (string)propertyInfo.GetValue(_typeToImport, null); string controlVal = ((RichTextBox)control).Rtf; if (val != controlVal) { propertyInfo.SetValue(_typeToImport, controlVal, null); } } if (control is NumericUpDown) { PropertyInfo propertyInfo = control.Tag as PropertyInfo; if (propertyInfo == null) { continue; } string typeName = propertyInfo.PropertyType.Name.ToLower(); switch (typeName) { case "int32": { int val = (int)propertyInfo.GetValue(_typeToImport, null); int controlVal = (int)((NumericUpDown)control).Value; if (val != controlVal) { propertyInfo.SetValue(_typeToImport, controlVal, null); } break; } case "int16": { Int16 val = (Int16)propertyInfo.GetValue(_typeToImport, null); Int16 controlVal = (Int16)((NumericUpDown)control).Value; if (val != controlVal) { propertyInfo.SetValue(_typeToImport, controlVal, null); } break; } case "double": { double val = (double)propertyInfo.GetValue(_typeToImport, null); double controlVal = (double)((NumericUpDown)control).Value; if (val != controlVal) { propertyInfo.SetValue(_typeToImport, controlVal, null); } break; } } } if (control is DateTimePicker) { PropertyInfo propertyInfo = control.Tag as PropertyInfo; if (propertyInfo == null) { continue; } string typeName = propertyInfo.PropertyType.Name.ToLower(); switch (typeName) { case "datetime": { DateTime val = (DateTime)propertyInfo.GetValue(_typeToImport, null); DateTime controlVal = ((DateTimePicker)control).Value; if (val != controlVal) { propertyInfo.SetValue(_typeToImport, controlVal, null); } break; } case "timespan": { TimeSpan val = (TimeSpan)propertyInfo.GetValue(_typeToImport, null); TimeSpan controlVal = ((DateTimePicker)control).Value.TimeOfDay; if (val != controlVal) { propertyInfo.SetValue(_typeToImport, controlVal, null); } break; } default: break; } } if (control is CheckBox) { PropertyInfo propertyInfo = control.Tag as PropertyInfo; if (propertyInfo == null) { continue; } bool val = (bool)propertyInfo.GetValue(_typeToImport, null); bool controlVal = ((CheckBox)control).Checked; if (val != controlVal) { propertyInfo.SetValue(_typeToImport, controlVal, null); } } if (control is AttachedFileControl) { PropertyInfo propertyInfo = control.Tag as PropertyInfo; if (propertyInfo == null) { continue; } AttachedFileControl fileControl = ((AttachedFileControl)control); AttachedFile val = (AttachedFile)propertyInfo.GetValue(_typeToImport, null); AttachedFile controlVal = fileControl.AttachedFile; fileControl.ApplyChanges(); if (val != controlVal) { propertyInfo.SetValue(_typeToImport, controlVal, null); } } if (control is LifelengthViewer) { PropertyInfo propertyInfo = control.Tag as PropertyInfo; if (propertyInfo == null) { continue; } Lifelength val = (Lifelength)propertyInfo.GetValue(_typeToImport, null); Lifelength controlVal = ((LifelengthViewer)control).Lifelength; if (!val.IsEqual(controlVal)) { propertyInfo.SetValue(_typeToImport, controlVal, null); } } if (control is ThresholdControl) { PropertyInfo propertyInfo = control.Tag as PropertyInfo; if (propertyInfo == null) { continue; } object val = propertyInfo.GetValue(_typeToImport, null); object controlVal = ((ThresholdControl)control).Threshold; if (val.ToString() != controlVal.ToString()) { propertyInfo.SetValue(_typeToImport, controlVal, null); } } if (control is DictionaryComboBox) { PropertyInfo propertyInfo = control.Tag as PropertyInfo; if (propertyInfo == null) { continue; } object val = propertyInfo.GetValue(_typeToImport, null); object controlVal = ((DictionaryComboBox)control).SelectedItem; if (val == null || controlVal == null || !val.Equals(controlVal)) { propertyInfo.SetValue(_typeToImport, controlVal, null); } } if (control is ComboBox) { PropertyInfo propertyInfo = control.Tag as PropertyInfo; if (propertyInfo == null) { continue; } object val = propertyInfo.GetValue(_typeToImport, null); object controlVal = ((ComboBox)control).SelectedItem; if (val == null || controlVal == null || !val.Equals(controlVal)) { propertyInfo.SetValue(_typeToImport, controlVal, null); } } } }