Ejemplo n.º 1
0
 /// <summary>
 /// Function that executes the given command on the database and returns the result.
 /// </summary>
 /// <param name="myquery">the query (stored procedure) to execute on the database.</param>
 /// <returns>A dataset which is filled with the table(s) with results from the stored procedure.</returns>
 public DataSet Query(string myquery)
 {
     DataSet TempDataSet = new DataSet();
     try
     {
         DB2DataAdapter DataAdapter = new DB2DataAdapter(myquery, ConnString);
         DataAdapter.Fill(TempDataSet);
     }
     catch (SqlException e_dbconn_sql)
     {
         //SocketClass.LogError(e_dbconn_sql, "LogServer.txt");
         //Create an error message
         TempDataSet = new DataSet("Replies");
         TempDataSet.Tables.Add("Reply");
         TempDataSet.Tables[0].Columns.Add("INT");
         DataRow newRow = TempDataSet.Tables[0].NewRow();
         newRow[0] = -404;
         TempDataSet.Tables[0].Rows.Add(newRow);
     }
     catch (TimeoutException e_dbconn_conn)
     {
         //SocketClass.LogError(e_dbconn_conn, "LogServer.txt");
         //Create an error message
         TempDataSet = new DataSet("Replies");
         TempDataSet.Tables.Add("Reply");
         TempDataSet.Tables[0].Columns.Add("INT");
         DataRow newRow = TempDataSet.Tables[0].NewRow();
         newRow[0] = -404;
         TempDataSet.Tables[0].Rows.Add(newRow);
     }
     return TempDataSet;
 }
