Exemplo n.º 1
0
        /// <summary>
        /// This Method calls the ApplyRules()
        /// </summary>
        /// <returns>
        /// Output data table from ApplyRules() .
        /// </returns>
        public static DataTable CalculateRuleSets(IRuleSets objIRuleSets)
        {
            //IntialiseOutputDatatable();

            //Assign the Value through Interface Members
            dtInput = objIRuleSets.DtInput;
            //sunRise = objIRuleSets.SunRise;
            //sunSet = objIRuleSets.SunSet;
            dtOutput = objIRuleSets.DtOutput;

            DELTAT = getColumnName(dtInput.Columns, "deltat");

            DataTable dt = ApplyRules();

            return dt;
        }
Exemplo n.º 2
0
        /// <summary>
        /// This Method calls the ApplyRules()
        /// </summary>
        /// <returns>
        /// Output data table from ApplyRules() .
        /// </returns>
        public static DataTable CalculateRuleSets(IRuleSets objIRuleSets)
        {
            //IntialiseOutputDatatable();

            //Assign the Value through Interface Members
            dtInputRaw = objIRuleSets.DtInput;
            startDate = objIRuleSets.StartDate;
            endDate = objIRuleSets.EndDate;
            dtOutput = objIRuleSets.DtOutput;
            sunRise = objIRuleSets.SunRise;
            sunSet = objIRuleSets.SunSet;

            //One day data= data from 1 am of current date to 12am of next daya
            //for eg. 17/5/2012 data = 17/5/2012 1:00:00 am to 18/5/2012 12:00:00 am
            dtInput = dtInputRaw.Select("" + DATE + " >= '" + startDate.AddHours(1) + "' and " + DATE + " <='" + endDate + "'").CopyToDataTable();

            //Check if all the required data is present
            PRECIPTYPE = getColumnName(dtInput.Columns, "PrecipType");

            DataTable dt = ApplyRules();

            return dt;
        }
Exemplo n.º 3
0
        public static DataTable CalculateRuleSets(IRuleSets objIRuleSets)
        {
            //IntialiseOutputDatatable();

            //Assign the Value through Interface Members
            dtInputRaw = objIRuleSets.DtInput;
            sunRise = objIRuleSets.SunRise;
            sunSet = objIRuleSets.SunSet;
            startDate = objIRuleSets.StartDate;
            endDate = objIRuleSets.EndDate;

            dtOutput = objIRuleSets.DtOutput;

            //Filter the Raw Data and extract only the data between start and end dates
            //One day data= data from 1 am of current date to 12am of next daya
            //for eg. 17/5/2012 data = 17/5/2012 1:00:00 am to 18/5/2012 12:00:00 am
            dtInput = dtInputRaw.Select("" + DATE + " >= '" + startDate.AddHours(1) + "' and " + DATE + " <='" + endDate + "'").CopyToDataTable();

            PRECIP = getColumnName(dtInput.Columns, "PrecipAmount");
            TEMPAIR = getColumnName(dtInput.Columns, "TempAir");
            HUMIDITY = getColumnName(dtInput.Columns, "Humidity");
            WIND_SPEED = getColumnName(dtInput.Columns, "WindSpeed_");
            WIND_GUST = getColumnName(dtInput.Columns, "WindSpeedMax");

            DataTable dt = ApplyRules();

            return dt;
        }
