Example #1
0
        public ActionResult Create(tbl_User myUser)
        {
            ViewData["Roles"] = new SelectList(roledb.GetUserRoles(), "User_Role", "User_Role_Descr");

            if (myUser.User_CAI.Trim().Length == 0)
                ModelState.AddModelError("User_CAI", "CAI is Required");

            if (myUser.User_FirstName.Trim().Length == 0)
                ModelState.AddModelError("User_FirstName", "First Name Required");

            if (myUser.User_LastName.Trim().Length == 0)
                ModelState.AddModelError("User_LastName", "Last Name Required");

            if (!ModelState.IsValid)
            {
                return View();
            }

            try
            {
                myUser.User_CAI = myUser.User_CAI.ToUpper().Trim();
                db.AddUser(myUser);
                db.Save();
                return RedirectToAction("Details", new { User_CAI = myUser.User_CAI, Error = "" });

            }
            catch(Exception ex)
            {
                ModelState.AddModelError("","Error: " + ex.Message);
                return View();
            }
        }
Example #2
0
		private void detach_tbl_Users(tbl_User entity)
		{
			this.SendPropertyChanging();
			entity.tbl_User_Role = null;
		}
Example #3
0
		private void attach_tbl_Users(tbl_User entity)
		{
			this.SendPropertyChanging();
			entity.tbl_User_Role = this;
		}
Example #4
0
 partial void Deletetbl_User(tbl_User instance);
Example #5
0
 partial void Updatetbl_User(tbl_User instance);
Example #6
0
 partial void Inserttbl_User(tbl_User instance);
Example #7
0
 public void DeleteUser(tbl_User myUser)
 {
     db.tbl_Users.DeleteOnSubmit(myUser);
 }
Example #8
0
 partial void Updatetbl_User(tbl_User instance);
Example #9
0
        private TimeSheetPackage GetTimeSheet(string User_CAI, DateTime firstDayOfThisMonth, DateTime lastDayOfThisMonth)
        {
            tbl_User myUser = userdb.GetUserByID(User_CAI);

            if (myUser.EmployeeNumber == "")
            {
                myUser.EmployeeNumber = "temp";
            }

            TimeSheetPackage myPackage = new TimeSheetPackage();

            myPackage.GrandTotal    = 0;
            myPackage.DayTotals     = new List <day>();
            myPackage.DaySacoTotals = sacodb.SacoDays(myUser.EmployeeNumber, firstDayOfThisMonth, lastDayOfThisMonth);
            myPackage.TimeSheets    = new List <timesheet>();
            for (DateTime d = firstDayOfThisMonth; d < lastDayOfThisMonth; d = d.AddDays(1))
            {
                myPackage.DayTotals.Add(new day()
                {
                    Month = d.Month, Year = d.Year, Day = d.Day, HoursWorked = 0M
                });
            }


            IQueryable <tbl_Resource> myResources = rdb.FindResourcesByCAI(User_CAI).OrderBy(t => t.tbl_Project.Project_Number);

            if (myResources.Count() > 0)
            {
                foreach (var res in myResources)
                {
                    if (ProjectExists((int)res.Project_ID))
                    {
                        timesheet resourceTimeSheet = new timesheet();

                        resourceTimeSheet.editStatus = true;

                        if (res.tbl_Project.tbl_Status.Status == "CLSD" ||
                            res.tbl_Project.tbl_Status.Status == "W" ||
                            res.tbl_Project.tbl_Status.Status == "TC"
                            )
                        {
                            resourceTimeSheet.editStatus = false;
                        }
                        if (res.active == false)
                        {
                            resourceTimeSheet.editStatus = false;
                        }

                        resourceTimeSheet.Resource_ID       = res.Resource_ID;
                        resourceTimeSheet.Project_ID        = (int)res.Project_ID;
                        resourceTimeSheet.Project_Number    = (int)res.tbl_Project.Project_Number;
                        resourceTimeSheet.Project_Name      = res.tbl_Project.Project_Name;
                        resourceTimeSheet.Project_Name_Abrv = res.tbl_Project.Project_Name;
                        resourceTimeSheet.SAP          = res.tbl_Project.SAP_Number;
                        resourceTimeSheet.WBS          = res.tbl_Project.WBS;
                        resourceTimeSheet.Status       = res.tbl_Project.tbl_Status.Status;
                        resourceTimeSheet.hide         = res.Hide;
                        resourceTimeSheet.ProjectHours = (!res.ResourceHours.HasValue) ? 0M: res.ResourceHours.Value;
                        decimal?test = this.GetHoursByResourceAndDate(res.Resource_ID, DateTime.Parse("01-Jan-2007"), lastDayOfThisMonth).Sum(s => s.Hours);
                        resourceTimeSheet.Total = (!test.HasValue) ? 0M : test.Value;


                        IQueryable <tbl_TimeSheet> timeList = this.GetHoursByResourceAndDate(
                            res.Resource_ID,
                            DateTime.Parse(String.Format("{0: yyyy/MM/dd 00:00:00}", firstDayOfThisMonth)),
                            DateTime.Parse(String.Format("{0: yyyy/MM/dd 23:59:59}", lastDayOfThisMonth))).OrderBy(t => t.Date);
                        decimal Monthtotal = 0M;

                        resourceTimeSheet.Days = new List <day>();
                        //Initialize Days to null values
                        int count = 1;
                        for (DateTime d = firstDayOfThisMonth; d < lastDayOfThisMonth; d.AddDays(1))
                        {
                            resourceTimeSheet.Days.Add(new day()
                            {
                                Day = count, HoursWorked = null
                            });
                            d = d.AddDays(1);
                            count++;
                        }

                        if (timeList.Count() > 0)
                        {
                            foreach (var t in timeList)
                            {
                                foreach (var d in resourceTimeSheet.Days)
                                {
                                    if (((DateTime)t.Date).Day == d.Day)
                                    {
                                        d.HoursWorked = (decimal)t.Hours;

                                        Monthtotal += (decimal)t.Hours;
                                    }
                                }
                            }
                        }


                        resourceTimeSheet.MonthTotal = Monthtotal;
                        if (resourceTimeSheet.SAP != "Leave")
                        {
                            myPackage.GrandTotal += Monthtotal;
                        }
                        for (int j = 0; j < resourceTimeSheet.Days.Count; j++)
                        {
                            if (resourceTimeSheet.Days[j].HoursWorked.HasValue)
                            {
                                if (resourceTimeSheet.SAP != "Leave")
                                {
                                    myPackage.DayTotals[j].HoursWorked += resourceTimeSheet.Days[j].HoursWorked.Value;
                                }
                            }
                        }
                        if (resourceTimeSheet.MonthTotal > 0 || resourceTimeSheet.hide == false)
                        {
                            myPackage.TimeSheets.Add(resourceTimeSheet);
                        }
                    }
                }
            }
            return(myPackage);
        }