Ejemplo n.º 2
0
 public override void dame_dataset_de(String consulta,DataSet data_set)
 {
     try
     {
         adaptador = new DB2DataAdapter();
         adaptador.SelectCommand = new DB2Command(consulta, conexion);
         adaptador.Fill(data_set);
     }
     catch (DB2Exception excepcion)
     {
         MessageBox.Show(excepcion.Message);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// [私有方法][内部调用]执行指定数据库连接对象/事务的命令,映射数据表并填充数据集,DataSet/TableNames/DB2Parameters.
        /// </summary>
        /// <remarks>
        /// 示例:  
        ///  FillDataset(conn, trans, CommandType.StoredProcedure, "GetOrders", ds, new string[] {"orders"}, new DB2Parameter("@prodid", 24));
        /// </remarks>
        /// <param name="connection">一个有效的数据库连接对象</param>
        /// <param name="transaction">一个有效的连接事务</param>
        /// <param name="commandType">命令类型 (存储过程,命令文本或其它)</param>
        /// <param name="commandText">存储过程名称或T-SQL语句</param>
        /// <param name="dataSet">要填充结果集的DataSet实例</param>
        /// <param name="tableNames">表映射的数据表数组
        /// 用户定义的表名 (可有是实际的表名.)
        /// </param>
        /// <param name="commandParameters">分配给命令的DB2Paramter参数数组</param>
        private static void FillDataset(DB2Connection connection, DB2Transaction transaction, CommandType commandType,
            string commandText, DataSet dataSet, string[] tableNames,
            params DB2Parameter[] commandParameters)
        {
            if (connection == null) throw new ArgumentNullException("connection");
            if (dataSet == null) throw new ArgumentNullException("dataSet");

            // 创建DB2Command命令,并进行预处理
            DB2Command command = new DB2Command();
            bool mustCloseConnection = false;
            PrepareCommand(command, connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection);

            // 执行命令
            using (DB2DataAdapter dataAdapter = new DB2DataAdapter(command))
            {

                // 追加表映射
                if (tableNames != null && tableNames.Length > 0)
                {
                    string tableName = "Table";
                    for (int index = 0; index < tableNames.Length; index++)
                    {
                        if (tableNames[index] == null || tableNames[index].Length == 0) throw new ArgumentException("The tableNames parameter must contain a list of tables, a value was provided as null or empty string.", "tableNames");
                        dataAdapter.TableMappings.Add(tableName, tableNames[index]);
                        tableName += (index + 1).ToString();
                    }
                }

                // 填充数据集使用默认表名称
                dataAdapter.Fill(dataSet);

                // 清除参数,以便再次使用.
                command.Parameters.Clear();
            }

            if (mustCloseConnection)
                connection.Close();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 执行数据集更新到数据库,指定inserted, updated, or deleted命令.
        /// </summary>
        /// <remarks>
        /// 示例:  
        ///  UpdateDataset(conn, insertCommand, deleteCommand, updateCommand, dataSet, "Order");
        /// </remarks>
        /// <param name="insertCommand">[追加记录]一个有效的T-SQL语句或存储过程</param>
        /// <param name="deleteCommand">[删除记录]一个有效的T-SQL语句或存储过程</param>
        /// <param name="updateCommand">[更新记录]一个有效的T-SQL语句或存储过程</param>
        /// <param name="dataSet">要更新到数据库的DataSet</param>
        /// <param name="tableName">要更新到数据库的DataTable</param>
        public static void UpdateDataset(DB2Command insertCommand, DB2Command deleteCommand, DB2Command updateCommand, DataSet dataSet, string tableName)
        {
            if (insertCommand == null) throw new ArgumentNullException("insertCommand");
            if (deleteCommand == null) throw new ArgumentNullException("deleteCommand");
            if (updateCommand == null) throw new ArgumentNullException("updateCommand");
            if (tableName == null || tableName.Length == 0) throw new ArgumentNullException("tableName");

            // 创建DB2DataAdapter,当操作完成后释放.
            using (DB2DataAdapter dataAdapter = new DB2DataAdapter())
            {
                // 设置数据适配器命令
                dataAdapter.UpdateCommand = updateCommand;
                dataAdapter.InsertCommand = insertCommand;
                dataAdapter.DeleteCommand = deleteCommand;

                // 更新数据集改变到数据库
                dataAdapter.Update(dataSet, tableName);

                // 提交所有改变到数据集.
                dataSet.AcceptChanges();
            }
        }
Ejemplo n.º 5
0
        /// <summary>Selectクエリを実行し、データセットを返す。</summary>
        /// <param name="ds">データセット</param>
        /// <remarks>
        /// SqlDataAdapterのFillを実行する。
        /// 通常、Dao経由で利用する。
        /// </remarks>
        public override void ExecSelectFill_DS(DataSet ds)
        {
            // SQL実行前の、
            // ・通常のパラメタライズド クエリ
            // ・動的パラメタライズド クエリ
            // 制御用メソッド
            this.PreExecQuery();

            // コネクション、トランザクションを設定
            this._cmd.Connection = this._cnn;
            this._cmd.Transaction = this._tx;

            // SelectCommandからデータアダプタを生成
            this._adpt = new DB2DataAdapter(this._cmd);

            // データをFill
            this._adpt.Fill(ds);
        }
		public DB2CommandBuilder (DB2DataAdapter adapter)
		{
			DataAdapter = adapter;
		}
Ejemplo n.º 7
0
        public DataTable GetReport(string sList, DateTime sStartDate, DateTime sEndDate, string sMyColumns, string sReportKind)
        {
            try
            {
                string selectCmd = "";

                if (sReportKind.ToString().Trim().ToUpper() == "一分鐘交通資料")
                {
                    selectCmd += "Select " + sMyColumns + " ";
                    //2009/12/18:SHIN:edit...改抓五分鐘table
                    selectCmd += "  From " + "db2inst1"  + "." + sTableName_VD1Min + " ";
                    //selectCmd += "  From " + "db2inst1"  + "." + sTableName_VD5Min + " ";
                    selectCmd += " Where DeviceName in " + sList + " ";
                    selectCmd += " and VD5MIN_FLAG=1 and datavalidity = 'V' ";
                    selectCmd += "   And Timestamp between timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "') ";
                    selectCmd += "                     and timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "') ";
                    selectCmd += " Order By DeviceName, TimeStamp ";
                }
                else if (sReportKind.ToString().Trim().ToUpper() == "一分鐘交通資料VD")
                {
                    selectCmd += "Select DeviceName ";
                    selectCmd += "  From " + "db2inst1"  + "." + sTableName_VD1Min + " ";
                    selectCmd += " Where DeviceName in " + sList + " ";
                    selectCmd += " and VD5MIN_FLAG=1 and datavalidity = 'V' ";
                    selectCmd += "   And Timestamp between timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "') ";
                    selectCmd += "                     and timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "') ";
                    selectCmd += " group by DeviceName ";
                    selectCmd += " Order By DeviceName ";
                }
                else if (sReportKind.ToString().Trim().ToUpper() == "五分鐘交通資料")
                {
                    selectCmd += "Select " + sMyColumns + " ";
                    selectCmd += "  From " + "db2inst1"  + "." + sTableName_VD5Min + " ";
                    selectCmd += " Where DeviceName in " + sList + " ";
                    selectCmd += "   And Timestamp between timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "') ";
                    selectCmd += "                     and timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "') ";
                    selectCmd += " Order By DeviceName, TimeStamp ";
                }
                else if (sReportKind.ToString().Trim().ToUpper() == "五分鐘交通資料VD")
                {
                    selectCmd += "Select DeviceName ";
                    selectCmd += "  From " + "db2inst1"  + "." + sTableName_VD5Min + " ";
                    selectCmd += " Where DeviceName in " + sList + " ";
                    selectCmd += "   And Timestamp between timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "') ";
                    selectCmd += "                     and timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "') ";
                    selectCmd += " group by DeviceName ";
                    selectCmd += " Order By DeviceName ";
                }
                else if (sReportKind.ToString().Trim().ToUpper() == "現點速率VD")
                {

                    selectCmd += "select a.DEVICENAME";
                    selectCmd += " From tblVdDataSpotSpeed a  ";
                    selectCmd += " left join tblSysParameter b on  char(a.car_class) = char(b.VariableName) and GroupName = 'car_class'  ";
                    selectCmd += " Where a.DeviceName in" + sList + " ";
                    selectCmd += " And a.Timestamp between timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "')   ";
                    selectCmd += " and timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "')  ";
                    selectCmd += " group by a.DeviceName  ";

                }
                else if (sReportKind.ToString().Trim().ToUpper() == "現點速率記錄")
                {

                    selectCmd += "select a.DEVICENAME,to_char(a.TimeStamp,'YYYY-MM-DD HH24:MI:SS') as TimeStamp,a.lane_id, ";
                    selectCmd += DBNAME + ".ZERO2DASH(a.car_volume)," + DBNAME + ".ZERO2DASH(a.car_speed) ";
                    selectCmd += " ,b.VariableValue," + DBNAME + ".ZERO2DASH(a.car_length) ";
                    selectCmd += " ," + DBNAME + ".ZERO2DASH(a.car_interval) ";
                    selectCmd += " From tblVdDataSpotSpeed a  ";
                    selectCmd += " left join tblSysParameter b on  char(a.car_class) = char(b.VariableName) and GroupName = 'car_class'  ";
                    selectCmd += " Where a.DeviceName in" + sList + " ";
                    selectCmd += " And a.Timestamp between timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "')   ";
                    selectCmd += " and timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "')  ";
                    selectCmd += " Order By a.DeviceName, a.TimeStamp  ";

                }
                else if (sReportKind.ToString().Trim().ToUpper() == "五分鐘車間距資料")
                {
                    selectCmd += "Select " + sMyColumns + " ";
                    selectCmd += "  From " + "db2inst1"  + "." + sTableName_VD5Min + " ";
                    selectCmd += " Where DeviceName in " + sList + " ";
                    selectCmd += "   And Timestamp between timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "') ";
                    selectCmd += "                     and timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "') ";
                    selectCmd += " Order By DeviceName, TimeStamp ";
                }
                else if (sReportKind.ToString().Trim().ToUpper() == "五分鐘車間距資料VD")
                {
                    selectCmd += "Select DEVICENAME ";
                    selectCmd += "  From " + "db2inst1"  + "." + sTableName_VD5Min + " ";
                    selectCmd += " Where DeviceName in " + sList + " ";
                    selectCmd += "   And Timestamp between timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "') ";
                    selectCmd += "                     and timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "') ";
                    selectCmd += " group by DeviceName  ";
                    selectCmd += " Order By DeviceName ";
                }
                else if (sReportKind.ToString().Trim().ToUpper() == "一分鐘車道使用率及車間距報表")
                {
                    selectCmd += "Select " + sMyColumns + " ";
                    //2009/12/18:SHIN:edit...改抓五分鐘table
                    selectCmd += "  From " + "db2inst1"  + "." + sTableName_VD1Min + " ";
                    //selectCmd += "  From " + "db2inst1"  + "." + sTableName_VD5Min + " ";
                    selectCmd += " Where DeviceName in " + sList + " ";
                    selectCmd += "   And Timestamp between timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "') ";
                    selectCmd += "                     and timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "') ";
                    selectCmd += " Order By DeviceName, TimeStamp ";

                }
                else if (sReportKind.ToString().Trim().ToUpper() == "一分鐘車道使用率及車間距報表VD")
                {
                    selectCmd += "Select DEVICENAME ";
                    //2009/12/18:SHIN:edit...改抓五分鐘table
                    selectCmd += "  From " + "db2inst1"  + "." + sTableName_VD1Min + " ";
                    //selectCmd += "  From " + "db2inst1"  + "." + sTableName_VD5Min + " ";
                    selectCmd += " Where DeviceName in " + sList + " ";
                    selectCmd += "   And Timestamp between timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "') ";
                    selectCmd += "                     and timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "') ";
                    selectCmd += " group by DeviceName  ";
                    selectCmd += " Order By DeviceName ";

                }
                else if (sReportKind.ToString().Trim().ToUpper() == "一小時交通資料")
                {
                    selectCmd += "Select " + sMyColumns + " ";
                    //2009/12/18:SHIN:edit...改抓五分鐘table
                    selectCmd += "  From " + "db2inst1"  + "." + sTableName_VD1Hr + " ";
                    //selectCmd += "  From " + "db2inst1"  + "." + sTableName_VD5Min + " ";
                    selectCmd += " Where DeviceName in " + sList + " ";
                    selectCmd += "   And Timestamp between timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "') ";
                    selectCmd += "                     and timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "') ";
                    selectCmd += " Order By DeviceName, TimeStamp ";
                }
                else if (sReportKind.ToString().Trim().ToUpper() == "一小時交通資料VD")
                {
                    selectCmd += "Select DEVICENAME ";
                    //2009/12/18:SHIN:edit...改抓五分鐘table
                    selectCmd += "  From " + "db2inst1"  + "." + sTableName_VD1Hr + " ";
                    //selectCmd += "  From " + "db2inst1"  + "." + sTableName_VD5Min + " ";
                    selectCmd += " Where DeviceName in " + sList + " ";
                    selectCmd += "   And Timestamp between timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "') ";
                    selectCmd += "                     and timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "') ";
                    selectCmd += " group by DeviceName  ";
                    selectCmd += " Order By DeviceName ";
                }
                else if (sReportKind.ToString().Trim().ToUpper() == "一天交通資料")
                {
                    selectCmd += "Select " + sMyColumns + " ";
                    //2009/12/18:SHIN:edit...改抓五分鐘table
                    selectCmd += "  From " + "db2inst1"  + "." + sTableName_VD1Day + " ";
                    //selectCmd += "  From " + "db2inst1"  + "." + sTableName_VD5Min + " ";
                    selectCmd += " Where DeviceName in " + sList + " ";
                    selectCmd += "   And Timestamp between timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "') ";
                    selectCmd += "                     and timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "') ";
                    selectCmd += " Order By DeviceName, TimeStamp ";
                }
                else if (sReportKind.ToString().Trim().ToUpper() == "一天交通資料VD")
                {
                    selectCmd += "Select DEVICENAME ";
                    //2009/12/18:SHIN:edit...改抓五分鐘table
                    selectCmd += "  From " + "db2inst1"  + "." + sTableName_VD1Day + " ";
                    //selectCmd += "  From " + "db2inst1"  + "." + sTableName_VD5Min + " ";
                    selectCmd += " Where DeviceName in " + sList + " ";
                    selectCmd += "   And Timestamp between timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "') ";
                    selectCmd += "                     and timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "') ";
                    selectCmd += " group by DeviceName  ";
                    selectCmd += " Order By DeviceName ";
                }
                else if (sReportKind.ToString().Trim().ToUpper() == "全區主線全日交通量統計")
                {
                    selectCmd += "Select l.LineName, ";
                    selectCmd += "       s.SectionName, ";
                    selectCmd += "       p.VariableValue, ";
                    selectCmd += "       (select " + "db2inst1"  + ".ZERO2DASH((case when MAX(v.car_volume) is null then 0 else MAX(v.car_volume) end)) from " + "db2inst1"  + "." + sTableName_VD1Day + " v, " + "db2inst1"  + "." + sTableName_DeviceConfig + " d where d.Devicename = v.Devicename and d.sectionid = s.sectionid and date(v.timestamp) between date(timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "')) and date(timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "')) ) as car_volume, ";
                    selectCmd += "       " + "db2inst1"  + "." + sFunction_MaxVol_Dev + "((select MAX(v.car_volume) from " + "db2inst1"  + "." + sTableName_VD1Day + " v, " + "db2inst1"  + "." + sTableName_DeviceConfig + " d where d.Devicename = v.Devicename and d.sectionid = s.sectionid and date(v.timestamp) between date(timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "')) and date(timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "'))), timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "'), s.sectionid) as DeviceList ";
                    selectCmd += "  From " + "db2inst1"  + "." + sTableName_GroupSection + " s LEFT JOIN " + "db2inst1"  + "." + sTableName_GroupDivision + " d1 ON d1.DivisionId = s.Start_DivisionId ";
                    selectCmd += "	                                                                                    LEFT JOIN " + "db2inst1"  + "." + sTableName_GroupDivision + " d2 ON d2.DivisionId = s.End_DivisionId ";
                    selectCmd += "                                                                                      LEFT JOIN " + "db2inst1"  + "." + sTableName_GroupLine + " l ON l.LineId = s.LineId ";
                    selectCmd += "                                                                                      LEFT JOIN (select VariableName, VariableValue from " + "db2inst1"  + "." + sTableName_Parameter + " where GroupName = 'DeviceDirection') p ON p.VariableName = s.Direction ";
                    selectCmd += " Where s.SectionId in " + sList + " ";
                    selectCmd += " Order By l.LineId, s.Direction, d1.Mileage ";
                }
                else if (sReportKind.ToString().Trim().ToUpper() == "全區匝道全日交通量統計")
                {
                    selectCmd += "Select r.LineName, ";
                    selectCmd += "       r.DivisionName, ";
                    selectCmd += "       r.DirectionDesc, ";
                    selectCmd += "       r.Volume, ";
                    selectCmd += "       r.Devicename";
                    selectCmd += "  From ( ";
                    selectCmd += "Select Distinct ";
                    selectCmd += "       r.LineName as LineName, ";
                    selectCmd += "       r.DivisionName as DivisionName, ";
                    selectCmd += "       r.DirectionDesc as DirectionDesc, ";
                    selectCmd += "       (select (case when MAX(v.car_volume) is null then '-' else char(MAX(v.car_volume)) end) ";
                    selectCmd += "          from " + "db2inst1"  + ".tblvddata1day v, ";
                    selectCmd += "               " + "db2inst1"  + ".tbldeviceconfig d ";
                    selectCmd += "         where d.devicename = v.devicename ";
                    selectCmd += "           and d.location = 'R' ";
                    selectCmd += "           and date(v.timestamp) between date(timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "')) and date(timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "')) ";
                    selectCmd += "           and d.SectionId = r.SectionId  ";
                    selectCmd += "           and UPPER(d.Location_R) = UPPER(r.Location_R) ";
                    selectCmd += "        ) as Volume, ";
                    selectCmd += "        " + "db2inst1"  + "." + sFunction_MaxVol_Dev_Ramp + "( ";
                    selectCmd += "        (select MAX(v.car_volume) from " + "db2inst1"  + ".tblvddata1day v, " + "db2inst1"  + ".tbldeviceconfig d ";
                    selectCmd += "          where d.devicename = v.devicename ";
                    selectCmd += "            and d.location = 'R' ";
                    selectCmd += "            and date(v.timestamp) between date(timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "')) and date(timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "')) ";
                    selectCmd += "            and d.SectionId = r.SectionId  ";
                    selectCmd += "            and UPPER(d.Location_R) = UPPER(r.Location_R) ";
                    selectCmd += "        ), timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "'), r.SectionId, r.Location_R) as Devicename, ";
                    selectCmd += "        r.LineId, r.Mileage ";
                    selectCmd += "  From " + "db2inst1"  + "." + sTableName_vwRamp + " r ";
                    selectCmd += " Where r.SectionId in " + sList + " ";
                    selectCmd += " ) r ";
                    selectCmd += " Order By r.LineId, r.Mileage ";
                }
                else if (sReportKind.ToString().Trim().ToUpper() == "現場終端設備狀態記錄統計")
                {
                    selectCmd += "Select l.Devicename as Devicename, ";
                    selectCmd += "       n.LineName as LineName, ";
                    selectCmd += "       (case when d.Location = 'R' and Location_R = 'I' then concat(p.VariableValue,'入口') ";
                    selectCmd += "             when d.Location = 'R' and Location_R = 'O' then concat(p.VariableValue,'出口') ";
                    selectCmd += "        else p.VariableValue end) as Location, ";
                    selectCmd += "       p2.VariableValue as Direction, ";
                    selectCmd += "       cast(round(cast(d.Mile_M as double)/1000,2) as decimal(8,2)) as Mileage, ";
                    selectCmd += "       Replace(l.Memo,':','/') as memo, ";
                    selectCmd += "       l.Timestamp as StartTimestamp, ";
                    selectCmd += "       '' as EndTimestamp ";
                    selectCmd += "  From " + "db2inst1"  + "." + sTableName_DeviceStatusLog + " l LEFT JOIN " + "db2inst1"  + "." + sTableName_DeviceConfig + " d LEFT JOIN " + "db2inst1"  + "." + sTableName_GroupLine + " n ON n.lineid = d.lineid ";
                    selectCmd += "                                                                                         LEFT JOIN (select VariableName, VariableValue from " + "db2inst1"  + "." + sTableName_Parameter + " where GroupName = 'Location') p ON p.VariableName = d.Location ";
                    selectCmd += "                                                                                         LEFT JOIN (select VariableName, VariableValue from " + "db2inst1"  + "." + sTableName_Parameter + " where GroupName = 'DeviceDirection') p2 ON p2.VariableName = d.Direction ";
                    selectCmd += "       ON d.Devicename = l.Devicename ";
                    selectCmd += " Where d.Device_Type in " + sList + " ";
                    selectCmd += "   And l.Timestamp between timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "') ";
                    selectCmd += "                       and timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "') ";
                    selectCmd += "   And (l.HW_Status_1 <> 0 OR ";
                    selectCmd += "        l.HW_Status_2 <> 0 OR ";
                    selectCmd += "        l.HW_Status_3 <> 0 OR ";
                    selectCmd += "        l.HW_Status_4 <> 0) ";
                    selectCmd += " Order By l.Timestamp, l.Devicename ";
                }
                else if (sReportKind.ToString().Trim().ToUpper() == "現場終端設備運作記錄")
                {
                    //selectCmd += "Select l.Devicename as Devicename, ";
                    //selectCmd += "       n.LineName as LineName, ";
                    //selectCmd += "       (case when d.Location = 'R' and Location_R = 'I' then concat(p.VariableValue,'入口') ";
                    //selectCmd += "             when d.Location = 'R' and Location_R = 'O' then concat(p.VariableValue,'出口') ";
                    //selectCmd += "        else p.VariableValue end ";
                    //selectCmd += "       ) as Location, ";
                    //selectCmd += "       p2.VariableValue as Direction, ";
                    //selectCmd += "       cast(round(cast(d.Mile_M as double)/1000,2) as decimal(8,2)) as Mileage, ";
                    //selectCmd += "       l.Timestamp, ";
                    //selectCmd += "       (case when l.connectstatus = 'Y' then '連線' else '離線' end) as connectstatus, ";
                    //selectCmd += "       (case when l.connectstatus <> 'Y' then '-' when l.connectstatus is null then '-' else " + "db2inst1"  + ".OP_STATUS(case when l.op_status is null then 0 else l.op_status end) end) as op_status, ";
                    //selectCmd += "       (case when l.connectstatus <> 'Y' then '-' when l.connectstatus is null then '-' else (case when l.display is null then '-' when l.display = '' then '-' else l.display end) end) as display ";
                    //selectCmd += "  From " + "db2inst1"  + "." + sTableName_DeviceStatusLog + " l LEFT JOIN " + "db2inst1"  + "." + sTableName_DeviceConfig + " d LEFT JOIN " + "db2inst1"  + "." + sTableName_GroupLine + " n ON n.lineid = d.lineid ";
                    //selectCmd += "                                                                                         LEFT JOIN (select VariableName, VariableValue from " + "db2inst1"  + "." + sTableName_Parameter + " where GroupName = 'Location') p ON p.VariableName = d.Location ";
                    //selectCmd += "                                                                                         LEFT JOIN (select VariableName, VariableValue from " + "db2inst1"  + "." + sTableName_Parameter + " where GroupName = 'DeviceDirection') p2 ON p2.VariableName = d.Direction ";
                    //selectCmd += "       ON d.Devicename = l.Devicename ";
                    //selectCmd += " Where d.Device_Type in " + sList + " ";
                    //selectCmd += "   And l.Timestamp between timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "') ";
                    //selectCmd += "                       and timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "') ";
                    //selectCmd += " Order By l.DeviceName, l.timestamp ";

                    selectCmd += "Select s.devicename,l.linename, loc.variablevalue,dir.variablevalue, ";
                    selectCmd += "       decimal(round(float(d.mile_m)/1000,2),8,2) as mileage,to_char(s.timestamp,'YYYY-MM-DD HH24:MI:SS'), ";
                    selectCmd += "       (case when s.type = 'C' then (case when s.result = 3 then '斷線' else '連線' end) else '' end) as comm_state, ";
                    selectCmd += "             (case when s.type = 'S' then DB2INST1.OP_STATUS((case when s.result is null then 0 else s.result end)) else '-' end) as op_status, ";
                    selectCmd += "        (case when s.type = 'D' then display else '-' end) as display ";
                    selectCmd += "  From db2inst1.tbldevicestatelog s";
                    selectCmd += " LEFt JOIN db2inst1.tbldeviceconfig d ON d.devicename = s.devicename ";
                    selectCmd += " LEFT JOIN db2inst1.tblgroupline l ON l.lineid = d.lineid ";
                    selectCmd += " LEFT JOIN (select variablename, variablevalue from db2inst1.tblsysparameter where UPPER(groupname) = 'LOCATION') loc ON loc.variablename = d.location  ";
                    selectCmd += " LEFT JOIN (select variablename, variablevalue from db2inst1.tblsysparameter where UPPER(groupname) = 'DEVICEDIRECTION') dir ON dir.variablename = d.direction ";
                    selectCmd += " Where s.type in ('C','S','D') and d.Device_Type in " + sList + " ";
                    selectCmd += "   And s.Timestamp between timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "') ";
                    selectCmd += "                       and timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "') ";
                }
                else if (sReportKind.ToString().Trim().ToUpper() == "設備狀態即時監視")
                {
                    //selectCmd += "Select d.device_type, ";
                    //selectCmd += "       d.Devicename, s.LINENAME, ";
                    //selectCmd += "       (case when l.connectstatus = 'Y' then '連線' when l.connectstatus = 'N' then '離線' else '-' end), ";
                    //selectCmd += "       (case when l.connectstatus <> 'Y' then '-' when l.connectstatus is null then '-' else " + "db2inst1"  + ".OP_MODE(case when d.op_mode is null then 0 else d.op_mode end) end) as op_mode, ";
                    //selectCmd += "       (case when l.connectstatus <> 'Y' then '-' when l.connectstatus is null then '-' else (case when l.memo is null then '-' when l.memo = '' then '-' else l.memo end) end) ";
                    ////selectCmd += "       ,d.DEVICENAME,m.MFCCName  ";
                    //selectCmd += "  From " + "db2inst1"  + "." + sTableName_DeviceConfig + " d LEFT JOIN ";
                    //selectCmd += "       " + "db2inst1"  + "." + sTableName_DeviceStatus + " l ON d.DEVICENAME=l.DEVICENAME LEFT JOIN ";
                    //selectCmd += "       " + "db2inst1"  + "." + sTableName_tblgroupline + " s ON d.LINEID=s.LINEID  ";
                    ////selectCmd += "       " + "db2inst1"  + "." + sTableName_tblMFCCConfig + " m ON d.MFCCId=m.MFCCId ";
                    ////selectCmd += "       " + "db2inst1"  + "." + sTableName_DeviceStatusLog + " l, ";
                    ////selectCmd += "       (select x.devicename, x.timestamp ";
                    ////selectCmd += "          from " + "db2inst1"  + "." + sTableName_DeviceStatusLog + " x ";
                    ////selectCmd += "         where x.timestamp = (select max(timestamp) from " + "db2inst1"  + "." + sTableName_DeviceStatusLog + " where devicename = x.devicename) ";
                    ////selectCmd += "         group by x.devicename, x.timestamp) xl ";
                    ////selectCmd += " Where l.devicename = d.devicename and d.LINEID=s.LINEID ";
                    ////selectCmd += "   And l.devicename = xl.devicename ";
                    ////selectCmd += "   And l.timestamp = xl.timestamp ";
                    //selectCmd += "   Where d.Device_Type in " + sList + " ";
                    //selectCmd += " Order By d.device_type, d.DeviceName,s.LINENAME ";

                    //SHIN add
                    selectCmd += "Select d.device_type, ";
                    selectCmd += "       d.Devicename, s.LINENAME, ";
                    selectCmd += "       (case when d.comm_state = 3 then '斷線' when d.enable = 'N' then '斷線'   else '連線' end), ";
                    selectCmd += "       (case when d.comm_state = 3 then '-' when d.enable = 'N' then '斷線' when d.comm_state is null then '-' else db2inst1.OP_MODE(case when d.op_mode is null then 0 else d.op_mode end) end) as op_mode, ";
                    selectCmd += "       (case when d.comm_state = 3 then '-' when d.enable = 'N' then '斷線' when d.comm_state is null  then '-' else (case when d.hw_status_1=0 and d.hw_status_2 =0 and d.hw_status_3=0 and d.hw_status_4=0  then '正常'  else db2inst1.DEVICESTATUS(d.hw_status_1,d.hw_status_2,d.hw_status_3,d.hw_status_4,d.device_type)  end) end)    ";
                    selectCmd += "  From " + "db2inst1"  + "." + sTableName_DeviceConfig + " d LEFT JOIN ";
                    selectCmd += "       " + "db2inst1"  + "." + sTableName_tblgroupline + " s ON d.LINEID=s.LINEID  ";
                    selectCmd += "   Where d.Device_Type in " + sList + " ";
                    selectCmd += " Order By d.device_type, d.DeviceName,s.LINENAME ";

                }
                else if (sReportKind.ToString().Trim().ToUpper() == "設備狀態即時監視2")
                {
                    selectCmd += "Select d.DEVICENAME,d.MFCCId   ";
                    selectCmd += "  From " + "db2inst1"  + "." + sTableName_DeviceConfig + " d left join  ";
                    selectCmd += "       " + "db2inst1"  + "." + sTableName_DeviceStatus + " l ON d.DEVICENAME=l.DEVICENAME left join";
                    selectCmd += "       " + "db2inst1"  + "." + sTableName_tblgroupline + " s  ON d.LINEID=s.LINEID";

                    selectCmd += "   Where d.Device_Type in " + sList + " ";
                    selectCmd += " Order By d.device_type, d.DeviceName,s.LINENAME ";
                }
                else if (sReportKind.ToString().Trim().ToUpper() == "全區主線小時路段平均速度統計")
                {
                    selectCmd += "Select l.LineName, s.SectionName, p.VariableValue, ";
                    selectCmd += "       " + "db2inst1"  + ".ZERO2DASH(INT(case when ";
                    selectCmd += "                  (select " + "db2inst1"  + ".DIV(SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.car_speed) * " + "db2inst1"  + "." + sFunction_ZERO + "(v.car_volume)), SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.car_volume)), 2) ";
                    selectCmd += "                     from " + "db2inst1"  + "." + sTableName_VD5Min + " v left join " + "db2inst1"  + "." + sTableName_DeviceConfig + " d on d.devicename = v.devicename ";
                    selectCmd += "                    where d.sectionid = s.sectionid ";
                    selectCmd += "                      and date(v.timestamp) between date(timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "')) and date(timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "')) ";
                    selectCmd += "                    group by d.sectionid ";
                    selectCmd += "                  ) is null then 0 ";
                    selectCmd += "        else                       ";
                    selectCmd += "                  (select cast(" + "db2inst1"  + ".DIV(SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.car_speed) * " + "db2inst1"  + "." + sFunction_ZERO + "(v.car_volume)), SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.car_volume)), 2) as decimal(8,2)) ";
                    selectCmd += "                     from " + "db2inst1"  + "." + sTableName_VD5Min + " v left join " + "db2inst1"  + "." + sTableName_DeviceConfig + " d on d.devicename = v.devicename ";
                    selectCmd += "                    where d.sectionid = s.sectionid ";
                    selectCmd += "                      and date(v.timestamp) between date(timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "')) and date(timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "')) ";
                    selectCmd += "                    group by d.sectionid )  ";
                    selectCmd += "        end)) as car_speed ";
                    selectCmd += "  From " + "db2inst1"  + "." + sTableName_GroupSection + " s LEFT JOIN " + "db2inst1"  + "." + sTableName_GroupDivision + " d1 ON d1.DivisionId = s.Start_DivisionId ";
                    selectCmd += "                                                                                      LEFT JOIN " + "db2inst1"  + "." + sTableName_GroupDivision + " d2 ON d2.DivisionId = s.End_DivisionId ";
                    selectCmd += "                                                                                      LEFT JOIN " + "db2inst1"  + "." + sTableName_GroupLine + " l ON l.LineId = s.LineId ";
                    selectCmd += "                                                                                      LEFT JOIN (select VariableName, VariableValue from " + "db2inst1"  + "." + sTableName_Parameter + " where GroupName = 'DeviceDirection') p ON p.VariableName = s.Direction ";
                    selectCmd += " Where s.SectionId in " + sList + " ";
                    selectCmd += " Order By l.LineId, s.Direction, d1.Mileage ";
                }
                else if (sReportKind.ToString().Trim().ToUpper() == "主線平均每日交通量統計")
                {
                    selectCmd += "Select x.Devicename, ";
                    selectCmd += "       l.LineName, ";
                    selectCmd += "       p.VariableValue as Direction, ";
                    selectCmd += "       cast(cast(d.Mile_M as double)/1000 as decimal(8,2)) as Mileage, ";
                    selectCmd += "       x.date, ";
                    selectCmd += "       " + "db2inst1"  + ".ZERO2DASH(x.connect_car_volume), ";
                    selectCmd += "       " + "db2inst1"  + ".ZERO2DASH(x.connect_car_volume_rate), ";
                    selectCmd += "       " + "db2inst1"  + ".ZERO2DASH(x.big_car_volume), ";
                    selectCmd += "       " + "db2inst1"  + ".ZERO2DASH(x.big_car_volume_rate), ";
                    selectCmd += "       " + "db2inst1"  + ".ZERO2DASH(x.small_car_volume), ";
                    selectCmd += "       " + "db2inst1"  + ".ZERO2DASH(x.small_car_volume_rate), ";
                    selectCmd += "       " + "db2inst1"  + ".ZERO2DASH(x.car_volume) ";
                    selectCmd += "  From ";
                    selectCmd += "( ";
                    selectCmd += "       Select v.Devicename, ";
                    selectCmd += "              date(v.Timestamp) as date, ";
                    selectCmd += "              (SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane1)) +  ";
                    selectCmd += "               SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane2)) +  ";
                    selectCmd += "               SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane3)) + ";
                    selectCmd += "               SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane4)) + ";
                    selectCmd += "               SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane5)) + ";
                    selectCmd += "               SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane6)) + ";
                    selectCmd += "               SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane7)) ";
                    selectCmd += "              ) as connect_car_volume, ";
                    selectCmd += "              int(" + "db2inst1"  + ".DIV( ";
                    selectCmd += "                            (SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane1)) +  ";
                    selectCmd += "                             SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane2)) +  ";
                    selectCmd += "                             SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane3)) + ";
                    selectCmd += "                             SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane4)) + ";
                    selectCmd += "                             SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane5)) + ";
                    selectCmd += "                             SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane6)) + ";
                    selectCmd += "                             SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane7)) ";
                    selectCmd += "                             ), ";
                    selectCmd += "                           SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.car_volume)), ";
                    selectCmd += "                           2 ";
                    selectCmd += "                          )*100) as connect_car_volume_rate, ";
                    selectCmd += "              (SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane1)) +  ";
                    selectCmd += "               SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane2)) +  ";
                    selectCmd += "               SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane3)) + ";
                    selectCmd += "               SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane4)) + ";
                    selectCmd += "               SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane5)) + ";
                    selectCmd += "               SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane6)) + ";
                    selectCmd += "               SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane7)) ";
                    selectCmd += "              ) as big_car_volume, ";
                    selectCmd += "              int(" + "db2inst1"  + ".DIV( ";
                    selectCmd += "                           (SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane1)) +  ";
                    selectCmd += "                            SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane2)) +  ";
                    selectCmd += "                            SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane3)) + ";
                    selectCmd += "                            SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane4)) + ";
                    selectCmd += "                            SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane5)) + ";
                    selectCmd += "                            SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane6)) + ";
                    selectCmd += "                            SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane7)) ";
                    selectCmd += "                            ), ";
                    selectCmd += "                           SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.car_volume)), ";
                    selectCmd += "                           2 ";
                    selectCmd += "                          )*100) as big_car_volume_rate, ";
                    selectCmd += "              (SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane1)) +  ";
                    selectCmd += "               SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane2)) +  ";
                    selectCmd += "               SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane3)) + ";
                    selectCmd += "               SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane4)) + ";
                    selectCmd += "               SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane5)) + ";
                    selectCmd += "               SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane6)) + ";
                    selectCmd += "               SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane7)) ";
                    selectCmd += "               ) as small_car_volume, ";
                    selectCmd += "              int(" + "db2inst1"  + ".DIV( ";
                    selectCmd += "                           (SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane1)) +  ";
                    selectCmd += "                            SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane2)) +  ";
                    selectCmd += "                            SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane3)) + ";
                    selectCmd += "                            SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane4)) + ";
                    selectCmd += "                            SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane5)) + ";
                    selectCmd += "                            SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane6)) + ";
                    selectCmd += "                            SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane7)) ";
                    selectCmd += "                            ), ";
                    selectCmd += "                           SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.car_volume)), ";
                    selectCmd += "                           2 ";
                    selectCmd += "                          )*100) as small_car_volume_rate, ";
                    selectCmd += "              SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.car_volume)) as car_volume ";
                    selectCmd += "         From " + "db2inst1"  + "." + sTableName_VD5Min + " v ";
                    selectCmd += "        Where date(v.Timestamp) between date(timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "')) and date(timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "')) ";
                    selectCmd += "        Group By v.Devicename, date(v.Timestamp) ";
                    selectCmd += ") x LEFT JOIN " + "db2inst1"  + "." + sTableName_DeviceConfig + " d LEFT JOIN " + "db2inst1"  + "." + sTableName_GroupLine + " l ON l.LineId = d.LineId  ";
                    selectCmd += "                                                                                             LEFT JOIN (select VariableName, VariableValue from " + "db2inst1"  + "." + sTableName_Parameter + " where GroupName = 'DeviceDirection') p ON p.VariableName = d.Direction ";
                    selectCmd += "    ON d.Devicename = x.Devicename  ";
                    selectCmd += " Where x.DeviceName in " + sList + " ";
                    selectCmd += " Order By d.LineId, d.Direction, x.DeviceName ";
                }
                else if (sReportKind.ToString().Trim().ToUpper() == "匝道平均每日交通量統計")
                {
                    selectCmd += "Select v.Devicename, ";
                    selectCmd += "       date(v.Timestamp) as date, ";
                    selectCmd += "       " + "db2inst1"  + ".ZERO2DASH(SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane1)) +  ";
                    selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane2)) +  ";
                    selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane3)) + ";
                    selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane4)) + ";
                    selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane5)) + ";
                    selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane6)) + ";
                    selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane7)) ";
                    selectCmd += "       ) as connect_car_volume, ";
                    selectCmd += "       cast( ";
                    selectCmd += "       " + "db2inst1"  + "." + sFunction_DIV + "( ";
                    selectCmd += "                    (SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane1)) +  ";
                    selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane2)) +  ";
                    selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane3)) + ";
                    selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane4)) + ";
                    selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane5)) + ";
                    selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane6)) + ";
                    selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane7)) ";
                    selectCmd += "                    ), ";
                    selectCmd += "                    SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.car_volume)), ";
                    selectCmd += "                    2 ";
                    selectCmd += "                   )*100 as decimal(8,2)) as connect_car_volume_rate, ";
                    selectCmd += "       " + "db2inst1"  + ".ZERO2DASH(SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane1)) +  ";
                    selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane2)) +  ";
                    selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane3)) + ";
                    selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane4)) + ";
                    selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane5)) + ";
                    selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane6)) + ";
                    selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane7)) ";
                    selectCmd += "       ) as big_car_volume, ";
                    selectCmd += "       cast( ";
                    selectCmd += "       " + "db2inst1"  + "." + sFunction_DIV + "( ";
                    selectCmd += "                    (SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane1)) +  ";
                    selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane2)) +  ";
                    selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane3)) + ";
                    selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane4)) + ";
                    selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane5)) + ";
                    selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane6)) + ";
                    selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane7)) ";
                    selectCmd += "                    ), ";
                    selectCmd += "                    SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.car_volume)), ";
                    selectCmd += "                    2 ";
                    selectCmd += "                    )*100 as decimal(8,2)) as big_car_volume_rate, ";
                    selectCmd += "       " + "db2inst1"  + ".ZERO2DASH(SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane1)) +  ";
                    selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane2)) +  ";
                    selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane3)) + ";
                    selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane4)) + ";
                    selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane5)) + ";
                    selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane6)) + ";
                    selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane7)) ";
                    selectCmd += "       ) as small_car_volume, ";
                    selectCmd += "       cast( ";
                    selectCmd += "       " + "db2inst1"  + "." + sFunction_DIV + "( ";
                    selectCmd += "                    (SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane1)) +  ";
                    selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane2)) +  ";
                    selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane3)) + ";
                    selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane4)) + ";
                    selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane5)) + ";
                    selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane6)) + ";
                    selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane7)) ";
                    selectCmd += "                    ), ";
                    selectCmd += "                    SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.car_volume)), ";
                    selectCmd += "                    2 ";
                    selectCmd += "                    )*100 as decimal(8,2)) as small_car_volume_rate, ";
                    selectCmd += "       " + "db2inst1"  + ".ZERO2DASH(SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.car_volume))) as car_volume ";
                    selectCmd += " From (Select * From " + "db2inst1"  + "." + sTableName_VD5Min + " v Where v.Timestamp Between timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "') and timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "')) v ";
                    selectCmd += "Where v.Devicename in " + sList + " ";
                    selectCmd += "Group By v.Devicename, date(v.Timestamp) ";
                    selectCmd += "Order By v.Devicename, date(v.Timestamp) ";
                }
                else if (sReportKind.ToString().Trim().ToUpper() == "小時交通流量統計")
                {
                    selectCmd += "Select v.timestamp as timestamp, ";
                    selectCmd += "       v.devicename as devicename, ";
                    selectCmd += "       " + "db2inst1"  + ".ZERO2DASH((case when v.connect_car_volume_lane1 < 0 then 0 else v.connect_car_volume_lane1 end) +  ";
                    selectCmd += "       (case when v.big_car_volume_lane1 < 0 then 0 else v.big_car_volume_lane1 end) +  ";
                    selectCmd += "       (case when v.small_car_volume_lane1 < 0 then 0 else v.small_car_volume_lane1 end) + ";
                    selectCmd += "       (case when v.connect_car_volume_lane2 < 0 then 0 else v.connect_car_volume_lane2 end) +  ";
                    selectCmd += "       (case when v.big_car_volume_lane2 < 0 then 0 else v.big_car_volume_lane2 end) +  ";
                    selectCmd += "       (case when v.small_car_volume_lane2 < 0 then 0 else v.small_car_volume_lane2 end) + ";
                    selectCmd += "       (case when v.connect_car_volume_lane3 < 0 then 0 else v.connect_car_volume_lane3 end) +  ";
                    selectCmd += "       (case when v.big_car_volume_lane3 < 0 then 0 else v.big_car_volume_lane3 end) +  ";
                    selectCmd += "       (case when v.small_car_volume_lane3 < 0 then 0 else v.small_car_volume_lane3 end) + ";
                    selectCmd += "       (case when v.connect_car_volume_lane4 < 0 then 0 else v.connect_car_volume_lane4 end) +  ";
                    selectCmd += "       (case when v.big_car_volume_lane4 < 0 then 0 else v.big_car_volume_lane4 end) +  ";
                    selectCmd += "       (case when v.small_car_volume_lane4 < 0 then 0 else v.small_car_volume_lane4 end) + ";
                    selectCmd += "       (case when v.connect_car_volume_lane5 < 0 then 0 else v.connect_car_volume_lane5 end) +  ";
                    selectCmd += "       (case when v.big_car_volume_lane5 < 0 then 0 else v.big_car_volume_lane5 end) +  ";
                    selectCmd += "       (case when v.small_car_volume_lane5 < 0 then 0 else v.small_car_volume_lane5 end) + ";
                    selectCmd += "       (case when v.connect_car_volume_lane6 < 0 then 0 else v.connect_car_volume_lane6 end) +  ";
                    selectCmd += "       (case when v.big_car_volume_lane6 < 0 then 0 else v.big_car_volume_lane6 end) +  ";
                    selectCmd += "       (case when v.small_car_volume_lane6 < 0 then 0 else v.small_car_volume_lane6 end)) ";
                    selectCmd += "       as total, ";
                    selectCmd += " ";
                    selectCmd += "       " + "db2inst1"  + ".ZERO2DASH((case when v.connect_car_volume_lane1 < 0 then 0 else v.connect_car_volume_lane1 end) +  ";
                    selectCmd += "       (case when v.connect_car_volume_lane2 < 0 then 0 else v.connect_car_volume_lane2 end) +  ";
                    selectCmd += "       (case when v.connect_car_volume_lane3 < 0 then 0 else v.connect_car_volume_lane3 end) +  ";
                    selectCmd += "       (case when v.connect_car_volume_lane4 < 0 then 0 else v.connect_car_volume_lane4 end) +  ";
                    selectCmd += "       (case when v.connect_car_volume_lane5 < 0 then 0 else v.connect_car_volume_lane5 end) +  ";
                    selectCmd += "       (case when v.connect_car_volume_lane6 < 0 then 0 else v.connect_car_volume_lane6 end)) as total_connect, ";
                    selectCmd += " ";
                    selectCmd += "       " + "db2inst1"  + ".ZERO2DASH((case when v.big_car_volume_lane1 < 0 then 0 else v.big_car_volume_lane1 end) +  ";
                    selectCmd += "       (case when v.big_car_volume_lane2 < 0 then 0 else v.big_car_volume_lane2 end) +  ";
                    selectCmd += "       (case when v.big_car_volume_lane3 < 0 then 0 else v.big_car_volume_lane3 end) +  ";
                    selectCmd += "       (case when v.big_car_volume_lane4 < 0 then 0 else v.big_car_volume_lane4 end) +  ";
                    selectCmd += "       (case when v.big_car_volume_lane5 < 0 then 0 else v.big_car_volume_lane5 end) +  ";
                    selectCmd += "       (case when v.big_car_volume_lane6 < 0 then 0 else v.big_car_volume_lane6 end)) as total_big, ";
                    selectCmd += " ";
                    selectCmd += "       " + "db2inst1"  + ".ZERO2DASH((case when v.small_car_volume_lane1 < 0 then 0 else v.small_car_volume_lane1 end) +  ";
                    selectCmd += "       (case when v.small_car_volume_lane2 < 0 then 0 else v.small_car_volume_lane2 end) +  ";
                    selectCmd += "       (case when v.small_car_volume_lane3 < 0 then 0 else v.small_car_volume_lane3 end) +  ";
                    selectCmd += "       (case when v.small_car_volume_lane4 < 0 then 0 else v.small_car_volume_lane4 end) +  ";
                    selectCmd += "       (case when v.small_car_volume_lane5 < 0 then 0 else v.small_car_volume_lane5 end) +  ";
                    selectCmd += "       (case when v.small_car_volume_lane6 < 0 then 0 else v.small_car_volume_lane6 end)) as total_small, ";
                    selectCmd += " ";//車道1
                    selectCmd += "       (case when c.lane_count >= 1 then char((case when v.connect_car_volume_lane1 < 0 then 0 else v.connect_car_volume_lane1 end) +  ";
                    selectCmd += "                                         (case when v.big_car_volume_lane1 < 0 then 0 else v.big_car_volume_lane1 end) +  ";
                    selectCmd += "                                         (case when v.small_car_volume_lane1 < 0 then 0 else v.small_car_volume_lane1 end)) ";
                    selectCmd += "        else '-' end) as lane1, ";
                    selectCmd += "       (case when c.lane_count >= 1 then char(case when v.connect_car_volume_lane1 < 0 then 0 else v.connect_car_volume_lane1 end) else '-' end) as lane1_connect, ";
                    selectCmd += "       (case when c.lane_count >= 1 then char(case when v.big_car_volume_lane1 < 0 then 0 else v.big_car_volume_lane1 end) else '-' end) as lane1_big, ";
                    selectCmd += "       (case when c.lane_count >= 1 then char(case when v.small_car_volume_lane1 < 0 then 0 else v.small_car_volume_lane1 end) else '-' end) as lane1_small, ";
                    selectCmd += " ";//車道2
                    selectCmd += "       (case when c.lane_count >= 2 then char((case when v.connect_car_volume_lane2 < 0 then 0 else v.connect_car_volume_lane2 end) +  ";
                    selectCmd += "                                         (case when v.big_car_volume_lane2 < 0 then 0 else v.big_car_volume_lane2 end) +  ";
                    selectCmd += "                                         (case when v.small_car_volume_lane2 < 0 then 0 else v.small_car_volume_lane2 end)) ";
                    selectCmd += "        else '-' end) as lane2, ";
                    selectCmd += "       (case when c.lane_count >= 2 then char(case when v.connect_car_volume_lane2 < 0 then 0 else v.connect_car_volume_lane2 end) else '-' end) as lane2_connect, ";
                    selectCmd += "       (case when c.lane_count >= 2 then char(case when v.big_car_volume_lane2 < 0 then 0 else v.big_car_volume_lane2 end) else '-' end) as lane2_big, ";
                    selectCmd += "       (case when c.lane_count >= 2 then char(case when v.small_car_volume_lane2 < 0 then 0 else v.small_car_volume_lane2 end) else '-' end) as lane2_small, ";
                    selectCmd += " ";//車道3
                    selectCmd += "       (case when c.lane_count >= 3 then char((case when v.connect_car_volume_lane3 < 0 then 0 else v.connect_car_volume_lane3 end) +  ";
                    selectCmd += "                                         (case when v.big_car_volume_lane3 < 0 then 0 else v.big_car_volume_lane3 end) +  ";
                    selectCmd += "                                         (case when v.small_car_volume_lane3 < 0 then 0 else v.small_car_volume_lane3 end)) ";
                    selectCmd += "        else '-' end) as lane3, ";
                    selectCmd += "       (case when c.lane_count >= 3 then char(case when v.connect_car_volume_lane3 < 0 then 0 else v.connect_car_volume_lane3 end) else '-' end) as lane3_connect, ";
                    selectCmd += "       (case when c.lane_count >= 3 then char(case when v.big_car_volume_lane3 < 0 then 0 else v.big_car_volume_lane3 end) else '-' end) as lane3_big, ";
                    selectCmd += "       (case when c.lane_count >= 3 then char(case when v.small_car_volume_lane3 < 0 then 0 else v.small_car_volume_lane3 end) else '-' end) as lane3_small, ";
                    selectCmd += " ";//車道4
                    selectCmd += "       (case when c.lane_count >= 4 then char((case when v.connect_car_volume_lane4 < 0 then 0 else v.connect_car_volume_lane4 end) +  ";
                    selectCmd += "                                         (case when v.big_car_volume_lane4 < 0 then 0 else v.big_car_volume_lane4 end) +  ";
                    selectCmd += "                                         (case when v.small_car_volume_lane4 < 0 then 0 else v.small_car_volume_lane4 end)) ";
                    selectCmd += "        else '-' end) as lane4, ";
                    selectCmd += "       (case when c.lane_count >= 4 then char(case when v.connect_car_volume_lane4 < 0 then 0 else v.connect_car_volume_lane4 end) else '-' end) as lane4_connect, ";
                    selectCmd += "       (case when c.lane_count >= 4 then char(case when v.big_car_volume_lane4 < 0 then 0 else v.big_car_volume_lane4 end) else '-' end) as lane4_big, ";
                    selectCmd += "       (case when c.lane_count >= 4 then char(case when v.small_car_volume_lane4 < 0 then 0 else v.small_car_volume_lane4 end) else '-' end) as lane4_small, ";
                    selectCmd += " ";//車道5
                    selectCmd += "       (case when c.lane_count >= 5 then char((case when v.connect_car_volume_lane5 < 0 then 0 else v.connect_car_volume_lane5 end) +  ";
                    selectCmd += "                                         (case when v.big_car_volume_lane5 < 0 then 0 else v.big_car_volume_lane5 end) +  ";
                    selectCmd += "                                         (case when v.small_car_volume_lane5 < 0 then 0 else v.small_car_volume_lane5 end)) ";
                    selectCmd += "        else '-' end) as lane5, ";
                    selectCmd += "       (case when c.lane_count >= 5 then char(case when v.connect_car_volume_lane5 < 0 then 0 else v.connect_car_volume_lane5 end) else '-' end) as lane5_connect, ";
                    selectCmd += "       (case when c.lane_count >= 5 then char(case when v.big_car_volume_lane5 < 0 then 0 else v.big_car_volume_lane5 end) else '-' end) as lane5_big, ";
                    selectCmd += "       (case when c.lane_count >= 5 then char(case when v.small_car_volume_lane5 < 0 then 0 else v.small_car_volume_lane5 end) else '-' end) as lane5_small, ";
                    selectCmd += " ";//車道6
                    selectCmd += "       (case when c.lane_count >= 6 then char((case when v.connect_car_volume_lane6 < 0 then 0 else v.connect_car_volume_lane6 end) +  ";
                    selectCmd += "                                         (case when v.big_car_volume_lane6 < 0 then 0 else v.big_car_volume_lane6 end) +  ";
                    selectCmd += "                                         (case when v.small_car_volume_lane6 < 0 then 0 else v.small_car_volume_lane6 end)) ";
                    selectCmd += "        else '-' end) as lane6, ";
                    selectCmd += "       (case when c.lane_count >= 6 then char(case when v.connect_car_volume_lane6 < 0 then 0 else v.connect_car_volume_lane6 end) else '-' end) as lane6_connect, ";
                    selectCmd += "       (case when c.lane_count >= 6 then char(case when v.big_car_volume_lane6 < 0 then 0 else v.big_car_volume_lane6 end) else '-' end) as lane6_big, ";
                    selectCmd += "       (case when c.lane_count >= 6 then char(case when v.small_car_volume_lane6 < 0 then 0 else v.small_car_volume_lane6 end) else '-' end) as lane6_small ";
                    selectCmd += " ";
                    //selectCmd += " From (Select * From " + "db2inst1"  + "." + sTableName_VD1Hr + " v Where v.Timestamp Between timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "') and timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "')) v, ";
                    selectCmd += " From (Select * From " + "db2inst1"  + "." + sTableName_VD5Min + " v Where v.Timestamp Between timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "') and timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "')) v, ";

                    selectCmd += "      " + "db2inst1"  + "." + sTableName_VdConfig + " c ";
                    selectCmd += "Where v.Devicename = c.Devicename ";
                    selectCmd += "  And v.Devicename in " + sList + " ";
                    selectCmd += "Order By v.Devicename, v.Timestamp ";
                }
                else if (sReportKind.ToString().Trim().ToUpper() == "小時交通平均速度統計")
                {
                    selectCmd += "Select v.timestamp as timestamp, ";
                    selectCmd += "       v.devicename as devicename, ";
                    selectCmd += "       " + "db2inst1"  + ".ZERO2DASH(ABS(v.car_speed)) as total, ";
                    selectCmd += "       " + "db2inst1"  + ".ZERO2DASH(case when c.lane_count >= 1 then ";
                    selectCmd += "                                         int(" + "db2inst1"  + ".DIV( " + "db2inst1"  + ".ZERO(v.connect_car_speed_lane1) * " + "db2inst1"  + ".ZERO(v.connect_car_volume_lane1) + ";
                    selectCmd += "                                                                 " + "db2inst1"  + ".ZERO(v.big_car_speed_lane1)     * " + "db2inst1"  + ".ZERO(v.big_car_volume_lane1) + ";
                    selectCmd += "                                                                 " + "db2inst1"  + ".ZERO(v.small_car_speed_lane1)   * " + "db2inst1"  + ".ZERO(v.small_car_volume_lane1) ";
                    selectCmd += "                                                                , ";
                    selectCmd += "                                                                 " + "db2inst1"  + ".ZERO(v.connect_car_volume_lane1) + " + "db2inst1"  + ".ZERO(v.big_car_volume_lane1) + " + "db2inst1"  + ".ZERO(v.small_car_volume_lane1) ";
                    selectCmd += "                                                                , ";
                    selectCmd += "                                                                 0 ";
                    selectCmd += "                                                               )) ";
                    selectCmd += "        else 0 end) as lane1, ";
                    selectCmd += "       " + "db2inst1"  + ".ZERO2DASH(case when c.lane_count >= 2 then ";
                    selectCmd += "                                          int(" + "db2inst1"  + ".DIV( " + "db2inst1"  + ".ZERO(v.connect_car_speed_lane2) * " + "db2inst1"  + ".ZERO(v.connect_car_volume_lane2) + ";
                    selectCmd += "                                                                  " + "db2inst1"  + ".ZERO(v.big_car_speed_lane2)     * " + "db2inst1"  + ".ZERO(v.big_car_volume_lane2) + ";
                    selectCmd += "                                                                  " + "db2inst1"  + ".ZERO(v.small_car_speed_lane2)   * " + "db2inst1"  + ".ZERO(v.small_car_volume_lane2) ";
                    selectCmd += "                                                                 , ";
                    selectCmd += "                                                                  " + "db2inst1"  + ".ZERO(v.connect_car_volume_lane2) + " + "db2inst1"  + ".ZERO(v.big_car_volume_lane2) + " + "db2inst1"  + ".ZERO(v.small_car_volume_lane2) ";
                    selectCmd += "                                                                 , ";
                    selectCmd += "                                                                  0 ";
                    selectCmd += "                                                                ))  ";
                    selectCmd += "        else 0 end) as lane2, ";
                    selectCmd += "       " + "db2inst1"  + ".ZERO2DASH(case when c.lane_count >= 3 then ";
                    selectCmd += "                                          int(" + "db2inst1"  + ".DIV( " + "db2inst1"  + ".ZERO(v.connect_car_speed_lane3) * " + "db2inst1"  + ".ZERO(v.connect_car_volume_lane3) + ";
                    selectCmd += "                                                                  " + "db2inst1"  + ".ZERO(v.big_car_speed_lane3)     * " + "db2inst1"  + ".ZERO(v.big_car_volume_lane3) + ";
                    selectCmd += "                                                                  " + "db2inst1"  + ".ZERO(v.small_car_speed_lane3)   * " + "db2inst1"  + ".ZERO(v.small_car_volume_lane3) ";
                    selectCmd += "                                                                 , ";
                    selectCmd += "                                                                  " + "db2inst1"  + ".ZERO(v.connect_car_volume_lane3) + " + "db2inst1"  + ".ZERO(v.big_car_volume_lane3) + " + "db2inst1"  + ".ZERO(v.small_car_volume_lane3) ";
                    selectCmd += "                                                                 , ";
                    selectCmd += "                                                                  0 ";
                    selectCmd += "                                                                ))  ";
                    selectCmd += "        else 0 end) as lane3, ";
                    selectCmd += "       " + "db2inst1"  + ".ZERO2DASH(case when c.lane_count >= 4 then  ";
                    selectCmd += "                                          int(" + "db2inst1"  + ".DIV( " + "db2inst1"  + ".ZERO(v.connect_car_speed_lane4) * " + "db2inst1"  + ".ZERO(v.connect_car_volume_lane4) + ";
                    selectCmd += "                                                                  " + "db2inst1"  + ".ZERO(v.big_car_speed_lane4)     * " + "db2inst1"  + ".ZERO(v.big_car_volume_lane4) + ";
                    selectCmd += "                                                                  " + "db2inst1"  + ".ZERO(v.small_car_speed_lane4)   * " + "db2inst1"  + ".ZERO(v.small_car_volume_lane4) ";
                    selectCmd += "                                                                 , ";
                    selectCmd += "                                                                  " + "db2inst1"  + ".ZERO(v.connect_car_volume_lane4) + " + "db2inst1"  + ".ZERO(v.big_car_volume_lane4) + " + "db2inst1"  + ".ZERO(v.small_car_volume_lane4) ";
                    selectCmd += "                                                                 , ";
                    selectCmd += "                                                                  0 ";
                    selectCmd += "                                                                )) ";
                    selectCmd += "        else 0 end) as lane4, ";
                    selectCmd += "       " + "db2inst1"  + ".ZERO2DASH(case when c.lane_count >= 5 then  ";
                    selectCmd += "                                          int(" + "db2inst1"  + ".DIV( " + "db2inst1"  + ".ZERO(v.connect_car_speed_lane5) * " + "db2inst1"  + ".ZERO(v.connect_car_volume_lane5) + ";
                    selectCmd += "                                                                  " + "db2inst1"  + ".ZERO(v.big_car_speed_lane5)     * " + "db2inst1"  + ".ZERO(v.big_car_volume_lane5) + ";
                    selectCmd += "                                                                  " + "db2inst1"  + ".ZERO(v.small_car_speed_lane5)   * " + "db2inst1"  + ".ZERO(v.small_car_volume_lane5) ";
                    selectCmd += "                                                                 , ";
                    selectCmd += "                                                                  " + "db2inst1"  + ".ZERO(v.connect_car_volume_lane5) + " + "db2inst1"  + ".ZERO(v.big_car_volume_lane5) + " + "db2inst1"  + ".ZERO(v.small_car_volume_lane5) ";
                    selectCmd += "                                                                 , ";
                    selectCmd += "                                                                  0 ";
                    selectCmd += "                                                                ))  ";
                    selectCmd += "        else 0 end) as lane5, ";
                    selectCmd += "       " + "db2inst1"  + ".ZERO2DASH(case when c.lane_count >= 6 then  ";
                    selectCmd += "                                          int(" + "db2inst1"  + ".DIV( " + "db2inst1"  + ".ZERO(v.connect_car_speed_lane6) * " + "db2inst1"  + ".ZERO(v.connect_car_volume_lane6) + ";
                    selectCmd += "                                                                  " + "db2inst1"  + ".ZERO(v.big_car_speed_lane6)     * " + "db2inst1"  + ".ZERO(v.big_car_volume_lane6) + ";
                    selectCmd += "                                                                  " + "db2inst1"  + ".ZERO(v.small_car_speed_lane6)   * " + "db2inst1"  + ".ZERO(v.small_car_volume_lane6) ";
                    selectCmd += "                                                                 , ";
                    selectCmd += "                                                                  " + "db2inst1"  + ".ZERO(v.connect_car_volume_lane6) + " + "db2inst1"  + ".ZERO(v.big_car_volume_lane6) + " + "db2inst1"  + ".ZERO(v.small_car_volume_lane6) ";
                    selectCmd += "                                                                 , ";
                    selectCmd += "                                                                  0 ";
                    selectCmd += "                                                                 ))  ";
                    selectCmd += "        else 0 end) as lane6 ";
                    selectCmd += " From (Select * From " + "db2inst1"  + "." + sTableName_VD1Hr + " v Where v.Timestamp Between timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "') and timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "')) v, ";
                    selectCmd += "      " + "db2inst1"  + "." + sTableName_VdConfig + " c ";
                    selectCmd += "Where v.Devicename = c.Devicename ";
                    selectCmd += "  And v.Devicename in " + sList + " ";
                    selectCmd += "Order By v.Devicename, v.Timestamp ";
                }
                else
                {
                    // Do Nothing ...
                }

                InitDB();

                da = new DB2DataAdapter(selectCmd, conn);
                DataTable DT = new DataTable();
                da.Fill(DT);
                da.Dispose();
                conn.Close();
                return DT;
            }
            catch (Exception ex)
            {
                sErrMsg = ex.Message;
                CloseDB();
                return null;
            }
        }