Exemplo n.º 4
0
        public void GetRulesetData(string ruleset, IRuleSets IRule)
        {
            try
            {
                switch (ruleset.ToLower())
                {
                    case "rs_bruchid":
                        if (IRule.DtInput != null && IRule.DtInput.Rows.Count != 0)
                            IRule.DtOutput = RS_Bruchid.CalculateRuleSets(IRule);
                        else
                        {
                            sHours = RS_Bruchid.StartHours;
                            eHours = RS_Bruchid.EndHours;
                            RulesetList = RS_Bruchid.RulesetSeriesList;
                        }
                        break;
                    case "rs_deltat":
                        if (IRule.DtInput != null && IRule.DtInput.Rows.Count != 0)
                            IRule.DtOutput = RS_DeltaT.CalculateRuleSets(IRule);
                        else
                        {
                            sHours = RS_DeltaT.StartHours;
                            eHours = RS_DeltaT.EndHours;
                            RulesetList = RS_DeltaT.RulesetSeriesList;
                        }
                        break;
                    case "rs_disease_potato_smith":
                        if (IRule.DtInput != null && IRule.DtInput.Rows.Count != 0)
                            IRule.DtOutput = RS_Disease_Potato_Smith.CalculateRuleSets(IRule);
                        else
                        {
                            sHours = RS_Disease_Potato_Smith.StartHours;
                            eHours = RS_Disease_Potato_Smith.EndHours;
                            RulesetList = RS_Disease_Potato_Smith.RulesetSeriesList;
                        }
                        break;
                    case "rs_earlyblight":
                        if (IRule.DtInput != null && IRule.DtInput.Rows.Count != 0)
                            IRule.DtOutput = RS_EarlyBlight.CalculateRuleSets(IRule);
                        else
                        {
                            sHours = RS_EarlyBlight.StartHours;
                            eHours = RS_EarlyBlight.EndHours;
                            RulesetList = RS_EarlyBlight.RulesetSeriesList;
                        }
                        break;
                    case "rs_frosttext":
                        if (IRule.DtInput != null && IRule.DtInput.Rows.Count != 0)
                            IRule.DtOutput = RS_FrostText.CalculateRuleSets(IRule);
                        else
                        {
                            sHours = RS_FrostText.StartHours;
                            eHours = RS_FrostText.EndHours;
                            RulesetList = RS_FrostText.RulesetSeriesList;
                        }
                        break;
                    case "rs_harvest":
                        if (IRule.DtInput != null && IRule.DtInput.Rows.Count != 0)
                            IRule.DtOutput = RS_Harvest.CalculateRuleSets(IRule);
                        else
                        {
                            sHours = RS_Harvest.StartHours;
                            eHours = RS_Harvest.EndHours;
                            RulesetList = RS_Harvest.RulesetSeriesList;
                        }
                        break;
                    case "rs_plant_cotton":
                        if (IRule.DtInput != null && IRule.DtInput.Rows.Count != 0)
                            IRule.DtOutput = RS_Plant_Cotton.CalculateRuleSets(IRule);
                        else
                        {
                            sHours = RS_Plant_Cotton.StartHours;
                            eHours = RS_Plant_Cotton.EndHours;
                            RulesetList = RS_Plant_Cotton.RulesetSeriesList;
                        }
                        break;
                    case "rs_plant_maize":
                        if (IRule.DtInput != null && IRule.DtInput.Rows.Count != 0)
                            IRule.DtOutput = RS_Plant_Maize.CalculateRuleSets(IRule);
                        else
                        {
                            sHours = RS_Plant_Maize.StartHours;
                            eHours = RS_Plant_Maize.EndHours;
                            RulesetList = RS_Plant_Maize.RulesetSeriesList;
                        }
                        break;
                    case "rs_plant_maize_heavy":
                        if (IRule.DtInput != null && IRule.DtInput.Rows.Count != 0)
                            IRule.DtOutput = RS_Plant_Maize_Heavy.CalculateRuleSets(IRule);
                        else
                        {
                            sHours = RS_Plant_Maize_Heavy.StartHours;
                            eHours = RS_Plant_Maize_Heavy.EndHours;
                            RulesetList = RS_Plant_Maize_Heavy.RulesetSeriesList;
                        }
                        break;
                    case "rs_plant_maize_light":
                        if (IRule.DtInput != null && IRule.DtInput.Rows.Count != 0)
                            IRule.DtOutput = RS_Plant_Maize_Light.CalculateRuleSets(IRule);
                        else
                        {
                            sHours = RS_Plant_Maize_Light.StartHours;
                            eHours = RS_Plant_Maize_Light.EndHours;
                            RulesetList = RS_Plant_Maize_Light.RulesetSeriesList;
                        }
                        break;
                    case "rs_plant_maize_medium":
                        if (IRule.DtInput != null && IRule.DtInput.Rows.Count != 0)
                            IRule.DtOutput = RS_Plant_Maize_Medium.CalculateRuleSets(IRule);
                        else
                        {
                            sHours = RS_Plant_Maize_Medium.StartHours;
                            eHours = RS_Plant_Maize_Medium.EndHours;
                            RulesetList = RS_Plant_Maize_Medium.RulesetSeriesList;
                        }
                        break;
                    case "rs_plant_sorghum":
                        if (IRule.DtInput != null && IRule.DtInput.Rows.Count != 0)
                            IRule.DtOutput = RS_Plant_Sorghum.CalculateRuleSets(IRule);
                        else
                        {
                            sHours = RS_Plant_Sorghum.StartHours;
                            eHours = RS_Plant_Sorghum.EndHours;
                            RulesetList = RS_Plant_Sorghum.RulesetSeriesList;
                        }
                        break;
                    case "rs_plant_sugarbeet_heavy":
                        if (IRule.DtInput != null && IRule.DtInput.Rows.Count != 0)
                            IRule.DtOutput = RS_Plant_Sugarbeet_Heavy.CalculateRuleSets(IRule);
                        else
                        {
                            sHours = RS_Plant_Sugarbeet_Heavy.StartHours;
                            eHours = RS_Plant_Sugarbeet_Heavy.EndHours;
                            RulesetList = RS_Plant_Sugarbeet_Heavy.RulesetSeriesList;
                        }
                        break;
                    case "rs_plant_sugarbeet_light":
                        if (IRule.DtInput != null && IRule.DtInput.Rows.Count != 0)
                            IRule.DtOutput = RS_Plant_Sugarbeet_Light.CalculateRuleSets(IRule);
                        else
                        {
                            sHours = RS_Plant_Sugarbeet_Light.StartHours;
                            eHours = RS_Plant_Sugarbeet_Light.EndHours;
                            RulesetList = RS_Plant_Sugarbeet_Light.RulesetSeriesList;
                        }
                        break;
                    case "rs_plant_sugarbeet_medium":
                        if (IRule.DtInput != null && IRule.DtInput.Rows.Count != 0)
                            IRule.DtOutput = RS_Plant_Sugarbeet_Medium.CalculateRuleSets(IRule);
                        else
                        {
                            sHours = RS_Plant_Sugarbeet_Medium.StartHours;
                            eHours = RS_Plant_Sugarbeet_Medium.EndHours;
                            RulesetList = RS_Plant_Sugarbeet_Medium.RulesetSeriesList;
                        }
                        break;
                    case "rs_preciptype":
                        if (IRule.DtInput != null && IRule.DtInput.Rows.Count != 0)
                            IRule.DtOutput = RS_PrecipType.CalculateRuleSets(IRule);
                        else
                        {
                            sHours = RS_PrecipType.StartHours;
                            eHours = RS_PrecipType.EndHours;
                            RulesetList = RS_PrecipType.RulesetSeriesList;
                        }
                        break;
                    case "rs_runoff":
                        if (IRule.DtInput != null && IRule.DtInput.Rows.Count != 0)
                            IRule.DtOutput = RS_RunOff.CalculateRuleSets(IRule);
                        else
                        {
                            sHours = RS_RunOff.StartHours;
                            eHours = RS_RunOff.EndHours;
                            RulesetList = RS_RunOff.RulesetSeriesList;
                        }
                        break;
                    case "rs_severeweathere":
                        if (IRule.DtInput != null && IRule.DtInput.Rows.Count != 0)
                            IRule.DtOutput = RS_SevereWeathere.CalculateRuleSets(IRule);
                        else
                        {
                            sHours = RS_SevereWeathere.StartHours;
                            eHours = RS_SevereWeathere.EndHours;
                            RulesetList = RS_SevereWeathere.RulesetSeriesList;
                        }
                        break;
                    case "sw_aerialspraygeneric":
                        if (IRule.DtInput != null && IRule.DtInput.Rows.Count != 0)
                            IRule.DtOutput = SW_AerialSprayGeneric.CalculateRuleSets(IRule);
                        else
                        {
                            sHours = SW_AerialSprayGeneric.StartHours;
                            eHours = SW_AerialSprayGeneric.EndHours;
                            RulesetList = SW_AerialSprayGeneric.RulesetSeriesList;
                        }
                        break;
                    case "sw_groundsprayfungicide":
                        if (IRule.DtInput != null && IRule.DtInput.Rows.Count != 0)
                            IRule.DtOutput = SW_GroundSprayFungicide.CalculateRuleSets(IRule);
                        else
                        {
                            sHours = SW_GroundSprayFungicide.StartHours;
                            eHours = SW_GroundSprayFungicide.EndHours;
                            RulesetList = SW_GroundSprayFungicide.RulesetSeriesList;
                        }
                        break;
                    case "sw_groundspraygeneric":
                        if (IRule.DtInput != null && IRule.DtInput.Rows.Count != 0)
                            IRule.DtOutput = SW_GroundSprayGeneric.CalculateRuleSets(IRule);
                        else
                        {
                            sHours = SW_GroundSprayGeneric.StartHours;
                            eHours = SW_GroundSprayGeneric.EndHours;
                            RulesetList = SW_GroundSprayGeneric.RulesetSeriesList;
                        }
                        break;
                    case "sw_groundsprayclomazone":
                        if (IRule.DtInput != null && IRule.DtInput.Rows.Count != 0)
                            IRule.DtOutput = SW_GroundSprayGenericClomazone.CalculateRuleSets(IRule);
                        else
                        {
                            sHours = SW_GroundSprayGenericClomazone.StartHours;
                            eHours = SW_GroundSprayGenericClomazone.EndHours;
                            RulesetList = SW_GroundSprayGenericClomazone.RulesetSeriesList;
                        }
                        break;

                    case "sw_groundsprayherbicide_ld":
                        if (IRule.DtInput != null && IRule.DtInput.Rows.Count != 0)
                            IRule.DtOutput = SW_GroundSprayHerbicide_LD.CalculateRuleSets(IRule);
                        else
                        {
                            sHours = SW_GroundSprayHerbicide_LD.StartHours;
                            eHours = SW_GroundSprayHerbicide_LD.EndHours;
                            RulesetList = SW_GroundSprayHerbicide_LD.RulesetSeriesList;
                        }
                        break;
                    case "sw_groundsprayherbicide_pe":
                        if (IRule.DtInput != null && IRule.DtInput.Rows.Count != 0)
                            IRule.DtOutput = SW_GroundSprayHerbicide_PE.CalculateRuleSets(IRule);
                        else
                        {
                            sHours = SW_GroundSprayHerbicide_PE.StartHours;
                            eHours = SW_GroundSprayHerbicide_PE.EndHours;
                            RulesetList = SW_GroundSprayHerbicide_PE.RulesetSeriesList;
                        }
                        break;
                    case "sw_groundsprayherbicide_sd":
                        if (IRule.DtInput != null && IRule.DtInput.Rows.Count != 0)
                            IRule.DtOutput = SW_GroundSprayHerbicide_SD.CalculateRuleSets(IRule);
                        else
                        {
                            sHours = SW_GroundSprayHerbicide_SD.StartHours;
                            eHours = SW_GroundSprayHerbicide_SD.EndHours;
                            RulesetList = SW_GroundSprayHerbicide_SD.RulesetSeriesList;
                        }
                        break;
                    case "sw_groundsprayvineandtree":
                        if (IRule.DtInput != null && IRule.DtInput.Rows.Count != 0)
                            IRule.DtOutput = SW_GroundSprayVineAndTree.CalculateRuleSets(IRule);
                        else
                        {
                            sHours = SW_GroundSprayVineAndTree.StartHours;
                            eHours = SW_GroundSprayVineAndTree.EndHours;
                            RulesetList = SW_GroundSprayVineAndTree.RulesetSeriesList;
                        }
                        break;

                    /*French Mobile Site - New RuleSet - Begin*/
                    case "sw_ground_frcp01":
                        if (IRule.DtInput != null && IRule.DtInput.Rows.Count != 0)
                            IRule.DtOutput = SW_Ground_frcp01.CalculateRuleSets(IRule);

                        else
                        {
                            sHours = SW_Ground_frcp01.StartHours;
                            eHours = SW_Ground_frcp01.EndHours;
                            RulesetList = SW_Ground_frcp01.RulesetSeriesList;
                        }
                        break;

                    /*French Mobile Site - New RuleSet - End*/
                }
            }

            catch (Exception ex)
            {
                AgriCastException currEx = new AgriCastException(objSvcPre.GetServiceDetails(), ex);
                AgriCastLogger.Publish(currEx, AgriCastLogger.LogType.Error);
                HttpContext.Current.Session["ErrorMessage"] = objComUtil.getTransText(Constants.TAB_RULESETLOAD_FAILURE) + ex.Message.ToString();
            }
        }
