Ejemplo n.º 1
0
 public bool Cmp(cmsStationSet SS)
 {
     if (
         SS.IP == this.IP &&
         SS.Port == this.Port &&
         SS.StaName == this.StaName &&
         SS.IPandPort == this.IPandPort
         )
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 2
0
        private void btn_Add_Click(object sender, EventArgs e)
        {
            string str1 = textBox_IP.Text;
            string str2 = textBox_SatName.Text;
            string str3 = textBox_Port.Text;

            if (str1 == "" || str2 == "" || str3 == "")
            {
                MessageBox.Show("Please complete the filling", "WARN");
            }
            else
            {
                if (fm.getValidIP(str1) != null && fm.getValidPort(str3) != -1)
                {
                    string insertstr = "insert into tb_StaSet(IP,StaName,Port,IPandPort) values('";
                    insertstr += str1 + "', '";
                    insertstr += str2 + "', '";
                    insertstr += str3 + "', '";
                    insertstr += str1 + ":" + str3 + "')";

                    cmsStationSet addSS = new cmsStationSet();
                    addSS.IP        = str1;
                    addSS.StaName   = str2;
                    addSS.Port      = str3;
                    addSS.IPandPort = str1 + ":" + str3;
                    bool isRepeat = true;
                    foreach (cmsStationSet tmpSS in FormMain.DataModel.StationSet)
                    {
                        if (addSS.Cmp(tmpSS))
                        {
                            isRepeat = false;
                            break;
                        }
                    }
                    if (isRepeat)
                    {
                        FormMain.DataModel.StationSet.Add(addSS);
                    }
                    else
                    {
                        MessageBox.Show("Repeat Infomation", "Warn");
                    }

                    DataLength++;
                    label_all.Text = DataLength.ToString();

                    update_Data(insertstr);
                    GetDatabaseData();
                }
                else
                {
                    if (fm.getValidIP(str1) == null && fm.getValidPort(str3) != -1)
                    {
                        MessageBox.Show("  IP  format error", "WARN");
                    }
                    else if (fm.getValidIP(str1) != null && fm.getValidPort(str3) == -1)
                    {
                        MessageBox.Show("  Port  format error", "WARN");
                    }
                    else
                    {
                        MessageBox.Show("IP and Port formats error", "WARN");
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void btn_confirm_Click(object sender, EventArgs e)
        {
            string ipn   = textBox_IPn.Text.Trim();
            string namen = textBox_SatNamen.Text.Trim();
            string portn = textBox_Portn.Text.Trim();

            if (true)
            {
                string sql = null;

                try
                {
                    sql  = " update tb_StaSet set";
                    sql += "    IP= '" + ipn;
                    sql += "' , Port= '" + portn;
                    sql += "' , StaName= '" + namen;
                    sql += "' , IPandPort= '" + ipn + ":" + portn;
                    sql += " 'Where IPandPort = '" + ip + ":" + port + "'";
                    for (int i = 0; i < FormMain.DataModel.StationSet.Count; i++)
                    {
                        cmsStationSet udSS = FormMain.DataModel.StationSet[i];
                        if (udSS.IPandPort == (ip + ":" + port))
                        {
                            udSS.IP        = ipn;
                            udSS.Port      = portn;
                            udSS.StaName   = namen;
                            udSS.IPandPort = ipn + ":" + portn;
                            FormMain.DataModel.StationSet[i] = udSS;
                        }
                    }

                    update_datagridView();
                }
                catch
                {
                    MessageBox.Show("change failed");
                }

                try
                {
                    sql  = " update tb_AreaSet set ";
                    sql += " IPandPort= '" + ipn + ":" + portn;
                    sql += "' , Map = replace( Map , '" + ip + ":" + port + "' , '" + ipn + ":" + portn + "' )";
                    sql += " Where IPandPort = '" + ip + ":" + port + "'";
                    for (int i = 0; i < FormMain.DataModel.AreaSet.Count; i++)
                    {
                        cmsAreaSet udAS = FormMain.DataModel.AreaSet[i];
                        if (udAS.IPport == (ip + ":" + port))
                        {
                            udAS.IPport = ipn + ":" + portn;
                            udAS.Map    = udAS.Map.Replace(ip + ":" + port, ipn + ":" + portn);
                            FormMain.DataModel.AreaSet[i] = udAS;
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("change failed");
                }

                try
                {
                    sql  = " update tb_Map set ";
                    sql += " MapInfo = replace( MapInfo , '" + ip + ":" + port + "' , '" + ipn + ":" + portn + "' )";
                    foreach (cmsMap udMap in FormMain.DataModel.Map)
                    {
                        udMap.MapInfo = udMap.MapInfo.Replace(ip + ":" + port, ipn + ":" + portn);
                    }
                }
                catch
                {
                    MessageBox.Show("change failed");
                }


                GetDatabaseData();
                LoadTreeView();
                this.Close();
            }
            else
            {
                MessageBox.Show("Fill in non-standard");
            }
        }