Ejemplo n.º 8
0
        public DataTable GetPeopleList()
        {
            try
            {
                string selectCmd = "";
                selectCmd += "Select UserId,UserName ";
                selectCmd += "  From " + sTableName_tblSysUser + " ";
                selectCmd += "  Order By USERID ";

                InitDB();

                da = new DB2DataAdapter(selectCmd, conn);
                DataTable DT = new DataTable();
                da.Fill(DT);
                da.Dispose();
                conn.Close();
                return DT;
            }
            catch (Exception ex)
            {
                sErrMsg = ex.Message;
                CloseDB();
                return null;
            }
        }
Ejemplo n.º 9
0
        public DataTable GetDeviceList(string DevType)
        {
            try
            {
                string selectCmd = "";
                selectCmd += "Select DeviceName ";
                selectCmd += "  From " + "db2inst1"  + "." + sTableName_DeviceConfig + " ";
                selectCmd += " Where Lower(Device_Type) = '" + DevType.ToString().Trim().ToLower() + "' ";
                selectCmd += " Order By DeviceName ";

                InitDB();

                da = new DB2DataAdapter(selectCmd, conn);
                DataTable DT = new DataTable();
                da.Fill(DT);
                da.Dispose();
                conn.Close();
                return DT;
            }
            catch (Exception ex)
            {
                sErrMsg = ex.Message;
                CloseDB();
                return null;
            }
        }
