Example #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            StringBuilder stb = new StringBuilder(Constant.PROTOCOL_XUNLUOSHU.ToString()).Append(Constant.SPLIT1);

            foreach (TreeNode ttn in treeView1.Nodes)
            {
                foreach (TreeNode ctn in ttn.Nodes)
                {
                    if (ctn.Checked)
                    {
                        if (stb.Length == 2)
                        {
                            stb.Append((ctn.Tag as Car).CarID);
                        }
                        else
                        {
                            stb.Append(Constant.SPLIT2).Append((ctn.Tag as Car).CarID);
                        }
                    }
                }
            }
            if (stb.Length == 2)
            {
                MessageBox.Show(this, "没有选择任何车辆");
                return;
            }
            stb.Append(Constant.SPLIT1).Append(CMD[listBox1.SelectedIndex]).Append(Constant.SPLIT1);
            switch (listBox1.SelectedIndex)
            {
            // case 0:
            //   if(textBox00.Text == "")
            //     {
            //       MessageBox.Show(this, "请填写中心短信号码");
            //        return;
            //    }
            //   stb.Append(textBox00.Text);
//break;
            //case 1:
            //   if(textBox10.Text == "")
            //  {
            //       MessageBox.Show(this, "请填写中心辅助短信号码");
            //       return;
            //   }
//stb.Append(textBox10.Text);
            //  break;
            case 2:
                stb.Append(this.numericUpDown60.Value);
                break;

            case 3:
                stb.Append(this.numericUpDown60.Value);

                break;

            case 4:
                stb.Append(numericUpDown40.Value);
                break;

            case 0:
                if (comboBox51.SelectedIndex == 0 || numericUpDown50.Value == 0)
                {
                    stb.Append(numericUpDown50.Value).Append(",");
                    // stb.Append(comboBox51.SelectedIndex).Append(",0,0,0,0,0,0"); //目前没用
                }
                if (textBox52.Text == "")
                {
                    MessageBox.Show(this, "请选取围栏");
                    return;
                }
                else
                {
                    // stb.Append(numericUpDown50.Value).Append(",");
                    //  stb.Append(comboBox51.SelectedIndex).Append(",");

                    double   x1   = Double.Parse(textBox52.Text);
                    double   y1   = Double.Parse(textBox53.Text);
                    double   x2   = Double.Parse(textBox54.Text);
                    double   y2   = Double.Parse(textBox55.Text);
                    String[] ss   = x1.ToString().Split('.');
                    string   xa   = ss[0];
                    string   x1_1 = ss[1];

                    string x1_1_str = "0" + "." + x1_1;

                    double   x1_n       = System.Convert.ToDouble(x1_1_str) * 60;
                    string[] ss_1       = x1_n.ToString("#0.0000").Split('.');
                    string   x1_1_1     = ss_1[0];
                    string   x1_1_1_1   = ss_1[1];
                    string   x1_1_1_1_1 = x1_1_1 + x1_1_1_1;
                    string   x1_re      = xa + x1_1_1_1_1;

                    //    MessageBox.Show(x1_re);    // 左下精度1


                    /////////////////////////////////////////////////

                    String[] ss_a = y1.ToString().Split('.');
                    string   ya   = ss_a[0];
                    string   y1_1 = ss_a[1];

                    string y1_1_str = "0" + "." + y1_1;

                    double   y1_n       = System.Convert.ToDouble(y1_1_str) * 60;
                    string[] ss_1_a     = y1_n.ToString("#0.0000").Split('.');
                    string   y1_1_1     = ss_1_a[0];
                    string   y1_1_1_1   = ss_1_a[1];
                    string   y1_1_1_1_1 = y1_1_1 + y1_1_1_1;
                    string   y1_re      = ya + y1_1_1_1_1;
                    // MessageBox.Show(y1_re);    // 左下伟度1
                    ///////////////////////////////////////////////
                    String[] ss_b  = x2.ToString().Split('.');
                    string   yaa   = ss_b[0];
                    string   y1_1a = ss_b[1];

                    string y1_1_stra = "0" + "." + y1_1a;

                    double   y1_na       = System.Convert.ToDouble(y1_1_stra) * 60;
                    string[] ss_1_b      = y1_na.ToString("#0.0000").Split('.');
                    string   y1_1_1a     = ss_1_b[0];
                    string   y1_1_1_1a   = ss_1_b[1];
                    string   y1_1_1_1_1a = y1_1_1a + y1_1_1_1a;
                    string   y1_rea      = yaa + y1_1_1_1_1a;
                    //   MessageBox.Show(y1_rea);

                    //////////////////////////////////////////////////

                    String[] ss_ba  = y2.ToString().Split('.');
                    string   yaaa   = ss_ba[0];
                    string   y1_1aa = ss_ba[1];

                    string y1_1_straa = "0" + "." + y1_1aa;

                    double   y1_naa       = System.Convert.ToDouble(y1_1_straa) * 60;
                    string[] ss_1_ba      = y1_naa.ToString("#0.0000").Split('.');
                    string   y1_1_1ab     = ss_1_ba[0];
                    string   y1_1_1_1ab   = ss_1_ba[1];
                    string   y1_1_1_1_1ab = y1_1_1ab + y1_1_1_1ab;
                    string   y1_reab      = yaaa + y1_1_1_1_1ab;
                    //  MessageBox.Show(y1_reab);

                    stb.Append(y1_re).Append("0").Append(x1_re).Append(y1_reab).Append("0").Append(y1_rea);


                    /*
                     * 1.只要求保留N位不四舍五入
                     *
                     * float f = 0.55555f;
                     * int i =(int)(f * 100);
                     * f = (float)(i*1.0)/100;
                     *
                     * 2.保留N位,并且四舍五入
                     *
                     * decimal d= decimal.Round(decimal.Parse("0.55555"),2);
                     *
                     * 3.保留N位,并且四舍五入
                     *
                     * Math.Round(0.55555,2)
                     *
                     * 4.保留N位,并且四舍五入
                     *
                     * double dbdata = 0.55555;
                     * string str1 = dbdata.ToString("f2");//fN 保留N位,四舍五入
                     *
                     * 5.保留N位,并且四舍五入
                     *
                     * string result = String.Format("{0:N2}", 0.55555);//2位
                     * string result = String.Format("{0:N3}", 0.55555);//3位
                     *
                     * 6.保留N位,并且四舍五入
                     *
                     * double s=0.55555;
                     * result=s.ToString("#0.00");//点后面几个0就保留几位
                     *
                     * 或者(求圆的面积和周长)
                     *
                     * double s = Convert.ToDouble(textBox1.Text);
                     * double mianji = Math.PI * s * s;
                     * textBox2.Text = mianji.ToString("F3");
                     * double zhouchang = 2 * Math.PI * s;
                     * textBox3.Text = zhouchang.ToString("F3");
                     *
                     *
                     *
                     *
                     *
                     */



                    /*
                     * if(y1 < 0)
                     *  stb.Append("S,");
                     * else stb.Append("N,");
                     * y1 = Math.Abs(y1); y2 = Math.Abs(y2);
                     * if(y1 > y2) //小的放前面
                     * {
                     *  temp = y1;
                     *  y1 = y2;
                     *  y2 = temp;
                     * }
                     * stb.Append(CoverLaToStr(y1)).Append(",");
                     * stb.Append(CoverLaToStr(y2)).Append(",");
                     *
                     * if(x1 < 0)
                     *  stb.Append("E,");
                     * else stb.Append("W,");
                     * x1 = Math.Abs(x1); x2 = Math.Abs(x2);
                     * if(x1 > x2)//小的放前面
                     * {
                     *  temp = x1;
                     *  x1 = x2;
                     *  x2 = temp;
                     * }
                     * stb.Append(CoverLoToStr(x1)).Append(",");
                     * stb.Append(CoverLoToStr(x2));
                     *
                     */
                }
                break;

            case 6:
                stb.Append(numericUpDown60.Value).Append(",");
                stb.Append(comboBox61.SelectedIndex + 1).Append(",");
                stb.Append(textBox62.Text);
                break;

            case 1:


                stb.Append(this.numericUpDown70.Value);



                break;

            case 8:
                if (textBox80.Text == "")
                {
                    MessageBox.Show(this, "请填写监听电话");
                    return;
                }
                stb.Append(textBox80.Text);
                break;

            case 9:
                stb.Append(comboBox91.SelectedIndex).Append(",");
                if (comboBox90.SelectedIndex == 1)   //解除断电
                {
                    stb.Append("0");
                }
                else if (FormMain.CheckPw())   //断电,需密码确认
                {
                    stb.Append(numericUpDown92.Value).Append(",");
                    stb.Append(numericUpDown92.Value).Append(",");
                    stb.Append(numericUpDown92.Value).Append(",");
                    stb.Append(numericUpDown92.Value);
                }
                else
                {
                    return;
                }
                break;

            case 10:
                if (comboBox100.SelectedIndex == 0)
                {
                    stb.Append("A0,0,0,0");
                }
                else
                {
                    stb.Append("A").Append(comboBox100.SelectedIndex + 4).Append(",");
                    if (comboBox101.SelectedIndex == 0)
                    {
                        stb.Append("0,0,");
                    }
                    else
                    {
                        stb.Append(comboBox101.SelectedIndex).Append(",");
                        stb.Append(numericUpDown102.Value).Append(",");
                    }
                    stb.Append(checkBox103.Checked ? "1" : "0");
                }
                break;

            case 11:
                String bin = "1111111";
                if (comboBox110.SelectedIndex == 0)   //允许断油
                {
                    bin += "0";
                }
                else
                {
                    bin += "1";
                }
                stb.Append(Pub.BinToHex(bin));
                break;

            case 12:    //远程开关门
                stb.Append(comboBox121.SelectedIndex);
                break;

            default:
                break;
            }
            if (FormMain.dataSocket.Connected)
            {
                FormMain.C_Set_Order(stb.ToString());
            }
            this.Close();
        }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            int           routeway = 0;
            StringBuilder stb      = new StringBuilder(Constant.PROTOCOL_TIANHE.ToString()).Append(Constant.SPLIT1);

            foreach (TreeNode ttn in treeView1.Nodes)
            {
                foreach (TreeNode ctn in ttn.Nodes)
                {
                    if (ctn.Checked)
                    {
                        routeway = (ctn.Tag as Car).Routeway;
                        if (stb.Length == 2)
                        {
                            stb.Append((ctn.Tag as Car).CarID);
                        }
                        else
                        {
                            stb.Append(Constant.SPLIT2).Append((ctn.Tag as Car).CarID);
                        }
                    }
                }
            }
            if (stb.Length == 2)
            {
                MessageBox.Show(this, "没有选择任何车辆");
                return;
            }
            stb.Append(Constant.SPLIT1);
            String time1 = DateTime.Now.ToString(",HHmmss,");
            String time2 = DateTime.Now.ToString(",HHmmss");

            switch (listBox1.SelectedIndex)
            {
            case 0:
                if (textBox00.Text == "")
                {
                    MessageBox.Show(this, "请填写中心短信号码");
                    return;
                }
                stb.Append("S2").Append(time1).Append(textBox00.Text);
                break;

            case 1:
                if (textBox10.Text == "")
                {
                    MessageBox.Show(this, "请填写中心辅助短信号码");
                    return;
                }
                stb.Append("S28").Append(time1).Append(textBox10.Text);
                break;

            case 2:
                if (textBox1001.Text == "")
                {
                    MessageBox.Show(this, "请填写接入点名称APN");
                    return;
                }
                stb.Append("S24").Append(time1).Append(textBox1001.Text);
                break;

            case 3:
                stb.Append("S23").Append(time1);
                stb.Append(numericUpDown20.Value).Append(",");
                stb.Append(numericUpDown21.Value).Append(",");
                stb.Append(numericUpDown22.Value).Append(",");
                stb.Append(numericUpDown23.Value).Append(",");
                stb.Append(numericUpDown24.Value).Append(",");
                stb.Append(numericUpDown25.Value);
                break;

            case 4:
                stb.Append("S14").Append(time1);
                stb.Append(Pub.KmsToKts((int)numericUpDown31.Value)).Append(",");
                stb.Append(Pub.KmsToKts((int)numericUpDown30.Value)).Append(",");
                stb.Append(numericUpDown32.Value);
                break;

            case 5:
                stb.Append("S33").Append(time1);
                stb.Append(Pub.KmsToKts((int)numericUpDown40.Value));
                break;

            case 6:
                stb.Append("S21").Append(time1);
                if (comboBox51.SelectedIndex == 0 || numericUpDown50.Value == 0)
                {
                    stb.Append(numericUpDown50.Value).Append(",");
                    stb.Append(comboBox51.SelectedIndex).Append(",");
                    stb.Append("0,0,0,0,0,0");
                }
                else if (textBox52.Text == "")
                {
                    MessageBox.Show(this, "请选取围栏");
                    return;
                }
                else
                {
                    stb.Append(numericUpDown50.Value).Append(",");
                    stb.Append(comboBox51.SelectedIndex).Append(",");
                    double x1 = Double.Parse(textBox52.Text),
                           y1 = Double.Parse(textBox53.Text),
                           x2 = Double.Parse(textBox54.Text),
                           y2 = Double.Parse(textBox55.Text),
                           temp;

                    if (y1 < 0)
                    {
                        stb.Append("S,");
                    }
                    else
                    {
                        stb.Append("N,");
                    }
                    y1 = Math.Abs(y1); y2 = Math.Abs(y2);
                    if (y1 > y2)    //小的放前面
                    {
                        temp = y1;
                        y1   = y2;
                        y2   = temp;
                    }
                    stb.Append(CoverLaToStr(y1)).Append(",");
                    stb.Append(CoverLaToStr(y2)).Append(",");

                    if (x1 < 0)
                    {
                        stb.Append("E,");
                    }
                    else
                    {
                        stb.Append("W,");
                    }
                    x1 = Math.Abs(x1); x2 = Math.Abs(x2);
                    if (x1 > x2)   //小的放前面
                    {
                        temp = x1;
                        x1   = x2;
                        x2   = temp;
                    }
                    stb.Append(CoverLoToStr(x1)).Append(",");
                    stb.Append(CoverLoToStr(x2));
                }
                break;

            case 7:
                stb.Append("S5").Append(time1);
                stb.Append(numericUpDown60.Value).Append(",");
                stb.Append(comboBox61.SelectedIndex + 1).Append(",");
                stb.Append(textBox62.Text);
                break;

            case 8:
                stb.Append("D1").Append(time1).Append(numericUpDown70.Value);
                stb.Append(",").Append(numericUpDown71.Value);
                break;

            case 9:
                stb.Append("S17").Append(time1);
                stb.Append(numericUpDown1011.Value);
                if (routeway < 2)   //gprs
                {
                    stb.Append(",").Append(numericUpDown1012.Value);
                }
                break;

            case 10:
                if (textBox80.Text == "")
                {
                    MessageBox.Show(this, "请填写监听电话");
                    return;
                }
                stb.Append("R8").Append(time1);
                stb.Append(textBox80.Text);
                break;

            case 11:
                stb.Append("S20").Append(time1);
                stb.Append(comboBox91.SelectedIndex).Append(",");
                if (comboBox90.SelectedIndex == 1)   //解除断电
                {
                    stb.Append("0");
                }
                else if (FormMain.CheckPw())   //断电,需密码确认
                {
                    stb.Append(numericUpDown92.Value).Append(",");
                    stb.Append(numericUpDown92.Value).Append(",");
                    stb.Append(numericUpDown92.Value).Append(",");
                    stb.Append(numericUpDown92.Value);
                }
                else
                {
                    return;
                }
                break;

            case 12:
                stb.Append("S19").Append(time1);
                if (comboBox100.SelectedIndex == 0)
                {
                    stb.Append("A0,0,0,0");
                }
                else
                {
                    stb.Append("A").Append(comboBox100.SelectedIndex + 4).Append(",");
                    if (comboBox101.SelectedIndex == 0)
                    {
                        stb.Append("0,0,");
                    }
                    else
                    {
                        stb.Append(comboBox101.SelectedIndex).Append(",");
                        stb.Append(numericUpDown102.Value).Append(",");
                    }
                    stb.Append(checkBox103.Checked ? "1" : "0");
                }
                break;

            case 13:
                stb.Append("S12").Append(time1);
                String bin = "111111";
                if (comboBox111.SelectedIndex == 0)   //允许S17
                {
                    bin += "0";
                }
                else
                {
                    bin += "1";
                }
                if (comboBox110.SelectedIndex == 0)   //允许断油
                {
                    bin += "0";
                }
                else
                {
                    bin += "1";
                }
                stb.Append(Pub.BinToHex(bin));
                break;

            case 14:
                stb.Append("S31").Append(time1);
                stb.Append(numericUpDown1021.Value).Append(",");
                stb.Append(numericUpDown1022.Value);
                break;

            case 15:
                stb.Append("S4").Append(time1);
                UInt16 c = 0xff;
                if (comboBox1031.SelectedIndex == 0)
                {
                    c -= 128;
                }
                if (comboBox1032.SelectedIndex == 0)
                {
                    c -= 64;
                }
                if (comboBox1033.SelectedIndex == 0)
                {
                    c -= 16;
                }
                if (comboBox1034.SelectedIndex == 0)
                {
                    c -= 8;
                }
                stb.Append((char)c).Append((char)0xff);
                break;

            case 16:
                stb.Append("S40").Append(time1);
                stb.Append(numericUpDown1041.Value).Append(",");
                stb.Append(numericUpDown1042.Value).Append(",");
                stb.Append(numericUpDown1043.Value).Append(",");
                stb.Append(numericUpDown1044.Value).Append(",");
                stb.Append(numericUpDown1045.Value).Append(",").Append((char)0xFF);
                break;

            case 17:
                break;

            case 18:
                break;

            ///////
            case 19:
                stb.Append("R7").Append(time2);
                break;

            case 20:
                stb.Append("A1").Append(time2);
                break;

            case 21:
                stb.Append("R1").Append(time2);
                break;

            case 22:
                stb.Append("S25").Append(time2);
                break;

            case 23:
                stb.Append("S32").Append(time1).Append("1");
                break;
            }
            String[] remark = new string[]
            {
                "设置中心短信号码",
                "设置辅助中心短信号码",
                "设置接入点名称APN",
                "设置GPRS中心",
                "设置超速报警速度",
                "设置超速提示速度",
                "设置电子围栏",
                "设置呼叫限制",
                "设置自动回传(D1)",
                "设置自动回传(S17)",
                "监听",
                "断油断电",
                "设置自定义报警",
                "设置终端参数",
                "设置温度报警",
                "系统设置",
                "设置疲劳驾驶监控",
                "远程开关门",
                "远程设防",
                "解除报警",
                "确认报警",
                "重启终端",
                "回复出厂设置",
                "查询里程"
            };
            stb.Append(Constant.SPLIT1).Append(remark[listBox1.SelectedIndex]);
            if (FormMain.dataSocket.Connected)
            {
                FormMain.C_Set_Order(stb.ToString());
            }
            this.Close();
        }