using System;
using System.Drawing;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using DataDynamics.ActiveReports;
using DataDynamics.ActiveReports.Document;
using System.Data;
namespace FPER
{
    /// 
    /// Summary description for NewActiveReport1.
    /// 
    public partial class AReportLog : DataDynamics.ActiveReports.ActiveReport
    {// ActiveReport Class 
        int index = 0;
        private ArrayList details;
        public bool findTime = false;
        public DateTime findStartTime;
        public DateTime findEndTime;
        public List findType = null;
        private int tleReceiverId = 0;
        private string tleFromToDate = "";
        private string tleAlarmType = "전체";
        private string tleAlarmLocation = "전체";
        public int ReceiverId { set { this.tleReceiverId = value; } }
        public string FromToDate { set { this.tleFromToDate = value; } }
        public string AlarmType { set { this.tleAlarmType = value; } }
        public string AlarmLocation { set { this.tleAlarmLocation = value; } }
        public ArrayList Details { set { this.details = value; } }
        public List LEventLog;
        bool live = false;
        public AReportLog(bool live)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            this.live = live;
        }
        private void AReportLog_DataInitialize(object sender, System.EventArgs eArgs)
        {// data init function 
            try
            {
                //txtTleReceiverId.Text = this.tleReceiverId.ToString();
                //txtTleFromToDate.Text = this.tleFromToDate;
                //txtTleAlarmType.Text = this.tleAlarmType;
                //txtTleAlarmLocation.Text = this.tleAlarmLocation;
                if (this.live)
                {
                    this.label1.Text = "수신기 이력 보고서 (현재내역)";
                }
                else
                {
                    this.label1.Text = "수신기 이력 보고서 (과거내역)";
                }
                if (findTime)
                {
                    this.textBox1.Text = string.Format("{0:D4}-{1:D2}-{2:D2} {3:D2}:{4:D2}:{5:D2} ~{6:D4}-{7:D2}-{8:D2} {9:D2}:{10:D2}:{11:D2}",
                      this.findStartTime.Year, this.findStartTime.Month, this.findStartTime.Day,
                      this.findStartTime.Hour, this.findStartTime.Minute, this.findStartTime.Second,
                      this.findEndTime.Year, this.findEndTime.Month, this.findEndTime.Day,
                      this.findEndTime.Hour, this.findEndTime.Minute, this.findEndTime.Second);
                }
                else
                {
                    this.textBox1.Text = "전체";
                }
                if (findType != null && findType.Count > 0)
                {
                    this.textBox2.Text = "";
                    foreach (string text in findType)
                    {
                        this.textBox2.Text += text;
                        this.textBox2.Text += ", ";
                    }
                    this.textBox2.Text = this.textBox2.Text.Substring(0, this.textBox2.Text.Length - 2);
                }
                else
                {
                    this.textBox2.Text = "전체";
                }
                this.PageSettings.Margins.Bottom = 0.3F;
                this.PageSettings.Margins.Left = 0.4F;
                this.PageSettings.Margins.Right = 0.3F;
                this.PageSettings.Margins.Top = 1F;
                this.PageSettings.PaperHeight = 11F;
                this.PageSettings.PaperWidth = 8.5F;
                this.Fields.Add("EventNumber");
                this.Fields.Add("EventTime");
                this.Fields.Add("DeviceName");
                this.Fields.Add("EventName");
                this.Fields.Add("EventPosition");
                this.Fields.Add("Circuit");
                this.Fields.Add("EventErrorStatus");
                this.textBox9.Text = string.Format("수신기 : {0}번", this.tleReceiverId);
                //this.Fields.Add("ConfirmYes");
                //this.Fields.Add("ConfirmDate");
                // Init some test data:
                //this.details = new ArrayList();
                //this.details.Add(new ReportDetail("A", 10.00, 2));
                //this.details.Add(new ReportDetail("B", 0.12, 1));
                //this.details.Add(new ReportDetail("C", 5.92, 3));
                //this.index = -1;
            }
            catch (Exception ex)
            {
                Util.UErrorMessage(ex, 0, 0);
            }
        }
        //private void AReportLog_FetchData(object sender, DataDynamics.ActiveReports.ActiveReport.FetchEventArgs eArgs) {
        //  try {
        //    if (this.index >= this.details.Count - 1) {
        //      eArgs.EOF = true;
        //      return;
        //    }
        //    else {
        //      eArgs.EOF = false;
        //    }
        //    AlarmLogPostDetail row = (AlarmLogPostDetail)this.details[++this.index];
        //    this.Fields["EventNumber"].Value = row.no;
        //    this.Fields["EventTime"].Value = row.alarmDate;
        //    this.Fields["DeviceName"].Value = row.alarmLocation;
        //    this.Fields["EventName"].Value = row.alarmType;
        //    this.Fields["EventPosition"].Value = row.alarmLocation;
        //    this.Fields["EventErrorStatus"].Value = row.no;
        //    this.Fields["EventTime"].Value = row.alarmDate;
        //    this.Fields["AlarmType"].Value = row.alarmType;
        //    this.Fields["AlarmLocation"].Value = row.alarmLocation;
        //    //this.Fields["ConfirmYes"].Value = row.confirmYes;
        //    //this.Fields["ConfirmDate"].Value = row.confirmDate;
        //  }
        //  catch (Exception ex) {
        //    Util.UErrorMessage(ex, 0, 0);
        //  }
        //}
        private void AReportLog_FetchData(object sender, FetchEventArgs eArgs)
        {  // set display data funtion 
            if (LEventLog == null || LEventLog.Count <= 0 || index >= LEventLog.Count)
            {
                eArgs.EOF = true;
            }
            else
            {
                if (LEventLog.Count > this.index)
                {
                    CEventLogData eventLog = this.LEventLog[this.index];
                    //if (FindReceiver(eventLog.receiverID) >= 0) 
                    {
                        //Receiver receiver = this.LReceiver[FindReceiver(eventLog.receiverID)];
                        this.Fields["EventNumber"].Value = this.index + 1;
                        this.Fields["EventTime"].Value = eventLog.EventTime;
                        this.Fields["EventPosition"].Value = eventLog.devicePosition;
                        this.Fields["EventName"].Value = eventLog.eventTypeName;//this.GetEventTypeName(eventLog.eventType);//LEventLog[this.index].EventName;
                        this.Fields["DeviceName"].Value = eventLog.deviceName;//this.GetDeviceName(eventLog);
                        this.Fields["Circuit"].Value = eventLog.Report_EventPositon;//eventLog.EventPositon; // cyim 2015.9.23 프린트 정보와 일치하도록 수정
                        switch (eventLog.Report_EventErrorStatus)//switch (eventLog.EventErrorStatus)// cyim 2015.9.23 프린트 정보와 일치하도록 수정
                        {// 0 : 운영,기타 , 1: 화재 발생, 2 : 화재 해제 3: 설비 작동 4: 설비 멈춤 5: 이상 발생 6: 이상 해제
                            case 0:
                                this.Fields["EventErrorStatus"].Value = "조작";
                                this.detail.BackColor = Color.White;
                                this.textBox8.BackColor = Color.White;
                                this.textBox8.ForeColor = Color.Black;
                                break;
                            case 1:
                                this.Fields["EventErrorStatus"].Value = "발생";
                                this.detail.BackColor = Color.FromArgb(255, 140, 140);
                                this.textBox8.BackColor = Color.White;
                                this.textBox8.ForeColor = Color.Red;
                                break;
                            case 2:
                                this.Fields["EventErrorStatus"].Value = "해제";
                                this.detail.BackColor = Color.FromArgb(255, 140, 140);
                                this.textBox8.BackColor = Color.White;
                                this.textBox8.ForeColor = Color.Blue;
                                break;
                            case 3:
                                this.Fields["EventErrorStatus"].Value = "발생";
                                this.detail.BackColor = Color.FromArgb(140, 140, 255);
                                this.textBox8.BackColor = Color.White;
                                this.textBox8.ForeColor = Color.Red;
                                break;
                            case 4:
                                this.Fields["EventErrorStatus"].Value = "해제";
                                this.detail.BackColor = Color.FromArgb(140, 140, 255);
                                this.textBox8.BackColor = Color.White;
                                this.textBox8.ForeColor = Color.Blue;
                                break;
                            case 5:
                                this.Fields["EventErrorStatus"].Value = "발생";
                                this.detail.BackColor = Color.FromArgb(220, 220, 220);
                                this.textBox8.BackColor = Color.White;
                                this.textBox8.ForeColor = Color.Red;
                                break;
                            case 6:
                                this.Fields["EventErrorStatus"].Value = "해제";
                                this.detail.BackColor = Color.FromArgb(220, 220, 220);
                                this.textBox8.BackColor = Color.White;
                                this.textBox8.ForeColor = Color.Blue;
                                break;
                        }
                        this.index++;
                        eArgs.EOF = false;
                    }
                }
            }
        }
        //private void NewActiveReport1_FetchData(object sender, FetchEventArgs eArgs) {
        //  if (LEventLog == null || LEventLog.Count <= 0 || index >= LEventLog.Count) {
        //    eArgs.EOF = true;
        //  }
        //  else {
        //    if (LEventLog.Count > this.index) {
        //      CEventLogData eventLog = this.LEventLog[this.index];
        //      if (FindReceiver(eventLog.receiverID) >= 0) {
        //        Receiver receiver = this.LReceiver[FindReceiver(eventLog.receiverID)];
        //        this.Fields["EventNumber"].Value = this.index + 1;
        //        this.Fields["EventTime"].Value = eventLog.EventTime;
        //        this.Fields["EventPosition"].Value = eventLog.EventPositon;
        //        this.Fields["EventName"].Value = this.GetEventTypeName(eventLog.eventType);//LEventLog[this.index].EventName;
        //        this.Fields["DeviceName"].Value = this.GetDeviceName(eventLog);
        //        //switch (eventLog.ioType) {
        //        //  case "A": {//전체
        //        //    if (Convert.ToInt32(eventLog.receiverID) > 0) {
        //        //      this.Fields["DeviceName"].Value = receiver.Name;
        //        //      //DBAccess.GetReceiverNameFromDB(this.receiverID);
        //        //    }
        //        //    break;
        //        //  }
        //        //  case "C": {// 통신
        //        //    if (Convert.ToInt32(eventLog.receiverID) > 0) {
        //        //      this.Fields["DeviceName"].Value = receiver.Name;
        //        //    }
        //        //    break;
        //        //  }
        //        //  case "B": {// 보드deviceName = DBAccess.GetBoardNameFromDB(this.receiverID, this.boardID);
        //        //    break;
        //        //  }
        //        //  case "L": {// 루프
        //        //    this.Fields["DeviceName"].Value = receiver.board[eventLog.boardID - 1].Name;
        //        //    // this.Fields["DeviceName"].Value = DBAccess.GetBoardNameFromDB(this.receiverID, this.boardID);
        //        //    this.Fields["DeviceName"].Value += string.Format(":{0}계통", LEventLog[this.index].loopNO.ToString());
        //        //    break;
        //        //  }
        //        //  case "R": {//중계기
        //        //    this.Fields["DeviceName"].Value = receiver.board[eventLog.boardID - 1].loop[eventLog.loopNO].repeater[eventLog.repeaterID - 1].Name;
        //        //    //this.Fields["DeviceName"].Value = DBAccess.GetRepeaterNameFromDB(this.receiverID, this.boardID, this.loopNO, this.repeaterID);
        //        //    break;
        //        //  }
        //        //  case "D": {// 장치
        //        //    break;
        //        //  }
        //        //  case "I": {//입력회로
        //        //    this.Fields["DeviceName"].Value = receiver.GetDeviceName(eventLog.boardID, eventLog.loopNO, eventLog.repeaterID, eventLog.deviceID, 1);
        //        //    //this.Fields["DeviceName"].Value = DBAccess.GetDeviceNameFromDB((this.receiverID), (this.boardID), (this.loopNO), (this.repeaterID), (this.deviceID), this.ioType);
        //        //    break;
        //        //  }
        //        //  case "O": {//출력회로
        //        //    this.Fields["DeviceName"].Value = receiver.GetDeviceName(eventLog.boardID, eventLog.loopNO, eventLog.repeaterID, eventLog.deviceID, 2);
        //        //    //this.Fields["DeviceName"].Value = DBAccess.GetDeviceNameFromDB(this.receiverID, (this.boardID), (this.loopNO), (this.repeaterID), (this.deviceID), this.ioType);
        //        //    break;
        //        //  }
        //        //  default: {
        //        //    break;
        //        //  }
        //        //}
        //        // this.Fields["DeviceName"].Value = LEventLog[this.index].DeviceName;
        //        switch (eventLog.EventErrorStatus) {
        //          case 0:
        //          this.Fields["EventErrorStatus"].Value = "조작";
        //          break;
        //          case 1:
        //          case 3:
        //          case 5:
        //          this.Fields["EventErrorStatus"].Value = "발생";
        //          break;
        //          case 2:
        //          case 4:
        //          case 6:
        //          this.Fields["EventErrorStatus"].Value = "해제";
        //          break;
        //          default:
        //          this.Fields["EventErrorStatus"].Value = "기타";
        //          break;
        //        }
        //        this.index++;
        //        eArgs.EOF = false;
        //      }
        //    }
        //  }
        //}
        //List LReceiver;
        //List LEventType;
        //public List LEventLog;
        //int index = 0;
        //string GetEventTypeName(string eventType) {
        //  string ret = "";
        //  foreach (CEventType etype in this.LEventType) {
        //    if (eventType == etype.eventType) {
        //      ret = etype.eventTypeName;
        //      break;
        //    }
        //  }
        //  return ret;
        //}
        //public AReportLog(List LReceiver, List LEventType) {
        //  //
        //  // Required for Windows Form Designer support
        //  //
        //  InitializeComponent();
        //  this.LReceiver = LReceiver;
        //  this.LEventType = LEventType;
        //}
        //private void NewActiveReport1_FetchData(object sender, FetchEventArgs eArgs) {
        //  if (LEventLog == null || LEventLog.Count <= 0 || index >= LEventLog.Count) {
        //    eArgs.EOF = true;
        //  }
        //  else {
        //    if (LEventLog.Count > this.index) {
        //      CEventLogData eventLog = this.LEventLog[this.index];
        //      if (FindReceiver(eventLog.receiverID) >= 0) {
        //        Receiver receiver = this.LReceiver[FindReceiver(eventLog.receiverID)];
        //        this.Fields["EventNumber"].Value = this.index + 1;
        //        this.Fields["EventTime"].Value = eventLog.EventTime;
        //        this.Fields["EventPosition"].Value = eventLog.EventPositon;
        //        this.Fields["EventName"].Value = this.GetEventTypeName(eventLog.eventType);//LEventLog[this.index].EventName;
        //        this.Fields["DeviceName"].Value = this.GetDeviceName(eventLog);
        //        //switch (eventLog.ioType) {
        //        //  case "A": {//전체
        //        //    if (Convert.ToInt32(eventLog.receiverID) > 0) {
        //        //      this.Fields["DeviceName"].Value = receiver.Name;
        //        //      //DBAccess.GetReceiverNameFromDB(this.receiverID);
        //        //    }
        //        //    break;
        //        //  }
        //        //  case "C": {// 통신
        //        //    if (Convert.ToInt32(eventLog.receiverID) > 0) {
        //        //      this.Fields["DeviceName"].Value = receiver.Name;
        //        //    }
        //        //    break;
        //        //  }
        //        //  case "B": {// 보드deviceName = DBAccess.GetBoardNameFromDB(this.receiverID, this.boardID);
        //        //    break;
        //        //  }
        //        //  case "L": {// 루프
        //        //    this.Fields["DeviceName"].Value = receiver.board[eventLog.boardID - 1].Name;
        //        //    // this.Fields["DeviceName"].Value = DBAccess.GetBoardNameFromDB(this.receiverID, this.boardID);
        //        //    this.Fields["DeviceName"].Value += string.Format(":{0}계통", LEventLog[this.index].loopNO.ToString());
        //        //    break;
        //        //  }
        //        //  case "R": {//중계기
        //        //    this.Fields["DeviceName"].Value = receiver.board[eventLog.boardID - 1].loop[eventLog.loopNO].repeater[eventLog.repeaterID - 1].Name;
        //        //    //this.Fields["DeviceName"].Value = DBAccess.GetRepeaterNameFromDB(this.receiverID, this.boardID, this.loopNO, this.repeaterID);
        //        //    break;
        //        //  }
        //        //  case "D": {// 장치
        //        //    break;
        //        //  }
        //        //  case "I": {//입력회로
        //        //    this.Fields["DeviceName"].Value = receiver.GetDeviceName(eventLog.boardID, eventLog.loopNO, eventLog.repeaterID, eventLog.deviceID, 1);
        //        //    //this.Fields["DeviceName"].Value = DBAccess.GetDeviceNameFromDB((this.receiverID), (this.boardID), (this.loopNO), (this.repeaterID), (this.deviceID), this.ioType);
        //        //    break;
        //        //  }
        //        //  case "O": {//출력회로
        //        //    this.Fields["DeviceName"].Value = receiver.GetDeviceName(eventLog.boardID, eventLog.loopNO, eventLog.repeaterID, eventLog.deviceID, 2);
        //        //    //this.Fields["DeviceName"].Value = DBAccess.GetDeviceNameFromDB(this.receiverID, (this.boardID), (this.loopNO), (this.repeaterID), (this.deviceID), this.ioType);
        //        //    break;
        //        //  }
        //        //  default: {
        //        //    break;
        //        //  }
        //        //}
        //        // this.Fields["DeviceName"].Value = LEventLog[this.index].DeviceName;
        //        switch (eventLog.EventErrorStatus) {
        //          case 0:
        //          this.Fields["EventErrorStatus"].Value = "조작";
        //          break;
        //          case 1:
        //          case 3:
        //          case 5:
        //          this.Fields["EventErrorStatus"].Value = "발생";
        //          break;
        //          case 2:
        //          case 4:
        //          case 6:
        //          this.Fields["EventErrorStatus"].Value = "해제";
        //          break;
        //          default:
        //          this.Fields["EventErrorStatus"].Value = "기타";
        //          break;
        //        }
        //        this.index++;
        //        eArgs.EOF = false;
        //      }
        //    }
        //  }
        //}
        //public int FindReceiver(int ReceiverID) {
        //  int ret = -1;
        //  for (int i = 0; i < LReceiver.Count; i++) {
        //    if (this.LReceiver[i] != null && LReceiver[i].ReceiverID == ReceiverID) {
        //      ret = i;
        //      break;
        //    }
        //  }
        //  return ret;
        //}
        //string GetDeviceName(CEventLogData eventLog) {
        //  string ret = "";
        //  if (FindReceiver(eventLog.receiverID) >= 0) {
        //    Receiver receiver = this.LReceiver[FindReceiver(eventLog.receiverID)];
        //    switch (eventLog.ioType) {
        //      case "A": {//전체
        //        if (Convert.ToInt32(eventLog.receiverID) > 0) {
        //          ret = receiver.Name;
        //          //DBAccess.GetReceiverNameFromDB(this.receiverID);
        //        }
        //        break;
        //      }
        //      case "C": {// 통신
        //        if (Convert.ToInt32(eventLog.receiverID) > 0) {
        //          ret = receiver.Name;
        //        }
        //        break;
        //      }
        //      case "B": {// 보드deviceName = DBAccess.GetBoardNameFromDB(this.receiverID, this.boardID);
        //        break;
        //      }
        //      case "L": {// 루프
        //        ret = receiver.board[eventLog.boardID - 1].Name;
        //        ret += string.Format(":{0}계통", LEventLog[this.index].loopNO.ToString());
        //        break;
        //      }
        //      case "R": {//중계기
        //        ret = receiver.board[eventLog.boardID - 1].loop[eventLog.loopNO].repeater[eventLog.repeaterID - 1].Name;
        //        break;
        //      }
        //      case "D": {// 장치
        //        break;
        //      }
        //      case "I": {//입력회로
        //        ret = receiver.GetDeviceName(eventLog.boardID, eventLog.loopNO, eventLog.repeaterID, eventLog.deviceID, 1);
        //        break;
        //      }
        //      case "O": {//출력회로
        //        ret = receiver.GetDeviceName(eventLog.boardID, eventLog.loopNO, eventLog.repeaterID, eventLog.deviceID, 2);
        //        break;
        //      }
        //      default: {
        //        break;
        //      }
        //    }
        //  }
        //  return ret;
        //}
        //public bool findTime = false;
        //public DateTime findStartTime;
        //public DateTime findEndTime;
        //public List findType = null;
        //private void NewActiveReport1_DataInitialize(object sender, EventArgs e) {
        //  if (findTime) {
        //    this.textBox1.Text = string.Format("{0:D4}-{1:D2}-{2:D2} {3:D2}:{4:D2}:{5:D2} ~{6:D4}-{7:D2}-{8:D2} {9:D2}:{10:D2}:{11:D2}",
        //      this.findStartTime.Year, this.findStartTime.Month, this.findStartTime.Day,
        //      this.findStartTime.Hour, this.findStartTime.Minute, this.findStartTime.Second,
        //      this.findEndTime.Year, this.findEndTime.Month, this.findEndTime.Day,
        //      this.findEndTime.Hour, this.findEndTime.Minute, this.findEndTime.Second);
        //  }
        //  else {
        //    this.textBox1.Text = "전체";
        //  }
        //  if (findType != null && findType.Count > 0) {
        //    this.textBox2.Text = "";
        //    foreach (string text in findType) {
        //      this.textBox2.Text += text;
        //      this.textBox2.Text += ", ";
        //    }
        //    this.textBox2.Text = this.textBox2.Text.Substring(0, this.textBox2.Text.Length - 2);
        //  }
        //  else {
        //    this.textBox2.Text = "전체";
        //  }
        ////public DateTime FindStartTime;
        ////public DateTime FindEndTime;
        ////public List FindType;
        //  this.PageSettings.Margins.Bottom = 0.3F;
        //  this.PageSettings.Margins.Left = 0.4F;
        //  this.PageSettings.Margins.Right = 0.3F;
        //  this.PageSettings.Margins.Top = 1F;
        //  this.PageSettings.PaperHeight = 11F;
        //  this.PageSettings.PaperWidth = 8.5F;
        //  this.Fields.Add("EventNumber");
        //  this.Fields.Add("EventTime");
        //  this.Fields.Add("EventPosition");
        //  this.Fields.Add("EventName");
        //  this.Fields.Add("DeviceName");
        //  this.Fields.Add("EventErrorStatus");
        //}
    }
}