示例#1
0
        /// <summary>
        /// Loads currently selected (or new) construction data
        /// </summary>
        private void LoadCurrentConstruction()
        {
            bool isNew = false;

            if (this.currentConstruction == null)
            {
                this.currentConstruction = new SdkConstruction();

                isNew = true;
            }

            this.tbx_GroupName.Text = isNew ? string.Empty : this.currentConstruction.Name;

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

            // Spacing has default value for new item
            this.tbx_Spacing.Text =
                (isNew)
                ? Karafa.Properties.Settings.Default.DefaultSpacing.ToString()
                : this.currentConstruction.Spacing.ToString();

            // LoadBoards
            this.currentSdkBoards = this.currentConstruction.SdkBoards;
            RefreshDatagrid(this.dg_Boards, this.currentConstruction.SdkBoards);
        }
示例#2
0
        /// <summary>
        /// Loads 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
                && this.dg_Constructions.SelectedItem is SdkConstruction)
            {
                //Load selected SDK construction
                this.currentConstruction = (SdkConstruction)this.dg_Constructions.SelectedItem;

                // Load its settings
                LoadCurrentConstruction();

                // Go to tab to update construction
                SwitchTabs(this.CurrentTab, this.tab_Step2);
            }
        }
示例#3
0
        /// <summary>
        /// Creates new construction and jumps to next step
        /// </summary>
        /// <param name="nextStep">TabItem to jump after creation new construction</param>
        private void CreateNewConstruction(TabItem nextStep)
        {
            // Create new SDK Construction
            this.currentConstruction = null;

            // Load its settings
            LoadCurrentConstruction();

            // Draw default SDk shapes
            this.IsResultValid = DrawDefaultShapes();

            // Go to step 1 to edit new construction
            SwitchTabs(CurrentTab, nextStep);
        }
示例#4
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;
        }
示例#5
0
        /// <summary>
        /// Gets total surface quantity and expression to count it
        /// </summary>
        /// <param name="construction">Construction to process</param>
        /// <param name="quantity">Total surface quantity</param>
        /// <param name="expession">Expression for all boards</param>
        private void CountSurface(SdkConstruction construction, out decimal quantity, ref string expession)
        {
            quantity = 0;

            foreach (SdkBoard board in construction.SdkBoards)
            {
                // Compose expression quantity
                expession +=
                    string.Format(
                        "\"{0}:\" {1} \"{2} {3}\"\n",
                        board.Name,
                        Utilities.StringUtils.FormatQuantityAsFloat(board.SdkSurfaceWithoutDoorsAndWIndows / 10000),
                        Properties.Resources.LABEL_SDK_IMPREGNATION,
                        SdkImpregnationEnumTranslator.GetTranslatedEnumName(board.Impregnation)
                    );

                // Add surfaces to total surface
                quantity += board.SdkSurfaceWithoutDoorsAndWIndows / 10000;
            }
        }
        /// <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 UpdateSdkConstructionMainItem(DatabaseConnection connection, SdkConstruction construction)
        {
            // Get index of Constructions -> MainItem is on the same index
            int index =
                this.SdkConstructions == null
                ? -1
                : this.SdkConstructions.IndexOf(construction);

            // Get new Main Item
            MainItem result = new SdkModule(null).CalculateConstruction(connection, construction, index);

            // New item
            if (index == -1)
            {
                this.SdkConstructions.Add(construction);
                this.SdkMainItems.Add(result);
                return;
            }

            // Old result
            this.SdkMainItems[index] = result;
        }
        /// <summary>
        /// Removes given SDK construction
        /// </summary>
        /// <param name="construction">Construction to remove</param>
        /// <returns>Returns corresponding MainItem</returns>
        public MainItem RemoveSdkConstruction(SdkConstruction construction)
        {
            int index = this.SdkConstructions.IndexOf(construction);

            if (index != -1)
            {
                // Remove construction and MainItem from proepr lists
                this.SdkConstructions.Remove(construction);
                MainItem item = this.SdkMainItems[index];
                this.SdkMainItems.Remove(item);

                return item;
            }

            return null;
        }