private void button3_Click(object sender, EventArgs e) { DateTime dt =new DateTime (); if (DateTime.TryParse(tb日期.Text, out dt)) { Def_电表数 电表数info = new Def_电表数(BasedateID); 电表数info.B电表数 = tb电表数.Text; 电表数info.B电能表变比及容量 = tb电能表变比及容量.Text; 电表数info.B稽核人 = tb稽核人.Text; 电表数info.B稽核日期 = tb稽核日期.Text; 电表数info.B日期 = tb日期.Text; 电表数info.B日平均 = tb日平均.Text; 电表数info.B月平均 = tb月平均.Text; 电表数Comend.UpDate电表数(电表数info); SQLExecute.Operate = "用户" + DBUser.CURR_USERID + "更新电表数信息,基站编号:" + BasedateID + ",电表数的日期为:" + 电表数info.B日期; SQLExecute.SaveOperate(); MessageBox.Show("添加成功 !", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); InitDic(); FlashUI(0); } else { MessageBox.Show("请选择日期!"); } }
/// <summary> /// 搜索 /// </summary> /// <param name="BasedateID"></param> /// <returns></returns> public static Dictionary<string, Def_电表数> Get电表数ByBasedateID(string BasedateID) { Dictionary<string, Def_电表数> Dic电表数 = new Dictionary<string, Def_电表数>(); Def_电表数 电表数 = null; string sql = "SELECT [ID] " + " ,[basedateID] " + " ,[电表数] " + " ,[电能表变比及容量] " + " ,[稽核人] " + " ,[稽核日期] " + " ,[日期] " + " ,[日平均] " + " ,[月平均] " + " FROM [New电表数] where basedateID = '" + BasedateID.ToString().Replace("'", "''") + "' ORDER BY [日期] "; DataTable dt = new DataTable("电表数"); SQLExecute.Convertdrtodt(SQLExecute.ExecuteReader(sql), dt); if (dt.Rows.Count == 0) { Dic电表数 = new Dictionary<string, Def_电表数>(); } else { for (int i = 0; i < dt.Rows.Count; i++) { 电表数 = new Def_电表数(BasedateID); 电表数.Index = dt.Rows[i]["ID"].ToString(); 电表数.B电表数 = dt.Rows[i]["电表数"].ToString(); 电表数.B电能表变比及容量 = dt.Rows[i]["电能表变比及容量"].ToString(); 电表数.B稽核人 = dt.Rows[i]["稽核人"].ToString(); 电表数.B稽核日期 = dt.Rows[i]["稽核日期"].ToString(); 电表数.B日期 = dt.Rows[i]["日期"].ToString(); 电表数.B日平均 = dt.Rows[i]["日平均"].ToString(); 电表数.B月平均 = dt.Rows[i]["月平均"].ToString(); Dic电表数.Add(电表数.B日期, 电表数); } } return Dic电表数; }
/// <summary> /// 添加 /// </summary> /// <param name="电表数"></param> public static void Insert电表数(Def_电表数 电表数) { string sql = "INSERT INTO [New电表数] " + " ([basedateID] " + " ,[电表数] " + " ,[电能表变比及容量] " + " ,[稽核人] " + " ,[稽核日期] " + " ,[日期] " + " ,[日平均] " + " ,[月平均])" + " VALUES " + " ('" + 电表数.BasedateID.ToString().Replace("'", "''") + "' " + ",'" + 电表数.B电表数.ToString().Replace("'", "''") + "' " + ",'" + 电表数.B电能表变比及容量.ToString().Replace("'", "''") + "' " + ",'" + 电表数.B稽核人.ToString().Replace("'", "''") + "' " + ",'" + 电表数.B稽核日期.ToString().Replace("'", "''") + "' " + ",'" + 电表数.B日期.ToString().Replace("'", "''") + "' " + ",'" + 电表数.B日平均.ToString().Replace("'", "''") + "' " + ",'" + 电表数.B月平均.ToString().Replace("'", "''") + "')"; SQLExecute.ExecuteNonQuery(sql); }
/// <summary> /// 根据listbox中选择的位置 刷新画面 /// </summary> /// <param name="i"></param> private void FlashUI(int i) { DateDef.New.Def_电表数 电表数Info = null; if (listBox1.Items.Count > 0 && dic电表数.Count > 0) { 电表数Info = dic电表数[listBox1.Items[i].ToString()]; if (电表数Info != null) { this.tb电表数.Text = 电表数Info.B电表数; this.tb电能表变比及容量.Text = 电表数Info.B电能表变比及容量; this.tb稽核人.Text = 电表数Info.B稽核人; this.tb稽核日期.Text = 电表数Info.B稽核日期; this.tb日期.Text = 电表数Info.B日期; this.tb日平均.Text = 电表数Info.B日平均; this.tb月平均.Text = 电表数Info.B月平均; } } else { 电表数Info = new DateDef.New.Def_电表数(BasedateID); this.tb电表数.Text = 电表数Info.B电表数; this.tb电能表变比及容量.Text = 电表数Info.B电能表变比及容量; this.tb稽核人.Text = 电表数Info.B稽核人; this.tb稽核日期.Text = 电表数Info.B稽核日期; this.tb日期.Text = 电表数Info.B日期; this.tb日平均.Text = 电表数Info.B日平均; this.tb月平均.Text = 电表数Info.B月平均; } }
/// <summary> /// 更新(带插入) /// </summary> /// <param name="电表数"></param> public static void UpDate电表数(Def_电表数 电表数) { string InsertSQL = "UPDATE [New电表数] " + " SET " + " [电表数] = '" +电表数.B电表数.ToString().Replace("'", "''") + "'" + " ,[电能表变比及容量]= '" +电表数.B电能表变比及容量.ToString().Replace("'", "''") + "'" + " ,[稽核人] = '" +电表数.B稽核人.ToString().Replace("'", "''") + "'" + " ,[稽核日期] = '" +电表数.B稽核日期.ToString().Replace("'", "''") + "'" + " ,[日平均] = '" +电表数.B日平均.ToString().Replace("'", "''") + "'" + " ,[月平均] = '" +电表数.B月平均.ToString().Replace("'", "''") + "'" + " WHERE [basedateID] ='" + 电表数.BasedateID.ToString().Replace("'", "''") + "' and [日期] = '" + 电表数.B日期.ToString().Replace("'", "''") + "' "; string UpDateSQL = "INSERT INTO [New电表数] " + " ([basedateID] " + " ,[电表数] " + " ,[电能表变比及容量] " + " ,[稽核人] " + " ,[稽核日期] " + " ,[日期] " + " ,[日平均] " + " ,[月平均])" + " VALUES " + " ('" + 电表数.BasedateID.ToString().Replace("'", "''") + "' " + ",'" + 电表数.B电表数.ToString().Replace("'", "''") + "' " + ",'" + 电表数.B电能表变比及容量.ToString().Replace("'", "''") + "' " + ",'" + 电表数.B稽核人.ToString().Replace("'", "''") + "' " + ",'" + 电表数.B稽核日期.ToString().Replace("'", "''") + "' " + ",'" + 电表数.B日期.ToString().Replace("'", "''") + "' " + ",'" + 电表数.B日平均.ToString().Replace("'", "''") + "' " + ",'" + 电表数.B月平均.ToString().Replace("'", "''") + "')"; string strSQL = null; strSQL += InsertSQL;//= string.Format("Update S_RoleDetail set [Power]='{0}' where [RoleID]='{1}' and ProgramID ='{2}'", dt.Rows[i][1].ToString().Replace("'", "''"), dt.Rows[0][2].ToString().Replace("'", "''"), dt.Rows[i][0].ToString().Replace("'", "''")); strSQL = strSQL + " if @@RowCount=0 "; strSQL = strSQL + UpDateSQL;//string.Format("Insert into S_RoleDetail ([RoleID],[ProgramID],[Power]) values ('{0}','{1}','{2}')", dt.Rows[0][2].ToString().Replace("'", "''"), dt.Rows[i][0].ToString().Replace("'", "''"), dt.Rows[i][1].ToString().Replace("'", "''")); SQLExecute.ExecuteNonQuery(strSQL); }