Пример #1
0
        //加载该登录员工的加班信息
        private void FrmOvertime_Load(object sender, EventArgs e)
        {
            OvertimeBll ob = new OvertimeBll();

            var datas = ob.QueryByEmpIdUsingDateSet(this.Tag.ToString());

            dataGridView1.DataSource = datas.Tables[0];
        }
Пример #2
0
 //点击datagridview里的单元格发生
 private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     //点击删除按钮
     if (e.ColumnIndex == 0 && e.RowIndex > -1) //如果是点击的是内容而不是列名之类的
     {
         int         row    = e.RowIndex;       //点击单元格的行索引
         string      id     = dataGridView1.Rows[row].Cells["编号"].Value.ToString();
         OvertimeBll ob     = new OvertimeBll();
         var         result = MessageBox.Show("删除后不可恢复,确定?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
         if (result == DialogResult.OK)
         {
             ob.DeleteById(id);
             dataGridView1.DataSource = ob.QueryByEmpIdUsingDateSet(this.Tag.ToString()).Tables[0];
             return;
         }
         else
         {
             return;
         }
     }
     ////////////////////////////////////////////////////////////
     //点击更新按钮
     else if (e.ColumnIndex == 1 && e.RowIndex > -1)
     {
         int    row     = e.RowIndex;
         string id      = dataGridView1.Rows[row].Cells["编号"].Value.ToString();   //该员工的员工号
         string tag     = this.Tag.ToString();
         string proName = dataGridView1.Rows[row].Cells["项目名"].Value.ToString();  //该员工需加班的项目名
         string date    = dataGridView1.Rows[row].Cells["开始时间"].Value.ToString(); //加班开始时间
         FrmOvertimeAddOrUpdate frmot = new FrmOvertimeAddOrUpdate(tag + " " + id + " " + proName + " " + date);
         frmot.ShowDialog();
         var res = frmot.DialogResult;
         if (res == DialogResult.OK)
         {
             OvertimeBll ob = new OvertimeBll();
             dataGridView1.DataSource = ob.QueryByEmpIdUsingDateSet(this.Tag.ToString()).Tables[0];
             return;
         }
     }
     else if (e.RowIndex > -1)
     {
         //设置点击任意单元格其一行内所有单元格高亮
         int hang = e.RowIndex;
         //dataGridView1.Rows[hang].Cells[0].Selected = true;
         //dataGridView1.Rows[hang].Cells[1].Selected = true;
         dataGridView1.Rows[hang].Cells[2].Selected = true;
         dataGridView1.Rows[hang].Cells[3].Selected = true;
         dataGridView1.Rows[hang].Cells[4].Selected = true;
         dataGridView1.Rows[hang].Cells[5].Selected = true;
         dataGridView1.Rows[hang].Cells[6].Selected = true;
         dataGridView1.Rows[hang].Cells[7].Selected = true;
         dataGridView1.Rows[hang].Cells[8].Selected = true;
         dataGridView1.Rows[hang].Cells[9].Selected = true;
         return;
     }
 }
Пример #3
0
 //查询按钮
 private void btnQuery_Click(object sender, EventArgs e)
 {
     if (!(datePickerStart.Value.CompareTo(datePickerEnd.Value) > 0))//如果时间选择合理
     {
         OvertimeBll ob        = new OvertimeBll();
         string      dateEnd   = datePickerEnd.Value.ToString("yyyy-MM-dd 24:00:00");
         string      dateStart = datePickerStart.Value.ToString("yyyy-MM-dd 00:00:00");
         var         datas     = ob.QueryDByIdAndDate(this.Tag.ToString(), dateStart, dateEnd);
         // = ob.QueryDByIdAndDate(date, this.Tag.ToString());
         dataGridView1.DataSource = datas.Tables[0];
     }
 }
