Пример #1
0
        /// <summary>
        /// Loads analysis for specified <see cref="Karafa.Modules.Import.MainItem"/>.
        /// </summary>
        /// <param name="databaseConnection">Connectio to database</param>
        /// <param name="id">ID of Mainitem</param>
        public void LoadAnalysisFromDatabase(Database.DatabaseConnection databaseConnection, string id)
        {
            string query = databaseConnection.CreateSelectCommandText(
                 Properties.Resources.VIEW_ANALYSIS,
                 null,
                 string.Format("CenikID = '{0}'", id),
                 null
            );

            DataSet dataSet = databaseConnection.ExecuteSelectQuery(query);

            if (dataSet == null || dataSet.Tables.Count == 0 || dataSet.Tables[0].Rows.Count == 0)
                return; // No analysis found

            // Create proepr items from loaded rows and add them to analysis
            foreach (DataRow row in dataSet.Tables[0].Rows)
            {
                string itemType = (string)row["Typ"];
                string relatedItemId = (string)row["PolozkaID"];

                object quantity = row["Mnozstvi"];
                decimal quantityPerUnit =
                    (quantity == null || quantity is System.DBNull)
                    ? 1
                    : Utilities.StringUtils.ParseDecimalFromString(quantity.ToString(), 1);

                object mainMU = row["CenikMJ"];
                string mainMeasuerUnit = (mainMU == null || mainMU is System.DBNull) ? string.Empty : mainMU.ToString();

                object itemMU = row["PolozkaMJ"];
                string itemMeasureUnit = (itemMU == null || itemMU is System.DBNull) ? string.Empty : itemMU.ToString();

                string usageMeasureUnit = Utilities.StringUtils.GetUsageMeasureUnit(
                            itemMeasureUnit,
                            mainMeasuerUnit
                        ); ;

                // Create proper item
                switch (itemType)
                {
                    case "Cenik":
                        break; // Main item is not part of its own analysis

                    case "Dodavka":
                        DeliveryItem delivery = new DeliveryItem(
                            GetRelatedItemByAnalysis(
                                databaseConnection,
                                Properties.Resources.VIEW_DELIVERIES,
                                relatedItemId
                            )
                        );
                        delivery.Usage = quantityPerUnit;
                        delivery.UsageMeasureUnit = usageMeasureUnit;

                        AddAnalysisItem(delivery);
                        break;

                    case "Material":
                        MaterialItem material = new MaterialItem(
                            GetRelatedItemByAnalysis(
                                databaseConnection,
                                Properties.Resources.VIEW_MATERIALS,
                                relatedItemId
                            )
                        );
                        material.Usage = quantityPerUnit;
                        material.UsageMeasureUnit = usageMeasureUnit;

                        AddAnalysisItem(material);
                        break;

                    case "Prace":
                        object work = row["PopisPrace"];
                        string workDescritpion = (work == null || work is System.DBNull) ? string.Empty : work.ToString();

                        WorkItem workitem = new WorkItem(
                            GetRelatedItemByAnalysis(
                                databaseConnection,
                                Properties.Resources.VIEW_WORKS,
                                relatedItemId
                            )
                        );
                        workitem.Usage = quantityPerUnit;
                        workitem.WorkDescription = workDescritpion;
                        workitem.UsageMeasureUnit = usageMeasureUnit;

                        AddAnalysisItem(workitem);
                        break;

                    case "Stroj":
                        MachineItem machine = new MachineItem(
                            GetRelatedItemByAnalysis(
                                databaseConnection,
                                Properties.Resources.VIEW_MACHINES,
                                relatedItemId
                            )
                        );
                        machine.Usage = quantityPerUnit;
                        machine.UsageMeasureUnit = usageMeasureUnit;

                        AddAnalysisItem(machine);
                        break;

                    default:
                        throw new ArgumentException(
                            string.Format(
                                Properties.Resources.ERROR_WRONG_ANALISYS_ITEM_TYPE_FORMATED,
                                itemType
                            )
                        );
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Add new material to existing hashtable with materials.
        /// If material is new add it to hashtable, 
        /// if material already is in hashtable, just sum their quantities (and quantity expressions)
        /// </summary>
        /// <param name="materials">Material hashtable (key = MaterialID, Value = Material)</param>
        /// <param name="material">Material to add to hashtable</param>
        /// <param name="constructionName">Construction name needed when quantities are summed for quantity expression</param>
        protected void AddMaterialToHashTable(Hashtable materials, MaterialItem material, string constructionName)
        {
            if (materials == null)
                return;

            string key = material.ID.Trim();

            if (materials.ContainsKey(key))
            {
                // Add quantity to existing material
                decimal originalQuantity = ((MaterialItem)materials[key]).Quantity;
                decimal newMaterialQuantity = material.Quantity;

                // Update their sum
                ((MaterialItem)materials[key]).Quantity =
                    originalQuantity + newMaterialQuantity;
            }
            else
            {
                // Add new material
                materials.Add(key, material);
            }
        }
Пример #3
0
        /// 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;
        }
Пример #4
0
        /// <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;
        }
Пример #5
0
        /// <summary>
        /// Sets material usage based on parameters
        /// </summary>
        /// <param name="material">Material to update</param>
        /// <param name="board">Sdk contstruction board</param>
        /// <param name="dimension">Specify the part of SDK construction material belongs to</param>
        /// <param name="usage">Usage for material quantity</param>
        private void SetSdkMaterialUsage(MaterialItem material, SdkBoard board, string dimension, decimal usage)
        {
            // Switch needs constants expressions in case, that is why can not be used

            decimal quantity = 0;
            // Quantity is based on dimension (type of construction) ...
            if (dimension.Equals(Properties.Resources.HTK_SDK_SURFACE_NO_IMPREGNATION))
            {
                quantity =
                    2 * board.SdkSurface_NoImpregnation
                    + board.SdkSurface_OneSideImpregnation;
                quantity /= 10000; //cm2 -> m2
            }
            else
                if (dimension.Equals(Properties.Resources.HTK_SDK_SURFACE_WITH_IMPREGNATION))
                {
                    quantity =
                        board.SdkSurface_OneSideImpregnation
                        + 2 * board.SdkSurface_BothSideImpregnation;
                    quantity /= 10000; //cm2 -> m2
                }
                else
                    if (dimension.Equals(Properties.Resources.HTK_SDK_BASE_FLOOR))
                    {
                        quantity = board.BaseAtFloor;
                        quantity /= 100; //cm -> m
                    }
                    else
                        if (dimension.Equals(Properties.Resources.HTK_SDK_VERTICAL_TRANSOM))
                        {
                            quantity = (decimal)board.VerticalTransomCount;
                        }
                        else
                            if (dimension.Equals(Properties.Resources.HTK_SDK_BASE_DOOR))
                            {
                                quantity = (decimal)board.DoorsWidth;
                                quantity /= 10; //cm -> m
                            }
                            else
                                if (dimension.Equals(Properties.Resources.HTK_SDK_END_ROOF))
                                {
                                    quantity = board.EndingAtRoof;
                                    quantity /= 10; //cm -> m
                                }
                                else
                                    if (dimension.Equals(Properties.Resources.HTK_SDK_END_CORNER))
                                    {
                                        quantity = (decimal)board.EndingAtCorner;
                                        quantity /= 10; //cm -> m
                                    }
                                    else
                                        if (dimension.Equals(Properties.Resources.HTK_SDK_END_WALL))
                                        {
                                            quantity = (decimal)board.EndingAtWall;
                                            quantity /= 10; //cm -> m
                                        }
                                        else
                                            if (dimension.Equals(Properties.Resources.HTK_SDK_OVERLAY))
                                            {
                                                quantity = (decimal)(board.DoorsOverlay + board.WindowsOverlay);
                                                quantity /= 10; //cm -> m
                                            }
                                            else
                                                if (dimension.Equals(Properties.Resources.HTK_SDK_VERTICAL_EDGES))
                                                {
                                                    quantity = (decimal)(board.WindowsEdgesToBeBought + board.DoorsEdgesToBeBought);
                                                }
                                                else
                                                {
                                                    quantity = 0;
                                                }

            // Save quantity
            material.Usage = quantity * usage;
        }
Пример #6
0
        /// <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;
        }