Exemplo n.º 1
0
        public ActionResult Index()
        {
            ApplicationUser currentUser = (from u in _context.Users
                                           where u.UserName == User.Identity.Name
                                           select u).FirstOrDefault();

            LeaveList list = new LeaveList();

            list.Holidays = _context.PublicHoliday.ToList();

            list.UserLeaves = (from u in _context.Users
                               where u.Manager.Id == currentUser.Id
                               select new UserLeave()
            {
                UserID = u.Id,
                Leaves = (from tbl in _context.Leave where tbl.User.Id == u.Id select tbl).ToList(),
                Name = u.FullName,
                EmploymentStartDate = u.EmploymentStartDate
            }).ToList();

            List <UserLeave> subLeaves = (from u in _context.Users
                                          where u.Manager.Manager.Id == currentUser.Id
                                          select new UserLeave()
            {
                UserID = u.Id,
                Leaves = (from tbl in _context.Leave where tbl.User.Id == u.Id select tbl).ToList(),
                Name = u.FullName,
                EmploymentStartDate = u.EmploymentStartDate
            }).ToList();

            list.UserLeaves.AddRange(subLeaves);

            list.Leaves = _context.Leave.Where(tbl => tbl.User.Id == currentUser.Id).ToList();

            list.Leaves = Deferral.AddDeferral(list.Leaves, list.Holidays);
            list.Leaves = Accrual.AddAccrual(currentUser.EmploymentStartDate, currentUser.FullName, list.Leaves);

            foreach (UserLeave userLeave in list.UserLeaves)
            {
                userLeave.Leaves = Deferral.AddDeferral(userLeave.Leaves, list.Holidays);
                userLeave.Leaves = Accrual.AddAccrual(userLeave.EmploymentStartDate, userLeave.Name, userLeave.Leaves);
            }

            list.FormModel = new LeaveFormModel()
            {
                StartDate     = DateTime.Now.Date,
                EndDate       = DateTime.Now.Date,
                UserID        = currentUser.Id,
                RequestDate   = DateTime.Now,
                LeaveStateID  = 1,
                Note          = "",
                Attachement   = "",
                Institution   = "",
                StudentNumber = ""
            };

            ViewBag.LeaveStateID = new SelectList(_context.LeaveState, "LeaveStateID", "Description", 1);

            return(View(list));
        }