Пример #4
0
        //点击添加按钮
        private void btnAdd_Click(object sender, EventArgs e)
        {
            FrmOvertimeAddOrUpdate overtime = new FrmOvertimeAddOrUpdate(this.Tag.ToString(), "添加");

            overtime.ShowDialog();                                             //点击添加按钮,弹出添加页面
            if (overtime.DialogResult == System.Windows.Forms.DialogResult.OK) //如果添加成功,刷新页面
            {
                OvertimeBll ob    = new OvertimeBll();
                var         datas = ob.QueryByEmpIdUsingDateSet(this.Tag.ToString()).Tables[0];
                if (datas != null)
                {
                    dataGridView1.DataSource = datas;
                }
            }
        }
Пример #5
0
        //点击确定按扭
        private void btnSure_Click(object sender, EventArgs e)
        {
            if (listBoxShow.Items.Count == 0 && myTxtProName.GetText() == string.Empty)//如果员工没有项目
            {
                MessageBox.Show("您没有项目");
                return;
            }
            if (listBoxShow.Visible == true)//如果可见,表示未点击选择
            {
                MessageBox.Show("请选择项目!");
                return;
            }

            var timeFrom  = TimePickerFrom.Value.ToShortTimeString(); //开始时间  时分表示
            var timeTo    = TimePickerTo.Value.ToShortTimeString();   //结束时间  时分表示
            int hourFrom  = Convert.ToInt16(timeFrom.Split(':')[0]);  //开始时间:小时
            int minteFrom = Convert.ToInt16(timeFrom.Split(':')[1]);  //开始时间 : 分钟
            int hourTo    = Convert.ToInt16(timeTo.Split(':')[0]);    //结束时间  小时
            int minteTo   = Convert.ToInt16(timeTo.Split(':')[1]);    //结束时间 分钟

            bool b = (hourTo * 60 + minteTo) > (hourFrom * 60 + minteFrom);

            if (!b && !cBoxNextDay.Checked)//开始时间不能晚于结束时间
            {
                MessageBox.Show("您输入的时间不合法");
                return;
            }
            if (myTxtReason.GetText() == string.Empty)
            {
                MessageBox.Show("请填写原因");
                return;
            }

            #region  用来计算 时长
            float duration;
            if (cBoxNextDay.Checked)//如果选择了,结束时间要加上24小时
            {
                int to   = (hourTo * 60 + minteTo + 1440);
                int from = (hourFrom * 60 + minteFrom);
                duration = (float)Math.Round(((to - from) / 60.0), 1);
            }//没有不用加
            else
            {
                int to   = (hourTo * 60 + minteTo);
                int from = (hourFrom * 60 + minteFrom);
                duration = (float)Math.Round(((to - from) / 60.0), 1);
            }
            #endregion

            #region 获取要添加或更新的类的内容
            Overtime ot     = new Overtime();
            var      proBll = new ProjectBll();
            ot.EmployeeId = myTxtEmpId.GetText();
            ot.ProjectId  = proBll.QueryByName(myTxtProName.GetText())[0].Id;//虽然项目名不可能相同,但是QueryByName()返回值我还是写成了集合,集合里只有一个元素,取索引0即可


            ot.DateTimeStart = DateTime.Parse(string.Format("{0} {1}", dateTime.Value.ToShortDateString(), timeFrom));
            if (cBoxNextDay.Checked)
            {
                ot.DateTimeEnd = DateTime.Parse(string.Format("{0} {1}", dateTime.Value.AddDays(1).ToShortDateString(), timeTo));
            }
            else
            {
                ot.DateTimeEnd = DateTime.Parse(string.Format("{0} {1}", dateTime.Value.ToShortDateString(), timeTo));
            }
            ot.Duration = duration;
            ot.Reason   = myTxtReason.GetText();
            ot.Status   = "已批";
            #endregion

            bool a = false;

            if (this.Text == "添加信息")//添加执行的代码
            {
                OvertimeBll oBll = new OvertimeBll();
                a = oBll.Add(ot);
            }
            else //更新执行的代码
            {
                OvertimeBll ob = new OvertimeBll();
                ot.Id = thisId;
                a     = ob.Update(ot);
            }

            if (a)
            {
                MessageBox.Show("成功");
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
            }
            else
            {
                MessageBox.Show("您这段时间已有加班记录");
                return;
            }
        }