/** * 添加接收电表信息 * @param ref ReceiveAmmeterInfo raInfo:接收电表信息 * @return int 值为Constant.OK:执行成功,值为Constant.ERROR为执行失败 * @author Rick **/ public int addRaInfo(ref ReceiveAmmeterInfo raInfo) { string strAdd = "insert into ReceiveInfo values (" + raInfo.ReceiveNo + ",'" + raInfo.ReceiveName + "'," + raInfo.Multipile + ")"; try { SQLUtl.ExecuteSql(strAdd); return Constant.OK; } catch (Exception) { return Constant.ERROR; } }
private void AddAmmeter_Click(object sender, EventArgs e) { if ("" == this.AmmeterNo_Add.Text.ToString().Trim()) { MessageBox.Show("电表编号不能为空!"); return; } bool state = false; if (Constant.OK != this.receiveAmmeterAction.checkRaInfoNo(this.AmmeterNo_Add.Text.ToString().Trim(), ref state)) { MessageBox.Show("数据库出错!"); return; } if (!state) { MessageBox.Show("该编号已经存在!"); return; } if (this.AmmeterName_Add.Text.ToString().Trim() == "") { MessageBox.Show("电表名称不能为空!"); return; } if (this.AmmeterMulti_Add.Text.ToString().Trim() == "") { MessageBox.Show("电表倍率不能为空!"); return; } ReceiveAmmeterInfo raInfo = new ReceiveAmmeterInfo(); raInfo.ReceiveNo = this.AmmeterNo_Add.Text.ToString().Trim(); raInfo.ReceiveName = this.AmmeterName_Add.Text.ToString().Trim(); raInfo.Multipile = this.AmmeterMulti_Add.Text.ToString().Trim(); if (Constant.OK == this.receiveAmmeterAction.addRaInfo(ref raInfo)) { MessageBox.Show("添加成功!"); this.AmmeterList_init(); return; } else { MessageBox.Show("添加失败!"); return; } }
private void UpdateAmmeter_Click(object sender, EventArgs e) { if (this.AmmeterList.SelectedIndex == -1) { MessageBox.Show("请选择电表编号!"); return; } if (this.AmmeterName.Text.ToString().Trim() == "") { MessageBox.Show("电表名称不能为空!"); return; } if (this.AmmeterMulti.Text.ToString().Trim() == "") { MessageBox.Show("电表倍率不能为空!"); return; } ReceiveAmmeterInfo raInfo = new ReceiveAmmeterInfo(); raInfo.ReceiveNo = this.AmmeterNo.Text.ToString().Trim(); raInfo.ReceiveName = this.AmmeterName.Text.ToString().Trim(); raInfo.Multipile = this.AmmeterMulti.Text.ToString().Trim(); if (Constant.OK == this.receiveAmmeterAction.updateRaInfo(raInfo.ReceiveNo, ref raInfo)) { MessageBox.Show("数据更新成功!"); return; } else { MessageBox.Show("数据更新失败!"); return; } }
private void AmmeterList_SelectedIndexChanged(object sender, EventArgs e) { if (-1 != this.AmmeterList.SelectedIndex) { string key = this.AmmeterList.SelectedItem.ToString().Trim().Split(' ')[0]; if ("" != key) { ReceiveAmmeterInfo raInfo = new ReceiveAmmeterInfo(); if (Constant.OK == this.receiveAmmeterAction.getRaInfoById(key, ref raInfo)) { this.AmmeterNo.Text = key; this.AmmeterName.Text = raInfo.ReceiveName; this.AmmeterMulti.Text = raInfo.Multipile; } } } }
/** * 更新接收电表信息 * @param string raNo:接收电表编号 * @param ref ReceiveAmmeterInfo raInfo:接收电表信息 * @return int 值为Constant.OK:执行成功,值为Constant.ERROR为执行失败 * @author Rick **/ public int updateRaInfo(string raNo, ref ReceiveAmmeterInfo raInfo) { string strUpdate = "update ReceiveInfo set ReceiveName = '" + raInfo.ReceiveName + "', Multipile = " + raInfo.Multipile + " where ReceiveNo = " + raNo; try { SQLUtl.ExecuteSql(strUpdate); return Constant.OK; } catch (Exception) { return Constant.ERROR; } }
/** * 添加新接收电表信息 * @param string raNo:接收电表编号 * @param ref ReceiveAmmeterInfo raInfo:接收电表信息 * @return int 值为Constant.OK:执行成功,值为Constant.ERROR为执行失败 * @author Rick **/ public int getRaInfoById(string raNo, ref ReceiveAmmeterInfo raInfo) { string strSelect = "select * from ReceiveInfo where ReceiveNo = " + raNo; try { DataSet ds = SQLUtl.Query(strSelect); DataTable dt = ds.Tables[0]; if (null != dt.Rows[0].ItemArray[0]) { raInfo.ReceiveNo = dt.Rows[0].ItemArray[0].ToString().Trim(); } else { raInfo.ReceiveNo = ""; } if (null != dt.Rows[0].ItemArray[1]) { raInfo.ReceiveName = dt.Rows[0].ItemArray[1].ToString().Trim(); } else { raInfo.ReceiveName = ""; } if (null != dt.Rows[0].ItemArray[2]) { raInfo.Multipile = dt.Rows[0].ItemArray[2].ToString().Trim(); } else { raInfo.Multipile = ""; } return Constant.OK; } catch (Exception) { return Constant.ERROR; } }