Exemplo n.º 2
0
        private void FillReport(bool isInitial = false, bool throwException = true)
        {
            List <XMLDictionary> statusList = Common.XMLDictionaryList(_systemService, "13");


            string rep_params        = vals.Text;
            ReportGenericRequest req = new ReportGenericRequest();

            req.paramString = rep_params;


            ListResponse <Model.Reports.RT601> resp = _reportsService.ChildGetAll <Model.Reports.RT601>(req);

            if (!resp.Success)
            {
                Common.ReportErrorMessage(resp, GetGlobalResourceObject("Errors", "Error_1").ToString(), GetGlobalResourceObject("Errors", "ErrorLogId").ToString());
            }
            errorMSG.Text = "";
            string format = _systemService.SessionHelper.GetDateformat();

            resp.Items.ForEach(s =>
            {
                s.endDateString   = s.endDate.ToString(format, CultureInfo.CurrentCulture);
                s.startDateString = s.startDate.ToString(format, CultureInfo.CurrentCulture);
                if (s.returnDate.HasValue)
                {
                    s.returnDateString = s.returnDate.Value.ToString(format, CultureInfo.CurrentCulture);
                }

                s.isPaidString = s.isPaid ? GetLocalResourceObject("Paid1").ToString() : GetLocalResourceObject("Paid0").ToString();
                s.statusString = statusList.Where(y => y.key == s.status).Count() != 0 ? statusList.Where(y => y.key == s.status).First().value : "";
            });
            Dictionary <string, string> parameters = Web.UI.Forms.Common.FetchReportParameters(texts.Text);
            LeaveList h = new LeaveList(parameters);

            h.DataSource = resp.Items;

            h.RightToLeft       = _systemService.SessionHelper.CheckIfArabicSession() ? DevExpress.XtraReports.UI.RightToLeft.Yes : DevExpress.XtraReports.UI.RightToLeft.No;
            h.RightToLeftLayout = _systemService.SessionHelper.CheckIfArabicSession() ? DevExpress.XtraReports.UI.RightToLeftLayout.Yes : DevExpress.XtraReports.UI.RightToLeftLayout.No;

            //string from = DateTime.Parse(req.Parameters["_fromDate"]).ToString(_systemService.SessionHelper.GetDateformat());
            //string to = DateTime.Parse(req.Parameters["_toDate"]).ToString(_systemService.SessionHelper.GetDateformat());
            string user = _systemService.SessionHelper.GetCurrentUser();


            h.Parameters["User"].Value = user;
            //  h.Parameters["Fitlers"].Value = texts.Text;
            h.CreateDocument();


            ASPxWebDocumentViewer1.DataBind();
            ASPxWebDocumentViewer1.OpenReport(h);
        }
 private void Button_Reset_Click(object sender, RoutedEventArgs e)
 {
     if ((baseControl as MainPage).UserRole == "USER")
     {
         MessageBox.Show("You are not allowed to reset the list!", "Access denied", MessageBoxButton.OK, MessageBoxImage.Exclamation);
         return;
     }
     if (MessageBox.Show("Are you sure you want to trancate the leave list?", "Confirm", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes)
     {
         LeaveList.Delete( );
     }
 }
        private void Button_Search_Click(object sender, RoutedEventArgs e)
        {
            if (lb_message.Visibility == System.Windows.Visibility.Visible)
            {
                MessageBox.Show(lb_message.Content.ToString());
                return;
            }
            StringBuilder rowConstraints = new StringBuilder( );

            if (icb_employeeID.Text.Length > 0)
            {
                rowConstraints.Append("Employees.EmployeeID = " + icb_employeeID.Text);
            }
            else if (icb_employees.Text.Length > 0)
            {
                rowConstraints.Append("Employees.EmployeeID IS NULL");
            }
            else
            {
                rowConstraints.Append("Employees.EmployeeID IS NOT NULL");
            }
            if (icb_subUnit.Text.Length > 0)
            {
                rowConstraints.Append(" AND Employees.Department = '" + icb_subUnit.Text + "'");
            }
            if (!checkBox.IsChecked.Value)
            {
                rowConstraints.Append(" AND Employees.PastEmployee = 'No'");
            }
            DataTable data = LeaveList.GetAllDistributedLeaveInfo(rowConstraints.ToString( ));

            if (dp_From.SelectedDate != null)
            {
                for (int i = data.Rows.Count - 1; i >= 0; i--)
                {
                    if (dp_From.SelectedDate.Value > new DateString(data.Rows[i][3]))
                    {
                        data.Rows.Remove(data.Rows[i]);
                    }
                }
            }
            if (dp_To.SelectedDate != null)
            {
                for (int i = data.Rows.Count - 1; i >= 0; i--)
                {
                    if (dp_To.SelectedDate.Value < new DateString(data.Rows[i][4]))
                    {
                        data.Rows.Remove(data.Rows[i]);
                    }
                }
            }
            FillDataGrid(dataManager.Data = data);
        }
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            MainPage mainPage       = baseControl as MainPage;
            string   rowConstraints = "";

            if (mainPage.UserRole == "USER")
            {
                rowConstraints          = "Employees.EmployeeID = " + mainPage.EmployeeID;
                icb_employees.IsEnabled = false;
                icb_subUnit.IsEnabled   = false;
            }
            icb_employees.Data = LeaveList.GetSpecificDistributedLeaveInfo("DISTINCT Employees.EmployeeName", rowConstraints);
            icb_subUnit.Data   = Employees.GetSpecificEmployeeInfo("DISTINCT Department", rowConstraints);
            if (mainPage.UserRole == "USER")
            {
                icb_employees.SelectedIndex = 0;
                icb_subUnit.SelectedIndex   = 0;
            }
        }
Exemplo n.º 6
0
        public LeaveRequest RequestLeave(LeaveType leaveType, int dayAmount)
        {
            Leave currentLeave = null;

            if (LeaveList == null)
            {
                throw new Exception("No leave allocated to employee");
            }

            currentLeave = LeaveList.SingleOrDefault(a => a.LeaveType == leaveType && a.IsActive);

            if (currentLeave == null)
            {
                throw new Exception("All leave has expired");
            }

            LeaveRequest leaveRequest = new LeaveRequest(currentLeave, dayAmount);

            return(leaveRequest);
        }
