Пример #1
0
    /// <summary>
    /// This function updates the time of the DataTable after queried from Oracle and update the  time to PT and the Station to  h
    /// human readable format
    /// </summary>
    /// <param name="myDT"></param>
    /// <returns>A modified DataTable with changes to Time and changes to Station </returns>
    private DataTable postTableQueryEdits(DataTable myDT)
    {
        DataTable newTable       = myDT.Clone();
        string    TIME_COL       = "Time";
        string    STATION_COL    = "Station";
        string    DOMAIN_COL     = "Domain";
        string    ALARM_LIST_COL = "AlarmList";

        //Make a copy of the station id column
        int stationIndex = newTable.Columns.IndexOf(STATION_COL);

        newTable.Columns.Remove(STATION_COL);
        DataColumn newStationCol = newTable.Columns.Add(STATION_COL);

        newStationCol.SetOrdinal(stationIndex);

        //Make a copy of the time column
        int timeIndex = newTable.Columns.IndexOf(TIME_COL);

        newTable.Columns.Remove(TIME_COL);
        DataColumn newTimeCol = newTable.Columns.Add(TIME_COL);

        newTimeCol.SetOrdinal(timeIndex);

        Random random = new Random();

        foreach (DataRow row in myDT.Rows)
        {
            DataRow newRow = newTable.Rows.Add();
            //The station number should be changed so that the STATION should be a human readable value and not just a number.
            //The time should be in Local time and not UTC
            // If it is anything else, just ignore it
            newRow.BeginEdit();
            foreach (DataColumn col in newTable.Columns)
            {
                //If Time. This should be in local pacific  time
                if (col == newTimeCol)
                {
                    Object temp = fmtDateTime(epochToDateTime(row[col.ColumnName]).ToLocalTime());
                    newRow.SetField(col, temp);
                }

                //If Station. This should be in a machine name format
                else if (col == newStationCol)
                {
                    //Get the Site prefix from the Domain Column. Note that not all alarm will have a Domain or a nature
                    string sitePrefix = row[DOMAIN_COL].ToString();

                    //Get the site ID from the STATION Column
                    int siteID = Convert.ToInt16(row[STATION_COL]);

                    //Get the Alarm List column from the Alarm Column. This is only used for matching the Front Ends.
                    string alarmListName = row[ALARM_LIST_COL].ToString();

                    string temp = "";
                    temp = SiteFactory.getComputerName(siteID);
                    newRow.SetField(col, temp);
                }
                else
                {
                    newRow.SetField(col, row[col.ColumnName]);
                }
            }
            newRow.AcceptChanges();
        }
        //Drop the alarms list column (as Victor doesn't want it
        newTable.Columns.Remove(ALARM_LIST_COL);
        return(newTable);
    }