コード例 #1
0
        protected void btn_Confirm_Click(object sender, EventArgs e)
        {
            try
            {
                string   OCODE     = ((SessionUser)Session["SessionUser"]).OCode;
                DateTime EDIT_DATE = DateTime.Now;
                Guid     userId    = ((SessionUser)Session["SessionUser"]).UserId;

                UserDAL               userDAl        = new UserDAL();
                Attendance_BLL        _attendancebll = new Attendance_BLL();
                List <HRM_ATTENDANCE> attendances    = new List <HRM_ATTENDANCE>();

                if (ckAttendanceAdjustment.Checked)  //individual
                {
                    if (txtbxEID.Text == "")
                    {
                        ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "func('Enter E-ID!')", true);
                        return;
                    }
                    if (txtDate.Text == "")
                    {
                        ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "func('Select Attendance Date!')", true);
                        return;
                    }

                    HRM_ATTENDANCE _attendance = new HRM_ATTENDANCE();

                    _attendance.EID             = txtbxEID.Text;
                    _attendance.Attendance_Date = Convert.ToDateTime(txtDate.Text);
                    _attendance.Remarks         = txtbxremark.Text;
                    _attendance.Edit_User       = userId;
                    _attendance.Edit_Date       = EDIT_DATE;
                    _attendance.OCode           = OCODE;
                    attendances.Add(_attendance);

                    if (attendances.Count > 0)
                    {
                        List <HRM_EMPLOYEES_VIEWER> lstEmpAttendnace = _attendancebll.GetEmployeesByEidForAttendance(txtbxEID.Text, Convert.ToDateTime(txtDate.Text), Convert.ToDateTime(txtDate.Text)); //check attendance data

                        if (lstEmpAttendnace.Count > 0)
                        {
                            Guid   UserID     = ((SessionUser)Session["SessionUser"]).UserId;
                            string PunishedBy = userDAl.getEIDbyUserGuidID(UserID);

                            int result = _attendancebll.DeleteAttendance(attendances, PunishedBy);

                            if (result == 1)
                            {
                                // insert/update leave/holiday attendnace status process by selected eid
                                aAttendance_RPT_Bll.Insert_Update_AbsentLeaveStatus_ByDate_EID(attendances, Convert.ToDateTime(txtDate.Text), Convert.ToDateTime(txtDate.Text));

                                ClearUI();
                                ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "func('Attendance Adjustment Successfull')", true);
                            }
                        }
                        else
                        {
                            ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "func('No Attendance Data Found!')", true);
                        }
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "func('No Employee selected in the list!')", true);
                    }
                }

                else  //dept/section/subsection wise process
                {
                    foreach (GridViewRow gvRow in grdview.Rows)
                    {
                        CheckBox       rowChkBox   = ((CheckBox)gvRow.FindControl("rowLevelCheckBox"));
                        HRM_ATTENDANCE _attendance = new HRM_ATTENDANCE();
                        if (rowChkBox.Checked == true)
                        {
                            Label   lblEID = ((Label)gvRow.FindControl("lblEID"));
                            TextBox txtbx  = ((TextBox)gvRow.FindControl("txtbx"));

                            _attendance.EID             = lblEID.Text;
                            _attendance.Attendance_Date = Convert.ToDateTime(txtDate.Text);
                            _attendance.Remarks         = txtbxremark.Text;
                            _attendance.Edit_User       = ((SessionUser)Session["SessionUser"]).UserId;
                            _attendance.Edit_Date       = DateTime.Now;
                            _attendance.OCode           = ((SessionUser)Session["SessionUser"]).OCode;
                            attendances.Add(_attendance);
                        }
                    }

                    if (attendances.Count > 0)
                    {
                        Guid   UserID     = ((SessionUser)Session["SessionUser"]).UserId;
                        string PunishedBy = userDAl.getEIDbyUserGuidID(UserID);

                        int result = _attendancebll.DeleteAttendance(attendances, PunishedBy);

                        if (result == 1)
                        {
                            // insert/update leave/holiday attendnace status process by selected eid
                            aAttendance_RPT_Bll.Insert_Update_AbsentLeaveStatus_ByDate_EID(attendances, Convert.ToDateTime(txtDate.Text), Convert.ToDateTime(txtDate.Text));

                            ClearUI();
                            ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "func('Attendance Adjustment Successfull')", true);
                        }
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "func('No Employee selected in the list!')", true);
                    }
                }
            }
            catch (Exception ex)
            {
                ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "func('" + ex.Message + "')", true);
            }
        }