Exemplo n.º 7
0
        public ApiBaseResult GetList(string access_token)
        {
            ApiBaseResult result = Check(access_token);

            if (result == null)
            {
                result = new ApiBaseResult();

                #region 获取数据

                string UserID = access_token.Substring(0, access_token.IndexOf("_"));

                var leavelist = from vw_LeaveList in db.vw_LeaveList where ((vw_LeaveList.StudentID == UserID) && (vw_LeaveList.StateBack == "0")) select vw_LeaveList;
                if (leavelist.Any())
                {
                    List <LeaveList> data = new List <LeaveList>();
                    foreach (vw_LeaveList item in leavelist)
                    {
                        LeaveList ll = new LeaveList();
                        ll.ID         = item.ID;
                        ll.Reasoon    = item.Reason;
                        ll.SubmitTime = item.Reason;
                        ll.Type       = item.LeaveType;
                        ll.State      = "";
                        ll.TimeLeave  = (DateTime)item.TimeLeave;
                        ll.TimeBack   = (DateTime)item.TimeBack;
                        if (item.StateLeave == "0")
                        {
                            ll.State = "待审核";
                        }
                        if (item.StateLeave == "1")
                        {
                            ll.State = "待销假";
                        }
                        ll.RejectNote   = (item.Notes == null) ? "" : item.Notes;
                        ll.LeaveWay     = (item.LeaveWay == null) ? "" : item.LeaveWay;
                        ll.BackWay      = (item.BackWay == null) ? "" : item.BackWay;
                        ll.LeaveAddress = (item.Address == null) ? "" : item.Address;
                        ll.Lesson       = (item.Lesson == null) ? "" : item.Lesson;
                        ll.TeacherName  = (item.Teacher == null) ? "" : item.Teacher;

                        data.Add(ll);
                    }
                    result.result = "success";
                    result.data   = data;
                }
                else
                {
                    result.result   = "success";
                    result.messages = "无待审核或待销假请假记录!";
                }

                #endregion

                return(result);
            }
            else
            {
                return(result);
            }
        }
Exemplo n.º 8
0
        public ApiBaseResult GetList(string access_token)
        {
            ApiBaseResult result = Check(access_token);

            if (result == null)
            {
                result = new ApiBaseResult();

                #region 获取数据

                string UserID = access_token.Substring(0, access_token.IndexOf("_"));

                var leavelist = from vw_LeaveList in db.vw_LeaveList where ((vw_LeaveList.StudentID == UserID)) orderby vw_LeaveList.SubmitTime descending select vw_LeaveList;
                if (leavelist.Any())
                {
                    List <vw_LeaveList> list = new List <vw_LeaveList>();
                    if (leavelist.Count() >= 30)
                    {
                        list = (List <vw_LeaveList>)leavelist.ToList().Take(30);
                    }
                    else
                    {
                        list = leavelist.ToList();
                    }

                    List <LeaveList> data = new List <LeaveList>();
                    foreach (vw_LeaveList item in leavelist)
                    {
                        string leaveTypeName = item.LeaveType.ToString().Trim();

                        LeaveList ll = new LeaveList();
                        ll.ID         = item.ID;
                        ll.Reasoon    = item.Reason;
                        ll.SubmitTime = item.SubmitTime.ToString("yyyy-MM-dd HH:MM:ss");
                        ll.Type       = item.LeaveType;
                        ll.State      = "";
                        ll.TimeLeave  = item.TimeLeave;
                        ll.TimeBack   = (DateTime)item.TimeBack;
                        if (item.StateLeave == "0" && item.StateBack == "0")
                        {
                            ll.State = "待审核";
                        }
                        if (item.StateLeave == "1" && item.StateBack == "0")
                        {
                            ll.State = "待销假";
                        }
                        if (item.StateLeave == "1" && item.StateBack == "1")
                        {
                            ll.State = "已销假";
                        }
                        if (item.StateLeave == "2" && item.StateBack == "1")
                        {
                            ll.State = "已驳回";
                        }
                        ll.RejectNote   = (item.Notes == null) ? "" : item.Notes;
                        ll.LeaveWay     = (item.LeaveWay == null) ? "" : item.LeaveWay;
                        ll.BackWay      = (item.BackWay == null) ? "" : item.BackWay;
                        ll.LeaveAddress = (item.Address == null) ? "" : item.Address;
                        ll.Lesson       = (item.Lesson == null) ? "" : item.Lesson;
                        ll.TeacherName  = (item.Teacher == null) ? "" : item.Teacher;

                        //上课请假、短期请假、长期请假 需要打印请假条
                        if (item.StateLeave == "1" && (leaveTypeName.Substring(0, 2) == "上课" || leaveTypeName.Substring(0, 2) == "短期" || leaveTypeName.Substring(0, 2) == "长期"))
                        {
                            ll.IsPrint = "1";//需要打印
                        }
                        else
                        {
                            ll.IsPrint = "0";//不需要打印
                        }

                        data.Add(ll);
                    }
                    result.result = "success";
                    result.data   = data;
                }
                else
                {
                    result.result   = "success";
                    result.messages = "无待审核或待销假请假记录!";
                }

                #endregion

                return(result);
            }
            else
            {
                return(result);
            }
        }