Exemplo n.º 5
0
        public void GetCompleteRuleset(string name, string allign, string aggregation, string datasource, int start, int end, string ruleset, string pallette, string Nodename, IRuleSets IRobj)
        {
            try
            {
                if (IRobj != null)
                {
                    IRule = IRobj;
                }
                GetcompleteSeriesList(allign);
                GetTableSeries(allign);
                Itable.dtTableSeries = Itable.dsSeriesData.Tables[0];
                Itable.dtTableLegends = Itable.dsSeriesData.Tables[1];

                //Getting start hours and end hours(to fetch extra data)
                GetRulesetData(ruleset, IRule);
                GetSeriesData(RulesetList, aggregation, datasource, start, end, sHours, eHours);

                DataTable dtByDays = Itable.dtSeries;

                DataColumn dc = new DataColumn();
                dc.ColumnName = getTranslatedText(FIRSTCOLNAME, objSvcInfo.Culture);
                dc.DefaultValue = null;
                dtByDays.Columns.Add(dc);

                int LastColIndex = dtByDays.Columns.Count - 1;
                for (int i = 0; i < dtByDays.Rows.Count; i++)
                {
                    DateTime Date = Convert.ToDateTime(dtByDays.Rows[i][0].ToString());
                    dtByDays.Rows[i][LastColIndex] = Date.Hour;
                }
                IRule.DtInput = dtByDays;

                IRule.StartDate = System.DateTime.Today.AddDays(start);
                IRule.EndDate = System.DateTime.Today.AddDays(end);
                if (IRule.StartDate > IRule.EndDate)
                {
                    DateTime tmp = IRule.StartDate;
                    IRule.StartDate = IRule.EndDate;
                    IRule.EndDate = tmp;
                }
                //if (start < end)
                //{
                //    IRule.StartDate = System.DateTime.Today.AddDays(start);
                //    IRule.EndDate = System.DateTime.Today.AddDays(end);
                //}
                //else
                //{
                //    IRule.StartDate = System.DateTime.Today.AddDays(end);
                //    IRule.EndDate = System.DateTime.Today.AddDays(start);

                //}

                ////Removing the last extra day at the end
                ////eg:- start 0, end 2 should get 2 days of data starting from current date
                //if (IRule.StartDate <= System.DateTime.Today && IRule.EndDate <= System.DateTime.Today)
                //{
                //    IRule.StartDate = IRule.StartDate.AddDays(1);
                //}
                //else
                //{
                //    IRule.EndDate = IRule.EndDate.AddDays(-1);
                //}

                GetRulesetData(ruleset, IRobj);

                //Itable.alSeries = new ArrayList();

                //for (int i = 1; i < LastColIndex; i++)
                //{
                //    Itable.alSeries.Add(dtByDays.Columns[i].ColumnName.ToString() + "," + Itable.dtTableSeries.Rows[i - 1][1].ToString() + "," + Itable.dtTableSeries.Rows[i - 1][0].ToString() + "," + Itable.dtTableSeries.Rows[i - 1][3].ToString());

                //}
            }
            catch (Exception ex)
            {
                AgriCastException currEx = new AgriCastException(objSvcPre.GetServiceDetails(), ex);
                AgriCastLogger.Publish(currEx, AgriCastLogger.LogType.Error);
                HttpContext.Current.Session["ErrorMessage"] = objComUtil.getTransText(Constants.TAB_RULESETLOAD_FAILURE) + ex.Message.ToString();

            }
        }
