private void btnSave_Click(object sender, EventArgs e) { if (this.txtName.Text.Trim().IsNullOrWhiteSpace()) { MessageBox.Show("名称不能为空,请输入"); this.txtName.Focus(); return; } if (this.showDeviceTypeId != 0) { try { // 更新 var showDeviceType = new ShowDeviceType { ID = this.showDeviceTypeId, Name = this.txtName.Text.Trim(), Company = this.txtCompany.Text, //Version=this.txtVersion.Text, Remark = this.txtRemark.Text.Trim() }; ShowDeviceType.Update(showDeviceType); MessageBox.Show(@"更新成功"); } catch (Exception ex) { XTrace.WriteException(ex); MessageBox.Show(@"更新失败"); } } else { try { // 保存 var showDeviceType = new ShowDeviceType { //ID = Convert.ToInt32(this.txtId.Text), Name = this.txtName.Text.Trim(), Company = this.txtCompany.Text, //Version = this.txtVersion.Text, Remark = this.txtRemark.Text.Trim() }; ShowDeviceType.Save(showDeviceType); MessageBox.Show("保存成功"); } catch (Exception ex) { XTrace.WriteException(ex); MessageBox.Show("保存失败"); } } this.InitShowDeviceTypeListView(); }
private void advPropertyGrid1_PropertyValueChanging(object sender, PropertyValueChangingEventArgs e) { //var item = GetObjAndField(e.PropertyPath); //var obj= item.Item1; //var propertyName = item.Item2; if (e.PropertyName.EqualIgnoreCase("ModularDevices")) { var ModularDeviceID = ModularDevice.FindAllByName(e.NewValue.ToString())[0].ID; selectObj.Item1.SetItem("ModularDeviceID", ModularDeviceID); } else if (e.PropertyName.EqualIgnoreCase("Sensors")) { var SensorId = Sensor.FindAllByName("name", e.NewValue, null, 0, 0)[0].ID; selectObj.Item1.SetItem("SensorId", SensorId); } else if (e.PropertyName.EqualIgnoreCase("ControlJobTypes")) { var ControlJobTypeId = ControlJobType.FindAllByName("name", e.NewValue, null, 0, 0)[0].Id; selectObj.Item1.SetItem("ControlJobTypeId", ControlJobTypeId); } else if (e.PropertyName.EqualIgnoreCase("RelayTypes")) { var RelayTypeId = RelayType.FindAllByName("name", e.NewValue, null, 0, 0)[0].Id; selectObj.Item1.SetItem("RelayTypeId", RelayTypeId); } else if (e.PropertyName.EqualIgnoreCase("DeviceTypes")) { var DeviceTypeSerialnum = DeviceType.FindAllByName("name", e.NewValue, null, 0, 0)[0].Serialnum; selectObj.Item1.SetItem("DeviceTypeSerialnum", DeviceTypeSerialnum); } else if (e.PropertyName.EqualIgnoreCase("ShowDeviceTypes")) { var ShowDeviceTypeID = ShowDeviceType.FindAllByName("name", e.NewValue, null, 0, 0)[0].ID; selectObj.Item1.SetItem("ShowDeviceTypeID", ShowDeviceTypeID); } else if (e.PropertyName.EqualIgnoreCase("CommunicateDevices")) { var CommunicateDeviceID = CommunicateDevice.FindAllByName("name", e.NewValue, null, 0, 0)[0].ID; selectObj.Item1.SetItem("CommunicateDeviceID", CommunicateDeviceID); } else if (e.PropertyName.EqualIgnoreCase("Farms")) { var FarmID = Farm.FindAllByName("name", e.NewValue, null, 0, 0)[0].ID; selectObj.Item1.SetItem("FarmID", FarmID); } else if (e.PropertyName.EqualIgnoreCase("FacilityTypes")) { var FacilityTypeSerialnum = FacilityType.FindAllByName("name", e.NewValue, null, 0, 0)[0].Serialnum; selectObj.Item1.SetItem("FacilityTypeSerialnum", FacilityTypeSerialnum); } else { selectObj.Item1.SetItem(e.PropertyName, e.NewValue); } }
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { var types = ShowDeviceType.FindAll(); var names = new ArrayList(); if (types != null && types.Count > 0) { names.AddRange(types); } return(new StandardValuesCollection(names)); }
/// <summary> /// 初始化展示设备类型列表 /// </summary> private void InitShowDeviceTypeListView() { this.listView1.Items.Clear(); List <ShowDeviceType> showDeviceTypeList = ShowDeviceType.FindAll(); foreach (var showDeviceType in showDeviceTypeList) { var strings = new string[] { showDeviceType.ID.ToString(), showDeviceType.Name, showDeviceType.Company, showDeviceType.Version, showDeviceType.Remark }; var listViewItem = new ListViewItem(strings); listViewItem.Tag = showDeviceType; this.listView1.Items.Add(listViewItem); } }
/// <summary> /// 初始化展示设备类型 /// </summary> private void InitShowDeviceType() { List <ShowDeviceType> showDeviceTypeList = ShowDeviceType.FindAll(); //foreach (var showDeviceType in showDeviceTypeList) //{ // this.cbShowDeviceTypeID.Items.Add(showDeviceType); // this.cbShowDeviceTypeID.DisplayMember = showDeviceType.ID.ToString(); // this.cbShowDeviceTypeID.ValueMember = showDeviceType.Name; //} if (showDeviceTypeList.Count > 0) { this.cbShowDeviceType.DataSource = showDeviceTypeList; this.cbShowDeviceType.DisplayMember = "Name"; this.cbShowDeviceType.ValueMember = "ID"; } }
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(); } }
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 ShowDeviceType) { var showDeviceType = this.listView1.SelectedItems[0].Tag as ShowDeviceType; var id = showDeviceType.ID; List <ShowDevice> showDeviceList = ShowDevice.FindAllByShowDeviceTypeID(id); if (showDeviceList != null) { MessageBox.Show("该设备类型在使用中,不能删除"); return; } ShowDeviceType.Delete(showDeviceType); this.InitShowDeviceTypeListView(); this.showDeviceTypeId = 0; } } } }