Ejemplo n.º 10
0
        public DataTable Get_RPT_VD(string sRPT, string sDevList)
        {
            try
            {
                string selectCmd = "";

                if (sRPT == "匝道平均每日交通量統計報表")
                {
                    selectCmd += "Select Distinct v.DeviceName as DEVICENAME , ";
                    selectCmd += "                l.LineName || p1.VariableValue || p2.VariableValue as ROADINFO1, ";
                    selectCmd += "                CONCAT(CONCAT(CONCAT(CONCAT(CONCAT(i.DivisionName,'-'),p2.VariableValue),'-'),(case when d.location_R = 'I' then '入口' else '出口' end)),'     (' || trim(char(v.Lane_Count)) || '車道)') as ROADINFO2 ";
                    selectCmd += "  From " + "db2inst1"  + "." + sTableName_VdConfig + " v, ";
                    selectCmd += "       " + "db2inst1"  + "." + sTableName_DeviceConfig + " d, ";
                    selectCmd += "       " + "db2inst1"  + "." + sTableName_GroupLine + " l, ";
                    selectCmd += "       " + "db2inst1"  + "." + sTableName_GroupSection + " s, ";
                    selectCmd += "       " + "db2inst1"  + "." + sTableName_GroupDivision + " i, ";
                    selectCmd += "       " + "db2inst1"  + "." + sTableName_Parameter + " p1, ";
                    selectCmd += "       " + "db2inst1"  + "." + sTableName_Parameter + " p2 ";
                    selectCmd += " Where v.DeviceName in (" + sDevList + " ) ";
                    selectCmd += "   And d.SectionId = s.SectionId ";
                    selectCmd += "   And s.Start_DivisionId = i.DivisionId ";
                    selectCmd += "   And v.DeviceName = d.DeviceName ";
                    selectCmd += "   And d.LineId = l.LineId ";
                    selectCmd += "   And p1.VariableName = d.Location ";
                    selectCmd += "   And p1.GroupName = 'Location' ";
                    selectCmd += "   And p2.VariableName = d.Direction ";
                    selectCmd += "   And p2.GroupName = 'DeviceDirection' ";
                    selectCmd += "Order By v.DeviceName ";
                }
                else if (sRPT == "小時交通流量統計" ||
                         sRPT == "小時交通平均速度統計報表"
                        )
                {
                    selectCmd += "Select Distinct v.DeviceName as DEVICENAME , ";
                    selectCmd += "                l.LineName || p1.VariableValue || p2.VariableValue as ROADINFO1, ";
                    selectCmd += "                (case when d.Location = 'R' then CONCAT(CONCAT(CONCAT(CONCAT(CONCAT(i.DivisionName,'-'),p2.VariableValue),'-'),(case when d.location_R = 'I' then '入口' else '出口' end)),'     (' || trim(char(v.Lane_Count)) || '車道)') ";
                    selectCmd += "                 else '里程:' || char(cast((float(l.EndMileage - l.StartMileage)/1000) as decimal(5,2))) || '(' || trim(char(v.lane_count)) || '車道)' end) as ROADINFO2 ";
                    selectCmd += "  From " + "db2inst1"  + "." + sTableName_VdConfig + " v, ";
                    selectCmd += "       " + "db2inst1"  + "." + sTableName_DeviceConfig + " d, ";
                    selectCmd += "       " + "db2inst1"  + "." + sTableName_GroupLine + " l, ";
                    selectCmd += "       " + "db2inst1"  + "." + sTableName_GroupSection + " s, ";
                    selectCmd += "       " + "db2inst1"  + "." + sTableName_GroupDivision + " i, ";
                    selectCmd += "       " + "db2inst1"  + "." + sTableName_Parameter + " p1, ";
                    selectCmd += "       " + "db2inst1"  + "." + sTableName_Parameter + " p2 ";
                    selectCmd += " Where v.DeviceName in (" + sDevList + " )";
                    selectCmd += "   And d.SectionId = s.SectionId ";
                    selectCmd += "   And s.Start_DivisionId = i.DivisionId ";
                    selectCmd += "   And v.DeviceName = d.DeviceName ";
                    selectCmd += "   And d.LineId = l.LineId ";
                    selectCmd += "   And p1.VariableName = d.Location ";
                    selectCmd += "   And p1.GroupName = 'Location' ";
                    selectCmd += "   And p2.VariableName = d.Direction ";
                    selectCmd += "   And p2.GroupName = 'DeviceDirection' ";
                    selectCmd += "Order By v.DeviceName ";
                }
                else if (sRPT == "現點速率調查交通資料記錄報表")
                {
                    selectCmd += "Select Distinct v.DeviceName as DEVICENAME , ";
                    selectCmd += "                l.LineName || p1.VariableValue || p2.VariableValue as ROADINFO1, ";
                    selectCmd += "                '里程:' || char(cast((float(l.EndMileage - l.StartMileage)/1000) as decimal(5,2))) || '(' || trim(char(v.lane_count)) || '車道)' as ROADINFO2 ";
                    selectCmd += "  From " + "db2inst1"  + "." + sTableName_VdConfig + " v, ";
                    selectCmd += "       " + "db2inst1"  + "." + sTableName_DeviceConfig + " d, ";
                    selectCmd += "       " + "db2inst1"  + "." + sTableName_GroupLine + " l, ";
                    selectCmd += "       " + "db2inst1"  + "." + sTableName_Parameter + " p1, ";
                    selectCmd += "       " + "db2inst1"  + "." + sTableName_Parameter + " p2 ";
                    selectCmd += " Where v.DeviceName in ( " + sDevList + " ) ";
                    selectCmd += "   And v.DeviceName = d.DeviceName ";
                    selectCmd += "   And d.LineId = l.LineId ";
                    selectCmd += "   And p1.VariableName = d.Location ";
                    selectCmd += "   And p1.GroupName = 'Location' ";
                    selectCmd += "   And p2.VariableName = d.Direction ";
                    selectCmd += "   And p2.GroupName = 'DeviceDirection' ";
                    selectCmd += "Order By v.DeviceName ";
                }
                else if (sRPT == "路段旅行時間記錄報表")
                {
                    selectCmd += "Select Distinct v.DeviceName as DEVICENAME , ";
                    selectCmd += "                l.LineName || p1.VariableValue || p2.VariableValue as ROADINFO1, ";
                    selectCmd += "                '里程:' || char(cast((float(l.EndMileage - l.StartMileage)/1000) as decimal(5,2))) || '(' || trim(char(v.lane_count)) || '車道)' as ROADINFO2 ";
                    selectCmd += "  From " + "db2inst1"  + "." + sTableName_VdConfig + " v, ";
                    selectCmd += "       " + "db2inst1"  + "." + sTableName_DeviceConfig + " d, ";
                    selectCmd += "       " + "db2inst1"  + "." + sTableName_GroupLine + " l, ";
                    selectCmd += "       " + "db2inst1"  + "." + sTableName_Parameter + " p1, ";
                    selectCmd += "       " + "db2inst1"  + "." + sTableName_Parameter + " p2 ";
                    selectCmd += " Where v.DeviceName in ( " + sDevList + " ) ";
                    selectCmd += "   And v.DeviceName = d.DeviceName ";
                    selectCmd += "   And d.LineId = l.LineId ";
                    selectCmd += "   And p1.VariableName = d.Location ";
                    selectCmd += "   And p1.GroupName = 'Location' ";
                    selectCmd += "   And p2.VariableName = d.Direction ";
                    selectCmd += "   And p2.GroupName = 'DeviceDirection' ";
                    selectCmd += "Order By v.DeviceName ";

                    selectCmd += " select  DISTINCT  (g.LineName ||  (case when substr(s.lineid,1,1) = 'N' then '高速公路' else '快速道路'  end) || p.variablevalue) as ROADINFO1, ";
                    selectCmd += " ' '  as ROADINFO2  ";
                    selectCmd += "  From " + "db2inst1"  + "." + sTableName_GroupSection + " s, ";
                    selectCmd += " left join (select variablename, variablevalue from db2inst1.tblsysparameter where upper(groupname) = 'DEVICEDIRECTION') p on p.variablename = s.direction  ";
                    selectCmd += " left join " + "db2inst1"  + "." + sTableName_tblgroupline + " g on s.LineId=g.LineId ";
                    selectCmd += " where s.lineid= 'T76' and s.Direction='E'  ";

                }
                else
                {
                    selectCmd += "Select Distinct v.DeviceName as DEVICENAME , ";
                    selectCmd += "                l.LineName || p1.VariableValue || p2.VariableValue as ROADINFO1, ";
                    selectCmd += "                '里程:' || char(cast((float(l.EndMileage - l.StartMileage)/1000) as decimal(5,2))) || '(' || trim(char(v.lane_count)) || '車道)' as ROADINFO2 ";
                    selectCmd += "  From " + "db2inst1"  + "." + sTableName_VdConfig + " v, ";
                    selectCmd += "       " + "db2inst1"  + "." + sTableName_DeviceConfig + " d, ";
                    selectCmd += "       " + "db2inst1"  + "." + sTableName_GroupLine + " l, ";
                    selectCmd += "       " + "db2inst1"  + "." + sTableName_Parameter + " p1, ";
                    selectCmd += "       " + "db2inst1"  + "." + sTableName_Parameter + " p2 ";
                    selectCmd += " Where v.DeviceName in (" + sDevList + ") ";
                    selectCmd += "   And v.DeviceName = d.DeviceName ";
                    selectCmd += "   And d.LineId = l.LineId ";
                    selectCmd += "   And p1.VariableName = d.Location ";
                    selectCmd += "   And p1.GroupName = 'Location' ";
                    selectCmd += "   And p2.VariableName = d.Direction ";
                    selectCmd += "   And p2.GroupName = 'DeviceDirection' ";
                    selectCmd += "Order By v.DeviceName ";
                }

                InitDB();

                da = new DB2DataAdapter(selectCmd, conn);
                DataTable DT = new DataTable();
                da.Fill(DT);
                da.Dispose();
                conn.Close();
                return DT;
            }
            catch (Exception ex)
            {
                sErrMsg = ex.Message;
                CloseDB();
                return null;
            }
        }
