using System; using System.Linq; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using BMS_D1000H.BMSConstData; using BMS_D1000H.DataStructs; using BMS_D1000H.Utils.Functions; namespace BMS_D1000H { public partial class fmHistory : Form { int disHistCount = 0; int hTotalSize = 0; int hCurrentPosition = 0; TAlarmList DisAlarmList; SmartX.SmartLabel[] hDateTime; SmartX.SmartLabel[] hEvent; SmartX.SmartLabel[] hAlarmName; SmartX.SmartLabel[] hPos; SmartX.SmartLabel[] hParam; public fmHistory() { InitializeComponent(); DisAlarmList.aData = new TAlarm[200]; CreateHistoryList(); ReloadControl(); } #region Control Re-loading private void ReloadControl() { this.SuspendLayout(); this.Controls.Clear(); for (int i = 0; i < 12; i++) { this.Controls.Add(hDateTime[i]); this.Controls.Add(hEvent[i]); this.Controls.Add(hAlarmName[i]); this.Controls.Add(hPos[i]); this.Controls.Add(hParam[i]); } this.Controls.Add(this.lbModelName); this.Controls.Add(this.lbModelSpec); //this.Controls.Add(this.btnHistDelete); this.Controls.Add(this.btnNext); this.Controls.Add(this.btnPrev); this.Controls.Add(this.btnRefresh); //this.Controls.Add(this.tbHistCount); this.Controls.Add(this.lbParam); this.Controls.Add(this.lbAlarmPos); this.Controls.Add(this.lbAlarmName); this.Controls.Add(this.lbAlarmType); this.Controls.Add(this.lbHistDateTime); this.Controls.Add(this.btnMain); this.Controls.Add(this.sfmHistory); this.ResumeLayout(false); } #endregion private void fmHistory_Load(object sender, EventArgs e) { DisAlarmList = ((fmBMSMain)(Owner)).BmsAlarmFile.GetAlarmList(); hTotalSize = DisAlarmList.count; DisplayHistory(true); DisplayHistoryData(true); tmrDisplay.Start(); } private void btnRefresh_Click(object sender, EventArgs e) { ((fmBMSMain)(Owner)).ScreenSaverTimeReset(); DisAlarmList = ((fmBMSMain)(Owner)).BmsAlarmFile.GetAlarmList(); hTotalSize = DisAlarmList.count; hCurrentPosition = 0; DisplayHistoryData(true); } private void tmrDisplay_Tick(object sender, EventArgs e) { DisplayHistory(false); } private void DisplayHistory(bool p) { if (p || (disHistCount != DisAlarmList.count)) { tbHistCount.Text = String.Format("{0}", DisAlarmList.count); disHistCount = DisAlarmList.count; } } private void HistListBoxClearAll() { for (int i = 0; i < 12; i++) { hDateTime[i].BorderStyle = BorderStyle.None; hDateTime[i].BackPictureBox = sfmHistory; hDateTime[i].Text = ""; hEvent[i].BorderStyle = BorderStyle.None; hEvent[i].BackPictureBox = sfmHistory; hEvent[i].Text = ""; hAlarmName[i].BorderStyle = BorderStyle.None; hAlarmName[i].BackPictureBox = sfmHistory; hAlarmName[i].Text = ""; hParam[i].BorderStyle = BorderStyle.None; hParam[i].BackPictureBox = sfmHistory; hParam[i].Text = ""; hPos[i].BorderStyle = BorderStyle.None; hPos[i].BackPictureBox = sfmHistory; hPos[i].Text = ""; } } private void HistListRowEnable(int hNo) { hDateTime[hNo].Visible = true; hEvent[hNo].Visible = true; hAlarmName[hNo].Visible = true; hParam[hNo].Visible = true; hPos[hNo].Visible = true; hDateTime[hNo].BackPictureBox = null; hEvent[hNo].BackPictureBox = null; hAlarmName[hNo].BackPictureBox = null; hParam[hNo].BackPictureBox = null; hPos[hNo].BackPictureBox = null; hDateTime[hNo].BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; hEvent[hNo].BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; hAlarmName[hNo].BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; hParam[hNo].BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; hPos[hNo].BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; } private void HistListBoxAdd(TAlarm nHist, int hNo) { if (hNo < 12) { hDateTime[hNo].Text = nHist.aTime.ToString("yyyy-MM-dd HH:mm:ss"); switch (nHist.aFlag) { case EventID.EVENT_INFO: // INFORMATION hEvent[hNo].BackColor = System.Drawing.Color.Empty; break; case EventID.EVENT_RECOVERY: // RECOVERY hEvent[hNo].BackColor = System.Drawing.Color.Green; break; case EventID.EVENT_WARNING: // WARNING hEvent[hNo].BackColor = System.Drawing.Color.Yellow; break; case EventID.EVENT_PROTECTION: // PROTECTION hEvent[hNo].BackColor = System.Drawing.Color.Red; break; } hEvent[hNo].Text = EventID.event_name[nHist.aFlag]; hAlarmName[hNo].Text = AlarmID.name[nHist.aNameNo]; switch (nHist.aNameNo) { case AlarmID.COV_PROTECTION: case AlarmID.COV_WARNING: case AlarmID.CUV_PROTECTION: case AlarmID.CUV_WARNING: hPos[hNo].Text = String.Format("{0}-{1}", PosID.pos[nHist.aPos], nHist.ctno); hParam[hNo].Text = String.Format("{0:#0.000}", Convert.ToDouble(nHist.aParam) / 1000); break; case AlarmID.OTC_PROTECTION: case AlarmID.OTC_WARNING: case AlarmID.OTD_PROTECTION: case AlarmID.OTD_WARNING: hPos[hNo].Text = String.Format("{0}-{1}", PosID.pos[nHist.aPos], nHist.ctno); hParam[hNo].Text = String.Format("{0:#0.0}", Convert.ToDouble(nHist.aParam) / 10); break; case AlarmID.SOV_PROTECTION: case AlarmID.SOV_WARNING: case AlarmID.SUV_PROTECTION: case AlarmID.SUV_WARNING: hPos[hNo].Text = PosID.pos[nHist.aPos]; hParam[hNo].Text = String.Format("{0:#0.0}", Convert.ToDouble(nHist.aParam) / 100); break; case AlarmID.OCC_PROTECTION: case AlarmID.OCC_WARNING: case AlarmID.OCD_PROTECTION: case AlarmID.OCD_WARNING: hPos[hNo].Text = PosID.pos[nHist.aPos]; hParam[hNo].Text = String.Format("{0:#0.0}", Convert.ToDouble(nHist.aParam) / 10); break; default: hPos[hNo].Text = PosID.pos[nHist.aPos]; break; } HistListRowEnable(hNo); } } private TAlarm Load_History(int data_no) { int ano; if (DisAlarmList.front < (data_no + 1)) { ano = AlarmID.MAX_ALARM_COUNT + (DisAlarmList.front - (data_no + 1)); return DisAlarmList.aData[ano % AlarmID.MAX_ALARM_COUNT]; } else { ano = DisAlarmList.front - (data_no + 1); return DisAlarmList.aData[ano % AlarmID.MAX_ALARM_COUNT]; } } void HistoryNextPage() { if (hTotalSize > 0) { hCurrentPosition += 12; if (hTotalSize <= hCurrentPosition) hCurrentPosition -= 12; } } void HistoryNextButtonClick() { ((fmBMSMain)(Owner)).ScreenSaverTimeReset(); HistoryNextPage(); DisplayHistoryData(true); } void HistoryPrevPage() { if (hTotalSize > 0) { if (hCurrentPosition >= 12) hCurrentPosition -= 12; else hCurrentPosition = 0; } } void HistoryPrevButtonClick() { ((fmBMSMain)(Owner)).ScreenSaverTimeReset(); HistoryPrevPage(); DisplayHistoryData(true); } private void DisplayHistoryData(bool p) { TAlarm dHist; HistListBoxClearAll(); for (int i = 0; i < 12; i++) { if (hTotalSize <= hCurrentPosition + i) break; dHist = Load_History(hCurrentPosition + i); HistListBoxAdd(dHist, i); } } private void CreateHistoryList() { hDateTime = new SmartX.SmartLabel[12]; hEvent = new SmartX.SmartLabel[12]; hAlarmName = new SmartX.SmartLabel[12]; hPos = new SmartX.SmartLabel[12]; hParam = new SmartX.SmartLabel[12]; for (int i = 0; i < 12; i++) { hDateTime[i] = new SmartX.SmartLabel(); hDateTime[i].BackPictureBox = sfmHistory; hDateTime[i].BackPictureBox1 = null; hDateTime[i].BackPictureBox2 = null; hDateTime[i].BorderColor = System.Drawing.Color.Black; hDateTime[i].BorderStyle = System.Windows.Forms.BorderStyle.None; hDateTime[i].Font = new System.Drawing.Font("Arial Black", 12F, System.Drawing.FontStyle.Bold); hDateTime[i].InitVisible = false; hDateTime[i].LineSpacing = 0F; hDateTime[i].Location = new System.Drawing.Point(8, 104 + (i * 26)); hDateTime[i].Name = String.Format("hDataTime{0}", i); hDateTime[i].Size = new System.Drawing.Size(200, 25); hDateTime[i].TabIndex = 16; hDateTime[i].Text = ""; hDateTime[i].TextHAlign = SmartX.SmartLabel.TextHorAlign.Middle; hDateTime[i].TextVAlign = SmartX.SmartLabel.TextVerAlign.Middle; hDateTime[i].Wordwrap = false; hEvent[i] = new SmartX.SmartLabel(); hEvent[i].BackPictureBox = sfmHistory; hEvent[i].BackPictureBox1 = null; hEvent[i].BackPictureBox2 = null; hEvent[i].BorderColor = System.Drawing.Color.Black; hEvent[i].BorderStyle = System.Windows.Forms.BorderStyle.None; hEvent[i].Font = new System.Drawing.Font("Arial Black", 12F, System.Drawing.FontStyle.Bold); hEvent[i].InitVisible = false; hEvent[i].LineSpacing = 0F; hEvent[i].Location = new System.Drawing.Point(210, 104 + (i * 26)); hEvent[i].Name = String.Format("hEvent{0}", i); hEvent[i].Size = new System.Drawing.Size(121, 25); hEvent[i].TabIndex = 16; hEvent[i].Text = ""; hEvent[i].TextHAlign = SmartX.SmartLabel.TextHorAlign.Middle; hEvent[i].TextVAlign = SmartX.SmartLabel.TextVerAlign.Middle; hEvent[i].Wordwrap = false; hAlarmName[i] = new SmartX.SmartLabel(); hAlarmName[i].BackPictureBox = sfmHistory; hAlarmName[i].BackPictureBox1 = null; hAlarmName[i].BackPictureBox2 = null; hAlarmName[i].BorderColor = System.Drawing.Color.Black; hAlarmName[i].BorderStyle = System.Windows.Forms.BorderStyle.None; hAlarmName[i].Font = new System.Drawing.Font("Arial Black", 12F, System.Drawing.FontStyle.Bold); hAlarmName[i].InitVisible = false; hAlarmName[i].LineSpacing = 0F; hAlarmName[i].Location = new System.Drawing.Point(333, 104 + (i * 26)); hAlarmName[i].Name = String.Format("hAlarmName{0}", i); hAlarmName[i].Size = new System.Drawing.Size(250, 25); hAlarmName[i].TabIndex = 16; hAlarmName[i].Text = ""; hAlarmName[i].TextHAlign = SmartX.SmartLabel.TextHorAlign.Left; hAlarmName[i].TextVAlign = SmartX.SmartLabel.TextVerAlign.Middle; hAlarmName[i].Wordwrap = false; hPos[i] = new SmartX.SmartLabel(); hPos[i].BackPictureBox = sfmHistory; hPos[i].BackPictureBox1 = null; hPos[i].BackPictureBox2 = null; hPos[i].BorderColor = System.Drawing.Color.Black; hPos[i].BorderStyle = System.Windows.Forms.BorderStyle.None; hPos[i].Font = new System.Drawing.Font("Arial Black", 12F, System.Drawing.FontStyle.Bold); hPos[i].InitVisible = false; hPos[i].LineSpacing = 0F; hPos[i].Location = new System.Drawing.Point(585, 104 + (i * 26)); hPos[i].Name = String.Format("hPos{0}", i); hPos[i].Size = new System.Drawing.Size(98, 25); hPos[i].TabIndex = 16; hPos[i].Text = ""; hPos[i].TextHAlign = SmartX.SmartLabel.TextHorAlign.Middle; hPos[i].TextVAlign = SmartX.SmartLabel.TextVerAlign.Middle; hPos[i].Wordwrap = false; hParam[i] = new SmartX.SmartLabel(); hParam[i].BackPictureBox = sfmHistory; hParam[i].BackPictureBox1 = null; hParam[i].BackPictureBox2 = null; hParam[i].BorderColor = System.Drawing.Color.Black; hParam[i].BorderStyle = System.Windows.Forms.BorderStyle.None; hParam[i].Font = new System.Drawing.Font("Arial Black", 12F, System.Drawing.FontStyle.Bold); hParam[i].InitVisible = false; hParam[i].LineSpacing = 0F; hParam[i].Location = new System.Drawing.Point(685, 104 + (i * 26)); hParam[i].Name = String.Format("hParam{0}", i); hParam[i].Size = new System.Drawing.Size(106, 25); hParam[i].TabIndex = 16; hParam[i].Text = ""; hParam[i].TextHAlign = SmartX.SmartLabel.TextHorAlign.Middle; hParam[i].TextVAlign = SmartX.SmartLabel.TextVerAlign.Middle; hParam[i].Wordwrap = false; } } private void btnPrev_Click(object sender, EventArgs e) { HistoryPrevButtonClick(); } private void btnNext_Click(object sender, EventArgs e) { HistoryNextButtonClick(); } private void btnMain_Click(object sender, EventArgs e) { ((fmBMSMain)(Owner)).ScreenSaverTimeReset(); // Main 폼 표시 Index가 0이면 Main폼을 의미 합니다. ((fmBMSMain)(Owner)).sfmMain.Show(0); } private void fmHistory_Activated(object sender, EventArgs e) { DisAlarmList = ((fmBMSMain)(Owner)).BmsAlarmFile.GetAlarmList(); hTotalSize = DisAlarmList.count; DisplayHistoryData(true); } private void btnHistDelete_Click(object sender, EventArgs e) { ((fmBMSMain)(Owner)).ScreenSaverTimeReset(); ((fmBMSMain)(Owner)).chfPassword.order_screen_no = ScreenID.HISTORY_SCREEN_ID; ((fmBMSMain)(Owner)).chfPassword.req_screen_no = ScreenID.HISTORY_SCREEN_ID; ((fmBMSMain)(Owner)).ScreenMode = ScreenID.PASSWORD_SCREEN_ID; ((fmBMSMain)(Owner)).sfmMain.Show(ScreenID.PASSWORD_SCREEN_ID); } } }