Exemplo n.º 6
0
        /*Unit Implementation in Web Services - End*/
        /*Unit Implementation in Web Services - Begin*/
        //Added a paramter strUnit
        public DataSet getTableDataForService(string allign, string name, IRuleSets IRobj, string strServiceName, string strModuleName, string strCul, string strUnit)
        {
            try
            {
                int step;
                const string THREEHOURLY = "3hourly";
                const string SIXHOURLY = "6hourly";
                const string EIGHTHOURLY = "8hourly";
                const string TWELVEHOURLY = "12hourly";
                const string HOURLY = "hourly";
                const string TBLDAYSROWS = "tblDaysRows";
                const string TBLSERIESROWS = "tblSeriesRows";
                string strDateFormat = "dddd M/dd";//Default format is  month/day

                DataSet dsTblSeries = new DataSet();
                DataTable dtTableSeries = new DataTable();
                DataTable dtSeriesData = new DataTable();
                DataSet dsTable = new DataSet();

                if (IRobj != null)
                {
                    IRule = IRobj;
                }

                strCulCode = strCul;
                objSvc.setSvcHandlerWebSvcValues(strServiceName, strModuleName);
                string strTblAttributes = objSvc.ReadAllignment(allign, name);
                int numOfDays = Convert.ToInt32(strTblAttributes.Split(',')[1]);
                string datasource = strTblAttributes.Split(',')[2];
                string aggregation = strTblAttributes.Split(',')[5];
                int start = Convert.ToInt32(strTblAttributes.Split(',')[3]);
                int end = Convert.ToInt32(strTblAttributes.Split(',')[4]);
                string ruleset = strTblAttributes.Split(',')[6];
                string pallette = strTblAttributes.Split(',')[7];
                string Nodename = strTblAttributes.Split(',')[8];

                /*IM01277709 - change in spray window. begin*/
                //if displayAMPM is specified , then the length will be 12
                string showAMPM = string.Empty;
                if (strTblAttributes.Split(',').Length == 12)
                    showAMPM = strTblAttributes.Split(',')[11];
                /*IM01277709 - change in spray window. END*/

                GetRulesetData(ruleset, IRule);
                List<string[]> alSeriesLegend = objSvc.getNodeList(allign);
                dsTblSeries = objSvc.GetTableSeries(allign, name);
                if (ruleset == string.Empty || ruleset == "")
                    dtTableSeries = dsTblSeries.Tables[0];
                else
                    dtTableSeries = RulesetList;

                /*Unit Implementation in Web Services - Begin*/
                if (dtTableSeries != null)
                {

                    dtTableSeries = objSvcPre.ChangeUnits(dtTableSeries, strUnit, string.Empty);
                }
                /*Unit Implementation in Web Services - End*/

                dtSeriesData = objTblSvc.GetSeriesData(dtTableSeries, aggregation, datasource, start, end, sHours, eHours);
                DataTable dtByDays = dtSeriesData;
                DataColumn dc = new DataColumn();
                dc.ColumnName = "";//FIRSTCOLNAME;
                dc.DefaultValue = null;
                dtByDays.Columns.Add(dc);

                if (ruleset == string.Empty || ruleset == "")
                {

                    int LastColIndex = dtByDays.Columns.Count - 1;
                    for (int i = 0; i < dtByDays.Rows.Count; i++)
                    {
                        DateTime Date = Convert.ToDateTime(dtByDays.Rows[i][0].ToString());
                        dtByDays.Rows[i][LastColIndex] = Date.Hour;
                    }

                    ArrayList alSeries = new ArrayList();

                    for (int i = 1; i < LastColIndex; i++)
                    {
                        alSeries.Add(dtByDays.Columns[i].ColumnName.ToString() + "," + dtTableSeries.Rows[i - 1][1].ToString() + "," + dtTableSeries.Rows[i - 1][0].ToString() + "," + dtTableSeries.Rows[i - 1][3].ToString());

                    }

                    if (allign.ToLower() == TBLDAYSROWS.ToLower())
                    {
                        if (aggregation.ToLower() == THREEHOURLY)
                        {
                            step = 3;
                        }
                        else if (aggregation.ToLower() == SIXHOURLY)
                        {
                            step = 6;
                        }
                        else if (aggregation.ToLower() == EIGHTHOURLY)
                        {
                            step = 8;
                        }
                        else if (aggregation.ToLower() == TWELVEHOURLY)
                        {
                            step = 12;
                        }
                        else if (aggregation.ToLower() == HOURLY)
                        {
                            step = 1;
                        }
                        else
                        {
                            step = 24;
                        }

                        foreach (string ser in alSeries)
                        {
                            string seriesPallette = ser.Split(',')[1].ToString();
                            string seriesName = ser.Split(',')[0].ToString();
                            string serie = ser.Split(',')[2].ToString();
                            /*IM01277709 - change in spray window. begin*/
                            //DataTable dtTrans = GenerateTransposedtblDaysRows(dtByDays, seriesName, aggregation, false, step);
                            DataTable dtTrans = GenerateTransposedtblDaysRows(dtByDays, seriesName, aggregation, false, step,showAMPM);
                            /*IM01277709 - change in spray window. end*/
                            if (dsTable.Tables.Count == 0 && step != 1)
                            {
                                dsTable.Tables.Add(getHeaderDetails(dtTrans, step));
                            }
                            PaletteMap objPm;
                            DataTable dtColor = new DataTable();
                            DataTable dt = new DataTable();
                            dt.TableName = getTranslatedText(ser.Split(',')[3], strCulCode); //"tbl" + seriesName;
                            DataRow dr;
                            if (seriesPallette.ToString() != "" && seriesPallette.ToLower() != "none")
                            {
                                objPm = createPallette(seriesPallette);

                                for (int k = 0; k < dtTrans.Rows.Count; k++)
                                {
                                    dr = dtColor.NewRow();
                                    for (int j = 0; j < dtTrans.Columns.Count; j++)
                                    {
                                        if (j > 0)
                                        {
                                            //Web service issue for French MobileSite - BEGIN*/
                                            //Color should always be added irrespective of whether the data is present or not.
                                            //"IF" block moved out of the null check statements.
                                            if (k == 0)
                                            {
                                                DataColumn dcColor = new DataColumn();
                                                dcColor.ColumnName = "Color" + (j - 1).ToString();
                                                dtColor.Columns.Add(dcColor);
                                            }
                                            //Web service issue for French MobileSite - END*/

                                            if (dtTrans.Rows[k][j].ToString() != "" && dtTrans.Rows[k][j].ToString() != "&nbsp;")
                                            {

                                                dr["Color" + (j - 1).ToString()] = objPm.getColor(Convert.ToDouble(dtTrans.Rows[k][j].ToString()), seriesName);
                                            }
                                        }

                                    }
                                    dtColor.Rows.Add(dr);
                                }
                            }
                            DataRow drTbl;
                            for (int m = 0; m < dtTrans.Rows.Count; m++)
                            {
                                drTbl = dt.NewRow();
                                for (int n = 0; n < (dtTrans.Columns.Count); n++)
                                {
                                    if (m == 0)
                                    {
                                        DataColumn dcVal = new DataColumn();
                                        DataColumn dcToolTip = new DataColumn();
                                        DataColumn dcColor = new DataColumn();
                                        dcVal.ColumnName = "Value" + n.ToString();
                                        dcToolTip.ColumnName = "ToolTip" + n.ToString();
                                        dcColor.ColumnName = "Color" + n.ToString();
                                        dt.Columns.Add(dcVal);
                                        dt.Columns.Add(dcToolTip);
                                        dt.Columns.Add(dcColor);
                                    }
                                    /* //Web service issue for French MobileSite - WS not working for non hourly configuration - BEGIN*/

                                    // drTbl["Value" + n.ToString()] = n == 0 ? dtTrans.Rows[m][n] : dtTrans.Rows[m][(n - 1).ToString()];
                                    drTbl["Value" + n.ToString()] = n == 0 ? dtTrans.Rows[m][n] : dtTrans.Rows[m][((n - 1) * step).ToString()];
                                    /*French mobile Site Web Service issue - WS not working for non hourly configuration - BEGIN*/

                                    drTbl["ToolTip" + n.ToString()] = "";
                                    if (dtColor.Rows.Count > 0)
                                        drTbl["Color" + n.ToString()] = n == 0 ? "" : dtColor.Rows[m]["Color" + (n - 1).ToString()];

                                    else
                                        drTbl["Color" + n.ToString()] = "";
                                }
                                dt.Rows.Add(drTbl);
                            }

                            //else
                            //{
                            //    dt = dtTrans;
                            //    dt.TableName = "tbl" + seriesName;
                            //}

                            dsTable.Tables.Add(dt);
                        }
                    }

                    else if (allign.ToLower() == TBLSERIESROWS.ToLower())
                    {
                        DataTable dtTransData = new DataTable();
                        PaletteMap objPm;

                        DataRow drColSeries;
                        //gvDynamic = new GridView();
                        if (aggregation.ToLower() != HOURLY)
                        {

                            if (aggregation.ToLower() == THREEHOURLY)
                            {
                                step = 3;
                            }
                            else if (aggregation.ToLower() == SIXHOURLY)
                            {
                                step = 6;
                            }
                            else if (aggregation.ToLower() == EIGHTHOURLY)
                            {
                                step = 8;
                            }
                            else if (aggregation.ToLower() == TWELVEHOURLY)
                            {
                                step = 12;
                            }
                            else
                            {
                                step = 24;
                            }
                            dtTransData = GenerateTransposedtblSeriesRows(dtByDays, numOfDays, aggregation, false, step);

                            if (dsTable.Tables.Count == 0 && step != 1)
                            {
                                dsTable.Tables.Add(getHeaderDetails(dtTransData, step));
                            }
                            string seriesPallette = "";
                            DataTable dtColorSeries = new DataTable();
                            for (int i = 0; i < dtTransData.Rows.Count; i++)
                            {
                                drColSeries = dtColorSeries.NewRow();
                                string serieName = dtTransData.Rows[i][0].ToString();
                                for (int j = 0; j < dtTransData.Columns.Count; j++)
                                {
                                    if (j == 0)
                                    {
                                        dtTransData.Rows[i][0] = getTranslatedText(alSeries[i].ToString().Split(',')[3], strCulCode);

                                    }

                                    if (j > 0)
                                    {
                                        foreach (string ser in alSeries)
                                        {
                                            if (ser.Split(',')[0].ToString() == serieName)
                                            {
                                                seriesPallette = ser.Split(',')[1].ToString();
                                                break;
                                            }

                                        }
                                        if (seriesPallette.ToString() != "" && seriesPallette.ToLower() != "none")
                                        {
                                            objPm = createPallette(seriesPallette);

                                            //Web service issue for French MobileSite - BEGIN*/
                                            //Changes made - the block below was moved out of if condition
                                            if (i == 0)
                                            {
                                                DataColumn dcColorSeries = new DataColumn();
                                                dcColorSeries.ColumnName = "Color" + j.ToString();
                                                dtColorSeries.Columns.Add(dcColorSeries);
                                            }
                                            //Web service issue for French MobileSite - END*/

                                            if (dtTransData.Rows[i][j].ToString() != "" && dtTransData.Rows[i][j].ToString() != "&nbsp;")
                                            {

                                                drColSeries["Color" + j.ToString()] = objPm.getColor(Convert.ToDouble(dtTransData.Rows[i][j].ToString()), dtTransData.Rows[i][0].ToString());

                                            }
                                        }
                                    }
                                }

                                dtColorSeries.Rows.Add(drColSeries);
                            }
                            DataTable dtTblSeries = new DataTable();
                            //dtTblSeries.TableName = "tbl_" + seriesName;
                            DataRow drTblSeries;
                            for (int m = 0; m < dtTransData.Rows.Count; m++)
                            {
                                drTblSeries = dtTblSeries.NewRow();
                                for (int n = 0; n < (dtTransData.Columns.Count); n++)
                                {
                                    if (m == 0)
                                    {
                                        DataColumn dcVal = new DataColumn();
                                        DataColumn dcToolTip = new DataColumn();
                                        DataColumn dcColor = new DataColumn();
                                        dcVal.ColumnName = "Value" + n.ToString();
                                        dcToolTip.ColumnName = "ToolTip" + n.ToString();
                                        dcColor.ColumnName = "Color" + n.ToString();
                                        dtTblSeries.Columns.Add(dcVal);
                                        dtTblSeries.Columns.Add(dcToolTip);
                                        dtTblSeries.Columns.Add(dcColor);
                                    }
                                    //if (n > 0)
                                    {
                                        drTblSeries["Value" + n.ToString()] = dtTransData.Rows[m][n];
                                        drTblSeries["ToolTip" + n.ToString()] = "";
                                        drTblSeries["Color" + n.ToString()] = n == 0 ? "" : dtColorSeries.Rows[m]["Color" + (n).ToString()];
                                    }
                                }
                                dtTblSeries.Rows.Add(drTblSeries);
                            }

                            dsTable.Tables.Add(dtTblSeries);
                        }

                        else
                        {
                            int k = 0;
                            int istep = 1;
                            while (k <= numOfDays)
                            {
                                if (start > end)
                                {
                                    int tmp = start;
                                    start = end;
                                    end = tmp;
                                }

                                dtTransData = GenerateTransposedtblSeriesRows(dtByDays, k, aggregation, false, istep);
                                if (dsTable.Tables.Count == 0)
                                {
                                    dsTable.Tables.Add(getHeaderDetails(dtTransData, istep));
                                }

                                string seriesPallette = "";
                                DataTable dtColorSeries = new DataTable();
                                for (int i = 0; i < dtTransData.Rows.Count; i++)
                                {
                                    drColSeries = dtColorSeries.NewRow();
                                    string serieName = dtTransData.Rows[i][0].ToString();
                                    for (int j = 0; j <= 24; j++)
                                    {
                                        if (j == 0)
                                        {
                                            dtTransData.Rows[i][0] = getTranslatedText(alSeries[i].ToString().Split(',')[3], strCulCode);

                                        }

                                        if (j > 0)
                                        {
                                            foreach (string ser in alSeries)
                                            {
                                                if (ser.Split(',')[0].ToString() == serieName)
                                                {
                                                    seriesPallette = ser.Split(',')[1].ToString();
                                                    break;
                                                }

                                            }
                                            if (seriesPallette.ToString() != "" && seriesPallette.ToLower() != "none")
                                            {
                                                objPm = createPallette(seriesPallette);
                                                if (dtTransData.Rows[i][j].ToString() != "" && dtTransData.Rows[i][j].ToString() != "&nbsp;")
                                                {
                                                    if (i == 0)
                                                    {
                                                        DataColumn dcColorSeries = new DataColumn();
                                                        dcColorSeries.ColumnName = "Color" + j.ToString();
                                                        dtColorSeries.Columns.Add(dcColorSeries);
                                                    }

                                                    drColSeries["Color" + j.ToString()] = objPm.getColor(Convert.ToDouble(dtTransData.Rows[i][j].ToString()), dtTransData.Rows[i][0].ToString());

                                                }
                                            }
                                        }
                                    }
                                    dtColorSeries.Rows.Add(drColSeries);
                                }
                                DataTable dtTblSeries = new DataTable();
                                //dtTblSeries.TableName = "tbl_" + seriesName;
                                DataRow drTblSeries;
                                for (int m = 0; m < dtTransData.Rows.Count; m++)
                                {
                                    drTblSeries = dtTblSeries.NewRow();
                                    for (int n = 0; n < (dtTransData.Columns.Count - 1); n++)
                                    {
                                        if (m == 0)
                                        {
                                            DataColumn dcVal = new DataColumn();
                                            DataColumn dcColor = new DataColumn();
                                            DataColumn dcToolTip = new DataColumn();
                                            dcVal.ColumnName = "Value" + n.ToString();
                                            dcToolTip.ColumnName = "ToolTip" + n.ToString();
                                            dcColor.ColumnName = "Color" + n.ToString();
                                            dtTblSeries.Columns.Add(dcVal);
                                            dtTblSeries.Columns.Add(dcToolTip);
                                            dtTblSeries.Columns.Add(dcColor);
                                        }
                                        drTblSeries["Value" + n.ToString()] = dtTransData.Rows[m][n.ToString()];
                                        drTblSeries["ToolTip" + n.ToString()] = "";
                                        drTblSeries["Color" + n.ToString()] = dtColorSeries.Rows[m]["Color" + (n + 1).ToString()];
                                    }
                                    dtTblSeries.Rows.Add(drTblSeries);
                                }
                                dsTable.Tables.Add(dtTblSeries);
                                k++;

                            }

                        }

                    }

                    return dsTable;
                }
                else
                {
                    PaletteMap objPm;
                    DataTable dtColorTooltip = new DataTable();
                    DataTable dtRuleSetData = new DataTable();
                    DataTable dtRSdata = new DataTable();
                    DataRow drRColor;
                    int LastColIndex = dtByDays.Columns.Count - 1;
                    for (int i = 0; i < dtByDays.Rows.Count; i++)
                    {
                        DateTime Date = Convert.ToDateTime(dtByDays.Rows[i][0].ToString());
                        dtByDays.Rows[i][LastColIndex] = Date.Hour;
                    }
                    IRule.DtInput = dtByDays;
                    if (start < end)
                    {
                        IRule.StartDate = System.DateTime.Today.AddDays(start);
                        IRule.EndDate = System.DateTime.Today.AddDays(end);
                    }
                    else
                    {
                        IRule.StartDate = System.DateTime.Today.AddDays(end);
                        IRule.EndDate = System.DateTime.Today.AddDays(start);

                    }

                    GetRulesetData(ruleset, IRobj);

                    //Itable.alSeries = new ArrayList();
                    ArrayList alSeries = new ArrayList();
                    for (int i = 1; i < LastColIndex; i++)
                    {
                        if (ruleset == string.Empty || ruleset == "")
                            alSeries.Add(dtByDays.Columns[i].ColumnName.ToString() + "," + dtTableSeries.Rows[i - 1][1].ToString() + "," + dtTableSeries.Rows[i - 1][0].ToString() + "," + dtTableSeries.Rows[i - 1][3].ToString());
                        else
                            alSeries.Add(dtByDays.Columns[i].ColumnName.ToString() + "," + dtTableSeries.Rows[i - 1][0].ToString());
                    }
                    if (allign.ToLower() == TBLDAYSROWS.ToLower())
                    {
                        /*IM01277709 - change in spray window. begin*/
                        //DataTable dtRulesetTrans = GenerateTransposedtblDaysRows(IRule.DtOutput, "value", aggregation, true, 1,showAMPM);
                        DataTable dtRulesetTrans = GenerateTransposedtblDaysRows(IRule.DtOutput, "value", aggregation, true, 1, showAMPM);
                        /*IM01277709 - change in spray window. end*/

                        objPm = createPallette(pallette);

                        for (int k = 0; k < dtRulesetTrans.Rows.Count; k++)
                        {
                            drRColor = dtColorTooltip.NewRow();
                            for (int j = 0; j < dtRulesetTrans.Columns.Count; j++)
                            {
                                if (j > 0)
                                {
                                    if (k == 0)
                                    {
                                        DataColumn dcColor = new DataColumn();
                                        dcColor.ColumnName = "Color" + (j - 1).ToString();
                                        dtColorTooltip.Columns.Add(dcColor);
                                        DataColumn dcToolTip = new DataColumn();
                                        dcToolTip.ColumnName = "ToolTip" + (j - 1).ToString();
                                        dtColorTooltip.Columns.Add(dcToolTip);
                                    }

                                    strDateFormat = VariantCulture.DateTimeFormat.ShortDatePattern;

                                    strDateFormat = "dddd " + strDateFormat.Substring(0, strDateFormat.Length - 5);

                                    ////check the culture code for "US" and change the date format
                                    //if (VariantCulture.ToString().Equals("en-US", StringComparison.InvariantCultureIgnoreCase))
                                    //    strDateFormat = VariantCulture.dateTimeInfo.ShortDatePattern.ToString().Substring(0, 5);//day/month format for US
                                    //else
                                    //    strDateFormat = "dddd M/dd";//month/day format for Non US

                                    var queryColor = from row in IRule.DtOutput.AsEnumerable()
                                                     where row.Field<string>("Day").Trim() == DateTime.ParseExact(HttpUtility.HtmlDecode(dtRulesetTrans.Rows[k][0].ToString()), strDateFormat, VariantCulture).ToShortDateString()
                                                                 && row.Field<string>("Hour").ToString(VariantCulture) == dtRulesetTrans.Columns[j].ColumnName
                                                     select row.Field<string>("ColorCode");
                                    if (queryColor.ToList().Count > 0 && queryColor.ToList()[0] != null && queryColor.ToList()[0] != "")
                                    {
                                        drRColor["Color" + (j - 1).ToString()] = objPm.getColor(Convert.ToDouble(queryColor.ToList()[0]), name);
                                    }

                                    var queryRestriction = from row in IRule.DtOutput.AsEnumerable()
                                                           where row.Field<string>("Day").Trim() == DateTime.ParseExact(HttpUtility.HtmlDecode(dtRulesetTrans.Rows[k][0].ToString()), strDateFormat, VariantCulture).ToShortDateString()
                                                    && row.Field<string>("Hour").ToString(VariantCulture) == dtRulesetTrans.Columns[j].ColumnName
                                                           select row.Field<string>("restrictions");

                                    if (queryRestriction.ToList().Count > 0 && queryRestriction.ToList()[0] != null)
                                    {
                                        string[] ToolTips = queryRestriction.ToList()[0].Split(',');
                                        string ToolTip = "";
                                        foreach (string restriction in ToolTips)
                                        {
                                            ToolTip = ToolTip + getTranslatedText(restriction, strCulCode) + ",";
                                        }
                                        ToolTip = ToolTip.Remove(ToolTip.LastIndexOf(','));

                                        drRColor["ToolTip" + (j - 1).ToString()] = ToolTip;
                                        //dtRulesetTrans.Rows[k][j].ToolTip = ToolTip.Remove(ToolTip.LastIndexOf(','));
                                    }
                                }

                            }
                            dtColorTooltip.Rows.Add(drRColor);
                        }
                        DataRow drTbl;
                        for (int m = 0; m < dtRulesetTrans.Rows.Count; m++)
                        {
                            drTbl = dtRSdata.NewRow();

                            if (m == 0)
                            {
                                DataColumn dcDate = new DataColumn();
                                dcDate.ColumnName = "Date";
                                dtRSdata.Columns.Add(dcDate);
                            }

                            for (int n = 0; n < (dtRulesetTrans.Columns.Count); n++)
                            {
                                if (m == 0)
                                {
                                    DataColumn dcVal = new DataColumn();
                                    DataColumn dcToolTip = new DataColumn();
                                    DataColumn dcColor = new DataColumn();
                                    dcVal.ColumnName = "Value" + n.ToString();
                                    dcToolTip.ColumnName = "ToolTip" + n.ToString();
                                    dcColor.ColumnName = "Color" + n.ToString();
                                    if (n != 0)
                                        dtRSdata.Columns.Add(dcVal);
                                    dtRSdata.Columns.Add(dcToolTip);
                                    dtRSdata.Columns.Add(dcColor);
                                }
                                if (n == 0)
                                {
                                    drTbl["Date"] = dtRulesetTrans.Rows[m][n];
                                    drTbl["ToolTip" + n.ToString()] = "";
                                    drTbl["Color" + n.ToString()] = "";
                                }
                                else
                                {
                                    drTbl["Value" + n.ToString()] = dtRulesetTrans.Rows[m][(n - 1).ToString()];
                                    drTbl["ToolTip" + n.ToString()] = dtColorTooltip.Rows[m]["ToolTip" + (n - 1).ToString()];
                                    drTbl["Color" + n.ToString()] = dtColorTooltip.Rows[m]["Color" + (n - 1).ToString()];
                                }
                            }
                            dtRSdata.Rows.Add(drTbl);
                        }
                        dsTable.Tables.Add(dtRSdata);
                    }
                    return dsTable;
                }

            }
            catch (Exception ex)
            {
                AgriCastException currEx = new AgriCastException(objSvcPre.GetServiceDetails(), ex);
                AgriCastLogger.Publish(currEx, AgriCastLogger.LogType.Error);
                throw ex;
            }
        }
