private void  除ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (this.listView1.SelectedItems.Count > 0)
     {
         //if (MessageBox.Show("是否删除该通讯设备类型?") == DialogResult.OK)
         if (MessageBox.Show("确定要删除该通讯设备类型吗?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
         {
             if (this.listView1.SelectedItems[0].Tag is CommunicateDeviceType)
             {
                 var communicateDeviceType = this.listView1.SelectedItems[0].Tag as CommunicateDeviceType;
                 var id = communicateDeviceType.ID;
                 List <CommunicateDevice> communicateDeviceList =
                     CommunicateDevice.FindAllByCommunicateDeviceTypeID(id);
                 if (communicateDeviceList != null)
                 {
                     MessageBox.Show("该设备类型已经在使用,不能删除");
                     return;
                 }
                 CommunicateDeviceType.Delete(communicateDeviceType);
                 this.InitCommunicateDeviceTypeListView();
                 this
                 .communicateDeviceTypeId = 0;
             }
         }
     }
 }
Example #2
0
        private static void Main()
        {
            //注册日志处理器
            ObjectContainer.Current.Register <Logger>(new Logger());

            var mutex = new Mutex(false, Setting.Current.SystemName);

            if (mutex.WaitOne(0, false))
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                //注册所有窗体
                FormHelper.RegisterForm();

                //数据库系统初始化
                CommunicateDeviceType.FindAllWithCache();
                Logger.Current.WriteLog("数据库管理系统初始化完成");

                //弹出主窗体
                Application.Run(FormHelper.FrmMain);
            }
            else
            {
                Logger.Current.WriteWarn("程序已启动");
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (this.txtName.Text.Trim().IsNullOrWhiteSpace())
            {
                MessageBox.Show("名称不能为空,请输入");
                this.txtName.Focus();
                return;
            }

            //if (ProtocalType.FindAllByName(this.txtName.Text) != null)
            //{
            //    MessageBox.Show("名称已经存在");
            //    this.txtName.Focus();
            //    return;
            //}
            if (this.communicateDeviceTypeId != 0)
            {
                try
                {
                    // 更新
                    var communicateDeviceType = new CommunicateDeviceType
                    {
                        ID     = this.communicateDeviceTypeId,
                        Name   = this.txtName.Text.Trim(),
                        Remark = this.txtRemark.Text.Trim()
                    };
                    CommunicateDeviceType.Update(communicateDeviceType);
                    MessageBox.Show("更新成功");
                }
                catch (Exception ex)
                {
                    XTrace.WriteException(ex);
                    MessageBox.Show("更新失败");
                }
            }
            else
            {
                try
                {
                    // 保存
                    var communicateDeviceType = new CommunicateDeviceType
                    {
                        Name   = this.txtName.Text.Trim(),
                        Remark = this.txtRemark.Text.Trim()
                    };
                    CommunicateDeviceType.Save(communicateDeviceType);
                    MessageBox.Show("保存成功");
                }
                catch (Exception ex)
                {
                    XTrace.WriteException(ex);
                    MessageBox.Show("保存失败");
                }
            }

            this.InitCommunicateDeviceTypeListView();
        }
Example #4
0
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            var types = CommunicateDeviceType.FindAll();
            var names = new ArrayList();

            if (types != null && types.Count > 0)
            {
                names.AddRange(types);
            }
            return(new StandardValuesCollection(names));
        }
        /// <summary>
        /// 初始化通讯设备类型列表
        /// </summary>
        private void InitCommunicateDeviceTypeListView()
        {
            this.listView1.Items.Clear();
            List <CommunicateDeviceType> communicateDeviceTypeList = CommunicateDeviceType.FindAll();

            foreach (var communicateDeviceType in communicateDeviceTypeList)
            {
                var strings = new string[]
                { communicateDeviceType.ID.ToString(), communicateDeviceType.Name, communicateDeviceType.Remark };
                var listViewItem = new ListViewItem(strings);
                listViewItem.Tag = communicateDeviceType;
                this.listView1.Items.Add(listViewItem);
            }
        }
Example #6
0
        /// <summary>
        /// 初始化通讯设备类型
        /// </summary>
        private void InitCommunicateDeviceType()
        {
            List <CommunicateDeviceType> communicateDeviceTypeList = CommunicateDeviceType.FindAll();

            //foreach (var communicateDeviceType in communicateDeviceTypeList)
            //{
            //    this.cbCommunicateDeviceType.Items.Add(communicateDeviceType);
            //    this.cbCommunicateDeviceType.DisplayMember = communicateDeviceType.ID.ToString();
            //    this.cbCommunicateDeviceType.ValueMember = communicateDeviceType.Name;
            //}
            if (communicateDeviceTypeList.Count > 0)
            {
                this.cbCommunicateDeviceType.DataSource    = communicateDeviceTypeList;
                this.cbCommunicateDeviceType.DisplayMember = "Name";
                this.cbCommunicateDeviceType.ValueMember   = "ID";
            }
        }
Example #7
0
 private void BaseConfig_Load(object sender, EventArgs e)
 {
     if (ClassName.EqualIgnoreCase("CommunicateDeviceType"))
     {
         this.Name = "CommunicateDeviceType";
         var types = CommunicateDeviceType.FindAll();
         this.dataGridViewX1.DataSource = types;
     }
     if (ClassName.EqualIgnoreCase("Sensor"))
     {
         this.Name = "Sensor";
         this.dataGridViewX1.DataSource = Sensor.FindAll();
     }
     if (ClassName.EqualIgnoreCase("RelayType"))
     {
         this.Name = "RelayType";
         this.dataGridViewX1.DataSource = RelayType.FindAll();
     }
     if (ClassName.EqualIgnoreCase("ControlJobType"))
     {
         this.Name = "ControlJobType";
         this.dataGridViewX1.DataSource = ControlJobType.FindAll();
     }
     if (ClassName.EqualIgnoreCase("DeviceType"))
     {
         this.Name = "DeviceType";
         this.dataGridViewX1.DataSource = DeviceType.FindAll();
     }
     if (ClassName.EqualIgnoreCase("FacilityType"))
     {
         this.Name = "FacilityType";
         this.dataGridViewX1.DataSource = FacilityType.FindAll();
     }
     if (ClassName.EqualIgnoreCase("ProtocalType"))
     {
         this.Name = "ProtocalType";
         this.dataGridViewX1.DataSource = ProtocalType.FindAll();
     }
     if (ClassName.EqualIgnoreCase("ShowDeviceType"))
     {
         this.Name = "ShowDeviceType";
         this.dataGridViewX1.DataSource = ShowDeviceType.FindAll();
     }
 }