Esempio n. 1
0
        private void treeView_dir_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
#if print
            ConsoleU.writeLine(String.Format("node selected. . {0}", e.Node.FullPath), ConsoleU.Level.Info);
#endif
            if (e.Node.Text == REMOTE_MENU)
            {
                dataGridView(); //load dsRandomXml from xml and Bound to dgb
                groupbox();

                if (sign == "on")
                {
                    dataGridView1.Visible = true;
                    groupBox1.Visible     = true;
                }
                else if (sign == "off")
                {
                    if (mSpSlot != null)
                    {
                        dataGridView1.Visible = true;
                        groupBox1.Visible     = true;

                        mRemote                 = new gf_remote(mSpSlot);// open remote form
                        mRemote.Owner           = this;
                        mRemote.Move           += new EventHandler(subFormMove);
                        mRemote.mMainFormTrans += new mainFormTrans(remoteEventReceive); //this is a delegate in order to  close subForm
                        mRemote.Show();
                        sign = "on";
                        this.AddOwnedForm(mRemote);
                        mDockRemote           = new DockU(this);//DockU
                        mDockRemote.isEnabled = true;
                        mDockRemote.position  = DockU.Position.MiddleRight;
                        mDockRemote.process(mRemote);
                        serialToolStripMenuItem.Enabled = false;
                    }
                    else
                    {
                        ConsoleU.writeLine(String.Format("No choice of serial"), ConsoleU.Level.Error);
                        treeView_dir.SelectedNode = null;
                        dataGridView1.Visible     = false;
                        groupBox1.Visible         = false;
                    }
                }
                else
                {
                    dataGridView1.Visible = false;
                    groupBox1.Visible     = false;
                }
            }
            else
            {
                dataGridView1.Visible = false;
                groupBox1.Visible     = false;
            }
        }
Esempio n. 2
0
        //Int32 mBytesRead=0;
        //Byte[] mReadBuffer = new Byte[10];
        void dataReceived(System.Object sender, System.IO.Ports.SerialDataReceivedEventArgs e) //received data
        {
            System.IO.Ports.SerialPort sp = (System.IO.Ports.SerialPort)sender;
            string indata = sp.ReadExisting();

            //if (sp.BytesToRead <= 0)
            //{
            //    ConsoleU.writeLine("empty trigger", ConsoleU.Level.Warning);
            //    return;
            //}
            //mBytesRead += sp.Read(mReadBuffer, mBytesRead, sp.BytesToRead);
            //ConsoleU.writeLine(string.Format("Data Received: {0}", System.Text.Encoding.Default.GetString (mReadBuffer)), ConsoleU.Level.Info);
            ConsoleU.writeLine(string.Format("Data Received: {0}", indata), ConsoleU.Level.Info);
        }
Esempio n. 3
0
        void loadRemoteTree()
        {
            treeView_dir.Nodes.Clear();
            DataTable dtTemp = new DataTable();

            String printInfo = "binding tree node... ...";

            ConsoleU.writeLine(printInfo, ConsoleU.Level.Warning);

            DataSet ds = new DataSet();

            /*dir=String.Format("{0}/{1}/{2}",
             * Directory.GetCurrentDirectory(), FILEPATH, CTRLNAME);*/
            dir = String.Format("{0}/{1}/{2}",
                                Application.StartupPath, FILEPATH, TREENAME);

            String fileExtension = System.IO.Path.GetExtension(dir);

            if (fileExtension != ".xml" || !System.IO.File.Exists(dir))
            {
                ConsoleU.writeLine("this file is not xml or path error,please select again!", ConsoleU.Level.Warning);
            }
            ds.ReadXml(dir);
            dtTemp = ds.Tables[DIRTREE];//this is Tree xml file

            if (dtTemp == null)
            {
                printInfo = "Cannot find node,please try again..."; ConsoleU.writeLine(printInfo, ConsoleU.Level.Warning); return;
            }
            if (dtTemp.Rows == null)
            {
                printInfo = "Cannot find node rows,please try again..."; ConsoleU.writeLine(printInfo, ConsoleU.Level.Warning); return;
            }

            Int32 index = 0;

            foreach (DataRow row in dtTemp.Rows)
            {
                if (Int32.Parse(row[PARENT].ToString()) == 0)
                {
                    treeView_dir.Nodes.Add(row[CURRENT].ToString(), row[CURRENTNMAE].ToString());
                    AddTreeNode(dtTemp.Rows, row[CURRENT].ToString(), treeView_dir.Nodes[index++]);
                }
            }
            treeView_dir.Nodes[0].Expand();
            treeView_dir.Nodes[0].ImageIndex = 0;
            treeView_dir.SelectedNode        = null;
        }
