private void SetKey(IntercoLogicalKey key)
 {
     this.IdProject = key.IdProject;
     this.IdPhase   = key.IdPhase;
     this.IdWP      = key.IdWP;
     this.WPCode    = key.WPCode;
 }
Esempio n. 2
0
        public static IntercoLogicalKey GetKey(DataRow row)
        {
            IntercoLogicalKey key = new IntercoLogicalKey();

            try
            {
                key.IdProject = (int)row["IdProject"];
                key.IdPhase   = (int)row["IdPhase"];
                key.IdWP      = (int)row["IdWP"];
            }
            catch (Exception ex)
            {
                throw new IndException(ex);
            }
            return(key);
        }
Esempio n. 3
0
        public static IntercoLogicalKey GetKey(TimingAndInterco intreco)
        {
            IntercoLogicalKey key = new IntercoLogicalKey();

            try
            {
                key.IdProject = intreco.IdProject;
                key.IdPhase   = intreco.IdPhase;
                key.IdWP      = intreco.IdWP;
            }
            catch (Exception ex)
            {
                throw new IndException(ex);
            }
            return(key);
        }
Esempio n. 4
0
        public static IntercoLogicalKey GetKey(int rowIndex, DataTable table)
        {
            if (table.Rows.Count <= rowIndex)
            {
                return(new IntercoLogicalKey());
            }

            IntercoLogicalKey key = new IntercoLogicalKey();

            try
            {
                DataRow row = table.Rows[rowIndex];
                key.IdProject = (int)row["IdProject"];
                key.IdPhase   = (int)row["IdPhase"];
                key.IdWP      = (int)row["IdWP"];
            }
            catch (Exception ex)
            {
                throw new IndException(ex);
            }
            return(key);
        }
Esempio n. 5
0
        private DataSet TransformIntercoDS(DataSet originalDS)
        {
            DataSet newDS = new DataSet();

            newDS.Tables.Add(originalDS.Tables[0].Copy());
            DataTable phasesTable = newDS.Tables[0];

            foreach (DataRow row in phasesTable.Rows)
            {
                row["PhaseCode"] = row["PhaseCode"] + " - " + row["PhaseName"];
            }

            DataTable countriesTable = this.GetEntity().GetCustomDataSet("GetWPIntercoCountries", this).Tables[0];

            //Get the table that has as columns the final first three columns of the result table
            DataTable structureTable = originalDS.Tables[1];

            DataTable valuesTable = originalDS.Tables[2];

            DataTable resultTable = new DataTable();

            #region Build Final Table and Phases Table Structure
            //Add the first three columns
            resultTable.Columns.Add(new DataColumn("IdProject", typeof(int)));
            resultTable.Columns.Add(new DataColumn("IdPhase", typeof(int)));
            resultTable.Columns.Add(new DataColumn("PhaseCode", typeof(string)));
            resultTable.Columns.Add(new DataColumn("IdWP", typeof(int)));
            resultTable.Columns.Add(new DataColumn("WPCode", typeof(string)));
            //Add the Total Column
            resultTable.Columns.Add(new DataColumn("HasBudget", typeof(bool)));
            resultTable.Columns.Add(new DataColumn("Total", typeof(decimal)));


            //Add the Total Column
            phasesTable.Columns.Add(new DataColumn("Total", typeof(decimal)));

            //Add the countries columns
            foreach (DataRow row in countriesTable.Rows)
            {
                string     countryName = row["CountryName"].ToString();
                int        countryId   = (int)row["IdCountry"];
                DataColumn countryCol  = new DataColumn(countryId.ToString(), typeof(decimal));
                countryCol.Caption      = countryName;
                countryCol.DefaultValue = "0.00";
                resultTable.Columns.Add(countryCol);

                countryCol         = new DataColumn(countryId.ToString(), typeof(decimal));
                countryCol.Caption = countryName;
                phasesTable.Columns.Add(countryCol);
            }
            #endregion Build Final Table Structure

            #region Add Rows int he Final Table Structure
            //this will add values only in the first three columns of each row
            foreach (DataRow row in structureTable.Rows)
            {
                DataRow newRow = resultTable.NewRow();
                newRow["IdProject"] = row["IdProject"];
                newRow["IdPhase"]   = row["IdPhase"];
                newRow["PhaseCode"] = row["PhaseCode"];
                newRow["IdWP"]      = row["IdWP"];
                //newRow["WPCode"] = row["WPCode"];
                newRow["WPCode"]    = row["WPCode"] + " - " + row["WPName"];
                newRow["HasBudget"] = row["HasBudget"];
                resultTable.Rows.Add(newRow);
            }
            #endregion Add Rows int he Final Table Structure

            #region Fill final DS with Interco values
            int resultIterator = 0;
            int valuesIterator = 0;
            while ((valuesIterator < valuesTable.Rows.Count) && (resultIterator < resultTable.Rows.Count))
            {
                IntercoLogicalKey resultKey = GetKey(resultIterator, resultTable);
                IntercoLogicalKey valuesKey = GetKey(valuesIterator, valuesTable);
                if (IntercoLogicalKey.AreKeysEqual(resultKey, valuesKey) && (!resultKey.IsNull()))
                {
                    //Fills the value from the value table in the result table
                    DataRow valuesRow = valuesTable.Rows[valuesIterator];
                    int     idCountry = (int)valuesRow["IdCountry"];
                    decimal percent   = (decimal)valuesRow["Percent"];

                    DataRow resultRow = resultTable.Rows[resultIterator];
                    resultRow.BeginEdit();
                    resultRow[idCountry.ToString()] = percent;
                    resultRow.EndEdit();
                    valuesIterator++;
                }
                else
                {
                    resultIterator++;
                }
            }
            #endregion Fill final DS with Interco values

            string expression = "";
            for (int i = FirstCountryColumn; i < resultTable.Columns.Count; i++)
            {
                DataColumn col = resultTable.Columns[i];
                if (col.ColumnName != "IsChanged")
                {
                    expression += "IsNull([" + col.ColumnName + "],0)+";
                }
            }
            if (expression != "")
            {
                resultTable.Columns["Total"].Expression = expression.Substring(0, expression.Length - 1);
            }

            resultTable.AcceptChanges();

            newDS.Tables.Add(resultTable);
            newDS.Tables[1].DefaultView.Sort = "PhaseCode,WPCode";
            newDS.AcceptChanges();
            return(newDS);
        }