/// <summary> /// Constructor /// </summary> /// <param name="item">Item to be shown</param> /// <param name="parentMainItem">Parent main item of analysis item or null for MainItem</param> public AnalysisItemDetailForm( ImportItemBase item, MainItem parentMainItem) { InitializeComponent(); this.detailedItem = item; this.parentMainItem = parentMainItem; this.txt_ParentMainItem.Text = string.Format( "{0} ({1} {2})", parentMainItem.Name, parentMainItem.Quantity, parentMainItem.MeasureUnit ); if (this.detailedItem is WorkItem) { this.lbl_WorkDescription.Visibility = System.Windows.Visibility.Visible; this.txt_WorkDescription.Visibility = System.Windows.Visibility.Visible; } this.Title = string.Format("{0} - {1}", this.Title, this.detailedItem.Name); this.loaded = false; this.recalculateParentUnitPrice = false; }
/// <summary> /// Constructor /// </summary> /// <param name="item">MainItem to be shown</param> /// <param name="connection">Karafa database connection</param> /// <param name="form">Parent CostCalculationForm</param> /// <param name="formSubSection">Currently selected SubSection on parent form</param> public MainItemDetailForm( MainItem item, DatabaseConnection connection, CostsCalculationForm form, SubSection formSubSection) { InitializeComponent(); this.detailedItem = item; this.dbConnection = connection; this.calculationForm = form; this.currentSubsection = formSubSection; this.Title = string.Format("{0} - {1}", this.Title, this.detailedItem.Name); this.evaluator = new ExpressionEvaluator(this.tbx_QuantityCounter, this.tbx_QuantityResults); this.loaded = false; this.shouldRecalculateAnalysisQuantity = false; }
/// <summary> /// Properly removes given MainItem /// </summary> /// <param name="mainItem">MainItem to delete</param> public void RemoveMainItem(MainItem mainItem) { // Is imported item? if (this.ImportedItemList.Contains(mainItem)) { this.ImportedItemList.Remove(mainItem); return; } // Must be item from AC if (this.AutomaticConstructions.RemoveMainItem(mainItem) == null) throw new InvalidOperationException("Failed to remove item: " + mainItem.ID); }
/// 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> /// Clears old material list and replaces it with new material list /// </summary> /// <param name="mainItem">Given main item to update its list</param> /// <param name="materials">Hashtable with new materials contained in values (key is smaterials ID)</param> protected void UpdateList(MainItem mainItem, Hashtable materials) { // Add all materials form materials hashtable foreach (MaterialItem material in materials.Values) { if (material != null) mainItem.Analysis.AddAnalysisItem(material); } }
/// <summary> /// Deletes selected main item if user wants to /// </summary> /// <param name="selectedItem">Item to delete</param> private void DeleteMainItem(MainItem selectedItem) { if (MessageBoxResult.Yes != MessageBoxLocalizer.ShowDialog( string.Format( Properties.Resources.MESSAGE_COSTS_DELETE_MAINITEM_FORMATED, selectedItem.Name ), Properties.Resources.MESSAGE_TITLE_DELETE, MessageBoxButton.YesNoCancel, MessageBoxImage.Question, new Dictionary<MessageBoxLocalizer.Buttons, string>() { {MessageBoxLocalizer.Buttons.YES, Properties.Resources.BUTTON_YES}, {MessageBoxLocalizer.Buttons.NO, Properties.Resources.BUTTON_NO}, {MessageBoxLocalizer.Buttons.CANCEL, Properties.Resources.BUTTON_CANCEL} } )) return; // Remove item this.CurrentSubSection.RemoveMainItem(selectedItem); // Refresh view RefreshDataGrid(this.dg_ImportedItems, this.CurrentSubSectionMainItems); }
/// <summary> /// For every material in list counts Usage to correspond to 1 m2 of construction, /// also counts proper quantity /// <param name="mainItem">MainItem with material to update</param> /// </summary> private void UpdateMaterialsCalculations(MainItem mainItem) { foreach (ImportItemBase item in mainItem.Analysis.ItemAnalysisList) { item.Usage /= mainItem.Quantity; item.Quantity = mainItem.CountAnalyzedItemQuantity(item.Usage); } }
/// <summary> /// Updates Materials needed in SDK construction /// </summary> /// <param name="connection">Database connection</param> /// <param name="construction">SDK Construction to calculate</param> /// <param name="index">Count of constructions in module</param> /// <returns>Returns list of MainItems woth porcessed constructions</returns> public MainItem CalculateConstruction(DatabaseConnection connection, SdkConstruction construction, int index) { // Result MainItem sdkMainItem = new MainItem(); sdkMainItem.ID = string.Format("{0}-{1}", Properties.Resources.MAIN_ITEM_ID_SDK, index); sdkMainItem.Name = construction.Name; sdkMainItem.MeasureUnit = Properties.Resources.LABEL_SDK_MEASURE_UNIT; sdkMainItem.Kind = Properties.Resources.TEXT_KIND_SDK; // Get construction result code to load materials from database string resultCode = construction.ResultCode; //No code, no material if (string.IsNullOrEmpty(resultCode)) { sdkMainItem.Note = Properties.Resources.MESSAGE_NO_MATERIAL_FOUND; return sdkMainItem; } // New set of materials Hashtable materials = new Hashtable(); // Get materials ID related to construction Result code DataSet materialRelations = connection.GetMaterialSourcesForAutomaticConstructions(resultCode); if (materialRelations == null) { sdkMainItem.Note = Properties.Resources.MESSAGE_NO_MATERIAL_FOUND; return sdkMainItem; } try { // Compose materials from all SdkBoard from construction foreach (SdkBoard board in construction.SdkBoards) { board.Spacing = construction.Spacing; // Browse all related 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 by its 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, sdkMainItem.MeasureUnit ); // Set its usage and quantity based on coeficient from database and quantity from construction SetSdkMaterialUsage(material, board, dimension.Trim(), usage); // Adds material to new hashtable result // Material can be new, or can be already used -> sum their quantities AddMaterialToHashTable(materials, material, construction.Name); } } // Get surface quantity and its expression string expession = string.Empty; decimal quantity = 0; CountSurface(construction, out quantity, ref expession); // Set proper data to MainItem sdkMainItem.Quantity += quantity; sdkMainItem.QuantityExpression += expession; // Aktualize material list and unit price UpdateList(sdkMainItem, materials); UpdateMaterialsCalculations(sdkMainItem); // Calculate initial UnitPrice of MainItem sdkMainItem.CalculateUnitPrice(); } catch (Exception ex) { Karafa.Errors.KarafaLogger.LogError(ex); } // Return result return sdkMainItem; }
/// <summary> /// Removes item from proper list /// </summary> /// <param name="mainItem">MainItem to remove</param> /// <returns>Returns associated construction to this item or NULL</returns> public ConstructionBase RemoveMainItem(MainItem mainItem) { ConstructionBase result; // Check chimneys if (this.ChimneyMainItems.Contains(mainItem)) { int index = this.ChimneyMainItems.IndexOf(mainItem); // Remove and return corresponding chimney result = this.ChimneyConstructions[index]; this.ChimneyConstructions.RemoveAt(index); // Remove item this.ChimneyMainItems.Remove(mainItem); return result; } // Check SDKs if (this.SdkMainItems.Contains(mainItem)) { int index = this.SdkMainItems.IndexOf(mainItem); // Remove and return corresponding SDK constructions result = this.SdkConstructions[index]; this.SdkConstructions.RemoveAt(index); // Remove item this.SdkMainItems.Remove(mainItem); return result; } // Item was not found in any list return null; }
/// <summary> /// Adds item to a proper list based on item's ID /// </summary> /// <param name="mainItem">Item to add</param> /// <param name="construction">Construction corresponding to MainItem to add</param> /// <returns>Returns true if item was added to some list, false if not</returns> public bool AddItem(MainItem mainItem, ConstructionBase construction) { // Is Chimney construction if (mainItem.ID.StartsWith(Properties.Resources.MAIN_ITEM_ID_CHIMNEY)) { if (construction is ChimneyConstruction) { // Add MainItem and construction this.ChimneyMainItems.Add(mainItem); this.ChimneyConstructions.Add(construction as ChimneyConstruction); return true; } } // Is SDK construction if (mainItem.ID.StartsWith(Properties.Resources.MAIN_ITEM_ID_SDK)) { // Add MainItem and construction if (construction is SdkConstruction) { this.SdkMainItems.Add(mainItem); this.SdkConstructions.Add(construction as SdkConstruction); return true; } } // Not found return false; }