private void button2_Click(object sender, EventArgs e) { mysql Mysql = new mysql(); int[] arr_ID = new int[3000]; //假设最大值为3000人 try { string sql_id = @"select * from pay"; //依照工作号筛选每个人,通过这个给每个人依次分配工资 MySqlDataReader dr = Mysql.GetRead(sql_id); while (dr.Read()) { arr_ID[i] = int.Parse(dr["id"].ToString()); string sql_rest = @"select rest_holiday from pay where id=" + arr_ID[i] + ""; int restday = int.Parse(Mysql.Executescalar(sql_rest).ToString()); if (Mysql.Executescalar(sql_rest) != null) { Monthsalary = daysalary * (30 - restday); } string sql_total = @"update pay set salary=" + Monthsalary + " where id=" + arr_ID[i] + " "; int result = Mysql.ExecuteNonQuery(sql_total); i++; } if (i != -1) { MessageBox.Show("分配工资成功!"); } else { MessageBox.Show("分配工资失败!"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { } }
private void button3_Click(object sender, EventArgs e) { Password_old = MD5.Upper(oldpwd.Text.Trim()); Password_new = MD5.Upper(newpwd.Text.Trim()); try { mysql Mysql = new mysql(); string sql = @"select password from users where user='******'"; string result = Mysql.Executescalar(sql).ToString(); if (result == Password_old) { Alter_success = true; } else { MessageBox.Show("原密码错误!请重新输入"); oldpwd.Text = ""; newpwd.Text = ""; Alter_success = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { } if (Alter_success == true) { try { mysql Mysql = new mysql(); string sql = @"update users set password='******' where user='******'"; int result_update = Mysql.ExecuteNonQuery(sql); if (result_update != -1) { MessageBox.Show("修改成功"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { } } }