123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using System.Xml;
- using System.IO;
- using System.Collections;
- namespace FPER {
- public partial class FormField : Form
- {
- public XMLReader xmlR = null;
- public List<XMLField> xField = null;
- public Dev_Type_Set DataType_Set = null;
- List<Button> LButton = new List<Button>();
- public ArrayList lActLoop = new ArrayList();
- Graphics g;
- int iGetDataIndex = 0;
-
-
-
-
- bool CommDaemonAck_Received = false;
- public FormField(List<XMLField> xField, Dev_Type_Set DataType_Set)
- {
- InitializeComponent();
- this.xField = xField;
- this.DataType_Set = DataType_Set;
-
- g = panel1.CreateGraphics();
- g.Clear(SystemColors.ControlLight);
- }
- MDIParent mdi = null;
- private void FormField_Load(object sender, EventArgs e)
- {
-
- SetStyle(ControlStyles.UserPaint, true);
-
- SetStyle(ControlStyles.AllPaintingInWmPaint, true);
-
- SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
- this.UpdateStyles();
-
-
- this.mdi = (MDIParent)this.MdiParent;
- this.mdi.SelectMenuIndex = 7;
- this.init();
- }
- private void init()
- {
- if (xField != null)
- {
-
- this.comboBox1.Items.Clear();
- foreach (XMLField field in xField)
- {
- this.comboBox1.Items.Add(field.Name);
- }
- if (xField.Count > 0)
- {
- this.comboBox1.SelectedIndex = 0;
- }
- }
- }
- void GetAllDataListForce()
- {
-
-
-
-
- int iBoardID = 0;
- int iLoopNo = 0;
- for (int iLoop = 0; iLoop < lActLoop.Count; iLoop++)
- {
- iBoardID = Convert.ToInt16(lActLoop[iLoop]) / 10;
- iLoopNo = Convert.ToInt16(lActLoop[iLoop]) % 10;
- this.getData(iBoardID, iLoopNo);
- System.Threading.Thread.Sleep(200);
- }
-
- }
- void GetDataList()
- {
- if (lActLoop.Count > 0)
- {
- int iBoardID = Convert.ToInt16(lActLoop[iGetDataIndex]) / 10;
- int iLoopNo = Convert.ToInt16(lActLoop[iGetDataIndex]) % 10;
- this.getData(iBoardID, iLoopNo);
- System.Threading.Thread.Sleep(200);
- iGetDataIndex++;
- if (iGetDataIndex >= lActLoop.Count)
- {
- iGetDataIndex = 0;
- }
- }
- }
- void GetAllDataList()
- {
-
- int iBoardID = 0;
- int iLoopNo = 0;
- for (int iLoop = 0; iLoop < lActLoop.Count; iLoop++)
- {
- iBoardID = Convert.ToInt16(lActLoop[iLoop]) / 10;
- iLoopNo = Convert.ToInt16(lActLoop[iLoop]) % 10;
-
-
-
-
- bool get = this.getData(iBoardID, iLoopNo);
- if (get == false)
- {
- this.SetComunicationError(iBoardID, iLoopNo, -3);
- }
-
-
-
-
- System.Threading.Thread.Sleep(200);
- }
- }
- void SetComunicationError(int boardID, int loopNo, int errorCode)
- {
-
- foreach (XMLDevice dev in this.xField[this.comboBox1.SelectedIndex].LDevice)
- {
- if (dev.Board_ID == boardID && dev.Loop_No == loopNo)
- {
- UpdateDev(dev, errorCode);
- }
-
- }
- }
-
- bool getData(int BoardID, int Loop)
- {
-
- if (CommDaemonAck_Received == true)
- {
- return false;
- }
- else
- {
- CommDaemonAck_Received = true;
-
- bool ret = false;
- MDIParent mdi = (MDIParent)this.MdiParent;
- dCommandResponse d = new dCommandResponse(UpdateData);
- CmdInfo cmd = new CmdInfo(prt_cmd_define.read_repeater_all, mdi.myReceiverID, 1, Loop, BoardID, d);
- ret = mdi.ui.runCommand(cmd);
- return ret;
- }
- }
-
-
-
-
- private bool Repeater_GetData_Circuit_CutInfo(RepeaterDeviceTypeInfo repinfo, XMLDevice dev)
- {
- if (dev == null) return false;
-
- if (dev.Inout_Type == "I")
- {
- if (repinfo.inDeviceTypeInfos[dev.Device_ID - 1] == null)
- return false;
- else
- return repinfo.inDeviceTypeInfos[dev.Device_ID - 1].CutFlag;
- }
- else
- {
- if (repinfo.outDeviceTypeInfos[dev.Device_ID - 1] == null)
- return false;
- else
- return repinfo.outDeviceTypeInfos[dev.Device_ID - 1].CutFlag;
- }
- }
- public void UpdateData(CmdInfo cmd)
- {
- try
- {
-
-
-
-
-
-
- CommDaemonAck_Received = false;
-
- if (cmd.ResponseData is RCVData_NACK)
- {
- #if _DEBUG
-
- #endif
- this.SetComunicationError(cmd.boardNo, cmd.loopNo, -2);
- }
- if (cmd.ResponseData is RCVData_ReadRepeaterPointAll)
- {
- RCVData_ReadRepeaterPointAll ResponseData = (RCVData_ReadRepeaterPointAll)cmd.ResponseData;
- RepeaterData[] data = ResponseData.Data;
- if (cmd.Command == prt_cmd_define.read_repeater_all || cmd.ResCommand == prt_res_define.read_repeater_all)
- {
-
- {
- ReceiverTypeInfo Receiverinfo = mdi.ui.MyReceiverTypeInfo;
- BoardTypeInfo brdinfo = Receiverinfo.Get_RepeaterType(ResponseData.TBD_ID);
- RepeaterDeviceTypeInfo[] repinfo;
- RepeaterPointUnit[] repdata;
-
- if (ResponseData.Repeater_loop == 0)
- {
- repinfo = brdinfo.Loop0_RepeaterType;
- repdata = brdinfo.Loop0_RepeaterUnit_Data;
- }
- else if (ResponseData.Repeater_loop == 1)
- {
- repinfo = brdinfo.Loop1_RepeaterType;
- repdata = brdinfo.Loop1_RepeaterUnit_Data;
- }
- else if (ResponseData.Repeater_loop == 2)
- {
- repinfo = brdinfo.Loop2_RepeaterType;
- repdata = brdinfo.Loop2_RepeaterUnit_Data;
- }
- else if (ResponseData.Repeater_loop == 3)
- {
- repinfo = brdinfo.Loop3_RepeaterType;
- repdata = brdinfo.Loop3_RepeaterUnit_Data;
- }
- else
- {
- repinfo = null;
- repdata = null;
- }
-
- foreach (XMLDevice dev in this.xField[this.comboBox1.SelectedIndex].LDevice)
- {
- if (dev.DevID != "")
- {
- int a = dev.Device_ID;
- if (dev.Board_ID == cmd.boardNo && dev.Loop_No == cmd.loopNo)
- {
- int status = -100;
- if (repdata[dev.Repeater_ID - 1].RepeaterErr)
- {
- status = -1;
- }
-
- else if (repinfo[dev.Repeater_ID - 1].CutFlag == true)
- {
- status = 4;
- }
-
- else if (Repeater_GetData_Circuit_CutInfo(repinfo[dev.Repeater_ID - 1], dev) == true)
- {
- status = 4;
- }
- else if (dev.Inout_Type == "I")
- {
- switch (dev.Device_ID)
- {
- case 1:
- status = data[dev.Repeater_ID - 1].Repeater_state_1;
- break;
- case 2:
- status = data[dev.Repeater_ID - 1].Repeater_state_2;
- break;
- case 3:
- status = data[dev.Repeater_ID - 1].Repeater_state_3;
- break;
- case 4:
- status = data[dev.Repeater_ID - 1].Repeater_state_4;
- break;
- }
- }
- else
- {
- switch (dev.Device_ID)
- {
- case 1:
- status = data[dev.Repeater_ID - 1].Repeater_output_1_W ? 0 : 1;
- break;
- case 2:
- status = data[dev.Repeater_ID - 1].Repeater_output_2_W ? 0 : 1;
- break;
- case 3:
- status = data[dev.Repeater_ID - 1].Repeater_output_3_W ? 0 : 1;
- break;
- case 4:
- status = data[dev.Repeater_ID - 1].Repeater_output_4_W ? 0 : 1;
- break;
- }
- }
-
-
- UpdateDev(dev, status);
-
- }
- }
-
- }
-
-
-
-
-
-
-
-
-
- }
- }
- }
-
-
-
-
-
-
-
-
-
- }
- catch (Exception ex)
- {
- Util.UErrorMessage(ex, 0, 0);
- }
- }
- void ClearActiveLoop()
- {
- lActLoop.Clear();
- }
- void AddActiveLoop(int iBoardID, int iLoopNo)
- {
-
-
-
-
-
-
- if (iBoardID == 0) return;
-
- int iConvert = iBoardID * 10 + iLoopNo;
- if (lActLoop.Contains(iConvert) == false)
- {
- lActLoop.Add(iConvert);
- }
- }
-
- Image GetTypeImage(string imgType)
- {
- Image ret = null;
- ret = DataType_Set.GetDevImage(imgType);
- return ret;
- }
- int selectedFieldIndex = -1;
- private void SetField(int fieldIndex)
- {
- try
- {
-
-
- if (formDevice != null && formDevice.Created)
- {
- this.formDevice.Visible = false;
- }
-
- if (this.selectedFieldIndex != fieldIndex && xField != null)
-
- {
- #if _DEBUG
-
- #endif
- this.selectedFieldIndex = fieldIndex;
- if (xField.Count > fieldIndex && xField[fieldIndex] != null)
- {
- this.timer1.Stop();
-
-
- ClearActiveLoop();
-
-
-
- #if _DEBUG
-
- #endif
- XMLField field = xField[fieldIndex];
- this.SetBaseImage(field.imagePath);
- #if _DEBUG
-
- #endif
- try
- {
- for (int i = 0; i < field.Count_Dev; i++)
- {
- XMLDevice dev = field.LDevice[i];
-
- AddActiveLoop(dev.Board_ID, dev.Loop_No);
- this.xField[fieldIndex].LDevice[i].Image = DataType_Set.GetDevImagePath(xField[fieldIndex].LDevice[i].DevIconID);
- this.SetDevImage(xField[fieldIndex].LDevice[i]);
- }
- for (int i = 0; i < xField[fieldIndex].LButton.Count; i++)
- {
- SetBtnImage(xField[fieldIndex].LButton[i]);
- }
- this.GetAllDataListForce();
-
-
- iGetDataIndex = 0;
- #if _DEBUG
-
- #endif
- }
- catch (Exception ex)
- {
- Util.UErrorMessage(ex, 0, 0);
- }
- #if _DEBUG
-
- #endif
-
-
-
- #if _DEBUG
-
- #endif
- this.timer1.Start();
- }
- }
- }
- catch (Exception ex)
- {
- Util.UErrorMessage(ex, 0, 0);
- }
- }
- public void SetBaseImage(string img_path)
- {
-
-
-
- Image Temp = Image.FromFile(img_path);
- g.DrawImage(Temp, 0, 0, Temp.Width, Temp.Height);
- }
- public void UpdateDev(XMLDevice device, int status)
- {
- if (device.Image == "")
- {
- #if _DEBUG
-
- #endif
- }
- else
- {
-
- Bitmap m_Dev = new Bitmap(GetTypeImage(device.DevIconID));
- g.DrawImage(m_Dev, device.Xposition, device.Yposition, m_Dev.Width, m_Dev.Height);
- string sPath = System.IO.Path.GetDirectoryName(device.Image);
- switch (status)
- {
- case 0:
- if (device.dev_type == "IC")
- {
- Bitmap m_Detect = new Bitmap(Path.Combine(sPath, "설비동작.png"));
- g.DrawImage(m_Detect, device.Xposition, device.Yposition, m_Detect.Width, m_Detect.Height);
- }
- else if ((device.dev_type == "IA") || (device.dev_type == "IB"))
- {
- Bitmap m_Detect = new Bitmap(Path.Combine(sPath, "화재감지.png"));
- g.DrawImage(m_Detect, device.Xposition, device.Yposition, m_Detect.Width, m_Detect.Height);
- }
- break;
- case 1:
- break;
- case 3:
- Bitmap m_Broken = new Bitmap(Path.Combine(sPath, "Error.png"));
- g.DrawImage(m_Broken, device.Xposition, device.Yposition, m_Broken.Width, m_Broken.Height);
- break;
-
- case 4:
- Bitmap m_Cut = new Bitmap(Path.Combine(sPath, "차단.png"));
- g.DrawImage(m_Cut, device.Xposition, device.Yposition, m_Cut.Width, m_Cut.Height);
- break;
- default:
- Bitmap m_Odd = new Bitmap(Path.Combine(sPath, "중계기이상.png"));
- g.DrawImage(m_Odd, device.Xposition, device.Yposition, m_Odd.Width, m_Odd.Height);
- break;
- }
- device.status = status;
-
- }
- }
- public void SetBtnImage(XMLButton button)
- {
-
- Bitmap m_Dev = new Bitmap(button.ImagePath);
- g.DrawImage(m_Dev, button.Xposition, button.Yposition, m_Dev.Width, m_Dev.Height);
-
- }
-
-
- public void SetDevImage(XMLDevice device)
- {
- if (device.DevIconID == "")
- {
- #if _DEBUG
-
- #endif
- }
- else
- {
-
- Bitmap m_Dev = new Bitmap(GetTypeImage(device.DevIconID));
- g.DrawImage(m_Dev, device.Xposition, device.Yposition, m_Dev.Width, m_Dev.Height);
-
- }
- }
- FormDevice formDevice = null;
- private void btnWinClose_Click(object sender, EventArgs e)
- {
- try
- {
- this.Close();
- }
- catch (Exception ex)
- {
- Util.UErrorMessage(ex, 0, 0);
- }
- }
- private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
- {
- this.SetField(this.comboBox1.SelectedIndex);
- }
- public void JumpField(int id)
- {
-
- if (this.comboBox1.Items.Count <= 0)
- return;
-
-
- if (this.comboBox1.InvokeRequired)
- {
- dCommandFuctionCall d = new dCommandFuctionCall(JumpField);
- this.comboBox1.Invoke(d, new object[] { id });
- }
- else
- {
- #if _DEBUG
-
- #endif
- for (int i = 0; i < this.xField.Count; i++)
- {
- if (id == this.xField[i].FieldID)
- {
- this.comboBox1.SelectedIndex = i;
-
- break;
- }
- }
- }
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
-
- GetDataList();
- }
- private void FormField_Activated(object sender, EventArgs e)
- {
- try
- {
- this.mdi.SelectMenuIndex = 7;
- }
- catch (Exception ex)
- {
- Util.UErrorMessage(ex, 0, 0);
- }
- }
- void FormField_Disposed(object sender, System.EventArgs e)
- {
- try
- {
- this.mdi.SelectMenuIndex = 0;
- g.Dispose();
- }
- catch (Exception ex)
- {
- Util.UErrorMessage(ex, 0, 0);
- }
- }
- private void FormField_FormClosing(object sender, FormClosingEventArgs e)
- {
- try
- {
- if (formDevice != null && formDevice.Created)
- {
- this.formDevice.Close();
- }
- }
- catch (Exception ex)
- {
- Util.UErrorMessage(ex, 0, 0);
- }
- }
-
- private void panel1_Paint(object sender, PaintEventArgs e)
- {
- selectedFieldIndex = -1;
- SetField(comboBox1.SelectedIndex);
- }
-
- private void panel1_MouseDown(object sender, MouseEventArgs e)
- {
-
-
-
- int i;
-
- int iX = e.Location.X;
- int iY = e.Location.Y;
-
- int iXX;
- int iYY;
-
-
-
-
-
-
- for (i = 0; i < xField[this.comboBox1.SelectedIndex].LButton.Count; i++)
- {
- iXX = xField[this.comboBox1.SelectedIndex].LButton[i].Xposition;
- iYY = xField[this.comboBox1.SelectedIndex].LButton[i].Yposition;
- if ((iX >= iXX) && (iX <= (iXX + xField[this.comboBox1.SelectedIndex].LButton[i].width)))
- {
- if ((iY >= iYY) && (iY <= (iYY + xField[this.comboBox1.SelectedIndex].LButton[i].height)))
- {
-
-
- comboBox1.SelectedIndex = xField[this.comboBox1.SelectedIndex].LButton[i].jumpField;
-
-
- break;
- }
- }
- }
-
- for (i = 0; i < xField[this.comboBox1.SelectedIndex].Count_Dev; i++)
- {
- iXX = xField[this.comboBox1.SelectedIndex].LDevice[i].Xposition;
- iYY = xField[this.comboBox1.SelectedIndex].LDevice[i].Yposition;
- if ((iX >= iXX) && (iX <= (iXX + 24)))
- {
- if ((iY >= iYY) && (iY <= (iYY + 24)))
- {
-
-
- if (formDevice == null)
- {
- formDevice = new FormDevice(this.mdi);
- formDevice.Owner = this;
- formDevice.Visible = false;
- formDevice.Show();
- }
-
- formDevice.Visible = false;
-
- formDevice.devID = this.xField[this.comboBox1.SelectedIndex].LDevice[i].DevID;
-
- formDevice.Text = this.xField[this.comboBox1.SelectedIndex].LDevice[i].dev_name;
-
- formDevice.SetDeviceInformText(string.Format(
- "장치 번호 : " + this.xField[this.comboBox1.SelectedIndex].LDevice[i].Device_ViewID +
- "\r\n장치 이름 : " + this.xField[this.comboBox1.SelectedIndex].LDevice[i].dev_name +
- "\r\n위 치 : " + this.xField[this.comboBox1.SelectedIndex].LDevice[i].position));
-
- formDevice.SetDeviceImage(GetTypeImage(this.xField[this.comboBox1.SelectedIndex].LDevice[i].DevIconID));
-
- formDevice.SetDeciceStatusText("상 태 : " + this.xField[this.comboBox1.SelectedIndex].LDevice[i].StatusStr);
-
- formDevice.Location = new Point(Control.MousePosition.X + 5, Control.MousePosition.Y + 5);
-
- formDevice.Visible = true;
-
-
- break;
- }
- }
- }
- }
- }
- }
|