Example #1
0
        public TaskForm(FoodServer.MainForm.DrawInfo d)
        {
            InitializeComponent();
            this.comboBox1.Text = d.name.Trim().ToString();
            drwInfo             = d;
            DetectQuray frm = new DetectQuray(d.user_id.ToString());

            frm.TopLevel        = false;
            frm.FormBorderStyle = FormBorderStyle.None;
            frm.Parent          = this.panel1;
            // frm.SetBounds(0,0,this.panel1.Width, this.panel1.Height);
            frm.Show();
        }
        private void button_ok_Click(object sender, EventArgs e)
        {
            ToolTip tt = new ToolTip();

            tt.IsBalloon = true;       //如果false就是一个方块型的提示框
            tt.SetToolTip(this.textBox_name, "请输入非数字名称!");
            tt.Show("请输入非数字名称!", this.textBox_name);
            // return;



            if (parameter.fuc == "update")
            {
                string strsql = "Update device SET "
                                + "Device_ID = '" + textBox_ID.Text.ToString() + "',"
                                + "Device_PassWord = '******',"
                                + "Device_Code = '" + textBox_Code.Text.ToString() + "',"
                                + "Device_Name = '" + textBox_name.Text.ToString() + "',"
                                + "Device_Addr = '" + textBox_Addr.Text.ToString() + "',"
                                + "Device_Type = '" + textBox_Type.Text.ToString() + "',"
                                + "Device_Ver = '" + textBox_version.Text.ToString() + "'"
                                + "WHERE Device_ID = " + IDNum + "";

                dbMySql.Open(databasename);
                dbMySql.ExcuteNonQuery(databasename, strsql);
                dbMySql.Close(databasename);
                this.Close();
                parent.Device_Load();
                newDeviceName     = textBox_name.Text.ToString();
                this.DialogResult = DialogResult.OK;
                MessageBox.Show("修改成功");
            }
            else
            {
                if (string.IsNullOrEmpty(textBox_name.Text.Trim()))
                {
                    MessageBox.Show("请输入终端名称!");
                    return;
                }
                else
                {
                    DataSet dataSet = new DataSet();
                    string  sql     = "SELECT * FROM device";
                    int     ret     = database.ReadDataBase(sql, "device", dataSet);
                    FoodServer.MainForm.m_csName = this.textBox_name.Text.Trim().ToString();
                    if (ret == 0)
                    {
                        foreach (DataRow row in dataSet.Tables["device"].Rows)
                        {
                            if (row["Device_Name"].ToString() == FoodServer.MainForm.m_csName)
                            {
                                MessageBox.Show("该终端已经存在,请重新输入终端名称!");
                                return;
                            }
                        }
                    }
                }

                // FoodServer.MainForm.m_userId = User_Name;
                FoodServer.MainForm.m_csAddress         = textBox_Addr.Text.Trim().ToString();
                FoodServer.MainForm.m_csDeviceType      = textBox_Type.Text.Trim().ToString();
                FoodServer.MainForm.m_csSoftwareVersion = textBox_version.Text.Trim().ToString();
                int    userid   = 0;
                int    group_id = 0;
                int    x        = 300;
                int    y        = 150;
                string strsql   = "Insert Into " +
                                  "device(Device_Group_ID,Device_Name,device.Device_Addr,device.Device_Type,device.Device_Ver, device.Device_X,device.Device_Y)"
                                  + "values('" + group_id + "','" + FoodServer.MainForm.m_csName + "','" + FoodServer.MainForm.m_csAddress + "','" + FoodServer.MainForm.m_csDeviceType + "','" + FoodServer.MainForm.m_csSoftwareVersion + "'," + x + "," + y + ")";
                try
                {
                    dbMySql.Open(databasename);
                    dbMySql.ExcuteNonQuery(databasename, strsql);
                    dbMySql.Close(databasename);

                    DataSet dataSet1 = new DataSet();
                    string  sql1     = "SELECT * FROM device";
                    int     re       = database.ReadDataBase(sql1, "device2", dataSet1);
                    if (re == 0)
                    {
                        foreach (DataRow r in dataSet1.Tables["device2"].Rows)
                        {
                            if (r["Device_Name"].ToString() == FoodServer.MainForm.m_csName)
                            {
                                userid = int.Parse(r["Device_ID"].ToString());
                            }
                        }
                    }

                    ImagControl mark = new ImagControl();
                    mark.Location   = new Point(150, 150);
                    mark.PicboxShow = "room-b.png";
                    mark.Center     = mark.Location;
                    mark.Cname      = this.textBox_name.Text.ToString();
                    fa.pictureBox1.Controls.Add(mark);
                    fa.treeView1.Refresh();
                    fa.reloadview();

                    // fa.dataGridView1.Refresh();

                    FoodServer.MainForm.DrawInfo line = new FoodServer.MainForm.DrawInfo();
                    line.imc     = mark;
                    line.user_id = userid;
                    line.name    = FoodServer.MainForm.m_csName;
                    fa.Pics.Add(line);
                    fa.PicsSave.Add(line);
                    fa.Redraw(line, mark.Center);

                    mark.MouseUp          += new System.Windows.Forms.MouseEventHandler(fa.Mouse_Up);
                    mark.MouseDown        += new System.Windows.Forms.MouseEventHandler(fa.MouseDown);
                    mark.MouseMove        += new System.Windows.Forms.MouseEventHandler(fa.MouseMove);
                    mark.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(fa.MouseDoubleClick);
                    mark.MouseHover       += new System.EventHandler(fa.MouseHover);
                    //Adds Line object to an arraylist
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                this.DialogResult = DialogResult.OK;
            }

            this.Close();
        }