Example #10
0
        public ReportPackage GetReportByUser(string User_CAI, DateTime myDateFrom, DateTime myDateTo)
        {
            //The Report Package is a container for all data that must be displayed on the Report View
            //The Report Package is used as the Model for the report index View
            //The Report Package contains the following:
            //  1. user information in the form of a user object
            //  2. collection of timesheets for active(unhidden) projects for the date period.
            //    The timesheet object contains project information and a collection of days.
            ReportPackage myPackage = new ReportPackage();


            tbl_User myuser = userdb.GetUserByID(User_CAI);

            myPackage.User          = myuser;
            myPackage.DateFrom      = myDateFrom;
            myPackage.DateTo        = myDateTo;
            myPackage.User_CAI      = User_CAI;
            myPackage.GrandTotal    = 0;
            myPackage.DayTotals     = new List <day>();
            myPackage.DaySacoTotals = sacodb.SacoDays(myuser.EmployeeNumber, myDateFrom, myDateTo);

            myPackage.TimeSheets = new List <timesheet>();
            int i = 1;

            for (DateTime d = myDateFrom; d < myDateTo.AddDays(1); d = d.AddDays(1))
            {
                myPackage.DayTotals.Add(new day()
                {
                    Number = i, Day = i, HoursWorked = 0M
                });
                i++;
            }
            IQueryable <tbl_Resource> myResources = rdb.FindResourcesByCAI(User_CAI).OrderBy(t => t.tbl_Project.Project_Number);

            if (myResources.Count() > 0)
            {
                foreach (var res in myResources)
                {
                    if (ProjectExists((int)res.Project_ID))
                    {
                        timesheet resourceTimeSheet = new timesheet();

                        resourceTimeSheet.editStatus = true;

                        if (res.tbl_Project.tbl_Status.Status == "CLSD")
                        {
                            resourceTimeSheet.editStatus = false;
                        }
                        if (res.active == false)
                        {
                            resourceTimeSheet.editStatus = false;
                        }

                        resourceTimeSheet.Resource_ID       = res.Resource_ID;
                        resourceTimeSheet.Project_ID        = (int)res.Project_ID;
                        resourceTimeSheet.Project_Number    = (int)res.tbl_Project.Project_Number;
                        resourceTimeSheet.Project_Name      = res.tbl_Project.Project_Name;
                        resourceTimeSheet.Project_Name_Abrv = res.tbl_Project.Project_Name;
                        resourceTimeSheet.SAP          = res.tbl_Project.SAP_Number;
                        resourceTimeSheet.WBS          = res.tbl_Project.WBS;
                        resourceTimeSheet.Status       = res.tbl_Project.tbl_Status.Status;
                        resourceTimeSheet.hide         = res.Hide;
                        resourceTimeSheet.ProjectHours = (!res.ResourceHours.HasValue) ? 0M : res.ResourceHours.Value;
                        decimal?test = this.GetHoursByResourceAndDate(res.Resource_ID, DateTime.Parse("01-Jan-2007"), DateTime.Now).Sum(s => s.Hours);
                        resourceTimeSheet.Total = (!test.HasValue) ? 0M : test.Value;


                        IQueryable <tbl_TimeSheet> timeList = this.GetHoursByResourceAndDate(
                            res.Resource_ID,
                            DateTime.Parse(String.Format("{0: yyyy/MM/dd 00:00:00}", myDateFrom)),
                            DateTime.Parse(String.Format("{0: yyyy/MM/dd 23:59:59}", myDateTo))).OrderBy(t => t.Date);
                        decimal Monthtotal = 0M;

                        resourceTimeSheet.Days = new List <day>();
                        //Initialize Days to null values

                        for (DateTime d = myDateFrom; d < myDateTo.AddDays(1); d = d.AddDays(1))
                        {
                            resourceTimeSheet.Days.Add(new day()
                            {
                                Day = d.Day, Month = d.Month, Year = d.Year, HoursWorked = null
                            });
                        }

                        if (timeList.Count() > 0)
                        {
                            foreach (var t in timeList)
                            {
                                foreach (var d in resourceTimeSheet.Days)
                                {
                                    if (((DateTime)t.Date).Day == d.Day && ((DateTime)t.Date).Month == d.Month && ((DateTime)t.Date).Year == d.Year)
                                    {
                                        d.HoursWorked = (decimal)t.Hours;
                                        Monthtotal   += (decimal)t.Hours;
                                    }
                                }
                            }
                        }


                        resourceTimeSheet.MonthTotal = Monthtotal;
                        if (resourceTimeSheet.SAP != "Leave")
                        {
                            myPackage.GrandTotal += Monthtotal;
                        }
                        for (int j = 0; j < resourceTimeSheet.Days.Count; j++)
                        {
                            if (resourceTimeSheet.Days[j].HoursWorked.HasValue)
                            {
                                if (resourceTimeSheet.SAP != "Leave")
                                {
                                    myPackage.DayTotals[j].HoursWorked += resourceTimeSheet.Days[j].HoursWorked.Value;
                                }
                            }
                        }
                        if (Monthtotal > 0 || resourceTimeSheet.hide == false)
                        {
                            myPackage.TimeSheets.Add(resourceTimeSheet);
                        }
                    }
                }
            }

            return(myPackage);
        }
