工资发放计算+ID选择输入
前面一直有遇到问题,工资没算对,在百分除的时候,用int型会变成0,所以在上面用了double型再导入比例
1 //工资发放 2 private void button1_Click(object sender, EventArgs e) 3 { 4 SqlHelper sqlHelper = new SqlHelper(); 5 string YearmonthPresent = DateTime.Today.ToString("yyyy-MM");//当前年月 6 bool button = sqlHelper.bPayoffBotton(YearmonthPresent);//本月是否发过工资 7 if (button)//判断已发的话,提示消息 8 { 9 MessageBox.Show("本月工资已发"); 10 } 11 else 12 { 13 DataTable dr = sqlHelper.workDays(YearmonthPresent);//根据年月与数据库中年月比对 14 int c_workDays = Convert.ToInt32(dr.Rows[0].ItemArray[1]); ;//这个月应上班的天数 15 int count = 0;//反馈信息 16 UserInfo userinfo = new UserInfo(); 17 //遍历出datagridview表中的数据 18 for (int i = 0; i < dataGridView1.Rows.Count; i++)//对datagridview中数据遍历 19 { 20 DataGridViewRow row = dataGridView1.Rows[i]; 21 gUserInfo.userNP.UserId = Convert.ToInt32(row.Cells["UserId"].Value);//id 22 gUserInfo.userNP.BasicWage = Convert.ToDouble(row.Cells["BasicWage"].Value);//基本工资 23 gUserInfo.userNP.PayOvertime = Convert.ToDouble(Convert.ToInt32(row.Cells["OvertimeNum"].Value) * 50);//加班工资(加班工资应该根据每个人月工资的比例来) 24 gUserInfo.userNP.AmountPayable = gUserInfo.userNP.PayOvertime + gUserInfo.userNP.BasicWage;//应付金额=加班工资+基本工资 25 26 //迟到次数 27 int c_lateNum=0; 28 int.TryParse(row.Cells["LateNum"].Value.ToString(), out c_lateNum); 29 gUserInfo.userNP.NumberOfLate = c_lateNum; 30 //请假次数 31 int c_absentNum=0; 32 int.TryParse(row.Cells["LeaveNum"].Value.ToString(), out c_absentNum); 33 gUserInfo.userNP.Absenteeism = c_absentNum; 34 //实际上班天数 35 int c_ondutyNum=0; 36 int.TryParse(row.Cells["OndutyDays"].Value.ToString(), out c_ondutyNum); 37 //加班次数 38 int c_overtimeNum=0; 39 int.TryParse(row.Cells["OvertimeNum"].Value.ToString(), out c_overtimeNum); 40 gUserInfo.userNP.OvertimeNum = c_overtimeNum; 41 if (c_ondutyNum == 0)//如果上班天数为0的话,看他是否加班了,就算他加班的钱 42 { 43 gUserInfo.userNP.NetPay = gUserInfo.userNP.PayOvertime - c_lateNum*10;//加班薪资-迟到薪资 44 } 45 else 46 { 47 gUserInfo.userNP.Deduct = c_lateNum*10; //扣除薪资=迟到次数*10 48 double d_percent = Convert.ToDouble(c_ondutyNum) / Convert.ToDouble(c_workDays); 49 gUserInfo.userNP.NetPay = d_percent * gUserInfo.userNP.BasicWage - gUserInfo.userNP.Deduct + gUserInfo.userNP.PayOvertime; //实发工资=实际上班天数/当月应上班天数*基本工资-扣除薪资+加班薪资 50 } 51 bool bpayOff = sqlHelper.bPayoff(userinfo); 52 if (bpayOff) 53 { 54 count += 1; 55 } 56 } 57 if (count==dataGridView1.Rows.Count)//对数据处理数量的判断 58 { 59 MessageBox.Show("录入成功"); 60 } 61 else 62 { 63 MessageBox.Show("error"); 64 return; 65 } 66 } 67 }
软件统计数据表
数据库
//主界面设计 private void Login_Load(object sender, EventArgs e) { //MessageBox.Show(System.DateTime.Now.ToString()); SqlHelper sqlHelper = new SqlHelper(); DataTable dt = sqlHelper.userIdName(); this.comboBox1.DataSource = dt;//设置查询结果集为控件的数据源 this.comboBox1.DisplayMember = dt.Columns[0].ColumnName.ToString();//显示相应列数据 this.comboBox1.ValueMember = dt.Columns[0].ColumnName.ToString();//设置值 }
//数据连接,显示数据库中的ID+用户名 public DataTable userIdName() { string sql = string.Format("SELECT CAST(UserId as varchar(50)) +' '+TrueName AS UserIdName FROM Users"); DataConn q = new DataConn(conStr); ArrayList paramlist = new ArrayList(); IDataParameter[] param = (IDataParameter[])paramlist.ToArray(typeof(IDataParameter)); return q.testDataTable(sql, param); }
1 private void button1_Click(object sender, EventArgs e) 2 { 3 //为了让用户记住自己ID,将其与姓名联系在一起,显示到combox控件中 4 string c_checkId = this.comboBox1.Text.Substring(0, 4);//取得字符串中指定的几个字符,SubString(m, n) ; m为需要截取的字符串索引位置, n为 截取长度 5 //获得数据,验证用户输入 6 // string c_checkId = textBox1.Text.Trim(); 7 string c_checkPwd = textBox2.Text.Trim(); 8 9 if (c_checkId == "" || c_checkPwd == "") 10 { 11 MessageBox.Show("请正确输入用户名或密码"); 12 return; 13 } 14 if (!ValidatorHelper.IsNumeric(c_checkId)) 15 { 16 MessageBox.Show("用户名必须是数字"); 17 return; 18 } 19 20 try 21 { 22 //获得用户ID 23 24 SqlHelper cs = new SqlHelper(); 25 bool it = cs.bIdPwd(c_checkId, c_checkPwd); 26 gUserInfo.userNP = new UserInfo(); 27 gUserInfo.userNP.UserId = Convert.ToInt32(c_checkId); 28 if (it) 29 { 30 this.DialogResult = DialogResult.OK; 31 } 32 else 33 { 34 MessageBox.Show("登录失败"); 35 } 36 } 37 catch (Exception ex) 38 { 39 MessageBox.Show(ex.Message); 40 } 41 42 43 }