예제 #1
0
      public void selectAllIsId(int id)
      {
          string sql1 = "select * from wage_info where id=@id ";

          Dictionary <string, Object> dic = new Dictionary <string, Object>();

          dic.Add("@id", wa.getId());
          ArrayList al = new ArrayList();

          al = sqlHelper.SelectInfo(sql1, dic);
          if (al != null && al.Count > 0)  //判断是有该数据
          {
              foreach (Object[] obj in al)
              {         //得到几行数据就能产生多少个对象
                  wa.setId((int)obj[0]);
                  wa.setStaff_id((int)obj[1]);
                  wa.setBasis((int)obj[2]);
                  wa.setAttendance((int)obj[3]);
                  wa.setPeformance((int)obj[4]);
                  wa.setOther((int)obj[5]);

                  wa.setReason((string)obj[6]);
                  wa.setTotal((int)obj[7]);
                  wa.setTime((DateTime)obj[8]);
              }
              comboBox1.Text = Convert.ToString(wa.getId());
              textBox2.Text  = Convert.ToString(wa.getAttendance());
              textBox3.Text  = Convert.ToString(wa.getPeformance());
              textBox4.Text  = Convert.ToString(wa.getOther());
              textBox6.Text  = Convert.ToString(wa.getReason());
              label10.Text   = Convert.ToString(wa.getTotal());
              label9.Text    = wa.getTime();
              foreach (ComboxItem c in comboBox2.Items)
              {
                  if (c.Values == st.getDepartment_id())
                  {
                      comboBox2.Text = c.Text;
                      break;
                  }
              }
              if (sql2 == null)
              {
                  sql2 = "select id from  wage_info  ";
                  al   = sqlHelper.SelectInfo(sql2, dic);
                  if (al != null && al.Count > 0)
                  {
                      foreach (Object[] obj in al)
                      {         //得到几行数据就能产生多少个对象
                          comboBox1.Items.Add((int)obj[0]);
                      }
                  }
                  else
                  {
                      MessageBox.Show("没有数据,请添加!", "提示");
                  }
              }
          }
          else
          {
              MessageBox.Show("该员工可能已被删除!", "提示");

              gl.myclos();
              sql2 = null;
              comboBox1.Items.Clear();
              comboBox2.Items.Clear();
          }
      }
예제 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            Staff  sta       = new Staff();
            MyDB   sqlHelper = new MyDB();
            string sql1      = "select * from staff_info where name=@name ";
            string sql2      = "select * from staff_info where name=@name and  password=@password ";
            string sql3      = "select * from wage_info where staff_id=@staff_id";
            Dictionary <string, Object> dic = new Dictionary <string, Object>();

            dic.Add("@name", texta.Text);
            dic.Add("@password", textb.Text);
            ArrayList al = new ArrayList();

            al = sqlHelper.SelectInfo(sql1, dic);
            if (al != null && al.Count > 0)//判断是否有用户名
            {
                al = sqlHelper.SelectInfo(sql2, dic);
                if (al != null && al.Count > 0)
                {
                    foreach (Object[] obj in al)
                    {   //得到几行数据就能产生多少个对象
                        sta.setId((int)obj[0]);
                        //强转成你需要的数据,强转很容易发生异常,所以数据库的约束性要强,对象类时要认真检查数据类型,多用try...catch
                        sta.setName((string)obj[1]);
                        sta.setPassword((string)obj[3]);

                        sta.setDepartment_id((int)obj[2]);
                        sta.setSex((string)obj[4]);
                        sta.setAge((int)obj[5]);
                        sta.setTime((DateTime)obj[6]);
                        sta.setPost((string)obj[7]);
                    }
                    dic.Add("@staff_id", sta.getId());
                    al = sqlHelper.SelectInfo(sql3, dic);
                    if (al != null && al.Count > 0)
                    {
                        Wage wage = new Wage();
                        foreach (Object[] obj in al)
                        {       //得到几行数据就能产生多少个对象
                            wage.setId((int)obj[0]);
                            wage.setStaff_id((int)obj[1]);
                            wage.setBasis((int)obj[2]);
                            wage.setAttendance((int)obj[3]);
                            wage.setPeformance((int)obj[4]);
                            wage.setOther((int)obj[5]);
                            wage.setReason((string)obj[6]);
                            wage.setTotal((int)obj[7]);
                            wage.setTime((DateTime)obj[8]);
                        }
                        MessageBox.Show("用户" + sta.getName() + "您好,\n您最新的工资为:" + wage.getTotal() + "\n详细信息:\n\t基础工资:" + wage.getBasis() + "\n\t考勤工资:" + wage.getAttendance() + "\n\t效绩工资:" + wage.getPeformance() + "\n\t其他工资:" + wage.getOther() + "\n\t原因:" + wage.getReason() + "\n更新时间" + wage.getTime(), "工资条");
                    }
                    else
                    {
                        MessageBox.Show(sta.getName() + "您好,您还没有工资哦!\n请继续努力吧!");
                    }
                }
                else
                {
                    label2.Text = "密码错误";
                }
            }
            else
            {
                label2.Text = "请检查用户名";
            }
        }