/// 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> /// 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; }