Exemplo n.º 7
0
        public DataTable getTableDataForExcelExport(string allign, string name, IRuleSets IRobj)
        {
            try
            {
                objSvcInfo = (ServiceInfo)HttpContext.Current.Session["serviceInfo"];
                strCulCode = objSvcInfo.Culture;
                PaletteMap objPm;
                DataSet dsTblSeries = new DataSet();
                DataTable dtTableSeries = new DataTable();
                DataTable dtSeriesData = new DataTable();
                DataSet dsTable = new DataSet();

                DataTable dt;

                string strTblAttributes = objSvc.ReadAllignment(allign, name);
                int numOfDays = Convert.ToInt32(strTblAttributes.Split(',')[1]);
                string datasource = strTblAttributes.Split(',')[2];
                string aggregation = strTblAttributes.Split(',')[5];
                int start = Convert.ToInt32(strTblAttributes.Split(',')[3]);
                int end = Convert.ToInt32(strTblAttributes.Split(',')[4]);
                //To handle current date
                //end = (end > 0 ? end - 1 : end + 1);
                string ruleset = strTblAttributes.Split(',')[6];
                string pallette = strTblAttributes.Split(',')[7];
                string Nodename = strTblAttributes.Split(',')[8];
                List<string[]> alSeriesLegend = objSvc.getNodeList(allign);
                dsTblSeries = objSvc.GetTableSeries(allign, name);
                dtTableSeries = dsTblSeries.Tables[0];
                //To change first column as based on the chosen unit
                dtTableSeries = objSvcPre.ChangeUnits(dtTableSeries, objSvcInfo.Unit, objSvcInfo.WUnit);

                if (ruleset == string.Empty || ruleset == "")
                {
                    dtSeriesData = objTblSvc.GetSeriesData(dtTableSeries, aggregation, datasource, start, end, sHours, eHours);

                    dt = dtSeriesData.Copy();
                    dt.TableName = getTranslatedText(Nodename, strCulCode);
                    dt.Columns[0].ColumnName = getTranslatedText(dt.Columns[0].ColumnName, strCulCode);
                    for (int i = 1; i < dt.Columns.Count; i++)
                    {
                        int count = 1;
                        string ColName = getTranslatedText(dtTableSeries.Rows[i - 1]["trnsTag"].ToString(), strCulCode);
                        for (int j = 0; j < dt.Columns.Count; j++)
                        {

                            if (dt.Columns[j].ColumnName == ColName)
                            {
                                ColName = ColName + "_" + count.ToString();
                            }

                        }

                        dt.Columns[i].ColumnName = ColName;

                    }
                    return dt;
                }
                else
                {

                    if (IRobj != null)
                    {
                        IRule = IRobj;
                    }
                    IRule.DtInput.Clear();
                    IRule.DtOutput.Clear();
                    GetRulesetData(ruleset, IRule);
                    dtSeriesData = objTblSvc.GetSeriesData(RulesetList, aggregation, datasource, start, end, sHours, eHours);

                    dt = dtSeriesData.Copy();
                    dt.TableName = name;
                    dt.Columns.Add("Hour");
                    int LastColIndex = dt.Columns.Count - 1;
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        DateTime Date = Convert.ToDateTime(dt.Rows[i][0].ToString());
                        dt.Rows[i][LastColIndex] = Date.Hour;
                    }
                    IRule.DtInput = dt;

                    IRule.StartDate = System.DateTime.Today.AddDays(start);
                    IRule.EndDate = System.DateTime.Today.AddDays(end);
                    if (IRule.StartDate > IRule.EndDate)
                    {
                        DateTime tmp = IRule.StartDate;
                        IRule.StartDate = IRule.EndDate;
                        IRule.EndDate = tmp;
                    }
                    //if (start < end)
                    //{
                    //    IRule.StartDate = System.DateTime.Today.AddDays(start);
                    //    IRule.EndDate = System.DateTime.Today.AddDays(end);
                    //}
                    //else
                    //{
                    //    IRule.StartDate = System.DateTime.Today.AddDays(end);
                    //    IRule.EndDate = System.DateTime.Today.AddDays(start);

                    //}

                    GetRulesetData(ruleset, IRule);
                    DataTable dtOut = IRule.DtOutput.Copy();

                    //dtOut.Rows.Add(DateTime.Today.ToShortDateString(), "1", "2", "X","ResLegRain,ResLegWind");
                    //dtOut.Rows.Add(DateTime.Today.ToShortDateString(), "1", "2", "X","ResLegRain,ResLegWind");

                    //create pallette
                    objPm = createPallette(pallette);

                    for (int i = 0; i < dtOut.Rows.Count; i++)
                    {

                        //get the recommendation text in case it exists
                        //if not, get the color  name
                        if (dtOut.Rows[i][2].ToString() != string.Empty)
                            dtOut.Rows[i][2] = objPm.getColor(double.Parse(dtOut.Rows[i][2].ToString()), name, "excel") == string.Empty ? System.Drawing.ColorTranslator.FromHtml(objPm.getColor(double.Parse(dtOut.Rows[i][2].ToString()), name)).Name : getTranslatedText(objPm.getColor(double.Parse(dtOut.Rows[i][2].ToString()), name, "excel"), strCulCode);

                        //get the restrictions
                        if (dtOut.Rows[i][3].ToString() != string.Empty)
                        {
                            //Get the Restrictions
                            string[] RestrictionLists = null;
                            if (!string.IsNullOrEmpty(dtOut.Rows[i][4].ToString()))
                            {
                                RestrictionLists = dtOut.Rows[i][4].ToString().Split(',');

                                string restriction = "";
                                foreach (string restrictionText in RestrictionLists)
                                {
                                    restriction = restriction + getTranslatedText(restrictionText, strCulCode) + ",";
                                }
                                dtOut.Rows[i][4] = restriction.Remove(restriction.LastIndexOf(','));
                            }
                        }

                    }

                    //remove the value column as it shoudnt be displayed in the excel
                    dtOut.Columns.Remove("value");
                    dtOut.AcceptChanges();

                    //Change the column names as per culture selected
                    for (int j = 0; j < dtOut.Columns.Count; j++)
                    {
                        dtOut.Columns[j].ColumnName = dtOut.Columns[j].ColumnName != "ColorCode" ? getTranslatedText(dtOut.Columns[j].ColumnName.ToString(), strCulCode) : getTranslatedText("Recommendation", strCulCode);
                    }

                    //Set the table name that comes up as sheet name
                    dtOut.TableName = getTranslatedText(Nodename, strCulCode);
                    return dtOut;
                }

            }
            catch (Exception ex)
            {
                AgriCastException currEx = new AgriCastException(objSvcPre.GetServiceDetails(), ex);
                AgriCastLogger.Publish(currEx, AgriCastLogger.LogType.Error);
                return null;
            }
        }
        /// <summary>
        /// This Method calls the ApplyRules()
        /// </summary>
        /// <returns>
        /// Output data table from ApplyRules() .
        /// </returns>
        //static public DataTable CalculateRuleSets(DataTable p_dtInput, DateTime p_sunRise, DateTime p_sunSet)
        public static DataTable CalculateRuleSets(IRuleSets objIRuleSets)
        {
            //IntialiseOutputDatatable();
            DataTable dt = null;
            //Assign the Value through Interface Members
            dtInputRaw = objIRuleSets.DtInput;
            startDate = objIRuleSets.StartDate;
            endDate = objIRuleSets.EndDate;
            dtOutput = objIRuleSets.DtOutput;
            sunRise = objIRuleSets.SunRise;
            sunSet = objIRuleSets.SunSet;

            //Filter the Raw Data and extract only the data between start and end dates
            //One day data= data from 1 am of current date to 12am of next daya
            //for eg. 17/5/2012 data = 17/5/2012 1:00:00 am to 18/5/2012 12:00:00 am
            dtInput = dtInputRaw.Select("" + DATE + " >= '" + startDate.AddHours(1) + "' and " + DATE + " <='" + endDate + "'").CopyToDataTable();

            //Check if all the required data is present
            PRECIP = getColumnName(dtInput.Columns, "PrecipAmount");
            SOILTEMP = getColumnName(dtInput.Columns, "soilTemp");
            MOISTURESOIL_SAND = getColumnName(dtInput.Columns, "MoistureSoilClay010cm");
            TEMPMIN = getColumnName(dtInput.Columns, "temp_min5");

            dt = ApplyRules();

            return dt;
        }
