示例#1
0
 public static Boolean SaveBinFile(DataLedArrayNode writeData, string targetPath)
 {
     try
     {
         using (BinaryWriter writer = new BinaryWriter(File.Open(targetPath, FileMode.Create)))
         {
             writer.Write((byte)(0xFF));
             writer.Write((byte)writeData.LedNumber);
             writer.Write((byte)writeData.StateNumber);
             writer.Write((byte)(0xFF));
             for (int stateIndex = 0; stateIndex < writeData.StateNumber; stateIndex++)
             {
                 ArrayList curState = (ArrayList)writeData.GetState(stateIndex);
                 Constants.StateType stateType = (Constants.StateType)curState[0];
                 writer.Write((byte)(stateType));
                 int temp;
                 switch (stateType)
                 {
                     case Constants.StateType.Data:
                         temp = (int)curState[1];// Get common value
                         writer.Write((byte)(temp));
                         for (int ledIndex = 0; ledIndex < writeData.LedNumber; ledIndex++)
                         {
                             temp = (int)curState[ledIndex + 2];
                             writer.Write((byte)(temp));
                         }
                         break;
                     case Constants.StateType.StartFor:
                         temp = (int)curState[1];
                         writer.Write((byte)(temp));
                         break;
                     case Constants.StateType.Endfor:
                         break;
                 }
                 writer.Write((Byte)0xFF);
             }
         }
         return true;
     }
     catch(Exception e)
     {
         MessageBox.Show(e.Message);
         return false;
     }
 }
        private void ShowLedData(DataLedArrayNode dataStructure)
        {
            //TODO:
            showList.Clear();
            pnLedNode.Controls.Clear();
            //ArrayList led_state= (ArrayList)dataStructure.Led[0];
            stateNumber = dataStructure.StateNumber;
            ledNumber = dataStructure.LedNumber;
            for (int stateIndex = 0; stateIndex < dataStructure.StateNumber; stateIndex++)
            {
                ArrayList CurState = (ArrayList)dataStructure.GetState(stateIndex);
                Constants.StateType StateType = dataStructure.GetStateType(stateIndex);
                switch (StateType)
                {
                    case Constants.StateType.Data:
                        for (int ledIndex = 0; ledIndex < dataStructure.LedNumber; ledIndex++)
                        {
                            LedNodeView StateNode = new LedNodeView();
                            StateNode.color = Color.Blue;
                            StateNode.Location = new System.Drawing.Point(10 + 30 * ledIndex, 5 + 30 * stateIndex);
                            StateNode.Size = new System.Drawing.Size(25, 25);
                            StateNode.Name = "LedNodeView" + (char)(ledIndex + 1) + (char)(stateIndex + 1);//LedNodeView + LedIndex + StateIndex
                            StateNode.Value = (int)CurState[ledIndex + 2];
                            StateNode.Type = Constants.StateType.Data;
                            StateNode.LedIndex = ledIndex;
                            StateNode.StateIndex = stateIndex;

                            StateNode.MouseClick += new MouseEventHandler(LedNodeView_Click);
                            StateNode.MouseWheel += new MouseEventHandler(LedNodeView_Mouse_Wheel);
                            StateNode.MouseDoubleClick += new MouseEventHandler(LedNodeView_Mouse_Double_Click);
                            StateNode.MouseMove += new MouseEventHandler(LedNodeView_MouseMove);
                            StateNode.MouseDown += new MouseEventHandler(pnLedNode_MouseDown);
                            StateNode.MouseUp += new MouseEventHandler(pnLedNode_MouseUp);
                            pnLedNode.Controls.Add(StateNode);
                            showList.Add(StateNode);
                            //if (curNode == null) curNode = StateNode;
                        }
                        break;
                    case Constants.StateType.StartFor:
                        LedNodeView StartForNode = new LedNodeView();
                        StartForNode.color = Color.Red;
                        StartForNode.Location = new System.Drawing.Point(10, 5 + 30 * stateIndex);
                        StartForNode.Size = new System.Drawing.Size((int)(30 * dataStructure.LedNumber) - 5, 25);
                        StartForNode.Name = "LedNodeView" + (char)1 + (char)(stateIndex + 1);//LedNodeView + StateIndex
                        StartForNode.Value = dataStructure.GetCommonValue(stateIndex);
                        StartForNode.Type = Constants.StateType.StartFor;
                        StartForNode.LedIndex = 0;
                        StartForNode.StateIndex = stateIndex;

                        StartForNode.MouseClick += new MouseEventHandler(LedNodeView_Click);
                        StartForNode.MouseWheel += new MouseEventHandler(LedNodeView_Mouse_Wheel);
                        pnLedNode.Controls.Add(StartForNode);
                        showList.Add(StartForNode);
                        break;
                    case Constants.StateType.Endfor:
                        LedNodeView EndForNode = new LedNodeView();
                        EndForNode.color = Color.Yellow;
                        EndForNode.Location = new System.Drawing.Point(10, 5 + 30 * stateIndex);
                        EndForNode.Size = new System.Drawing.Size((int)(30 * dataStructure.LedNumber) - 5, 25);
                        EndForNode.Name = "LedNodeView" + (char)1 + (char)(stateIndex + 1);//LedNodeView + StateIndex
                        EndForNode.Value = (int)Constants.MAX_BRIGHT;
                        EndForNode.Type = Constants.StateType.Endfor;
                        EndForNode.LedIndex = 0;
                        EndForNode.StateIndex = stateIndex;
                        EndForNode.Text = "}";
                        //EndForNode.TextAlign = StringAlignment.Far;

                        EndForNode.MouseClick += new MouseEventHandler(LedNodeView_Click);
                        EndForNode.MouseWheel += new MouseEventHandler(LedNodeView_Mouse_Wheel);
                        pnLedNode.Controls.Add(EndForNode);
                        showList.Add(EndForNode);
                        break;
                }
            }
            if (curIndex != defaultIndex)
            {
                SelectNode(curIndex.stateIndex, curIndex.ledIndex);
            }
        }