Exemplo n.º 1
0
        /*****************************************Functions*********************************************/
        public OEEMachine(int deviceID, string name, OEETypes.GROUP_TYPE type)
        {
            _id     = deviceID;
            _type   = type;
            _name   = (_id + 1).ToString() + "号" + name;
            _status = new OEETypes.MachineStatus()
            {
                outputPlanned   = 0,
                outputQualified = 0,
                // statusPoints = new List<OEETypes.StatusPoint>(),
                // hoursDataTable = new DataTable()
            };


            plannedOutput     = 0;
            qualifiedOutput   = 0;
            maintainanceHours = 0;
            prepareHours      = 0;

            statusPoints   = new List <OEETypes.StatusPoint>();
            hoursDataTable = new DataTable();
            DataColumn dc1 = new DataColumn("time");

            dc1.DataType = typeof(System.String);
            DataColumn dc2 = new DataColumn("value1");

            dc2.DataType = typeof(System.String);
            DataColumn dc3 = new DataColumn("value2");

            dc2.DataType = typeof(System.String);
            hoursDataTable.Columns.Add(dc1);
            hoursDataTable.Columns.Add(dc2);
            hoursDataTable.Columns.Add(dc3);

            maintainanceDataTable = new DataTable();
            DataColumn dc4 = new DataColumn("timestamp1");

            dc4.DataType = typeof(System.String);
            DataColumn dc5 = new DataColumn("timestamp2");

            dc5.DataType = typeof(System.String);
            maintainanceDataTable.Columns.Add(dc4);
            maintainanceDataTable.Columns.Add(dc5);
        }
        private void ShowCastingHoursList()
        {
            DataGridView gridView = this.HoursDataGridView;

            gridView.Rows.Clear();
            AddDataGridViewHeaders();
            int index = 0;

            for (DateTime date = startDate; date <= endDate; date = date.AddDays(1))
            {
                int      paramsLength = machineGroups[selectedMachineGroup].Count * MACHINEHOUR_LIST_HEADER.Length + MACHINEHOUR_LIST_ADDITION.Length;
                string[] value        = new string[paramsLength];
                int      col          = 0;
                int      total        = (int)Math.Ceiling((endDate - startDate).TotalMinutes);
                DateTime qStart       = OEEUtils.ConvertToStartOfDay(date);;
                DateTime qEnd         = OEEUtils.ConvertToEndOfDay(date);

                DateTime startTimePoint   = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
                long     startTime_offset = (long)Math.Ceiling((startDate - startTimePoint).TotalSeconds);
                long     endTime_offset   = (long)Math.Ceiling((qEnd - startTimePoint).TotalSeconds);

                value[col++] = index.ToString();
                value[col++] = date.ToString("MM/dd");

                foreach (OEEMachine machine in machineGroups[selectedMachineGroup].Machines)
                {
                    DataRow[] dr;
                    int       off   = 0;
                    int       idle  = 0;
                    int       work  = 0;
                    int       alarm = 0;
                    int       valid = 0;
                    string    cmd;
                    OEETypes.MachineStatus machineStatus = machine.Status;
                    DataTable dt = machineStatus.hoursDataTable;

                    try
                    {
                        value[col++] = total.ToString();
                        cmd          = "time>'" + startTime_offset + "' and time<'" + endTime_offset + "' and value1='" + gVariable.MACHINE_STATUS_DOWN + "'";
                        dr           = dt.Select(cmd);
                        off          = dr.Count();
                        value[col++] = off.ToString();
                        cmd          = "time>'" + startTime_offset + "' and time<'" + endTime_offset + "' and value1='" + gVariable.MACHINE_STATUS_IDLE + "'";
                        dr           = dt.Select(cmd);
                        idle         = dr.Count();
                        value[col++] = idle.ToString();
                        cmd          = "time>'" + startTime_offset + "' and time<'" + endTime_offset + "' and value1='" + gVariable.MACHINE_STATUS_STARTED + "'";
                        dr           = dt.Select(cmd);
                        work         = dr.Count();
                        value[col++] = work.ToString();
                        cmd          = "time>'" + startTime_offset + "' and time<'" + endTime_offset + "' and value1>='" + gVariable.MACHINE_STATUS_DEVICE_ALARM + "'";
                        dr           = dt.Select(cmd);
                        alarm        = dr.Count();
                        value[col++] = alarm.ToString();
                        valid        = total - idle - alarm;
                        value[col++] = valid.ToString();
                    }
                    catch (Exception)
                    {
                        off          = 0;
                        value[col++] = off.ToString();
                        idle         = 0;
                        value[col++] = idle.ToString();
                        work         = 0;
                        value[col++] = work.ToString();
                        alarm        = 0;
                        value[col++] = alarm.ToString();
                        valid        = 0;
                        value[col++] = valid.ToString();
                    }
                }
                index++;
                gridView.Rows.Add(value);
            }
        }