/// <summary> /// Loads currently selected (or new) construction data /// </summary> private void LoadCurrentConstruction() { bool isNew = false; if (this.currentConstruction == null) { this.currentConstruction = new ChimneyConstruction(); isNew = true; } // Load selections this.cbx_Option_1.SelectedIndex = (isNew) ? -1 : this.currentConstruction.SelectedOptions[0]; this.cbx_Option_2.SelectedIndex = (isNew) ? -1 : this.currentConstruction.SelectedOptions[1]; this.cbx_Option_3.SelectedIndex = (isNew) ? -1 : this.currentConstruction.SelectedOptions[2]; this.cbx_Option_4.SelectedIndex = (isNew) ? -1 : this.currentConstruction.SelectedOptions[3]; this.cbx_Option_5.SelectedIndex = (isNew) ? -1 : this.currentConstruction.SelectedOptions[4]; this.cbx_Air.IsChecked = this.currentConstruction.IsWithVentilation; // Load construction data this.tbx_Name.Text = this.currentConstruction.Name; this.tbx_ChimneyHeigth.Text = this.currentConstruction.ChimneyHeight.ToString(); this.tbx_ChimneyHeadHeight.Text = this.currentConstruction.ChimneyHeadHeight.ToString(); }
/// <summary> /// Loads data for newly selected construction /// </summary> /// <param name="sender">Sender</param> /// <param name="e">EventArgs</param> private void OnConstructionsSelectionChanged(object sender, SelectionChangedEventArgs e) { if (this.dg_Constructions.SelectedItem != null) { //Load selected Chimney construction this.currentConstruction = (ChimneyConstruction)this.dg_Constructions.SelectedItem; // Load its settings LoadCurrentConstruction(); // Go to tab to update construction SwitchTabs(this.CurrentTab, this.tab_Step1); } }
/// <summary> /// Creates new construction and jump to next step /// </summary> /// <param name="nextStep">TabItem to jump after creation new construction</param> private void CreateNewChimneyConstruction(TabItem nextStep) { // Create new SDK Construction this.currentConstruction = null; // Load its settings LoadCurrentConstruction(); // Draw invalid default chimney this.IsResultValid = DrawDefaultChimney(); // Go to step 1 to edit new construction SwitchTabs(CurrentTab, nextStep); }
/// Updates materials needed in Chimney construction /// </summary> /// <param name="connection">Database connection</param> /// <param name="construction">Chímney construction to calculate</param> /// <param name="index">Number of constructions in module</param> /// <returns>Returns MainItems list calculated from constructions</returns> public MainItem CalculateConstruction(DatabaseConnection connection, ChimneyConstruction construction, int index) { // Result MainItem chimneyMainItem = new MainItem(); chimneyMainItem.Analysis = new ItemAnalysis(); chimneyMainItem.ID = string.Format("{0}-{1}", Properties.Resources.MAIN_ITEM_ID_CHIMNEY, index); chimneyMainItem.Name = construction.Name; chimneyMainItem.MeasureUnit = Properties.Resources.LABEL_CHIMNEY_MEASURE_UNIT; chimneyMainItem.Quantity = 1; chimneyMainItem.Kind = Properties.Resources.TEXT_KIND_CHIMNEY; // Get construction result code to load materials string resultCode = construction.ResultCode; if (string.IsNullOrEmpty(resultCode)) { chimneyMainItem.Note = Properties.Resources.MESSAGE_NO_MATERIAL_FOUND; return chimneyMainItem; } // New material set Hashtable materials = new Hashtable(); // Create MainItem for every construction // Load materials related to construction result code DataSet materialRelations = connection.GetMaterialSourcesForAutomaticConstructions(resultCode); if (materialRelations == null) { chimneyMainItem.Note = Properties.Resources.MESSAGE_NO_MATERIAL_FOUND; return chimneyMainItem; } try { // Browse all loaded materials foreach (DataRow relatedMaterial in materialRelations.Tables[0].Rows) { // All columns are marked as NOT NULL in databse string materialID = relatedMaterial["MaterialID"] as string; string dimension = relatedMaterial["Rozmer"] as string; decimal usage = Utilities.StringUtils.ParseDecimalFromString( relatedMaterial["Mnozstvi"].ToString(), 0 ); // Load material from database by id DataSet materialSet = connection.GetMaterialById(materialID); if (materialSet == null || materialSet.Tables[0].Rows.Count == 0) continue; // No material found // Create Material MaterialItem material = new MaterialItem(materialSet.Tables[0].Rows[0]); material.UsageMeasureUnit = Utilities.StringUtils.GetUsageMeasureUnit( material.MeasureUnit, chimneyMainItem.MeasureUnit ); // Set its usage and quantity based on coeficient from database and quantity from construction SetChimneyMaterialUsage(material, construction, dimension.Trim(), usage); material.Quantity = chimneyMainItem.CountAnalyzedItemQuantity(material.Usage); // Adds material to new hashtable result // Material can be new, or can be already used -> sum their quantities AddMaterialToHashTable(materials, material, construction.Name); } // Update material list an unit price UpdateList(chimneyMainItem, materials); chimneyMainItem.CalculateUnitPrice(); } catch (Exception ex) { Karafa.Errors.KarafaLogger.LogError(ex); } // Return result return chimneyMainItem; }
/// <summary> /// Sets material usage based on parameters /// </summary> /// <param name="material">Material to update</param> /// <param name="construction">Sdk contstruction</param> /// <param name="dimension">Specify the part of SDK construction material belongs to</param> /// <param name="usage">Coeficient for material quantity</param> private void SetChimneyMaterialUsage(MaterialItem material, ChimneyConstruction construction, string dimension, decimal usage) { // Switch needs constants expressions in case, that is why can not be used decimal quantity; // Quantity is based on dimension and coeficient if (dimension.Equals(Properties.Resources.HTK_CHIM_CHIMNEY_COUNT)) { quantity = construction.ChimneysCount; } else if (dimension.Equals(Properties.Resources.HTK_CHIM_REDUCTED_HEIGHT)) { // Reduce height quantity = (decimal)(construction.ChimneyHeight - Properties.Settings.Default.ChimneyReduction); quantity /= 100; // cm -> m } else if (dimension.Equals(Properties.Resources.HTK_CHIM_CLEAN_HEIGHT)) { quantity = (decimal)(construction.ChimneyHeight - construction.ChimneyHeadHeight); quantity /= 100; // cm -> m } else if (dimension.Equals(Properties.Resources.HTK_CHIM_CHIMNEY_HEIGHT)) { quantity = (decimal)construction.ChimneyHeight / 100; // cm -> m } else if (dimension.Equals(Properties.Resources.HTK_CHIM_CHIMNEY_HEAD_HEIGHT)) { quantity = (decimal)construction.ChimneyHeadHeight / 100; // cm -> m } else { quantity = 0; } // Save quantity material.Usage = usage * quantity; }
/// <summary> /// When construction is being saved, corresponding MainItem has to be updated /// </summary> /// <param name="connection">Database connection</param> /// <param name="construction">Construction to update/add</param> public void UpdateChimneyConstructionMainItem(DatabaseConnection connection, ChimneyConstruction construction) { // Get index of Constructions -> MainItem is on the same index int index = this.ChimneyConstructions == null ? -1 : this.ChimneyConstructions.IndexOf(construction); // Get new Main Item MainItem result = new ChimneyModule(null).CalculateConstruction(connection, construction, index); // New item if (index == -1) { this.ChimneyConstructions.Add(construction); this.ChimneyMainItems.Add(result); return; } // Old result this.ChimneyMainItems[index] = result; }
/// <summary> /// Removes given Chimney construction /// </summary> /// <param name="construction">Construction to remove</param> /// <returns>Returns corresponding MainItem</returns> public MainItem RemoveChimneyConstruction(ChimneyConstruction construction) { int index = this.ChimneyConstructions.IndexOf(construction); if (index != -1) { // Remove construction and MainItem from proepr lists this.ChimneyConstructions.Remove(construction); MainItem item = this.ChimneyMainItems[index]; this.ChimneyMainItems.Remove(item); return item; } return null; }