Ejemplo n.º 11
0
        public DataTable Get_RPT_TrafficDataLogSection(string Lineid, string direction, string start_D, string end_D, DateTime sStartDate, DateTime sEndDate)
        {
            try
            {
                string selectCmd = "";

                selectCmd += " select to_char(d.TimeStamp,'YYYY/MM/DD HH24:MI'),sum(d.TravelTime)/60 ";
                selectCmd += " from " + "db2inst1"  + "." + sTableName_tblTrafficDataLogSection + " d left join " + "db2inst1"  + "." + sTableName_GroupSection + " g on d.SectionId=g.SectionId ";
                selectCmd += "                                                                                                left join " + "db2inst1"  + "." + sTableName_GroupDivision + " gs on g.START_DIVISIONID = gs.DIVISIONID ";
                selectCmd += "  where g.lineid= '" + Lineid + "' and g.Direction='" + direction + "' and gs.Mileage between ( select  Mileage from TBLGROUPDIVISION where  DivisionId='" + start_D + "') ";
                selectCmd += " and ( select  Mileage from TBLGROUPDIVISION where  DivisionId='" + end_D + " ') ";
                selectCmd += " and d.TimeStamp between timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "') ";
                selectCmd += "                       and timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "') ";
                selectCmd += "group by d.Timestamp ";

                InitDB();

                da = new DB2DataAdapter(selectCmd, conn);
                DataTable DT = new DataTable();
                da.Fill(DT);
                da.Dispose();
                conn.Close();
                return DT;
            }
            catch (Exception ex)
            {
                sErrMsg = ex.Message;
                CloseDB();
                return null;
            }
        }
