Ejemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            CheckTxtbox();
            try
            {
                if (Ishave(txtipaddr) == false)
                {
                    ora.ExecuteSql("update b_devices t set t.sip='" + txtipaddr.Text + "',t.resource_name='" + txtname.Text + "',t.pos_tc='" + comboBox1.SelectedValue.ToString() + "' where t.sip='" + Ip + "' and t.resource_name='" + Hostname + "'");
                    MessageBox.Show("此点位信息已经更新成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    //string path = System.Environment.CurrentDirectory + "//config//" + Flag + ".txt";
                    //string[] lines = System.IO.File.ReadAllLines(path);
                    ////转换
                    //List<string> list = new List<string>();
                    //list.AddRange(lines);
                    //for (int i = 0; i < list.Count; i++)
                    //{
                    //    if (list[i].ToString().Contains(Hostname + "," + Ip))
                    //    {
                    //        list[i] = txtname.Text + "," + txtipaddr.Text + "," + txtX.Text + "," + txtY.Text;
                    //    }
                    //}

                    //lines = list.ToArray();
                    ////保存
                    //File.WriteAllLines(path, lines, Encoding.UTF8);
                    //File.w
                    // MessageBox.Show(lines.ToString());
                    //MessageBox.Show("此点位信息已经更新成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    //this.Close();
                    Anj_Jk frm = (Anj_Jk)this.Owner;
                    frm.DeleteButton();
                    frm.AddbuttonInfo("images/" + Flag + ".jpg");
                }
                else
                {
                    MessageBox.Show(txtipaddr.Text + "已经存在,请不要重复更新!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 2
0
 private void button1_Click(object sender, EventArgs e)
 {
     // string path = System.Environment.CurrentDirectory + "//config//" + Flag + ".txt";
     //if(File.Exists(path))
     //{
     //    string[] line = File.ReadAllLines(path, Encoding.UTF8);
     //foreach(string str in line)
     //{
     //    if (str.Contains(txtname.Text + "," + txtipaddr.Text) || str.Contains(txtname.Text) || str.Contains(txtipaddr.Text))
     //    {
     //        MessageBox.Show("此点位已经存在,请重新添加!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
     //        return;
     //    }
     //}
     //StreamWriter sw = new StreamWriter(path, true);
     //sw.WriteLine(txtname.Text+","+txtipaddr.Text+","+txtX.Text+","+txtY.Text);
     //sw.Close();
     if (checkBox1.Checked == false)
     {
         if (CheckTxtbox() == false)
         {
             return;
         }
         try
         {
             if (Ishave(txtipaddr) == false)
             {
                 ora.ExecuteSql("insert into b_devices (id,sip,resource_name,pos_x,pos_y,pos_tc) values (SEQ_B_DEVICES.NEXTVAL,'" + txtipaddr.Text + "','" + txtname.Text + "','" + txtX.Text + "','" + txtY.Text + "','" + comboBox1.Text + "')");
                 Anj_Jk frm = (Anj_Jk)this.Owner;
                 frm.DeleteButton();
                 frm.AddbuttonInfo("images/" + Flag + ".jpg");
             }
             else
             {
                 MessageBox.Show("此点位已经存在,请重新添加!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.ToString(), "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     else
     {
         if (CheckTxtbox() == false)
         {
             return;
         }
         if (CheckInput(txttc) == false)
         {
             txtname.BackColor = Color.Red;
             return;
         }
         else
         {
             ora = new OracleHelper(constr);
             DataTable dt = ora.GetDt("select distinct t.pos_tc  from b_devices t where t.pos_tc is not null");
             //string path = System.Environment.CurrentDirectory + "//config//Position.txt";      //读取Position文件中显示层
             if (txtname.Text == "" || txtname.Text == null)
             {
                 MessageBox.Show("请输入图层名称!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 return;
             }
             if (dt.Rows.Count > 0)
             {
                 //string str = File.ReadAllText(path);
                 // string[] line = File.ReadAllLines(path, Encoding.Default);
                 for (int i = 0; i < dt.Rows.Count; i++)
                 {
                     if (dt.Rows[i]["pos_tc"].ToString() == txtname.Text.ToString().Trim())
                     {
                         MessageBox.Show("图层名称已经存在,请重新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                         return;
                     }
                 }
             }
             if (openFileDialog1.ShowDialog() == DialogResult.OK)
             {
                 string   oldName   = openFileDialog1.FileName;
                 string[] splitName = oldName.Split('.');
                 string   ext       = splitName[splitName.Length - 1];
                 string   dbName    = "\\images\\" + txttc.Text.ToString().Trim() + "." + ext;
                 string   newName   = System.Environment.CurrentDirectory + dbName;
                 File.Copy(oldName, newName, true);
                 //File.AppendAllText(path, txtname.Text.ToString().Trim() + "\r\n");
                 ora.ExecuteSql("insert into b_devices (id,sip,resource_name,pos_x,pos_y,pos_tc) values (SEQ_B_DEVICES.NEXTVAL,'" + txtipaddr.Text + "','" + txtname.Text + "','" + txtX.Text + "','" + txtY.Text + "','" + txttc.Text.Trim() + "')");
                 string paths = System.Environment.CurrentDirectory + "//config//" + txtname.Text.ToString().Trim() + ".txt";
                 if (File.Exists(paths) == false)
                 {
                     File.CreateText(paths);
                 }
                 MessageBox.Show("图层已经成功添加!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 txtname.Text = "";
             }
         }
     }
 }