Exemplo n.º 9
0
        /*Unit Implementation in Web Services - End*/
        //Method to fetch the table module details
        /*Unit Implementation in Web Services - Begin*/
        //Added a new parameter - strUnit
        public List<table> getTableData(double dStnLat, double dStnLong, int iAtl, int iMaxDist, int iMaxAltDiff, IRuleSets objIRuleset, string strNode, string strNodeName, string strCultureCode, string strServiceName, string strModuleName, string strLangID,string strUnit)
        {
            DataSet dsTbl = new DataSet();
            objTableSvc.setTableWebServiceValues(dStnLat, dStnLong, iAtl, iMaxDist, iMaxAltDiff);
            /*Unit Implementation in Web Services - Begin*/
            dsTbl = objTblPre.getTableDataForService(strNode, strNodeName, objIRuleset, strServiceName, strModuleName, strCultureCode, strUnit);
            /*Unit Implementation in Web Services - End*/
            List<table> tablelist = new List<table>();
            table tbl;
            tableRow tr = new tableRow();
            tableCell tc;
            HeaderRow hr1 = new HeaderRow();
            HeaderRow hr2 = new HeaderRow();
            HeaderCell hc;

            if (dsTbl.Tables[0].TableName.ToLower().Contains("header") && dsTbl.Tables.Count == 2)
            {
                tbl = new table();
                tbl.HeaderRows = new List<HeaderRow>();
                tbl.TableName = dsTbl.Tables[1].TableName;

                hr1.HeaderCells = new List<HeaderCell>();
                hr2.HeaderCells = new List<HeaderCell>();
                int count = 0;
                string day = "";
                string prevVal = "";
                foreach (DataRow dr in dsTbl.Tables[0].Rows)
                {
                    if (count == 0)
                    {
                        hc = new HeaderCell();
                        hc.Value = "";
                        hc.Colspan = "1";
                        hr1.HeaderCells.Add(hc);
                        hc = new HeaderCell();
                        hc.Value = "";
                        hc.Colspan = "1";
                        hr2.HeaderCells.Add(hc);
                    }
                    if (prevVal != dr[0].ToString().Split(',')[0] && !(dr[0].ToString().Split(',')[1].EndsWith("0")))
                    {
                        hc = new HeaderCell();
                        day = DateTime.Parse(dr[0].ToString().Split(',')[0].ToString()).DayOfWeek.ToString();
                        hc.Value = day;
                        hc.Colspan = dr[1].ToString();
                        hr1.HeaderCells.Add(hc);
                        prevVal = dr[0].ToString().Split(',')[0];
                    }
                    HeaderCell hc1 = new HeaderCell();
                    hc1.Value = dr[0].ToString().Split(',')[1].ToString();
                    hc1.Colspan = "1";
                    hr2.HeaderCells.Add(hc1);
                    count++;
                }
                tbl.HeaderRows.Add(hr1);
                tbl.HeaderRows.Add(hr2);

                tbl.tableRows = new List<tableRow>();
                foreach (DataRow dr in dsTbl.Tables[1].Rows)
                {
                    tr = new tableRow();
                    tr.tableCells = new List<tableCell>();
                    for (int i = 0; i < (dsTbl.Tables[1].Columns.Count/3); i++)
                    {
                        tc = new tableCell();
                        tc.Value = dr[0 + (i * 3)].ToString();
                        tc.ToolTip = dr[1 + (i * 3)].ToString();
                        tc.bgColor = dr[2 + (i * 3)].ToString();
                        if (i == 0)
                        {
                            tc.Color = "";
                            tc.CellImage = "";
                        }
                        else
                        {
                            Color bgColor = new Color();
                            bgColor = ColorTranslator.FromHtml(tc.bgColor);
                            tc.Color = ColorTranslator.FromHtml("#" + objCommonUtil.ContrastColor(bgColor).Name).Name;
                            /********IM01144144 - New Agricast Webservices - icons URL - BEGIN ***************************/
                            //tc.CellImage = objCommonUtil.toBase64(GetImage(tc.Value, tc.Color, tc.bgColor));
                            tc.CellImage = GetImage(tc.Value, tc.Color, tc.bgColor);
                            /********IM01144144 - New Agricast Webservices - icons URL - END ***************************/
                        }
                        if (i == 0)
                            tc.Header = "true";
                        else
                            tc.Header = "";
                        tr.tableCells.Add(tc);
                    }
                    tbl.tableRows.Add(tr);
                }

                tablelist.Add(tbl);
            }
            else
            {
                foreach (DataTable dt in dsTbl.Tables)
                {
                    tbl = new table();
                    tbl.HeaderRows = new List<HeaderRow>();
                    tbl.TableName = dt.TableName.ToString();

                    hr1.HeaderCells = new List<HeaderCell>();
                    for (int i = 0; i < (dt.Columns.Count / 3);i++ )
                    {
                        hc = new HeaderCell();
                        if (i == 0)
                            hc.Value = objLocSearchSvc.getTranslatedText("hour", strLangID);
                        else
                            hc.Value = (i-1).ToString();
                        hc.Colspan = "1";
                        hr1.HeaderCells.Add(hc);
                    }
                    tbl.HeaderRows.Add(hr1);

                    tbl.tableRows = new List<tableRow>();
                    foreach (DataRow dr in dt.Rows)
                    {
                        tr = new tableRow();
                        tr.tableCells = new List<tableCell>();
                        for (int i = 0; i < (dr.Table.Columns.Count/3); i++)
                        {
                            tc = new tableCell();
                            tc.Value = dr[0 + (i * 3)].ToString();
                            tc.ToolTip = dr[1 + (i * 3)].ToString();
                            tc.bgColor = dr[2 + (i * 3)].ToString();
                            if (i == 0)
                            {
                                tc.Color = "";
                                tc.CellImage = "";
                            }
                            else
                            {
                                Color bgColor = new Color();
                                bgColor = ColorTranslator.FromHtml(tc.bgColor);
                                tc.Color = ColorTranslator.FromHtml("#" + objCommonUtil.ContrastColor(bgColor).Name).Name;
                                /********IM01144144 - New Agricast Webservices - icons URL - BEGIN ***************************/
                                //tc.CellImage =  objCommonUtil.toBase64(GetImage(tc.Value, tc.Color, tc.bgColor));
                                tc.CellImage = GetImage(tc.Value, tc.Color, tc.bgColor);
                                /********IM01144144 - New Agricast Webservices - icons URL - END ***************************/
                            }
                            if (i == 0)
                                tc.Header = "true";
                            else
                                tc.Header = "";
                            tr.tableCells.Add(tc);
                        }
                        tbl.tableRows.Add(tr);
                    }

                    tablelist.Add(tbl);
                }
            }
             return tablelist;
        }