Ejemplo n.º 12
0
        public DataTable GetctrlRPT_OPR1_01(string sDevList, string sPeopleList, DateTime sStartDate, DateTime sEndDate)
        {
            try
            {
                string DevNames = "('CMS-N1-L-250-E-2','CMS-N1-N-251.3','CMS-N1-N-247.6','CMS-N1-N-241.7','CMS-N1-L-240-E-2','CMS-N1-N-231.8','CMS-N1-L-230-E-2','CMS-N1-N-221.3','CMS-N1-L-219-E-3','CMS-N1-L-219-E-2','CMS-N1-N-219.0','CMS-N1-N-212','CMS-N1-L-211-E-2','CMS-N1-N-199.6','CMS-N1-L-198-N-3','CMS-N1-N-190.6','CMS-N1-L-188-N-2','CMS-N1-L-188-N-3','CMS-N1-N-183.2','CMS-N1-L-181-N-2','CMS-N1-N-179.7','CMS-N1-L-178-N-2','CMS-N1-N-175.6','CMS-N1-L-174-N-2','CMS-N1-N-169.1','CMS-N1-L-168-N-2','CMS-N1-N-163.4','CMS-N1-N-161.6','CMS-N1-S-158-N-2','CMS-N1-S-158-N-1','CMS-N1-N-150.8','CMS-N1-N-133.7','CMS-N1-L-132-N-2','CMS-N1-N-118.3','CMS-N1-N-111.4','CMS-N1-L-110-N-3')";
                string selectCmd = "";
                selectCmd += "Select to_char(v.OperationTime,'YYYY-MM-DD HH24:MI:SS') AS OperationTime,v.OperationName,v.DeviceName,v.OperationDesc,COALESCE(l.USERNAME,'') AS USERNAME1 ";
                selectCmd += "       ,case when v.OperationResult=1 then '成功' else '失敗' end as OperationResult ";
                selectCmd += "  From " + DBNAME + "." + "TBLSYSOPERATION v LEFT JOIN " + DBNAME + ".tblSysUser" + " l  ON  v.USERID=l.USERID ";
                selectCmd += " Where v.devicename in " + DevNames + " ";
                selectCmd += " and v.OperationTime between '" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "' ";
                selectCmd += "                       and '" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "' ";
                //selectCmd += " AND l.USERNAME in " + GetSelectCmd(user) + " ";
                selectCmd += " Order By USERNAME,OperationTime,DeviceName ";

                //selectCmd += "Select to_char(v.OperationTime,'YYYY-MM-DD HH24:MI:SS') AS OperationTime,v.OperationName,v.DeviceName,v.OperationDesc,COALESCE(l.USERNAME,'') AS USERNAME1 ";
                //selectCmd += "       ,case when v.OperationResult=1 then '成功' else '失敗' end as OperationResult ";
                //selectCmd += "  From " + "db2inst1"  + "." + sTableName_TBLSYSOPERATION + " v LEFT JOIN " + "db2inst1"  + "." + sTableName_tblSysUser + " l  ON  v.USERID=l.USERID ";
                //selectCmd += " Where v.OperationName in " + sDevList + " ";
                //selectCmd += " AND v.OperationTime between '" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "' ";
                //selectCmd += "                       and '" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "' ";
                //if (sPeopleList != "")
                //{
                //    selectCmd += " AND l.USERNAME in " + sPeopleList + " ";
                //}
                //selectCmd += " Order By OperationTime,DeviceName ";

                InitDB();

                da = new DB2DataAdapter(selectCmd, conn);
                DataTable DT = new DataTable();
                da.Fill(DT);
                da.Dispose();
                conn.Close();
                return DT;
            }
            catch (Exception ex)
            {
                sErrMsg = ex.Message;
                CloseDB();
                return null;
            }
        }
Ejemplo n.º 13
0
        public DataTable Get_RPT_SectionCarSpeed(string sList, DateTime sStartDate, DateTime sEndDate)
        {
            try
            {
                string selectCmd = "";
                //selectCmd += "Select l.LineName, s.SectionName, p.VariableValue, ";
                //selectCmd += "       (case when ";
                //selectCmd += "                  (select " + "db2inst1"  + ".DIV(SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.car_speed) * " + "db2inst1"  + "." + sFunction_ZERO + "(v.car_volume)), SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.car_volume)), 2) ";
                //selectCmd += "                     from " + "db2inst1"  + "." + sTableName_VD5Min + " v left join " + "db2inst1"  + "." + sTableName_DeviceConfig + " d on d.devicename = v.devicename ";
                //selectCmd += "                    where d.sectionid = s.sectionid ";
                //selectCmd += "                      and date(v.timestamp) between date(timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "')) and date(timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "')) ";
                //selectCmd += "                    group by d.sectionid ";
                //selectCmd += "                  ) is null then 0 ";
                //selectCmd += "        else                       ";
                //selectCmd += "                  (select cast(" + "db2inst1"  + ".DIV(SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.car_speed) * " + "db2inst1"  + "." + sFunction_ZERO + "(v.car_volume)), SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.car_volume)), 2) as decimal(8,2)) ";
                //selectCmd += "                     from " + "db2inst1"  + "." + sTableName_VD5Min + " v left join " + "db2inst1"  + "." + sTableName_DeviceConfig + " d on d.devicename = v.devicename ";
                //selectCmd += "                    where d.sectionid = s.sectionid ";
                //selectCmd += "                      and date(v.timestamp) between date(timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "')) and date(timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "')) ";
                //selectCmd += "                    group by d.sectionid )  ";
                //selectCmd += "        end) as car_speed ";
                //selectCmd += "  From " + "db2inst1"  + "." + sTableName_GroupSection + " s LEFT JOIN " + "db2inst1"  + "." + sTableName_GroupDivision + " d1 ON d1.DivisionId = s.Start_DivisionId ";
                //selectCmd += "                                                                                      LEFT JOIN " + "db2inst1"  + "." + sTableName_GroupDivision + " d2 ON d2.DivisionId = s.End_DivisionId ";
                //selectCmd += "                                                                                      LEFT JOIN " + "db2inst1"  + "." + sTableName_GroupLine + " l ON l.LineId = s.LineId ";
                //selectCmd += "                                                                                      LEFT JOIN (select VariableName, VariableValue from " + "db2inst1"  + "." + sTableName_Parameter + " where GroupName = 'DeviceDirection') p ON p.VariableName = s.Direction ";
                //selectCmd += " Where s.SectionName in " + sList + " ";
                //selectCmd += " Order By l.LineId, s.Direction, d1.Mileage ";

                selectCmd += "Select l.LineName, s.SectionName, p.VariableValue, ";
                selectCmd += "       " + "db2inst1"  + ".ZERO2DASH(INT(case when ";
                selectCmd += "                  (select " + "db2inst1"  + ".DIV(SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.car_speed) * " + "db2inst1"  + "." + sFunction_ZERO + "(v.car_volume)), SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.car_volume)), 2) ";
                selectCmd += "                     from " + "db2inst1"  + "." + sTableName_VD5Min + " v left join " + "db2inst1"  + "." + sTableName_DeviceConfig + " d on d.devicename = v.devicename ";
                selectCmd += "                    where d.sectionid = s.sectionid ";
                selectCmd += "                      and date(v.timestamp) between date(timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "')) and date(timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "')) ";
                selectCmd += "                    group by d.sectionid ";
                selectCmd += "                  ) is null then 0 ";
                selectCmd += "        else                       ";
                selectCmd += "                  (select cast(" + "db2inst1"  + ".DIV(SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.car_speed) * " + "db2inst1"  + "." + sFunction_ZERO + "(v.car_volume)), SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.car_volume)), 2) as decimal(8,2)) ";
                selectCmd += "                     from " + "db2inst1"  + "." + sTableName_VD5Min + " v left join " + "db2inst1"  + "." + sTableName_DeviceConfig + " d on d.devicename = v.devicename ";
                selectCmd += "                    where d.sectionid = s.sectionid ";
                selectCmd += "                      and date(v.timestamp) between date(timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "')) and date(timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "')) ";
                selectCmd += "                    group by d.sectionid )  ";
                selectCmd += "        end)) as car_speed ";
                selectCmd += "  From " + "db2inst1"  + "." + sTableName_GroupSection + " s LEFT JOIN " + "db2inst1"  + "." + sTableName_GroupDivision + " d1 ON d1.DivisionId = s.Start_DivisionId ";
                selectCmd += "                                                                                      LEFT JOIN " + "db2inst1"  + "." + sTableName_GroupDivision + " d2 ON d2.DivisionId = s.End_DivisionId ";
                selectCmd += "                                                                                      LEFT JOIN " + "db2inst1"  + "." + sTableName_GroupLine + " l ON l.LineId = s.LineId ";
                selectCmd += "                                                                                      LEFT JOIN (select VariableName, VariableValue from " + "db2inst1"  + "." + sTableName_Parameter + " where GroupName = 'DeviceDirection') p ON p.VariableName = s.Direction ";
                selectCmd += " Where s.SectionName in " + sList + " ";
                selectCmd += " Order By l.LineId, s.Direction, d1.Mileage ";

                InitDB();

                da = new DB2DataAdapter(selectCmd, conn);
                DataTable DT = new DataTable();
                da.Fill(DT);
                da.Dispose();
                conn.Close();
                return DT;
            }
            catch (Exception ex)
            {
                sErrMsg = ex.Message;
                CloseDB();
                return null;
            }
        }
Ejemplo n.º 14
0
        public DataTable Get_RPT_RAMPFULLDAY(string sDevList, DateTime sStartDate, DateTime sEndDate)
        {
            try
            {
                string selectCmd = "";
                selectCmd += "Select r.LineName, ";
                selectCmd += "       r.DivisionName, ";
                selectCmd += "       r.DirectionDesc, ";
                selectCmd += "       r.Volume, ";
                selectCmd += "       r.Devicename";
                selectCmd += "  From ( ";
                selectCmd += "Select Distinct ";
                selectCmd += "       r.LineName as LineName, ";
                selectCmd += "       r.DivisionName as DivisionName, ";
                selectCmd += "       r.DirectionDesc as DirectionDesc, ";
                selectCmd += "       (select (case when MAX(v.car_volume) is null then '-' when MAX(v.car_volume)=0  then '-' else char(MAX(v.car_volume)) end) ";
                selectCmd += "          from " + "db2inst1"  + ".tblvddata1day v, ";
                selectCmd += "               " + "db2inst1"  + ".tbldeviceconfig d ";
                selectCmd += "         where d.devicename = v.devicename ";
                selectCmd += "           and d.location = 'R' ";
                selectCmd += "           and date(v.timestamp) between date(timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "')) and date(timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "')) ";
                selectCmd += "           and d.SectionId = r.SectionId  ";
                selectCmd += "           and UPPER(d.Location_R) = UPPER(r.Location_R) ";
                selectCmd += "        ) as Volume, ";
                selectCmd += "        " + "db2inst1"  + "." + sFunction_MaxVol_Dev_Ramp + "( ";
                selectCmd += "        (select MAX(v.car_volume) from " + "db2inst1"  + ".tblvddata1day v, " + "db2inst1"  + ".tbldeviceconfig d ";
                selectCmd += "          where d.devicename = v.devicename ";
                selectCmd += "            and d.location = 'R' ";
                selectCmd += "            and date(v.timestamp) between date(timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "')) and date(timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "')) ";
                selectCmd += "            and d.SectionId = r.SectionId  ";
                selectCmd += "            and UPPER(d.Location_R) = UPPER(r.Location_R) ";
                selectCmd += "        ), timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "'), r.SectionId, r.Location_R) as Devicename, ";
                selectCmd += "        r.LineId, r.Mileage ";
                selectCmd += "  From " + "db2inst1"  + "." + sTableName_vwRamp + " r ";
                selectCmd += " Where r.SectionName in " + sDevList + " ";
                selectCmd += " ) r ";
                selectCmd += " Order By r.LineId, r.Mileage ";

                InitDB();

                da = new DB2DataAdapter(selectCmd, conn);
                DataTable DT = new DataTable();
                da.Fill(DT);
                da.Dispose();
                conn.Close();
                return DT;
            }
            catch (Exception ex)
            {
                sErrMsg = ex.Message;
                CloseDB();
                return null;
            }
        }
Ejemplo n.º 15
0
        public DataTable GetCtrlRPT_HDA_11vd(string sList, DateTime sStartDate, DateTime sEndDate)
        {
            try
            {
                string selectCmd = "";

                selectCmd += "Select v.Devicename";
                selectCmd += " From (Select * From " + "db2inst1"  + "." + sTableName_VD5Min + " v Where v.Timestamp Between timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "') and timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "')) v ";
                selectCmd += "Where v.Devicename in " + sList + " ";
                selectCmd += "Group By v.Devicename ";
                selectCmd += "Order By v.Devicename ";

                InitDB();

                da = new DB2DataAdapter(selectCmd, conn);
                DataTable DT = new DataTable();
                da.Fill(DT);
                da.Dispose();
                conn.Close();
                return DT;
            }
            catch (Exception ex)
            {
                sErrMsg = ex.Message;
                CloseDB();
                return null;
            }
        }
Ejemplo n.º 16
0
        public DataTable GetNewspaper(string NowTime)
        {
            string selectCmd = "";

            selectCmd += " select  g.LINEID,l.LINENAME,s.VARIABLEVALUE as Direction  ";
             selectCmd += " ,div1.DIVISIONNAME || '-'  ||  div2.DIVISIONNAME as from_location  ";
             selectCmd += " ,(case when t.CAR_SPEED=-1 then '-' else char(t.CAR_SPEED) end) as average_speed   ";
             selectCmd += " ,(case when t.CAR_SPEED >= 0 then  (case when  t.CAR_SPEED >= 80 then '順暢' when  t.CAR_SPEED < 80 and  t.CAR_SPEED >=40  then '車多'    ";
             selectCmd += " when t.CAR_SPEED < 40 then '壅塞'  end) else '-' end)  as congested  ";
             selectCmd += " from TBLTRAFFICDATALOGSECTION t   ";
             selectCmd += " left join db2inst1.tblGroupSection g on t.sectionid=g.sectionid   ";
             selectCmd += " left join db2inst1.tblGroupDivision div1 on g.START_DIVISIONID = div1.DIVISIONID   ";
             selectCmd += " left join db2inst1.tblGroupDivision div2 on g.END_DIVISIONID = div2.DIVISIONID    ";
             selectCmd += " left join db2inst1.tblGroupLine  l on g.LINEID = l.LINEID    ";
             selectCmd += "  left join db2inst1.tblSysParameter  s ON s.GroupName='DeviceDirection' and g.Direction=s.VARIABLENAME   ";
             selectCmd += " where   t.CAR_SPEED < 80  and t.CAR_SPEED >= 0 and g.LINEID not in('T72','T74','T76','T78') and  ";
             selectCmd += " Timestamp ='" + NowTime + ":00'    ";
             selectCmd += " order by g.LINEID,Timestamp,g.direction,div1.MILEAGE    ";
            InitDB();
            da = new DB2DataAdapter(selectCmd, conn);
            DataTable DT = new DataTable();
            da.Fill(DT);

            da.Dispose();
            CloseDB();
            return DT;
        }
