public static Model_PDAInfo EditPDAs(Model_PDAInfo pdaInfo) { string sql = ""; //判断PDA设备编号 (系统唯一)是否是唯一的 if (pdaInfo.Id == 0) { Model_PDAInfo mp = GetPDAOnly(pdaInfo); if (mp != null) { throw new Exception("设备编号已存在"); } } else { sql = "select * from device_info where id=?id"; MySqlParameter[] pdapara = new MySqlParameter[1]; pdapara[0] = new MySqlParameter("id", pdaInfo.Id); Model_PDAInfo mp = _SqlHelp.ExecuteObject <Model_PDAInfo>(sql, pdapara); if (mp.Number != pdaInfo.Number) { Model_PDAInfo mpda = GetPDAOnly(pdaInfo); if (mpda != null) { throw new Exception("设备编号已存在"); } } } if (pdaInfo.Id == 0) { sql = "insert into device_info(number,name,createAt,actived) values(?number,?name,?createAt,?actived) ;"; } else { sql = "update device_info set number=?number,name=?name,createAt=?createAt,actived=?actived where id=?id ;"; } MySqlParameter[] para = new MySqlParameter[5]; para[0] = new MySqlParameter("number", pdaInfo.Number); para[1] = new MySqlParameter("name", pdaInfo.Name); para[2] = new MySqlParameter("createAt", pdaInfo.CreateAt); para[3] = new MySqlParameter("actived", pdaInfo.Actived); para[4] = new MySqlParameter("id", pdaInfo.Id); int result = 0; if (pdaInfo.Id == 0) { result = _SqlHelp.ExecuteNonQuery(sql, para); } else { result = _SqlHelp.ExecuteNonQuery(sql, para); } if (result != 1) { throw new Exception("操作失败"); } return(pdaInfo); }
/// <summary> /// 删除 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tsmDelete_Click(object sender, EventArgs e) { try { Model_PDAInfo mp = dataGridView1.SelectedRows[0].Tag as Model_PDAInfo; mp.Activedk__BackingField = Enum_Active.Disable; if (MessageBox.Show("确定是否删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { ResultModelOfModel_PDAInfod4FqxSXX pdalist = cs.EditPDA(mp); if (pdalist.Code != 0) { MessageBox.Show(pdalist.Message); } else { MessageBox.Show("操作成功,PDA已停用"); DeviceLoad(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// 绑定目的地 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tsmBindingDestination_Click(object sender, EventArgs e) { Model_PDAInfo mppdain = dataGridView1.SelectedRows[0].Tag as Model_PDAInfo; FrmPDADestination pdadt = new FrmPDADestination(); pdadt.mp = mppdain; pdadt.ShowDialog(); }
/// <summary> /// 更新 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tsmUpdate_Click(object sender, EventArgs e) { Model_PDAInfo mp = dataGridView1.SelectedRows[0].Tag as Model_PDAInfo; FrmPDAUpdate pdaupte = new FrmPDAUpdate(); pdaupte.udtmp = mp; pdaupte._ParentPad = this; pdaupte.ShowDialog(); }
public static Model_PDAInfo GetPDAOnly(Model_PDAInfo pdaInfo) { string sql = "select * from device_info where number=?number"; MySqlParameter[] pdapara = new MySqlParameter[1]; pdapara[0] = new MySqlParameter("number", pdaInfo.Number); Model_PDAInfo pda = _SqlHelp.ExecuteObject <Model_PDAInfo>(sql, pdapara); return(pda); }
private void btnSave_Click(object sender, EventArgs e) { try { if (txtDeviceNumber.Text.Trim() == string.Empty) { MessageBox.Show("设备编号不能为空"); return; } if (Encoding.Default.GetBytes(txtDeviceNumber.Text.Trim()).Length > 10) { MessageBox.Show("设备编号不能超过10"); return; } if (txtDeviceName.Text.Trim() == string.Empty) { MessageBox.Show("设备名称不能为空"); return; } if (Encoding.Default.GetBytes(txtDeviceName.Text.Trim()).Length > 50) { MessageBox.Show("设备名称不能超过50"); return; } Model_PDAInfo pda = new Model_PDAInfo(); pda.Idk__BackingField = udtmp.Idk__BackingField; pda.Numberk__BackingField = txtDeviceNumber.Text.Trim(); pda.Namek__BackingField = txtDeviceName.Text.Trim(); pda.CreateAtk__BackingField = udtmp.CreateAtk__BackingField; if (rdbEnabled.Checked == true) { pda.Activedk__BackingField = Enum_Active.Enabled; } else { pda.Activedk__BackingField = Enum_Active.Disable; } ResultModelOfModel_PDAInfod4FqxSXX pdalist = cs.EditPDA(pda); if (pdalist.Code != 0) { MessageBox.Show(pdalist.Message); } else { MessageBox.Show("操作成功"); _ParentPad.PdaLoad(); this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// 编辑或删除PDA信息 /// Id不为0时表示编辑PDA信息 /// Id为-1时通过PDA编号删除该PDA /// Id为0时表示添加PDA信息 /// </summary> /// <param name="pdaInfo">PDA信息</param> /// <returns></returns> public ResultModel <Model_PDAInfo> EditPDA(Model_PDAInfo pdaInfo) { ResultModel <Model_PDAInfo> result = new ResultModel <Model_PDAInfo>(); try { result.Data = DeviceServer.EditPDAs(pdaInfo); } catch (Exception ex) { result.Code = 1; result.Message = ex.Message; } return(result); }
/// <summary> /// 根据编号查询指定设备信息 /// </summary> /// <param name="num">设备编号</param> /// <returns></returns> public static Model_PDAInfo GetPDAInfoByNum(string num) { try { string sql = "select id,number,name from device_info where number=?num and actived=0"; MySqlParameter[] para = new MySqlParameter[1]; para[0] = new MySqlParameter("num", num); Model_PDAInfo model = _SqlHelp.ExecuteObject <Model_PDAInfo>(sql, para); if (model == null) { throw new Exception("该设备信息未激活或已被删除!"); } return(model); } catch (Exception ex) { throw ex; } }