/// <summary> /// 删除 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDelete_Click(object sender, EventArgs e) { try { int pdaId = Convert.ToInt32(dataGridView1.SelectedCells[0].Value); if (MessageBox.Show("确定是否删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { Model_Destination destination = new Model_Destination(); destination.Idk__BackingField = pdaId; ResultModelOfModel_Destinationd4FqxSXX dest = cs.EditPDADestination(destination); if (dest.Code != 0) { MessageBox.Show(dest.Message); } else { MessageBox.Show("操作成功!"); PDADest(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnSave_Click(object sender, EventArgs e) { try { if (txtDestination.Text.Trim() == string.Empty) { MessageBox.Show("目的地不能为空"); return; } if (Encoding.Default.GetBytes(txtDestination.Text.Trim()).Length > 20) { MessageBox.Show("目的地不能超过20"); return; } Model_Destination destination = new Model_Destination(); destination.Addressk__BackingField = txtDestination.Text.Trim(); destination.DeviceIdk__BackingField = mp.Idk__BackingField; ResultModelOfModel_Destinationd4FqxSXX dest = cs.EditPDADestination(destination); if (dest.Code != 0) { MessageBox.Show(dest.Message); } else { MessageBox.Show("操作成功"); txtDestination.Text = string.Empty; PDADest(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// 编辑PDA目的地信息 /// </summary> /// <param name="destination">PDA目的地主体</param> /// <returns></returns> public ResultModel <Model_Destination> EditPDADestination(Model_Destination destination) { ResultModel <Model_Destination> result = new ResultModel <Model_Destination>(); try { result.Data = DeviceServer.EditPDADestinations(destination); } catch (Exception ex) { result.Code = 1; result.Message = ex.Message; } return(result); }
/// <summary> /// 添加PDA 设备目的地 /// </summary> /// <param name="destination"></param> /// <returns></returns> public static Model_Destination EditPDADestinations(Model_Destination destination) { string sql = ""; if (destination.Id == 0) { sql = "insert into device_destination(deviceId,address) values(?deviceId,?address); "; } else { sql = "delete from device_destination where id=?id ;"; } MySqlParameter[] para = new MySqlParameter[3]; para[0] = new MySqlParameter("deviceId", destination.DeviceId); para[1] = new MySqlParameter("address", destination.Address); para[2] = new MySqlParameter("id", destination.Id); int result = _SqlHelp.ExecuteNonQuery(sql, para); if (result != 1) { throw new Exception("操作失败"); } return(destination); }