Exemplo n.º 9
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (icb_leaveType.Text.Length == 0 || dp_leavingDate.SelectedDate == null || dp_joiningDate.SelectedDate == null)
            {
                MessageBox.Show("Please fill in the required details.", "Incomplete", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }
            if (lb_message.Visibility == System.Windows.Visibility.Visible)
            {
                MessageBox.Show(lb_message.Content + "!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            DateTime appliedLeavingDate = dp_leavingDate.SelectedDate.Value;
            DateTime appliedJoiningDate = dp_joiningDate.SelectedDate.Value;

            if (appliedLeavingDate < DateTime.Today)
            {
                MessageBox.Show("Leaving date cannot be a past date.", "Date Past", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            MainPage   mainPage           = baseControl as MainPage;
            string     columns            = "LeavingDate, JoiningDate";
            string     rowConstraints     = "EmployeeID = " + mainPage.EmployeeID;
            DataTable  data               = LeaveList.GetSpecificLeaveInfo(columns, rowConstraints);
            string     clashInfo          = "";
            DateString currentLeavingDate = new DateString( );
            DateString currentJoiningDate = new DateString( );

            foreach (DataRow row in data.Rows)
            {
                currentLeavingDate = row[0].ToString( );
                currentJoiningDate = row[1].ToString( );

                if (appliedLeavingDate >= currentLeavingDate && appliedLeavingDate <= currentJoiningDate ||
                    appliedJoiningDate >= currentLeavingDate && appliedJoiningDate <= currentJoiningDate ||
                    appliedLeavingDate < currentLeavingDate && appliedJoiningDate > currentJoiningDate)
                {
                    clashInfo = "You are already assigned a leaving date of " + currentLeavingDate + " and a joining date of " + currentJoiningDate;
                    break;
                }
            }
            if (clashInfo.Length > 0)
            {
                MessageBox.Show(clashInfo);
                return;
            }
            mainPage.LeaveAssignmentPage.Load( );
            mainPage.LeaveAssignmentPage.icb_employeeID.Text         = mainPage.EmployeeID;
            mainPage.LeaveAssignmentPage.icb_leaveTypes.Text         = icb_leaveType.Text;
            mainPage.LeaveAssignmentPage.dp_leavingDate.SelectedDate = dp_leavingDate.SelectedDate;
            mainPage.LeaveAssignmentPage.dp_joiningDate.SelectedDate = dp_joiningDate.SelectedDate;
            object balance = mainPage.LeaveAssignmentPage.lb_balance.Content;

            if (balance.ToString( ).Length == 0 || balance.ToString( ) == "!!" || double.Parse(balance.ToString( )) < 0)
            {
                if (MessageBox.Show("Application might not be granted due to balance issues.\nDo you still wish to continue?", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
                {
                    return;
                }
            }
            LeaveApplications.SendApplication(mainPage.EmployeeID, icb_leaveType.Text.Replace("'", "''"), dp_leavingDate.SelectedDate.Value, dp_joiningDate.SelectedDate.Value, tb_description.Text.Replace("'", "''"));
            MessageBox.Show("Application sent!", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
        }
Exemplo n.º 10
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            MainPage     mainPage = baseControl as MainPage;
            Stack <Page> jobStack = mainPage.JobStack;

            if (icb_employeeID.Text.Length == 0 || icb_leaveTypes.Text.Length == 0 || dp_leavingDate.SelectedDate == null || dp_joiningDate.SelectedDate == null)
            {
                MessageBox.Show("Please fill in the required fields.", "Incomplete", MessageBoxButton.OK, MessageBoxImage.Asterisk);
                return;
            }
            if (lb_message.Visibility == System.Windows.Visibility.Visible)
            {
                MessageBox.Show(lb_message.Content.ToString( ) + "!", "Invalid Interval", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            if (dp_leavingDate.SelectedDate.Value < DateTime.Today)
            {
                MessageBox.Show("Leaving date cannot be a past date.", "Date Past", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            DataTable data               = LeavePeriods.GetLeavePeriods( );
            string    startingDate       = "";
            string    endingDate         = "";
            bool      leavingDateIsValid = false;
            bool      joiningDateIsValid = false;

            foreach (DataRow row in data.Rows)
            {
                if (dp_leavingDate.SelectedDate.Value >= new DateString(row[0]))
                {
                    startingDate       = row[0].ToString( );
                    leavingDateIsValid = true;
                    break;
                }
            }
            foreach (DataRow row in data.Rows)
            {
                if (dp_joiningDate.SelectedDate.Value.AddDays(-1) <= new DateString(row[1]))
                {
                    endingDate         = row[1].ToString( );
                    joiningDateIsValid = true;
                    break;
                }
            }
            if (!leavingDateIsValid || !joiningDateIsValid)
            {
                MessageBox.Show("The leave period is not valid. Please enter a valid one or reconfigure.", "Invalid Leave Period", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }
            if (lb_balance.Content.ToString( ) == "!!")
            {
                MessageBox.Show("The interval you entered exceeds the bounds!", "Too Big Interval", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            if (lb_balance.Content.ToString( ).Length == 0)
            {
                if (MessageBox.Show("No balance available. Do you wish to entitle?", "No Balance", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes)
                {
                    EntitlementsAdder entitlementsAdder = mainPage.EntitlementsAdder;
                    jobStack.Push(this);
                    mainPage.Container.Navigate(entitlementsAdder);
                    entitlementsAdder.icb_employees.Text  = icb_employees.Text;
                    entitlementsAdder.icb_employeeID.Text = icb_employeeID.Text;
                    entitlementsAdder.icb_leaveTypes.Text = icb_leaveTypes.Text;
                    entitlementsAdder.icb_validFrom.Text  = startingDate;
                    entitlementsAdder.icb_validTo.Text    = endingDate;
                }
                else
                {
                    MessageBox.Show("Leave Not Assigned!", "Failure", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                return;
            }
            if (double.Parse(lb_balance.Content.ToString( )) < 0)
            {
                MessageBoxResult result = MessageBox.Show("Balance is insufficient! Do you wish to update entitlement?", "Insufficient Balance", MessageBoxButton.YesNoCancel, MessageBoxImage.Exclamation);
                if (result != MessageBoxResult.No)
                {
                    if (result == MessageBoxResult.Yes)
                    {
                        EntitlementsViewer entitlementsViewer = mainPage.EntitlementsViewer;
                        mainPage.JobStack.Push(this);
                        mainPage.Container.Navigate(entitlementsViewer);
                        entitlementsViewer.icb_employeeID.Text = icb_employeeID.Text;
                        entitlementsViewer.icb_employees.Text  = icb_employees.Text;
                        entitlementsViewer.icb_leaveTypes.Text = icb_leaveTypes.Text;
                        entitlementsViewer.icb_validFrom.Text  = startingDate;
                        entitlementsViewer.icb_validTo.Text    = endingDate;
                    }
                    return;
                }
            }
            string        values          = icb_employeeID.Text + ", '" + icb_leaveTypes.Text + "', '" + new DateString(dp_leavingDate.SelectedDate.Value) + "', '" + new DateString(dp_joiningDate.SelectedDate.Value) + "', " + lostBalance + ", '" + tb_commentBox.Text.Replace("'", "''") + "'";
            string        changes         = "Balance = " + lb_balance.Content;
            StringBuilder rowConstraints  = new StringBuilder("EmployeeID = " + icb_employeeID.Text + " AND LeaveType = '" + icb_leaveTypes.Text + "'");
            StringBuilder dateConstraints = new StringBuilder( );

            try     {
                Entitlements.UpdateEntitlementInfo(changes, rowConstraints.ToString( ));
                LeaveList.AssignLeave(values);
                data = LeaveApplications.FetchDetails("LeavingDate, JoiningDate", rowConstraints.ToString( ));
                foreach (DataRow row in data.Rows)
                {
                    if (new DateString(row[0].ToString( )) >= dp_leavingDate.SelectedDate && new DateString(row[1].ToString( )) <= dp_joiningDate.SelectedDate)
                    {
                        dateConstraints.Append("LeavingDate = '" + row[0] + "' AND JoiningDate = '" + row[1] + "' OR ");
                    }
                }
                dateConstraints.Append("1 = 2");
                rowConstraints.Append(" AND (" + dateConstraints.ToString( ) + ")");
                LeaveApplications.RejectApplications(rowConstraints.ToString( ));
                MessageBox.Show("Leave Assigned Successfully!", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
            }       catch (System.Data.SqlClient.SqlException exception)     {
                MessageBox.Show(exception.Message);
            }
            if (jobStack.Count > 0)
            {
                mainPage.Container.Navigate(jobStack.Pop( ));
            }
        }