Exemplo n.º 10
0
        /// <summary>
        /// This Method calls the ApplyRules()
        /// </summary>
        /// <returns>
        /// Output data table from ApplyRules() .
        /// </returns>
        //static public DataTable CalculateRuleSets(DataTable p_dtInput, DateTime p_sunRise, DateTime p_sunSet)
        public static DataTable CalculateRuleSets(IRuleSets objIRuleSets)
        {
            //IntialiseOutputDatatable();
            DataTable dt = null;

            //Filter the Raw Data and extract only the data between start and end dates
            //One day data= data from 1 am of current date to 12am of next daya
            //for eg. 17/5/2012 data = 17/5/2012 1:00:00 am to 18/5/2012 12:00:00 am
            dtInput = dtInputRaw.Select("" + DATE + " >= '" + startDate.AddHours(1) + "' and " + DATE + " <='" + endDate + "'").CopyToDataTable();

            //Assign the Value through Interface Members
            dtInputRaw = objIRuleSets.DtInput;
            startDate = objIRuleSets.StartDate;
            endDate = objIRuleSets.EndDate;
            dtOutput = objIRuleSets.DtOutput;
            sunRise = objIRuleSets.SunRise;
            sunSet = objIRuleSets.SunSet;
            TEMP_MAX = getColumnName(dtInput.Columns, "temp");

            //Apply rules
            dt = ApplyRules();

            return dt;
        }