Esempio n. 4
0
 //private void timer1_Tick(object sender, EventArgs e)
 private void LoopRandom()
 {
     while (true)
     {
         if (gf_main.testBegin)      //click test button
         {
             if (gf_main.randomOrNo) //click random button
             {
                 ranID = ran.Next(cc_control.dtEvent.Rows.Count);
                 if (cc_control.dtEvent.Rows[ranID][gf_main.CTRLLINE].ToString() != "")//avoid empty event
                 {
                     ConsoleU.writeLine(String.Format("you click: {0} button, \"{1}\"", cc_control.dtEvent.Rows[ranID][gf_main.CTRLEVENTNAME].ToString(), cc_control.dtEvent.Rows[ranID][gf_main.CTRLLINE].ToString()), ConsoleU.Level.Info);
                     ProtocolObject.remoteWrite(SocProtocol.Drive.remote, System.Text.Encoding.ASCII.GetBytes(cc_control.dtEvent.Rows[ranID][gf_main.CTRLLINE].ToString()));
                     System.Threading.Thread.Sleep(2000);
                 }
             }
             else
             {
                 for (int i = gf_main.dgvIndex; i < gf_main.dsRandomXml.Tables[0].Rows.Count; i++)
                 {
                     string[] random = gf_main.dsRandomXml.Tables[0].Rows[i]["serialize_Text"].ToString().Split(',');
                     foreach (string mRandom in random)
                     {
                         for (int index = 0; index < cc_control.dtEvent.Rows.Count; index++)
                         {
                             if (!gf_main.testBegin)//click test button
                             {
                                 break;
                             }
                             if (mRandom == cc_control.dtEvent.Rows[index][gf_main.CTRLEVENTNAME].ToString())
                             {
                                 ConsoleU.writeLine(String.Format("you click: {0} button, \"{1}\"", cc_control.dtEvent.Rows[index][gf_main.CTRLEVENTNAME].ToString(), cc_control.dtEvent.Rows[index][gf_main.CTRLLINE].ToString()), ConsoleU.Level.Info);
                                 ProtocolObject.remoteWrite(SocProtocol.Drive.remote, System.Text.Encoding.ASCII.GetBytes(cc_control.dtEvent.Rows[index][gf_main.CTRLLINE].ToString()));
                                 System.Threading.Thread.Sleep(2000);
                             }
                         }
                     }
                 }
             }
         }
         Thread.Sleep(1000);
     }
 }
Esempio n. 5
0
        private void button_Click(object sender, EventArgs e)
        {
            Button btn_Click = (Button)sender;

            if (gf_main.serializeSigh == "serialize")
            {
                gf_serialize a = mMainFormTrans("serializeFrm");
                a.remoteEventReceive(btn_Click.Text);
                return;
            }

            for (int i = 0; i < cc_control.dtEvent.Rows.Count; i++)
            {
                if (cc_control.dtEvent.Rows[i][gf_main.CTRLEVENTNAME].ToString() == btn_Click.Text)
                {
                    ConsoleU.writeLine(String.Format("you click: {0} button, \"{1}\"", btn_Click.Text, cc_control.dtEvent.Rows[i][gf_main.CTRLLINE].ToString()), ConsoleU.Level.Info);
                    ProtocolObject.remoteWrite(SocProtocol.Drive.remote, System.Text.Encoding.ASCII.GetBytes(cc_control.dtEvent.Rows[i][gf_main.CTRLLINE].ToString()));

                    break;
                }
            }
        }
