/// <summary>The save properties_ click.</summary> /// <param name="sender">The sender.</param> /// <param name="e">The e value.</param> private void SavePropertiesClick(object sender, EventArgs e) { this.AllPropertiesDGW.EndEdit(); this.allShownPresentedPropertiesXmlInstance.XmlWriteProperties( this.allShownPresentedPropertiesXmlInstance.PropertiesList); var saveShown = new SaveFileDialog { InitialDirectory = string.IsNullOrEmpty(Settings.Default.FileFolder) ? this.allShownPresentedPropertiesXmlInstance.LoadSaveDirectory : Settings.Default.FileFolder }; if (saveShown.ShowDialog() == DialogResult.OK) { try { PresentedPropertiesXml.XmlWriteProperties( this.allShownPresentedPropertiesXmlInstance.PropertiesList, saveShown.FileName); Settings.Default.FileFolder = Path.GetDirectoryName(saveShown.FileName); Settings.Default.Save(); } catch (Exception ee) { Debug.WriteLine(ee.ToString()); } } }
/// <summary>The load ts b_ click.</summary> /// <param name="sender">The sender.</param> /// <param name="e">The e value.</param> private void LoadTsbClick(object sender, EventArgs e) { var openShown = new OpenFileDialog { InitialDirectory = string.IsNullOrEmpty(Settings.Default.FileFolder) ? this.allShownPresentedPropertiesXmlInstance.LoadSaveDirectory : Settings.Default.FileFolder }; if (openShown.ShowDialog() == DialogResult.OK) { try { var loadedProperties = PresentedPropertiesXml.ReadPropertiesListFromFile(openShown.FileName); if (loadedProperties.Count > 0) { this.newShownPresentedPropertiesXmlInstance.PropertiesList = loadedProperties; Settings.Default.FileFolder = Path.GetDirectoryName(openShown.FileName); Settings.Default.Save(); } this.ShownPropertiesDGW.DataSource = this.newShownPresentedPropertiesXmlInstance.PropertiesList; this.ShownPropertiesDGW.Refresh(); PresentedPropertiesManage.ChangeHiddenValuesByOtherFile( ref this.allShownPresentedPropertiesXmlInstance, ref this.newShownPresentedPropertiesXmlInstance); this.allShownPresentedPropertiesXmlInstance.ForceReadFile(); } catch (Exception ee) { Debug.WriteLine(ee.ToString()); } } }
/// <summary>Initializes a new instance of the <see cref="AllPropertiesDialog"/> class. /// Instantiates a user control for handling all properties.</summary> /// <param name="parentForm">A form in relation location of this form is set.</param> /// <param name="allPresentedPropertiesXmlInstance">PresentedPropertiesXml instance which contains all properties.</param> /// <param name="shownPresentedPropertiesXmlInstance">PresentedPropertiesXml instance which contains shown properties.</param> /// <param name="methodToLocalize">Delegate method to use for localization.</param> public AllPropertiesDialog( Form parentForm, ref PresentedPropertiesXml allPresentedPropertiesXmlInstance, ref PresentedPropertiesXml shownPresentedPropertiesXmlInstance, LocalisationDelegate methodToLocalize) { this.InitializeComponent(); this.InitializeAllPropertiesDialog(parentForm, ref allPresentedPropertiesXmlInstance, ref shownPresentedPropertiesXmlInstance, methodToLocalize); }
/// <summary>Initializes a user control for handling all properties.</summary> /// <param name="newParentForm">A form in relation location of this form is set.</param> /// <param name="allPresentedPropertiesXmlInstance">PresentedPropertiesXml instance which contains all properties.</param> /// <param name="shownPresentedPropertiesXmlInstance">PresentedPropertiesXml instance which contains shown properties.</param> /// <param name="methodToLocalize">Delegate method to use for localization.</param> public void InitializeAllPropertiesDialog( Form newParentForm, ref PresentedPropertiesXml allPresentedPropertiesXmlInstance, ref PresentedPropertiesXml shownPresentedPropertiesXmlInstance, LocalisationDelegate methodToLocalize) { // Add quick search this.quickSearchUserCntrl = new QuickSearchForDGW(); this.quickSearchUserCntrl.SetReferenceProperties(ref this.AllPropertiesDGW); var quickSearchUserCntrlControlHost = new ToolStripControlHost(this.quickSearchUserCntrl) { Alignment = ToolStripItemAlignment.Right }; this.quickSearchUserCntrl.Width = 140; this.AllPropertiesToolStrip.SuspendLayout(); this.AllPropertiesToolStrip.Items.Add(quickSearchUserCntrlControlHost); this.AllPropertiesToolStrip.ResumeLayout(); if (methodToLocalize != null) { methodToLocalize(this); methodToLocalize(this.contextMenuStrip1); this.validationErrorLabel.Text = "albl_Change_default_property_name"; methodToLocalize(this.validationErrorLabel); } this.AllPropertiesDGW.AutoGenerateColumns = false; this.AllPropertiesDGW.SelectionChanged += this.ShownPropertiesDGWSelectionChanged; this.AllPropertiesDGW.KeyDown += this.AllPropertiesDGWKeyDown; this.AllPropertiesDGW.Sorted += this.AllPropertiesDGWSorted; PresentedPropertiesManage.ChangeHiddenValuesByOtherFile( ref allPresentedPropertiesXmlInstance, ref shownPresentedPropertiesXmlInstance); allPresentedPropertiesXmlInstance.ForceReadFile(); this.newShownPresentedPropertiesXmlInstance = shownPresentedPropertiesXmlInstance; this.allShownPresentedPropertiesXmlInstance = allPresentedPropertiesXmlInstance; this.AllPropertiesDGW.DataSource = this.allShownPresentedPropertiesXmlInstance.PropertiesList; this.AllPropertiesDGW.ReadOnly = false; this.AllPropertiesDGW.AllowUserToAddRows = true; this.AllPropertiesDGW.AllowUserToDeleteRows = true; this.AllPropertiesDGW.SelectionMode = DataGridViewSelectionMode.CellSelect; this.AllPropertiesDGW.Columns[0].ReadOnly = false; }
/// <summary>Makes a new properties file from other files shown properties.</summary> /// <param name="shown">New properties.</param> /// <param name="all">File from which visible new properties is done.</param> /// <returns><c>false.</c> if write to file fails.</returns> public static bool MakeFileFromOtherFilesHiddenProperties( ref PresentedPropertiesXml shown, ref PresentedPropertiesXml all) { // unordered list of shown properties to be constructed var newShownProperties = new SearchableSortableBindingList <PresentedProperties>(); // add all non-hidden properties to the shown list foreach (var allProperty in all.PropertiesList.Where(allProperty => !allProperty.Hidden)) { newShownProperties.Add(allProperty); } // ordered list of shown properties to be constructed var orderedNewShownProperties = new SearchableSortableBindingList <PresentedProperties>(); // copy original ordering from shown.PropertiesList to orderedNewShownProperties foreach (var shownProperty in shown.PropertiesList) { for (var i = 0; i < newShownProperties.Count; i++) { // Compares to Name if (!newShownProperties[i].Equals(shownProperty)) { continue; } orderedNewShownProperties.Add(newShownProperties[i]); newShownProperties.RemoveAt(i); break; } } // put newly shown properties to the end of the list foreach (var shownProperty in newShownProperties.Where(shownProperty => !orderedNewShownProperties.Contains(shownProperty))) { orderedNewShownProperties.Add(shownProperty); } shown.PropertiesList = orderedNewShownProperties; return(shown.XmlWriteProperties(shown.PropertiesList)); }
/// <summary>Initializes a new instance of the <see cref="PropertiesForm"/> class. /// Initializes a form to select showable properties.</summary> /// <param name="parentForm">A form in relation location of this form is set.</param> /// <param name="allPresentedPropertiesXmlInstance">PresentedPropertiesXml instance which contains all properties.</param> /// <param name="shownPresentedPropertiesXmlInstance">PresentedPropertiesXml instance which contains shown properties.</param> /// <param name="localizationMethod">Delegate method to use for localization.</param> /// <param name="showShownProperties">If true, shown properties are shown in separate panel as well as move properties buttons.</param> public PropertiesForm( Form parentForm, ref PresentedPropertiesXml allPresentedPropertiesXmlInstance, ref PresentedPropertiesXml shownPresentedPropertiesXmlInstance, LocalisationDelegate localizationMethod, bool showShownProperties) { this.InitializeComponent(); this.StartPosition = FormStartPosition.Manual; if (parentForm != null) { this.TopMost = parentForm.TopMost; this.Location = this.GetLocation(parentForm.Location); } else { this.Location = this.GetLocation(Screen.PrimaryScreen.WorkingArea.Location); } this.splitContainer1.Panel1Collapsed = !showShownProperties; this.allPropertiesDialog1.ShowIncludedColumn(!showShownProperties); this.ownAllPresentedPropertiesXmlInstance = allPresentedPropertiesXmlInstance; this.ownShownPresentedPropertiesXmlInstance = shownPresentedPropertiesXmlInstance; this.allPropertiesDialog1.InitializeAllPropertiesDialog( parentForm, ref allPresentedPropertiesXmlInstance, ref shownPresentedPropertiesXmlInstance, localizationMethod); this.shownPropertiesDialog1.InitializeShownPropertiesDialog( parentForm, ref allPresentedPropertiesXmlInstance, ref shownPresentedPropertiesXmlInstance, localizationMethod); if (localizationMethod != null) { localizationMethod(this); } this.FormClosing += this.PropertiesFormFormClosing; }
/// <summary>Change properties hidden values in first property file /// so that properties that are in second property file are shown.</summary> /// <param name="all">All the properties.</param> /// <param name="shown">The shown.</param> /// <returns>false if write to file fails.</returns> public static bool ChangeHiddenValuesByOtherFile( ref PresentedPropertiesXml all, ref PresentedPropertiesXml shown) { foreach (var allProperty in all.PropertiesList) { allProperty.Visible = false; foreach (var shownProperty in shown.PropertiesList) { if (shownProperty.Name == allProperty.Name) { allProperty.Visible = true; } } } return(all.XmlWriteProperties(all.PropertiesList)); }
/// <summary>Initialises a user control for handling all properties.</summary> /// <param name="newParentForm">A form in relation location of this form is set.</param> /// <param name="allPresentedPropertiesXmlInstance">PresentedPropertiesXml instance which contains all properties.</param> /// <param name="shownPresentedPropertiesXmlInstance">PresentedPropertiesXml instance which contains shown properties.</param> /// <param name="methodToLocalize">Delegate method to use for localization.</param> public void InitializeShownPropertiesDialog( Form newParentForm, ref PresentedPropertiesXml allPresentedPropertiesXmlInstance, ref PresentedPropertiesXml shownPresentedPropertiesXmlInstance, LocalisationDelegate methodToLocalize) { if (methodToLocalize != null) { methodToLocalize(this); } this.ShownPropertiesDGW.AutoGenerateColumns = false; this.ShownPropertiesDGW.SelectionMode = DataGridViewSelectionMode.FullRowSelect; this.ShownPropertiesDGW.CellMouseClick += this.ShownPropertiesDGWCellMouseClick; this.ShownPropertiesDGW.SelectionChanged += this.AllPropertiesDGWSelectionChanged; this.newShownPresentedPropertiesXmlInstance = shownPresentedPropertiesXmlInstance; this.allShownPresentedPropertiesXmlInstance = allPresentedPropertiesXmlInstance; this.ShownPropertiesDGW.DataSource = this.newShownPresentedPropertiesXmlInstance.PropertiesList; // this.FormClosing += new FormClosingEventHandler(ShownPropertiesDialog_FormClosing); }
/// <summary>Initializes a new instance of the <see cref="ShownPropertiesDialog"/> class. /// Instantiates a user control for handling all properties.</summary> /// <param name="parentForm">A form in relation location of this form is set.</param> /// <param name="allPresentedPropertiesXmlInstance">PresentedPropertiesXml instance which contains all properties.</param> /// <param name="shownPresentedPropertiesXmlInstance">PresentedPropertiesXml instance which contains shown properties.</param> /// <param name="methodToLocalize">Delegate method to use for localization.</param> public ShownPropertiesDialog( Form parentForm, ref PresentedPropertiesXml allPresentedPropertiesXmlInstance, ref PresentedPropertiesXml shownPresentedPropertiesXmlInstance, LocalisationDelegate methodToLocalize) { this.InitializeComponent(); if (methodToLocalize != null) { methodToLocalize(this); } this.ShownPropertiesDGW.AutoGenerateColumns = false; this.ShownPropertiesDGW.SelectionMode = DataGridViewSelectionMode.FullRowSelect; this.ShownPropertiesDGW.CellMouseClick += this.ShownPropertiesDGWCellMouseClick; this.ShownPropertiesDGW.SelectionChanged += this.AllPropertiesDGWSelectionChanged; this.newShownPresentedPropertiesXmlInstance = shownPresentedPropertiesXmlInstance; this.allShownPresentedPropertiesXmlInstance = allPresentedPropertiesXmlInstance; this.ShownPropertiesDGW.DataSource = this.newShownPresentedPropertiesXmlInstance.PropertiesList; }
/// <summary>Merges all properties list from PropertiesToMerge to this instance properties list.</summary> /// <param name="propertiesToMerge">Properties to merge.</param> public void MergeProperties(PresentedPropertiesXml propertiesToMerge) { var propertiesExists = new SearchableSortableBindingList <PresentedProperties>(); foreach (var property in propertiesToMerge.PropertiesList) { foreach (var oldProperty in this.PropertiesList) { if (oldProperty.Equals(property)) { oldProperty.Copy(property); propertiesExists.Add(property); } } } foreach (var property in propertiesToMerge.PropertiesList.Where(property => !propertiesExists.Contains(property))) { this.PropertiesList.Add(property); } }
/// <summary>The value of objects property (report or UDA), returned in units given in PresentedProperties propertyType.</summary> /// <param name="thisPart">The object for which to get amount.</param> /// <param name="property">The property to get the value for.</param> /// <param name="presentedPropertiesInstance">The Presented Properties Instance.</param> /// <returns>Value of objects property. If both UDA and Report properties are declared, returns value of report property.</returns> public static object GetPartPropertyValue(ModelObject thisPart, PresentedProperties property, PresentedPropertiesXml presentedPropertiesInstance) { var isReportProperty = !string.IsNullOrEmpty(property.ReportPropertyName); var propertvalueY = GetPropertvalueYBasedOnType( presentedPropertiesInstance, thisPart, property, isReportProperty); try { switch (GetBaseType(property.PropertyType)) { case PropertyTypes.Int: return(string.IsNullOrEmpty(propertvalueY) ? 0 : Convert.ToInt32(propertvalueY)); case PropertyTypes.String: return(propertvalueY); case PropertyTypes.Date: return(string.IsNullOrEmpty(propertvalueY) ? null : (object)Convert.ToDateTime(propertvalueY)); default: return(string.IsNullOrEmpty(propertvalueY) ? 0.0 : Convert.ToDouble(propertvalueY)); } } catch (Exception ee) { Debug.WriteLine(ee); } return(null); }
/// <summary>The value of objects property (report or UDA), returned in units given in PresentedProperties propertyType.</summary> /// <param name="thisPart">The object for which to get amount.</param> /// <param name="visibleName">Name of the property is properties xml file.</param> /// <param name="presentedPropertiesInstance">The Presented Properties Instance.</param> /// <returns>Value of objects property. If both UDA and Report properties are declared, returns value of report property.</returns> public static object GetPartPropertyValue(ModelObject thisPart, string visibleName, PresentedPropertiesXml presentedPropertiesInstance) { object result = null; PresentedProperties thisProperty = null; if (presentedPropertiesInstance.GetPropertyByName(visibleName, ref thisProperty)) { result = GetPartPropertyValue(thisPart, thisProperty, presentedPropertiesInstance); } return(result); }
/// <summary>The get property value based on type.</summary> /// <param name="presentedPropertiesInstance">The presented properties instance.</param> /// <param name="part">The part value.</param> /// <param name="thisProperty">The this property.</param> /// <param name="isReportProperty">The is report property.</param> /// <param name="roundDoubles">The round doubles.</param> /// <returns>The System.String.</returns> private static string GetPropertvalueYBasedOnType( PresentedPropertiesXml presentedPropertiesInstance, ModelObject part, PresentedProperties thisProperty, bool isReportProperty, bool roundDoubles = true) { var type = thisProperty.PropertyType; var decimals = thisProperty.Decimals; var propertyName = thisProperty.ReportPropertyName; if (!isReportProperty) { propertyName = thisProperty.UdaPropertyName; } var result = string.Empty; var intValue = 0; var doubleValue = 0.0; var stringValue = string.Empty; var baseDate = new DateTime(1970, 1, 1); var doubleFromat = roundDoubles ? "N" + decimals.ToString(CultureInfo.InvariantCulture) : "G"; switch (type.ToLower()) { case PropertyTypes.Pieces: result = "1"; break; case PropertyTypes.Formula: if (GetAttributeByUDAFormula(presentedPropertiesInstance, part, propertyName, out doubleValue)) { result = doubleValue.ToString(doubleFromat); } break; case PropertyTypes.Int: GetProperty(part, propertyName, isReportProperty, ref intValue); result = intValue.ToString(CultureInfo.InvariantCulture); break; case PropertyTypes.Mm: case PropertyTypes.Mm2: case PropertyTypes.Mm3: case PropertyTypes.Double: GetProperty(part, propertyName, isReportProperty, ref doubleValue); result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.String: GetProperty(part, propertyName, isReportProperty, ref stringValue); result = stringValue; break; case PropertyTypes.Date: if (!propertyName.StartsWith("EXTERNAL.")) { GetProperty(part, propertyName, isReportProperty, ref intValue); if (intValue != 0) { baseDate = baseDate.AddSeconds(intValue); result = baseDate.ToString(CultureInfo.InvariantCulture); } } else { GetProperty(part, propertyName, isReportProperty, ref stringValue); result = stringValue; } break; case PropertyTypes.Kg: GetProperty(part, propertyName, isReportProperty, ref doubleValue); result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.Ton: GetProperty(part, propertyName, isReportProperty, ref doubleValue); doubleValue = doubleValue / 1000; result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.Cm: GetProperty(part, propertyName, isReportProperty, ref doubleValue); doubleValue = doubleValue / 10; result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.M: GetProperty(part, propertyName, isReportProperty, ref doubleValue); doubleValue = doubleValue / 1000; result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.Cm2: GetProperty(part, propertyName, isReportProperty, ref doubleValue); doubleValue = doubleValue / 100; result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.M2: GetProperty(part, propertyName, isReportProperty, ref doubleValue); doubleValue = doubleValue / 1000000; result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.Cm3: GetProperty(part, propertyName, isReportProperty, ref doubleValue); doubleValue = doubleValue / 1000; result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.M3: GetProperty(part, propertyName, isReportProperty, ref doubleValue); doubleValue = doubleValue / 1000000000; result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.Inch: GetProperty(part, propertyName, isReportProperty, ref doubleValue); doubleValue = doubleValue / 25.4; result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.Inch2: GetProperty(part, propertyName, isReportProperty, ref doubleValue); doubleValue = doubleValue / 645.16; result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.Inch3: GetProperty(part, propertyName, isReportProperty, ref doubleValue); doubleValue = doubleValue / 16387.064; result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.Ft: GetProperty(part, propertyName, isReportProperty, ref doubleValue); doubleValue = doubleValue / 304.8; result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.Ft2: GetProperty(part, propertyName, isReportProperty, ref doubleValue); doubleValue = doubleValue / 92903.04; result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.Ft3: GetProperty(part, propertyName, isReportProperty, ref doubleValue); doubleValue = doubleValue / 28316846.6; result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.Yard: GetProperty(part, propertyName, isReportProperty, ref doubleValue); doubleValue = doubleValue / 914.4; result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.Yard2: GetProperty(part, propertyName, isReportProperty, ref doubleValue); doubleValue = doubleValue / 836127.36; result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.Yard3: GetProperty(part, propertyName, isReportProperty, ref doubleValue); doubleValue = doubleValue / 764554857.984; result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.Lbs: GetProperty(part, propertyName, isReportProperty, ref doubleValue); doubleValue = doubleValue / 0.45359237; result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.TonShort: GetProperty(part, propertyName, isReportProperty, ref doubleValue); doubleValue = doubleValue / 907.18474; result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.TonLong: GetProperty(part, propertyName, isReportProperty, ref doubleValue); doubleValue = doubleValue / 1016.0469088; result = doubleValue.ToString(doubleFromat); break; } return(result ?? string.Empty); }
private static bool GetAttributeByUDAFormula( PresentedPropertiesXml presentedPropertiesInstance, ModelObject modelObj, string udaEquation, out double resultValue) { var removeChar = new[] { '+', '-', '*', '/', '(', ')' }; const string DelimStr = " "; var delimiter = DelimStr.ToCharArray(); string insertAddstr; var findIndex = 0; double doubleValue; var culInfo = CultureInfo.CurrentCulture; var usCulInfo = new CultureInfo("en-us"); resultValue = 0.0; var findString = udaEquation; for (var i = 0; i < removeChar.Length; i++) { findString = findString.Replace(removeChar[i].ToString(CultureInfo.InvariantCulture), " "); } var splitKey = findString.Split(delimiter); var tempKey = new string[splitKey.Length]; for (var i = 0; i < splitKey.Length; i++) { if (splitKey[i].Length <= 0) { continue; } var isDouble = double.TryParse(splitKey[i], NumberStyles.Any, culInfo, out doubleValue); if (isDouble == false) { isDouble = double.TryParse(splitKey[i], NumberStyles.Any, usCulInfo, out doubleValue); } if (isDouble == false) { tempKey[i] = splitKey[i]; insertAddstr = "_UDA_" + i.ToString(CultureInfo.InvariantCulture); findIndex = udaEquation.IndexOf(splitKey[i], findIndex, StringComparison.Ordinal); findIndex = findIndex + splitKey[i].Length; udaEquation = udaEquation.Insert(findIndex, insertAddstr); } } for (var i = 0; i < tempKey.Length; i++) { if (null == tempKey[i] || tempKey[i].Length == 0) { continue; } PresentedProperties property = null; if (!presentedPropertiesInstance.GetPropertyByNameOrModelPropertyName(tempKey[i], ref property)) { continue; } // Maybe should use just visible property name? var propertvalueY = GetPropertvalueYBasedOnType( presentedPropertiesInstance, modelObj, property, true, false); try { doubleValue = Convert.ToDouble(propertvalueY); insertAddstr = tempKey[i] + "_UDA_" + i.ToString(CultureInfo.InvariantCulture); udaEquation = udaEquation.Replace(insertAddstr, doubleValue.ToString(CultureInfo.InvariantCulture)); } catch (Exception ee) { Debug.WriteLine(ee); return(false); } } var mathEval = new MathEvaluate(); if (mathEval.Parse(udaEquation) && mathEval.Error == false) { mathEval.Infix2Postfix(); mathEval.EvaluatePostfix(); } if (mathEval.Error) { if (mathEval.ErrorDescription != MathEvaluate.DivideByZero) { return(false); } } else { resultValue = mathEval.Result; } return(true); }