Exemplo n.º 11
0
        /// <summary>
        /// This Method calls the ApplyRules()
        /// </summary>
        /// <returns>
        /// Output data table from ApplyRules() .
        /// </returns>
        //static public DataTable CalculateRuleSets(DataTable p_dtInput, DateTime p_sunRise, DateTime p_sunSet)
        public static DataTable CalculateRuleSets(IRuleSets objIRuleSets)
        {
            //IntialiseOutputDatatable();
            DataTable dt = null;

            //Assign the Value through Interface Members
            dtInputRaw = objIRuleSets.DtInput;
            startDate = objIRuleSets.StartDate;
            endDate = objIRuleSets.EndDate;
            dtOutput = objIRuleSets.DtOutput;
            sunRise = objIRuleSets.SunRise;
            sunSet = objIRuleSets.SunSet;

            //Set the Cell Value to default
            strCellValue = strDefaultCellValue;

                     //Filter the Raw Data and extract only the data between start and end dates
            //One day data= data from 1 am of current date to 12am of next daya
            //for eg. 17/5/2012 data = 17/5/2012 1:00:00 am to 18/5/2012 12:00:00 am
            dtInput = dtInputRaw.Select("" + DATE + " >= '" + startDate.AddHours(1) + "' and " + DATE + " <='" + endDate + "'").CopyToDataTable();

            //Check if all the required data is present
            PRECIP = getColumnName(dtInput.Columns, "PrecipAmount");
            TEMP = getColumnName(dtInput.Columns, "TempAir");
            HUMID = getColumnName(dtInput.Columns, "Humidity");

            dt = ApplyRules();

            return dt;
        }
Exemplo n.º 12
0
        public static DataTable CalculateRuleSets(IRuleSets objIRuleSets)
        {
            //IntialiseOutputDatatable();

            //Assign the Value through Interface Members
            dtInputRaw = objIRuleSets.DtInput;
            sunRise = objIRuleSets.SunRise;
            sunSet = objIRuleSets.SunSet;
            startDate = objIRuleSets.StartDate;
            endDate = objIRuleSets.EndDate;

            dtOutput = objIRuleSets.DtOutput;
            dtOutput.Columns[0].DataType = typeof(DateTime);
            //Filter the Raw Data and extract only the data between start and end dates
            //One day data= data from 1 am of current date to 12am of next daya
            //for eg. 17/5/2012 data = 17/5/2012 1:00:00 am to 18/5/2012 12:00:00 am

            dtInput = dtInputRaw.Select("" + DATE + " >= '" + startDate.AddHours(1).ToString("yyyy-MM-dd HH:mm:ss") + "' and " + DATE + " <='" + endDate.ToString("yyyy-MM-dd HH:mm:ss") + "'").CopyToDataTable();

            PRECIP = getColumnName(dtInput.Columns, "PrecipAmount");
            TEMPAIR = getColumnName(dtInput.Columns, "TempAir");
            HUMIDITY = getColumnName(dtInput.Columns, "Humidity");
            WIND_SPEED = getColumnName(dtInput.Columns, "WindSpeed_");
            WIND_GUST = getColumnName(dtInput.Columns, "WindSpeedMax");

            DataTable dt = ApplyRules();

            DataTable dttemp = new DataTable();

            decimal maxtemp = 0;
            for (int i = 1; i <= 5; i++)
            {
                dttemp = dtInputRaw.Select("" + DATE + " >= '" + startDate.AddDays(i - 1).AddHours(0).ToString("yyyy-MM-dd HH:mm:ss") + "' and " + DATE + " <='" + startDate.AddDays(i - 1).AddHours(24).ToString("yyyy-MM-dd HH:mm:ss") + "'").CopyToDataTable();

                maxtemp = (decimal)dttemp.Compute("MAX([" + TEMPAIR + "])", "");
                if (maxtemp > 20 && maxtemp <= 25)
                {
                    DataRow[] rows = dt.Select("day >= '" + startDate.AddDays(i - 1).AddHours(11).ToString("yyyy-MM-dd HH:mm:ss") + "' and day <='" + startDate.AddDays(i - 1).AddHours(18).ToString("yyyy-MM-dd HH:mm:ss") + "'");
                    for (int j = 0; j < rows.Length; j++)
                    {
                        rows[j]["value"] = GetRestrictionLetter("E1");
                        rows[j]["restrictions"] = GetRestrictionTransTag("E1");
                        if (rows[j]["ColorCode"].ToString().Length > 1)
                        {
                            rows[j]["ColorCode"] = rows[j]["ColorCode"].ToString().Substring(rows[j]["ColorCode"].ToString().Length - 1);

                        }
                    }
                }
                else if (maxtemp > 25)
                {
                    DataRow[] rows = dt.Select("day >= '" + startDate.AddDays(i - 1).AddHours(1).ToString("yyyy-MM-dd HH:mm:ss") + "' and day <='" + startDate.AddDays(i - 1).AddHours(24).ToString("yyyy-MM-dd HH:mm:ss") + "'");
                    for (int j = 0; j < rows.Length; j++)
                    {
                        rows[j]["value"] = GetRestrictionLetter("E1");
                        rows[j]["restrictions"] = GetRestrictionTransTag("E1");
                        if (rows[j]["ColorCode"].ToString().Length > 1)
                        {
                            rows[j]["ColorCode"] = rows[j]["ColorCode"].ToString().Substring(rows[j]["ColorCode"].ToString().Length - 1);

                        }
                    }
                }

                dttemp = null;
                maxtemp = 0;
            }

            return dt;
        }
Exemplo n.º 13
0
        /// <summary>
        /// This Method calls the ApplyRules()
        /// </summary>
        /// <returns>
        /// Output data table from ApplyRules() .
        /// </returns>
        //static public DataTable CalculateRuleSets(DataTable p_dtInput, DateTime p_sunRise, DateTime p_sunSet)
        public static DataTable CalculateRuleSets(IRuleSets objIRuleSets)
        {
            //IntialiseOutputDatatable();

            dtInputRaw = objIRuleSets.DtInput;
            startDate = objIRuleSets.StartDate;
            endDate = objIRuleSets.EndDate;
            dtOutput = objIRuleSets.DtOutput;
            sunRise = objIRuleSets.SunRise;
            sunSet = objIRuleSets.SunSet;

            //One day data= data from 1 am of current date to 12am of next daya
            //for eg. 17/5/2012 data = 17/5/2012 1:00:00 am to 18/5/2012 12:00:00 am
            dtInput = dtInputRaw.Select("" + DATE + " >= '" + startDate.AddHours(1) + "' and " + DATE + " <='" + endDate + "'").CopyToDataTable();

            HUMID = getColumnName(dtInput.Columns, "Humidity");
            WINDGUSTS = getColumnName(dtInput.Columns, "WindSpeedMax");
            PRECIPTYPE = getColumnName(dtInput.Columns, "PrecipType");
            TEMP_MIN = getColumnName(dtInput.Columns, "temp_min");
            TEMP_MIN_5 = getColumnName(dtInput.Columns, "temp_min5");
            TEMP_MAX = getColumnName(dtInput.Columns, "temp_max");
            PROB_PRECIP = getColumnName(dtInput.Columns, "PrecipProbability_h");
            PRECIP_EXTRA = getColumnName(dtInput.Columns, "precipextrapolated");

            PROB_THUNDER = getColumnName(dtInput.Columns, "ThunderstormProbability_h");

            DataTable dt = ApplyRules();

            return dt;
        }