Ejemplo n.º 17
0
        public DataTable Get_RPT_VD5MIN(string sDevList, DateTime sStartDate, DateTime sEndDate)
        {
            try
            {
                string selectCmd = "";
                selectCmd += "Select (case when v.DataValidityRate< 100 then '*' else '' end),(case when v.priority = 1 then To_CHAR(v.timestamp,'MM/DD') ";
                selectCmd += "             when v.priority = 2 then To_CHAR(v.timestamp,'HH24:MI')";
                selectCmd += "        else '' end) as timestamp, ";
                selectCmd += "       v.devicename as devicename,  ";
                selectCmd += "       v.degree,  ";
                //selectCmd += "       (case when v.total < 0 then 0 else v.total end), ";
                selectCmd += "       DB2INST1.ZERO2DASH(case when v.total < 0 then 0 else v.total end), ";
                selectCmd += "       (case when c.lane_count >= 1 then char(case when v.lane1 <= 0 then '-' else char(v.lane1) end) else '-' end), ";
                selectCmd += "       (case when c.lane_count >= 1 then char(case when v.lane1_connect = '-1' OR v.lane1_connect = '0' then '-' else v.lane1_connect end) else '-' end),  ";
                selectCmd += "       (case when c.lane_count >= 1 then char(case when v.lane1_big = '-1' OR v.lane1_big = '0' then '-' else v.lane1_big end) else '-' end), ";
                selectCmd += "       (case when c.lane_count >= 1 then char(case when v.lane1_small = '-1' OR v.lane1_small = '0' then '-' else v.lane1_small end) else '-' end),  ";
                selectCmd += " ";
                selectCmd += "       (case when c.lane_count >= 2 then char(case when v.lane2 <= 0 then '-' else char(v.lane2) end) else '-' end), ";
                selectCmd += "       (case when c.lane_count >= 2 then char(case when v.lane2_connect = '-1' OR v.lane2_connect = '0' then '-' else v.lane2_connect end) else '-' end),  ";
                selectCmd += "       (case when c.lane_count >= 2 then char(case when v.lane2_big = '-1' OR v.lane2_big = '0' then '-' else v.lane2_big end) else '-' end), ";
                selectCmd += "       (case when c.lane_count >= 2 then char(case when v.lane2_small = '-1' OR v.lane2_small = '0' then '-' else v.lane2_small end) else '-' end),  ";
                selectCmd += " ";
                selectCmd += "       (case when c.lane_count >= 3 then char(case when v.lane3 <= 0 then '-' else char(v.lane3) end) else '-' end), ";
                selectCmd += "       (case when c.lane_count >= 3 then char(case when v.lane3_connect = '-1' OR v.lane3_connect = '0' then '-' else v.lane3_connect end) else '-' end),  ";
                selectCmd += "       (case when c.lane_count >= 3 then char(case when v.lane3_big = '-1' OR v.lane3_big = '0' then '-' else v.lane3_big end) else '-' end), ";
                selectCmd += "       (case when c.lane_count >= 3 then char(case when v.lane3_small = '-1' OR v.lane3_small = '0' then '-' else v.lane3_small end) else '-' end),  ";
                selectCmd += " ";
                selectCmd += "       (case when c.lane_count >= 4 then char(case when v.lane4 <= 0 then '-' else char(v.lane4) end) else '-' end), ";
                selectCmd += "       (case when c.lane_count >= 4 then char(case when v.lane4_connect = '-1' OR v.lane4_connect = '0' then '-' else v.lane4_connect end) else '-' end),  ";
                selectCmd += "       (case when c.lane_count >= 4 then char(case when v.lane4_big = '-1' OR v.lane4_big = '0' then '-' else v.lane4_big end) else '-' end), ";
                selectCmd += "       (case when c.lane_count >= 4 then char(case when v.lane4_small = '-1' OR v.lane4_small = '0' then '-' else v.lane4_small end) else '-' end),  ";
                selectCmd += " ";
                selectCmd += "       (case when c.lane_count >= 5 then char(case when v.lane5 <= 0 then '-' else char(v.lane5) end) else '-' end), ";
                selectCmd += "       (case when c.lane_count >= 5 then char(case when v.lane5_connect = '-1' OR v.lane5_connect = '0' then '-' else v.lane5_connect end) else '-' end),  ";
                selectCmd += "       (case when c.lane_count >= 5 then char(case when v.lane5_big = '-1' OR v.lane5_big = '0' then '-' else v.lane5_big end) else '-' end), ";
                selectCmd += "       (case when c.lane_count >= 5 then char(case when v.lane5_small = '-1' OR v.lane5_small = '0' then '-' else v.lane5_small end) else '-' end),  ";
                selectCmd += " ";
                selectCmd += "       (case when c.lane_count >= 6 then char(case when v.lane6 <= 0 then '-' else char(v.lane6) end) else '-' end), ";
                selectCmd += "       (case when c.lane_count >= 6 then char(case when v.lane6_connect = '-1' OR v.lane6_connect = '0' then '-' else v.lane6_connect end) else '-' end),  ";
                selectCmd += "       (case when c.lane_count >= 6 then char(case when v.lane6_big = '-1' OR v.lane6_big = '0' then '-' else v.lane6_big end) else '-' end), ";
                selectCmd += "       (case when c.lane_count >= 6 then char(case when v.lane6_small = '-1' OR v.lane6_small = '0' then '-' else v.lane6_small end) else '-' end),  ";
                selectCmd += "  v.priority  ";
                selectCmd += "  From " + "db2inst1"  + "." + sTableName_VWRPT_VD5MIN + " v, ";
                selectCmd += "       " + "db2inst1"  + "." + sTableName_VdConfig + " c ";
                selectCmd += " Where c.devicename = v.devicename ";
                selectCmd += "   And c.devicename in " + sDevList + " ";
                selectCmd += "   And v.timestamp between timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "') ";
                selectCmd += "                       and timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "') ";
                selectCmd += " Order By v.timestamp, v.devicename, v.priority ";

                InitDB();

                da = new DB2DataAdapter(selectCmd, conn);
                DataTable DT = new DataTable();
                da.Fill(DT);
                da.Dispose();
                conn.Close();
                return DT;
            }
            catch (Exception ex)
            {
                sErrMsg = ex.Message;
                CloseDB();
                return null;
            }
        }
Ejemplo n.º 18
0
        public DataTable GetRampSection()
        {
            string selectCmd = "";

            selectCmd += "Select r.LineId, ";
            selectCmd += "       r.LineName, ";
            selectCmd += "       r.SectionId, ";
            selectCmd += "       r.SectionName, ";
            selectCmd += "       r.Direction as Direction1, ";
            selectCmd += "       p.VariableValue as Direction1Desc ";
            selectCmd += "  From " + "db2inst1"  + "." + sTableName_vwRamp + " r LEFT JOIN (select VariableName, VariableValue from " + "db2inst1"  + "." + sTableName_Parameter + " where GroupName = 'DeviceDirection') p ON p.VariableName = r.Direction ";
            selectCmd += " Order By r.LineId, r.Direction, r.Mileage ";

            InitDB();
            da = new DB2DataAdapter(selectCmd, conn);
            DataTable DT = new DataTable();
            da.Fill(DT);

            da.Dispose();
            CloseDB();
            return DT;
        }
Ejemplo n.º 19
0
        public DataTable Get_RPT_VD5MIN_INTERVAL(string sDevList, DateTime sStartDate, DateTime sEndDate)
        {
            try
            {
                string selectCmd = "";
                selectCmd += "Select To_CHAR(v.timestamp,'MM/DD HH24:MI') as timestamp,  ";
                selectCmd += "       v.devicename, ";
                selectCmd += "		 (case when c.lane_count >= 1 then char(case when v.utility_lane1 <= 0 then '-' else char(v.utility_lane1) end) else '-' end),  ";
                selectCmd += "       (case when c.lane_count >= 1 then char(case when v.length_lane1 <= 0 then '-' else char(v.length_lane1) end) else '-' end),  ";
                selectCmd += "       (case when c.lane_count >= 1 then char(case when v.average_car_interval_lane1 <= 0 then '-' else char(v.average_car_interval_lane1) end) else '-' end), ";
                selectCmd += "";
                selectCmd += "		 (case when c.lane_count >= 2 then char(case when v.utility_lane2 <= 0 then '-' else char(v.utility_lane2) end) else '-' end),  ";
                selectCmd += "       (case when c.lane_count >= 2 then char(case when v.length_lane2 <= 0 then '-' else char(v.length_lane2) end) else '-' end),  ";
                selectCmd += "       (case when c.lane_count >= 2 then char(case when v.average_car_interval_lane2 <= 0 then '-' else char(v.average_car_interval_lane2) end) else '-' end), ";
                selectCmd += "";
                selectCmd += "		 (case when c.lane_count >= 3 then char(case when v.utility_lane3 <= 0 then '-' else char(v.utility_lane3) end) else '-' end),  ";
                selectCmd += "       (case when c.lane_count >= 3 then char(case when v.length_lane3 <= 0 then '-' else char(v.length_lane3) end) else '-' end),  ";
                selectCmd += "       (case when c.lane_count >= 3 then char(case when v.average_car_interval_lane3 <= 0 then '-' else char(v.average_car_interval_lane3) end) else '-' end), ";
                selectCmd += "";
                selectCmd += "		 (case when c.lane_count >= 4 then char(case when v.utility_lane4 <= 0 then '-' else char(v.utility_lane4) end) else '-' end),  ";
                selectCmd += "       (case when c.lane_count >= 4 then char(case when v.length_lane4 <= 0 then '-' else char(v.length_lane4) end) else '-' end),  ";
                selectCmd += "       (case when c.lane_count >= 4 then char(case when v.average_car_interval_lane4 <= 0 then '-' else char(v.average_car_interval_lane4) end) else '-' end), ";
                selectCmd += "";
                selectCmd += "		 (case when c.lane_count >= 5 then char(case when v.utility_lane5 <= 0 then '-' else char(v.utility_lane5) end) else '-' end),  ";
                selectCmd += "       (case when c.lane_count >= 5 then char(case when v.length_lane5 <= 0 then '-' else char(v.length_lane5) end) else '-' end),  ";
                selectCmd += "       (case when c.lane_count >= 5 then char(case when v.average_car_interval_lane5 <= 0 then '-' else char(v.average_car_interval_lane5) end) else '-' end), ";
                selectCmd += "";
                selectCmd += "		 (case when c.lane_count >= 6 then char(case when v.utility_lane6 <= 0 then '-' else char(v.utility_lane6) end) else '-' end),  ";
                selectCmd += "       (case when c.lane_count >= 6 then char(case when v.length_lane6 <= 0 then '-' else char(v.length_lane6) end) else '-' end),  ";
                selectCmd += "       (case when c.lane_count >= 6 then char(case when v.average_car_interval_lane6 <= 0 then '-' else char(v.average_car_interval_lane6) end) else '-' end), ";
                selectCmd += "";
                selectCmd += "       (case when v.car_length <= 0 then '-' else char(v.car_length) end), ";
                selectCmd += "       (case when v.average_car_interval <= 0 then '-' else char(v.average_car_interval) end) ";
                selectCmd += "        ";
                selectCmd += "  From " + "db2inst1"  + "." + sTableName_VWRPT_VD5MIN_INTERVAL + " v, ";
                selectCmd += "       " + "db2inst1"  + "." + sTableName_VdConfig + " c ";
                selectCmd += " Where c.devicename = v.devicename ";
                selectCmd += "   And c.devicename in " + sDevList + " ";
                selectCmd += "   And v.timestamp between timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "') ";
                selectCmd += "                       and timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "') ";
                selectCmd += " Order By v.timestamp, v.devicename ";

                InitDB();

                da = new DB2DataAdapter(selectCmd, conn);
                DataTable DT = new DataTable();
                da.Fill(DT);
                da.Dispose();
                conn.Close();
                return DT;
            }
            catch (Exception ex)
            {
                sErrMsg = ex.Message;
                CloseDB();
                return null;
            }
        }
Ejemplo n.º 20
0
        public DataTable GetAllSectionDev()
        {
            string selectCmd = "";

            selectCmd += "Select l.LineName, ";
            selectCmd += "       s.SectionName, ";
            selectCmd += "       p.VariableValue, ";
            selectCmd += "       (select MAX(v.car_volume) from " + "db2inst1"  + "." + sTableName_VD1Day + " v, " + "db2inst1"  + "." + sTableName_DeviceConfig + " d where d.Devicename = v.Devicename and d.sectionid = s.sectionid and date(v.timestamp) = date(current timestamp - 1 DAYS) ) as car_volume, ";
            selectCmd += "       " + "db2inst1"  + "." + sFunction_MaxVol_Dev + "((select MAX(v.car_volume) from " + "db2inst1"  + "." + sTableName_VD1Day + " v, " + "db2inst1"  + "." + sTableName_DeviceConfig + " d where d.Devicename = v.Devicename and d.sectionid = s.sectionid and date(v.timestamp) = date(current timestamp - 1 DAYS)), current timestamp - 1 DAYS, s.sectionid) as DeviceList ";
            selectCmd += "  From " + "db2inst1"  + "." + sTableName_GroupSection + " s LEFT JOIN " + "db2inst1"  + "." + sTableName_GroupDivision + " d1 ON d1.DivisionId = s.Start_DivisionId ";
            selectCmd += "	                                                                                    LEFT JOIN " + "db2inst1"  + "." + sTableName_GroupDivision + " d2 ON d2.DivisionId = s.End_DivisionId ";
            selectCmd += "                                                                                      LEFT JOIN " + "db2inst1"  + "." + sTableName_GroupLine + " l ON l.LineId = s.LineId ";
            selectCmd += "                                                                                      LEFT JOIN (select VariableName, VariableValue from " + "db2inst1"  + "." + sTableName_Parameter + " where GroupName = 'DeviceDirection') p ON p.VariableName = s.Direction ";
            selectCmd += " Order By l.LineId, s.Direction, d1.Mileage ";

            InitDB();
            da = new DB2DataAdapter(selectCmd, conn);
            DataTable DT = new DataTable();
            da.Fill(DT);

            da.Dispose();
            CloseDB();
            return DT;
        }
