Пример #1
0
        private void btnDelEquip_Click(object sender, RoutedEventArgs e)
        {
            var      fdf   = equipList;
            Equip4DB equip = dgEquip.SelectedItem as Equip4DB;

            if (equip == null)
            {
                MessageBox.Show("请选择一个设备");
                return;
            }
            string name = equip.Name;

            if (MessageBox.Show("同时将删除" + name + "相关的IP地址,继续么?", "警告", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
            {
                string delIPSql    = string.Format("delete from IPAddress where IP_EquipID = {0}", equip.Index);
                string delEquipSql = string.Format("delete from Equipments where Equip_Index = {0}", equip.Index);
                if (App.DBHelper.ExecuteTransaction(new List <string>()
                {
                    delIPSql, delEquipSql
                }))
                {
                    App.InitInformation();  //不初始化的话,如果删除掉一个设备,同时拓扑等程序打开的话,会调用
                    if (RefreshEvent != null)
                    {
                        RefreshEvent(null, null);
                    }
                }
                else
                {
                    MessageBox.Show("删除失败");
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 添加设备,在equipNameList、数据库、equipList中同时添加
        /// </summary>
        private void btnAddEquip_Click(object sender, RoutedEventArgs e)
        {
            string equipName = tbAddEquipName.Text;
            string equipType = cbbAddEquipType.Text;

            if (equipNameList.Contains(equipName))
            {
                MessageBox.Show("已经有这个设备了");
                return;
            }
            if (string.IsNullOrEmpty(equipName))
            {
                MessageBox.Show("请输入设备名称");
                return;
            }
            if (equipType.Equals("选择类型"))
            {
                MessageBox.Show("请选择设备类型");
                return;
            }
            int    typeIndex = Convert.ToInt32(App.DBHelper.returnScalar("SELECT Type_Index FROM EquipmentType WHERE Type_Name = '" + equipType + "'"));
            string insertSql = string.Format("INSERT INTO Equipments(Equip_Name, Equip_TypeIndex) values('{0}',{1})", equipName, typeIndex);

            if (App.DBHelper.ExecuteReturnBool(insertSql))
            {
                equipNameList.Add(equipName);
                int      equipIndex = Convert.ToInt32(App.DBHelper.returnScalar("SELECT Equip_Index FROM Equipments WHERE Equip_Name = '" + equipName + "'"));
                Equip4DB equip      = new Equip4DB(equipIndex, equipName);
                equip.TypeIndex = typeIndex;
                equip.TypeName  = equipType;
                equipList.Add(equip);
            }
        }
Пример #3
0
        private void InitDataGridEquipments()
        {
            SqlDataReader dr = App.DBHelper.returnReader("SELECT Equip_Index, Equip_Name, Type_Index, Type_Name FROM Equipments INNER JOIN EquipmentType ON Equip_TypeIndex = Type_Index");

            while (dr.Read())
            {
                Equip4DB equip = new Equip4DB(Convert.ToInt32(dr["Equip_Index"]), dr["Equip_Name"] as string);
                equip.TypeIndex = Convert.ToInt32(dr["Type_Index"]);
                equip.TypeName  = dr["Type_Name"] as string;
                equipList.Add(equip);
            }
            dr.Close();
            dgcEquipType.ItemsSource      = typeList;
            dgEquip.ItemsSource           = equipList;
            dgcEquipName.ItemsSource      = equipNameList;
            cbbAddEquipType.ItemsSource   = typeList;
            cbbAddIPEquipName.ItemsSource = equipNameList;

            // dgEquip.SelectedItem
        }
Пример #4
0
 private void dgEquip_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (dgEquip.SelectedItem != null)
     {
         Equip4DB selectedItem = dgEquip.SelectedItem as Equip4DB;
         if (selectedItem != null)
         {
             string equipName = (dgEquip.SelectedItem as Equip4DB).Name;
             int    n         = dgIPInfo.Items.Count;
             for (int i = 0; i < n; i++)
             {
                 DataGridRow row = dgIPInfo.ItemContainerGenerator.ContainerFromIndex(i) as DataGridRow;
                 if ((dgIPInfo.Items[i] as IPInfor4DB).EquipName.Equals(equipName))
                 {
                     row.Visibility = Visibility.Visible;
                 }
                 else
                 {
                     row.Visibility = Visibility.Collapsed;
                 }
             }
         }
     }
 }