Esempio n. 6
0
        public static string serializeSigh = ""; //为了区分是命令还是添加修改序列化
        public gf_main(string[] args)
        {
            InitializeComponent();
#if printf
            Text = String.Format("{0} v{1} < build {2} >", Text, gf_main.VERSION, DateTime.Now.ToString());
            ConsoleU.writeLine(Text, ConsoleU.Level.Warning);

            string mArgs = String.Empty;
            foreach (string arg in args)
            {
                mArgs += arg + " ";
            }
            mArgs = mArgs.Trim();

            ConsoleU.writeLine(String.Format("args = \"{0}\"", mArgs), ConsoleU.Level.Warning);
            ConsoleU.writeLine(String.Format("work dir = \"{0}\"", Application.StartupPath),
                               ConsoleU.Level.Warning);
#endif

            debugToolStripMenuItem.Checked = true;//for debug initialize selected

            toolStripStatusLabel1.Text = String.Format(" {0} {1} v{2} < build {2} >", "     ", Text, VERSION, DateTime.Now.ToString());
        }
        Int32 load(String fileName)
        {
            DataTable dtTemp = new DataTable();

            mcontrolItems.Clear();

            String printInfo = "binding control... ...";

            ConsoleU.writeLine(printInfo, ConsoleU.Level.Warning);

            DataSet ds            = new DataSet();
            String  fileExtension = System.IO.Path.GetExtension(fileName);

            if (fileExtension != ".xml" || !System.IO.File.Exists(fileName))
            {
                ConsoleU.writeLine("this file is not xml or path error,please select again!", ConsoleU.Level.Warning);
            }
            ds.ReadXml(fileName);
            dtTemp = ds.Tables[gf_main.DIRCTRL];

            DataSet dsEvent = new DataSet();//load  xml about event DataSet

            dsEvent.ReadXml(fileName);

            if (dtTemp == null)
            {
                printInfo = "Cannot find node,please try again..."; ConsoleU.writeLine(printInfo, ConsoleU.Level.Warning); return(-1);
            }
            if (dtTemp.Rows == null)
            {
                printInfo = "Cannot find node rows,please try again..."; ConsoleU.writeLine(printInfo, ConsoleU.Level.Warning); return(-1);
            }

            foreach (DataRow row in dtTemp.Rows)
            {
                cc_control ctrl = new cc_control();
                try
                { ctrl.Ctr_Text = row[gf_main.CTRLTEXT].ToString(); }
                catch (FormatException) { }
                try
                { ctrl.Ctr_X = Int32.Parse(row[gf_main.CTRLX].ToString()); }
                catch (FormatException) { }
                try
                { ctrl.Ctr_Y = Int32.Parse(row[gf_main.CTRLY].ToString()); }
                catch (FormatException) { }
                try
                { ctrl.Ctr_Width = Int32.Parse(row[gf_main.CTRLWIDTH].ToString()); }
                catch (FormatException) { }
                try
                { ctrl.Ctr_Height = Int32.Parse(row[gf_main.CTRLHEIGHT].ToString()); }
                catch (FormatException) { }
                try
                { ctrl.Ctr_Type = row[gf_main.CTRLTYPE].ToString(); }
                catch (FormatException) { }


                DataRelationCollection childRelations = dtTemp.ChildRelations;//relationship building
                if (childRelations.Count > 0)
                {
                    DataRelation relation = childRelations[String.Format("{0}_{1}", gf_main.DIRCTRL, gf_main.DIREVENT)];
                    DataRow[]    ruleRows = row.GetChildRows(relation);
                    foreach (DataRow ruleRow in ruleRows)
                    {
                        ctrl.mevent.addEvent(ruleRow, dsEvent.Tables[gf_main.DIREVENT]);//init ion controls event
                    }
                }

                mcontrolItems.Add(ctrl);
            }
#if ctrlPrintf
            ConsoleU.writeLine(String.Format("control loaded. . {0}", ctrlCount), ConsoleU.Level.Normal);
#endif
            return(0);
        }