Example #11
0
 public void DeleteUser(tbl_User myUser)
 {
     db.tbl_Users.DeleteOnSubmit(myUser);
 }
Example #12
0
 public void AddUser(tbl_User myUser)
 {
     db.tbl_Users.InsertOnSubmit(myUser);
 }
Example #13
0
 private void detach_tbl_Users(tbl_User entity)
 {
     this.SendPropertyChanging();
     entity.tbl_User_Role = null;
 }
Example #14
0
 private void attach_tbl_Users(tbl_User entity)
 {
     this.SendPropertyChanging();
     entity.tbl_User_Role = this;
 }
Example #15
0
 partial void Deletetbl_User(tbl_User instance);
Example #16
0
        public ActionResult Edit(tbl_User myUser)
        {
            string str = Request.Form[0];
            if (myUser.User_CAI.Trim().Length == 0)
                ModelState.AddModelError("User_CAI", "CAI is Required");

            if (myUser.User_FirstName.Trim().Length == 0)
                ModelState.AddModelError("User_FirstName", "First Name Required");

            if (myUser.User_LastName.Trim().Length == 0)
                ModelState.AddModelError("User_LastName", "Last Name Required");

            if (myUser.User_Role.Trim().Length == 0)
                ModelState.AddModelError("User_Role", "Role Required");

            if (!ModelState.IsValid)
            {
                ViewData["Roles"] = new SelectList(roledb.GetUserRoles(), "User_Role", "User_Role_Descr", myUser.User_Role);

                return View(myUser);
            }

            try
            {
                tbl_User dbUser = db.GetUserByID(myUser.User_CAI);
                dbUser.User_CAI = myUser.User_CAI;
                dbUser.User_FirstName = myUser.User_FirstName;
                dbUser.User_LastName = myUser.User_LastName;
                dbUser.EmployeeNumber = myUser.EmployeeNumber;
                dbUser.CompanyName = myUser.CompanyName;
                dbUser.CompanyID = myUser.CompanyID;
                dbUser.User_Role = myUser.User_Role;
                dbUser.active = myUser.active;
                db.Save();
                return RedirectToAction("Details",new {User_CAI = myUser.User_CAI});

            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", "Error: " + ex.Message);
                return View();
            }
        }
Example #17
0
 public void AddUser(tbl_User myUser)
 {
     db.tbl_Users.InsertOnSubmit(myUser);
 }
Example #18
0
 partial void Inserttbl_User(tbl_User instance);