/** * 添加变压器信息 * @param refTransformerLose t_lose:变损信息 * @return int 值为Constant.OK:执行成功,值为Constant.ERROR为执行失败 * @author Rick **/ public int addTInfo(ref TransformerInfo t_info) { string strAdd = "insert into TransformerInfo values (" + t_info.TransformerNo + ",'" + t_info.TransformerName + "'," + t_info.TransformerLoseNo + ")"; try { SQLUtl.ExecuteSql(strAdd); return Constant.OK; } catch (Exception) { return Constant.ERROR; } }
private void T_Add_Button_Click(object sender, EventArgs e) { if ("" == this.T_Code_Add.Text.Trim()) { MessageBox.Show("变压器代码不能为空!"); return; } bool state = false; this.t_info_action.checkTInfoNo(this.T_Code_Add.Text.Trim(), ref state); if (!state) { MessageBox.Show("该变压器代码已经存在!"); return; } TransformerInfo t_info = new TransformerInfo(); t_info.TransformerNo = this.T_Code_Add.Text.Trim(); if ("" == this.T_Name_Add.Text.Trim()) { MessageBox.Show("变压器名称不能为空!"); return; } t_info.TransformerName = this.T_Name_Add.Text.Trim(); if (-1 == this.T_Lose_Add.SelectedIndex) { MessageBox.Show("请选择所属变损类型!"); return; } t_info.TransformerLoseNo = this.T_Lose_Add.SelectedIndex.ToString().Trim().Split(' ')[0]; if (Constant.OK == this.t_info_action.addTInfo(ref t_info)) { MessageBox.Show("添加成功!"); this.T_List_init(); this.T_Name_Add.Text = ""; this.T_Lose_Add.SelectedIndex = -1; this.T_Code_Add.Text = ""; } else { MessageBox.Show("添加失败!"); } }
private void T_Update_Click(object sender, EventArgs e) { TransformerInfo t_info = new TransformerInfo(); if (-1 == this.T_List.SelectedIndex) { MessageBox.Show("请选择要更新的变压器!"); return; } t_info.TransformerNo = this.T_List.SelectedItem.ToString().Trim().Split(' ')[0]; if (this.T_Name.Text.Trim() == "") { MessageBox.Show("变压器名称不能为空!"); return; } t_info.TransformerName = this.T_Name.Text.Trim(); if (-1 == this.T_Lose_Type.SelectedIndex) { MessageBox.Show("请选择变损类型!"); return; } t_info.TransformerLoseNo = this.T_Lose_Type.SelectedItem.ToString().Split(' ')[0]; if (Constant.OK == this.t_info_action.updateTInfo(t_info.TransformerNo, ref t_info)) { MessageBox.Show("更新成功!"); return; } else { MessageBox.Show("更新失败!"); return; } }
private void T_List_SelectedIndexChanged(object sender, EventArgs e) { TransformerInfo transfomerInfo = new TransformerInfo(); TransformerLose transformerLose = new TransformerLose(); if (-1 != this.T_List.SelectedIndex) { if (Constant.OK == this.t_info_action.getTInfoById(this.T_List.SelectedItem.ToString().Trim().Split(' ')[0], ref transfomerInfo)) { this.T_Code.Text = transfomerInfo.TransformerNo; this.T_Code.Enabled = false; this.T_Name.Text = transfomerInfo.TransformerName; if ("" != transfomerInfo.TransformerLoseNo) { if (Constant.OK == this.t_lose_action.getTLoseTypeById(transfomerInfo.TransformerLoseNo, ref transformerLose)) { string item = transformerLose.TransformerLoseNo + " " + transformerLose.TransformerType + " " + transformerLose.StandarVolume; this.T_Lose_Type.SelectedItem = item; } }else { //do nothing } } } }
/** * 更新变压器信息 * @param string t_info_no:变压器编号 * @param ref AreaInfo areaInfo:台区信息 * @return int 值为Constant.OK:执行成功,值为Constant.ERROR为执行失败 * @author Rick **/ public int updateTInfo(string t_info_no, ref TransformerInfo t_info) { string strUpdate = "update TransformerInfo set TransformerName = '" + t_info.TransformerName + "', TransformerLoseNo = " + t_info.TransformerLoseNo + " where TransformerNo = " + t_info_no; try { SQLUtl.ExecuteSql(strUpdate); return Constant.OK; } catch (Exception) { return Constant.ERROR; } }
/** * 添加新变压器信息 * @param string t_info_no:变压器编号 * @param ref TransformerLose t_lose:台区信息 * @return int 值为Constant.OK:执行成功,值为Constant.ERROR为执行失败 * @author Rick **/ public int getTInfoById(string t_info_no, ref TransformerInfo t_info) { string strSelect = "select * from TransformerInfo where TransformerNo = " + t_info_no; try { DataSet ds = SQLUtl.Query(strSelect); DataTable dt = ds.Tables[0]; if (null != dt.Rows[0].ItemArray[0]) { t_info.TransformerNo = dt.Rows[0].ItemArray[0].ToString().Trim(); } else { t_info.TransformerNo = ""; } if (null != dt.Rows[0].ItemArray[1]) { t_info.TransformerName = dt.Rows[0].ItemArray[1].ToString().Trim(); } else { t_info.TransformerName = ""; } if (null != dt.Rows[0].ItemArray[2]) { t_info.TransformerLoseNo = dt.Rows[0].ItemArray[2].ToString().Trim(); } else { t_info.TransformerLoseNo = ""; } return Constant.OK; } catch (Exception) { return Constant.ERROR; } }