Esempio n. 8
0
        void loadCtrls()
        {
            if (mctrls.ctrlCount > 0)
            {
                Int32 index = 0;
                foreach (cc_control ctrl in mctrls.ctrlsItem)
                {
                    if (ctrl.Ctr_Type == "button")
                    {
                        System.Windows.Forms.Button button;
                        button          = (new System.Windows.Forms.Button());
                        button.Name     = "button_" + index;
                        button.Text     = ctrl.Ctr_Text;
                        button.TabIndex = index;
                        this.Controls.Add(button);

                        button.Location = new System.Drawing.Point(ctrl.Ctr_X, ctrl.Ctr_Y);
                        button.Size     = new System.Drawing.Size(ctrl.Ctr_Width, ctrl.Ctr_Height);
                        button.UseVisualStyleBackColor = true;
                        button.Click += new System.EventHandler(button_Click);
                        //button.Enter += new System.EventHandler(button_Enter);

                        String channelColor = "0,1,2,3,4,5,6,7,8,9,UP,DOWN,LEFT,RIGHT"; //set channel color
                        //下面是我在网上搜集的
                        System.Drawing.Drawing2D.GraphicsPath myPath = new System.Drawing.Drawing2D.GraphicsPath();

                        foreach (String mChannelColor in channelColor.Split(','))
                        {
                            if (ctrl.Ctr_Text == mChannelColor)
                            {
                                //绘制从边缘向内收缩4像素的椭圆
                                myPath.AddEllipse(new Rectangle(4, 4, button.Width - 8, button.Height - 8));
                                //'设置按钮形状为该椭圆形状
                                button.Region = new Region(myPath);
                                //填充渐变
                                Bitmap   B = new Bitmap(button.Width, button.Height);;
                                Graphics G = Graphics.FromImage(B);;

                                G.FillPath(new System.Drawing.Drawing2D.LinearGradientBrush(new Point(4, 4), new Point(4, button.Height), Color.Yellow, Color.Red), myPath);
                                //描绘椭圆边框
                                G.DrawEllipse(new Pen(Brushes.Black, 3), new Rectangle(4, 4, button.Width - 8, button.Height - 8));
                                //设置为其背景,不影响Image属性
                                button.BackgroundImage = B;
                                //取消难看的自有边框
                                button.FlatAppearance.BorderSize = 0;
                                //使用“抬起”效果是为了使按钮文字有点击响应视觉
                                button.FlatStyle = FlatStyle.Popup;
                            }
                        }
                        button.FlatStyle = FlatStyle.Popup;

                        if (ctrl.Ctr_Text == "RED")
                        {
                            button.BackColor = System.Drawing.Color.Red;
                        }
                        if (ctrl.Ctr_Text == "GREEN")
                        {
                            button.BackColor = System.Drawing.Color.Green;
                        }
                        if (ctrl.Ctr_Text == "YELLOW")
                        {
                            button.BackColor = System.Drawing.Color.Yellow;
                        }
                        if (ctrl.Ctr_Text == "BLUE")
                        {
                            button.BackColor = System.Drawing.Color.Blue;
                        }
                        //button.Click+=new EventHandler();
#if print
                        ConsoleU.writeLine(String.Format("buttonName={0}\"buttonText={1}\"X={2}\"Y={3}", button.Name, button.Text, ctrl.Ctr_X, ctrl.Ctr_Y), ConsoleU.Level.Info);
#endif
                    }
                    index++;
                }
            }
        }