Ejemplo n.º 21
0
        public DataTable GetDeviceList()
        {
            try
            {
                string selectCmd = "";
                selectCmd += "Select DISTINCT DEVICE_TYPE as OperationName ";
                selectCmd += "  From " + "db2inst1"  + "." + sTableName_DeviceConfig + " ";
                selectCmd += " Order By DEVICE_TYPE ";

                InitDB();

                da = new DB2DataAdapter(selectCmd, conn);
                DataTable DT = new DataTable();
                da.Fill(DT);
                da.Dispose();
                conn.Close();
                return DT;
            }
            catch (Exception ex)
            {
                sErrMsg = ex.Message;
                CloseDB();
                return null;
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// <para>Create a <see cref="DB2DataAdapter"/> with the given update behavior and connection.</para>
        /// </summary>
        /// <param name="updateBehavior">
        /// <para>One of the <see cref="UpdateBehavior"/> values.</para>
        /// </param>
        /// <param name="connection">
        /// <para>The open connection to the database.</para>
        /// </param>
        /// <returns>An <see cref="DB2DataAdapter"/>.</returns>
        /// <exception cref="ArgumentNullException">
        /// <para><paramref name="connection"/> can not be <see langword="null"/> (Nothing in Visual Basic).</para>
        /// </exception>
        protected override DbDataAdapter GetDataAdapter(UpdateBehavior updateBehavior, IDbConnection connection)
        {
            string queryStringToBeFilledInLater = String.Empty;
            DB2DataAdapter adapter = new DB2DataAdapter(queryStringToBeFilledInLater, (DB2Connection)connection);

            if (updateBehavior == UpdateBehavior.Continue)
            {
                adapter.RowUpdated += new DB2RowUpdatedEventHandler(OnDB2RowUpdated);
            }
            return adapter;
        }
Ejemplo n.º 23
0
        public DataTable GetDevList()
        {
            string selectCmd = "";

            selectCmd += "Select VariableName ";
            selectCmd += "  From " + "db2inst1"  + "." + sTableName_Parameter + " ";
            selectCmd += " Where UPPER(GroupName) = 'DEVICE_TYPE' ";
            selectCmd += " Order By GroupName, SysId ";

            InitDB();
            da = new DB2DataAdapter(selectCmd, conn);
            DataTable DT = new DataTable();
            da.Fill(DT);

            da.Dispose();
            CloseDB();
            return DT;
        }
Ejemplo n.º 24
0
 public DB2CommandBuilder(DB2DataAdapter adapter)
 {
     DataAdapter = adapter;
 }
Ejemplo n.º 25
0
        public DataTable GetDirectionNS()
        {
            string selectCmd = "";
            selectCmd += "Select  s.Direction as Direction1, p.VariableValue as Direction1Desc  ";
            selectCmd += "From db2inst1.tblGroupSection s  ";
            selectCmd += "LEFT JOIN (select VariableName, VariableValue from db2inst1.tblSysParameter where GroupName = 'DeviceDirection') p ON p.VariableName = s.Direction ";
            selectCmd += "where  s.Direction in " + "('N','S') ";
            selectCmd += "group by s.Direction,p.VariableValue ";
            selectCmd += "Order By  s.Direction ";

            InitDB();
            da = new DB2DataAdapter(selectCmd, conn);
            DataTable DT = new DataTable();
            da.Fill(DT);

            da.Dispose();
            CloseDB();
            return DT;
        }
Ejemplo n.º 26
0
        public DataTable GetFieldList()
        {
            try
            {
                string selectCmd = "";
                selectCmd += "Select * ";
                selectCmd += "  From " + sTableName_SysColumns + " ";
                selectCmd += " Where UPPER(TBCreator) = '" + "db2inst1"  + "' ";
                selectCmd += "   And UPPER(TBName) = '" + sTableName_VD5Min.ToString().ToUpper() + "' ";
                selectCmd += " Order By ColNo ";

                InitDB();

                da = new DB2DataAdapter(selectCmd, conn);
                DataTable DT = new DataTable();
                da.Fill(DT);
                da.Dispose();
                conn.Close();
                return DT;
            }
            catch (Exception ex)
            {
                sErrMsg = ex.Message;
                CloseDB();
                return null;
            }
        }
Ejemplo n.º 27
0
        public DataTable GetLineName()
        {
            string selectCmd = "";

            selectCmd += "select LineId,LineName ";
            selectCmd += "  From " + "db2inst1"  + "." + sTableName_tblgroupline + " ";
            selectCmd += " Order By LINEID ";

            InitDB();
            da = new DB2DataAdapter(selectCmd, conn);
            DataTable DT = new DataTable();
            da.Fill(DT);

            da.Dispose();
            CloseDB();
            return DT;
        }
Ejemplo n.º 28
0
        /// <summary>
        /// 执行指定数据库连接对象的命令,指定存储过程参数,返回DataSet.
        /// </summary>
        /// <remarks>
        /// 示例:  
        ///  DataSet ds = ExecuteDataset(conn, CommandType.StoredProcedure, "GetOrders", new DB2Parameter("@prodid", 24));
        /// </remarks>
        /// <param name="connection">一个有效的数据库连接对象</param>
        /// <param name="commandType">命令类型 (存储过程,命令文本或其它)</param>
        /// <param name="commandText">存储过程名或T-SQL语句</param>
        /// <param name="commandParameters">DB2Paramter参数数组</param>
        /// <returns>返回一个包含结果集的DataSet</returns>
        public static DataSet ExecuteDataset(DB2Connection connection, CommandType commandType, string commandText, params DB2Parameter[] commandParameters)
        {
            if (connection == null) throw new ArgumentNullException("connection");

            // 预处理
            DB2Command cmd = new DB2Command();
            bool mustCloseConnection = false;
            PrepareCommand(cmd, connection, (DB2Transaction)null, commandType, commandText, commandParameters, out mustCloseConnection);

            // 创建DB2DataAdapter和DataSet.
            using (DB2DataAdapter da = new DB2DataAdapter(cmd))
            {
                DataSet ds = new DataSet();

                // 填充DataSet.
                da.Fill(ds);

                cmd.Parameters.Clear();

                if (mustCloseConnection)
                    connection.Close();

                return ds;
            }
        }
Ejemplo n.º 29
0
        public DataTable GetLineSection()
        {
            string selectCmd = "";

            //selectCmd += "Select l.LineId, ";
            //selectCmd += "       l.LineName, ";
            //selectCmd += "       s.SectionId, ";
            //selectCmd += "       s.SectionName, ";
            //selectCmd += "       s.Direction as Direction1, ";
            //selectCmd += "       p.VariableValue as Direction1Desc ";
            //selectCmd += "  From " + "db2inst1"  + "." + sTableName_GroupSection + " s LEFT JOIN " + "db2inst1"  + "." + sTableName_GroupDivision + " d1 ON d1.DivisionId = s.Start_DivisionId ";
            //selectCmd += "	                                                                                    LEFT JOIN " + "db2inst1"  + "." + sTableName_GroupDivision + " d2 ON d2.DivisionId = s.End_DivisionId ";
            //selectCmd += "                                                                                      LEFT JOIN " + "db2inst1"  + "." + sTableName_GroupLine + " l ON l.LineId = s.LineId ";
            //selectCmd += "                                                                                      LEFT JOIN (select VariableName, VariableValue from " + "db2inst1"  + "." + sTableName_Parameter + " where GroupName = 'DeviceDirection') p ON p.VariableName = s.Direction ";
            //selectCmd += " Order By l.LineId, s.Direction, d1.Mileage ";

            selectCmd += "Select l.LineId, ";
            selectCmd += "       l.LineName, ";
            selectCmd += "       s.SectionId, ";
            selectCmd += "       s.SectionName, ";
            selectCmd += "       s.Direction as Direction1, ";
            selectCmd += "       p.VariableValue as Direction1Desc ";
            selectCmd += "  From " + "db2inst1"  + "." + sTableName_GroupSection + " s LEFT JOIN " + "db2inst1"  + "." + sTableName_GroupDivision + " d1 ON d1.DivisionId = s.Start_DivisionId ";
            selectCmd += "	                                                                                    LEFT JOIN " + "db2inst1"  + "." + sTableName_GroupDivision + " d2 ON d2.DivisionId = s.End_DivisionId ";
            selectCmd += "                                                                                      LEFT JOIN " + "db2inst1"  + "." + sTableName_GroupLine + " l ON l.LineId = s.LineId ";
            selectCmd += "                                                                                      LEFT JOIN (select VariableName, VariableValue from " + "db2inst1"  + "." + sTableName_Parameter + " where GroupName = 'DeviceDirection') p ON p.VariableName = s.Direction ";
            selectCmd += "                                                                                      LEFT JOIN " + "db2inst1"  + "." + sTableName_DeviceConfig + " d on  s.SectionId = d.LineId ";
            selectCmd += "                                                                                      LEFT JOIN " + "db2inst1"  + "." + sTableName_tblMFCCConfig + " m on d.MFCCID=m.MFCCID ";
            selectCmd += " Order By l.LineId, s.Direction, d1.Mileage ";

            InitDB();
            da = new DB2DataAdapter(selectCmd, conn);
            DataTable DT = new DataTable();
            da.Fill(DT);

            da.Dispose();
            CloseDB();
            return DT;
        }
Ejemplo n.º 30
0
        /// <summary>
        /// 执行指定事务的命令,指定参数,返回DataSet.
        /// </summary>
        /// <remarks>
        /// 示例:  
        ///  DataSet ds = ExecuteDataset(trans, CommandType.StoredProcedure, "GetOrders", new DB2Parameter("@prodid", 24));
        /// </remarks>
        /// <param name="transaction">事务</param>
        /// <param name="commandType">命令类型 (存储过程,命令文本或其它)</param>
        /// <param name="commandText">存储过程名或T-SQL语句</param>
        /// <param name="commandParameters">DB2Paramter参数数组</param>
        /// <returns>返回一个包含结果集的DataSet</returns>
        public static DataSet ExecuteDataset(DB2Transaction transaction, CommandType commandType, string commandText, params DB2Parameter[] commandParameters)
        {
            if (transaction == null) throw new ArgumentNullException("transaction");
            if (transaction != null && transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");

            // 预处理
            DB2Command cmd = new DB2Command();
            bool mustCloseConnection = false;
            PrepareCommand(cmd, transaction.Connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection);

            // 创建 DataAdapter & DataSet
            using (DB2DataAdapter da = new DB2DataAdapter(cmd))
            {
                DataSet ds = new DataSet();
                da.Fill(ds);
                cmd.Parameters.Clear();
                return ds;
            }
        }
Ejemplo n.º 31
0
        public DataTable Get_RPT_RampDayVolume(string sList, DateTime sStartDate, DateTime sEndDate)
        {
            try
            {
                string selectCmd = "";

                //selectCmd += "Select ROW_NUMBER() over() as RowNum, ";
                //selectCmd += "       v.Devicename, ";
                //selectCmd += "       date(v.Timestamp) as date, ";
                //selectCmd += "       (SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane1)) +  ";
                //selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane2)) +  ";
                //selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane3)) + ";
                //selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane4)) + ";
                //selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane5)) + ";
                //selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane6)) + ";
                //selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane7)) ";
                //selectCmd += "       ) as connect_car_volume, ";
                //selectCmd += "       cast( ";
                //selectCmd += "       " + "db2inst1"  + "." + sFunction_DIV + "( ";
                //selectCmd += "                    (SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane1)) +  ";
                //selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane2)) +  ";
                //selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane3)) + ";
                //selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane4)) + ";
                //selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane5)) + ";
                //selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane6)) + ";
                //selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane7)) ";
                //selectCmd += "                    ), ";
                //selectCmd += "                    SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.car_volume)), ";
                //selectCmd += "                    2 ";
                //selectCmd += "                   )*100 as decimal(8,2)) as connect_car_volume_rate, ";
                //selectCmd += "       (SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane1)) +  ";
                //selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane2)) +  ";
                //selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane3)) + ";
                //selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane4)) + ";
                //selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane5)) + ";
                //selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane6)) + ";
                //selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane7)) ";
                //selectCmd += "       ) as big_car_volume, ";
                //selectCmd += "       cast( ";
                //selectCmd += "       " + "db2inst1"  + "." + sFunction_DIV + "( ";
                //selectCmd += "                    (SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane1)) +  ";
                //selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane2)) +  ";
                //selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane3)) + ";
                //selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane4)) + ";
                //selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane5)) + ";
                //selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane6)) + ";
                //selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane7)) ";
                //selectCmd += "                    ), ";
                //selectCmd += "                    SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.car_volume)), ";
                //selectCmd += "                    2 ";
                //selectCmd += "                    )*100 as decimal(8,2)) as big_car_volume_rate, ";
                //selectCmd += "       (SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane1)) +  ";
                //selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane2)) +  ";
                //selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane3)) + ";
                //selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane4)) + ";
                //selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane5)) + ";
                //selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane6)) + ";
                //selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane7)) ";
                //selectCmd += "       ) as small_car_volume, ";
                //selectCmd += "       cast( ";
                //selectCmd += "       " + "db2inst1"  + "." + sFunction_DIV + "( ";
                //selectCmd += "                    (SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane1)) +  ";
                //selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane2)) +  ";
                //selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane3)) + ";
                //selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane4)) + ";
                //selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane5)) + ";
                //selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane6)) + ";
                //selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane7)) ";
                //selectCmd += "                    ), ";
                //selectCmd += "                    SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.car_volume)), ";
                //selectCmd += "                    2 ";
                //selectCmd += "                    )*100 as decimal(8,2)) as small_car_volume_rate, ";
                //selectCmd += "       SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.car_volume)) as car_volume ";
                //selectCmd += " From (Select * From " + "db2inst1"  + "." + sTableName_VD5Min + " v Where v.Timestamp Between timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "') and timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "')) v ";
                //selectCmd += "Where v.Devicename in " + sList + " ";
                //selectCmd += "Group By v.Devicename, date(v.Timestamp) ";
                //selectCmd += "Order By v.Devicename, date(v.Timestamp) ";

                selectCmd += "Select ROW_NUMBER() over() as RowNum, ";
                selectCmd += "       v.Devicename, ";
                selectCmd += "       date(v.Timestamp) as date, ";
                selectCmd += "       " + "db2inst1"  + ".ZERO2DASH(SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane1)) +  ";
                selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane2)) +  ";
                selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane3)) + ";
                selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane4)) + ";
                selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane5)) + ";
                selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane6)) + ";
                selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane7)) ";
                selectCmd += "       ) as connect_car_volume, ";
                selectCmd += "       cast( ";
                selectCmd += "       " + "db2inst1"  + "." + sFunction_DIV + "( ";
                selectCmd += "                    (SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane1)) +  ";
                selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane2)) +  ";
                selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane3)) + ";
                selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane4)) + ";
                selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane5)) + ";
                selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane6)) + ";
                selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.connect_car_volume_lane7)) ";
                selectCmd += "                    ), ";
                selectCmd += "                    SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.car_volume)), ";
                selectCmd += "                    2 ";
                selectCmd += "                   )*100 as decimal(8,2)) as connect_car_volume_rate, ";
                selectCmd += "       " + "db2inst1"  + ".ZERO2DASH(SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane1)) +  ";
                selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane2)) +  ";
                selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane3)) + ";
                selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane4)) + ";
                selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane5)) + ";
                selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane6)) + ";
                selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane7)) ";
                selectCmd += "       ) as big_car_volume, ";
                selectCmd += "       cast( ";
                selectCmd += "       " + "db2inst1"  + "." + sFunction_DIV + "( ";
                selectCmd += "                    (SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane1)) +  ";
                selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane2)) +  ";
                selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane3)) + ";
                selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane4)) + ";
                selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane5)) + ";
                selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane6)) + ";
                selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.big_car_volume_lane7)) ";
                selectCmd += "                    ), ";
                selectCmd += "                    SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.car_volume)), ";
                selectCmd += "                    2 ";
                selectCmd += "                    )*100 as decimal(8,2)) as big_car_volume_rate, ";
                selectCmd += "       " + "db2inst1"  + ".ZERO2DASH(SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane1)) +  ";
                selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane2)) +  ";
                selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane3)) + ";
                selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane4)) + ";
                selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane5)) + ";
                selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane6)) + ";
                selectCmd += "        SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane7)) ";
                selectCmd += "       ) as small_car_volume, ";
                selectCmd += "       cast( ";
                selectCmd += "       " + "db2inst1"  + "." + sFunction_DIV + "( ";
                selectCmd += "                    (SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane1)) +  ";
                selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane2)) +  ";
                selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane3)) + ";
                selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane4)) + ";
                selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane5)) + ";
                selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane6)) + ";
                selectCmd += "                     SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.small_car_volume_lane7)) ";
                selectCmd += "                    ), ";
                selectCmd += "                    SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.car_volume)), ";
                selectCmd += "                    2 ";
                selectCmd += "                    )*100 as decimal(8,2)) as small_car_volume_rate, ";
                selectCmd += "       " + "db2inst1"  + ".ZERO2DASH(SUM(" + "db2inst1"  + "." + sFunction_ZERO + "(v.car_volume))) as car_volume ";
                selectCmd += " From (Select * From " + "db2inst1"  + "." + sTableName_VD5Min + " v Where v.Timestamp Between timestamp('" + sStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "') and timestamp('" + sEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "')) v ";
                selectCmd += "Where v.Devicename in " + sList + " ";
                selectCmd += "Group By v.Devicename, date(v.Timestamp) ";
                selectCmd += "Order By v.Devicename, date(v.Timestamp) ";

                InitDB();

                da = new DB2DataAdapter(selectCmd, conn);
                DataTable DT = new DataTable();
                da.Fill(DT);
                da.Dispose();
                conn.Close();
                return DT;
            }
            catch (Exception ex)
            {
                sErrMsg = ex.Message;
                CloseDB();
                return null;
            }
        }