public bool AddPeriod(byte in_colorRed, byte in_colorGreen, byte in_colorBlue, DateTime in_PeriodStartTime, DateTime in_PeriodEndTime, bool is_last)
        {
            Section temp = new Section(in_colorRed, in_colorGreen, in_colorBlue, in_PeriodStartTime, in_PeriodEndTime, is_last);
            this.Data.Add(temp);

            this.SetEmpty_property = false;
            return true;
        }
예제 #2
0
        public Section[] GetTimeLineData(DateTime in_StartTime, DateTime in_EndTime, DateTime in_CURR)
        {
            Section[] NULL_return = new Section[0];
            if (!this.Initialized) return NULL_return;

            Section[] a1;

            String SQLQuery = @"SELECT DISTINCT
                                [MachineState]
                                ,COLORS.[ColorValue]
                                ,[StartTime]
                                ,[EndTime]
                                FROM [SFI_local_PC_SQL].[dbo].[tbl_slc_MachineStateHistory]
                                INNER JOIN
                                [SFI_local_PC_SQL].[dbo].[tbl_slc_MachineStates] AS COLORS
                                ON [MachineState]=COLORS.StatusCode
                                WHERE 
                                [StartTime]>=CONVERT(DATETIME,'" + in_StartTime.ToString("yyyy-MM-dd HH:mm:ss") + "',120) AND [StartTime]<CONVERT(DATETIME,'" + in_EndTime.ToString("yyyy-MM-dd HH:mm:ss") + "',120)" +
                                "OR [EndTime]>=CONVERT(DATETIME,'" + in_StartTime.ToString("yyyy-MM-dd HH:mm:ss") + "',120) AND [StartTime]<CONVERT(DATETIME,'" + in_EndTime.ToString("yyyy-MM-dd HH:mm:ss") + "',120)" +
                                "OR [StartTime]<CONVERT(DATETIME,'" + in_StartTime.ToString("yyyy-MM-dd HH:mm:ss") + "',120) AND CONVERT(DATETIME,'" + in_StartTime.ToString("yyyy-MM-dd HH:mm:ss") + "',120)<CONVERT(DATETIME,'" + in_CURR.ToString("yyyy-MM-dd HH:mm:ss") + "',120) AND [EndTime] IS NULL " +
                                "ORDER BY [StartTime] asc";


            String SQLQuery_getCount = @"SELECT DISTINCT
                                    [MachineState]
                                    ,COLORS.[ColorValue]
                                    ,[StartTime]
                                    FROM [SFI_local_PC_SQL].[dbo].[tbl_slc_MachineStateHistory]
                                    INNER JOIN
                                    [SFI_local_PC_SQL].[dbo].[tbl_slc_MachineStates] AS COLORS
                                    ON [MachineState]=COLORS.StatusCode
                                    WHERE 
                                    [StartTime] BETWEEN CONVERT(DATETIME,'" + in_StartTime.ToString("yyyy-MM-dd HH:mm:ss") + "',120) AND CONVERT(DATETIME,'" + in_EndTime.ToString("yyyy-MM-dd HH:mm:ss") + "',120)" +
                                    "ORDER BY [StartTime] asc";

            //get count
            Int32 RecordsCount=0;
            using (SqlConnection con = new SqlConnection(this.ConnectionString))
            {
                con.Open();

                using (SqlCommand cmd = new SqlCommand(SQLQuery, con))
                {
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            RecordsCount++;
                        }
                    }
                }
            }
             
            using (SqlConnection con = new SqlConnection(this.ConnectionString))
            {
                con.Open();

                using (SqlCommand cmd = new SqlCommand(SQLQuery, con))
                {
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        a1 = new Section[RecordsCount];
                        for (int i = 0; i < RecordsCount; i++)
                        {
                            reader.Read();
                            a1[i] = new Section();
                            a1[i].MachineState = reader.GetInt32(0);
                            a1[i].StartTime = reader.GetDateTime(2);

                            try
                            {
                                a1[i].EndTime = reader.GetDateTime(3);
                            }
                            catch
                            {
                                a1[i].EndTime = DateTime.MaxValue;
                            }
                            a1[i].colorBlue = Convert.ToByte(reader.GetInt64(1) >> 16);
                            a1[i].colorGreen = Convert.ToByte((reader.GetInt64(1) >> 8) & 255);
                            a1[i].colorRed = Convert.ToByte((reader.GetInt64(1)  & 255));
                            
                        }
                    }
                }
            }

            return a1;
        }