コード例 #1
0
        public int SubmitRequest(Request request)
        {
            int requestId = request.RequestId;

            using (SGSDBEntities db = new SGSDBEntities())
            {
                Request item = db.Requests.SingleOrDefault(x => x.RequestId == requestId);

                if (item == null)
                {
                    item = new Request();
                }

                item.RequestTypeId = request.RequestTypeId;
                item.Status        = request.Status;
                item.Reimb_Desc    = request.Reimb_Desc;
                item.Reimb_Amt     = request.Reimb_Amt;
                item.RequestedBy   = request.RequestedBy;

                if (request.Status == RequestStatusEnum.ForApproval.ToString())
                {
                    item.RequestedDate = DateHelper.DateTimeNow;
                }

                if (item.RequestId == 0)
                {
                    item.RequestNo   = "TMP";
                    item.CreatedDate = DateHelper.DateTimeNow;
                    item.CreatedBy   = request.CreatedBy;
                    item.RecState    = "A";
                    db.Requests.Add(item);
                }
                else
                {
                    item.ModifiedBy   = request.ModifiedBy;
                    item.ModifiedDate = DateHelper.DateTimeNow;
                }

                db.SaveChanges();
                requestId      = item.RequestId;
                item.RequestNo = String.Format("R-{0:D7}", requestId);
                db.SaveChanges();

                request = item;
            }

            if (request.Status == RequestStatusEnum.ForApproval.ToString())
            {
                ApprovalManager.Instance.AddRequestApprovals(request);
            }

            return(requestId);
        }
コード例 #2
0
        public void AddRequestApprovals(Request request)
        {
            RequestType requestType = RequestManager.Instance.GetRequestType(request.RequestTypeId);

            string[] approvers = requestType.Approvers.Split('|');

            using (SGSDBEntities db = new SGSDBEntities())
            {
                foreach (string approver in approvers)
                {
                    Approval item = new Approval();
                    item.ApprovalType   = "Request";
                    item.RequestId      = request.RequestId;
                    item.ApprovalStatus = RequestStatusEnum.ForApproval.ToString();
                    item.ApproverId     = Convert.ToInt32(approver);
                    item.RequestedDate  = request.RequestedDate;
                    item.RequestedBy    = request.RequestedBy.Value;
                    item.CreatedDate    = DateHelper.DateTimeNow;
                    item.CreatedBy      = "system";
                    db.Approvals.Add(item);
                }

                db.SaveChanges();
            }
        }
コード例 #3
0
        public void Save(string fileName, string UploadedBy)
        {
            string con =
                @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileName + ";" +
                @"Extended Properties='Excel 8.0;HDR=Yes;'";

            using (OleDbConnection connection = new OleDbConnection(con))
            {
                connection.Open();
                OleDbCommand command = new OleDbCommand("select * from [DTS$]", connection);
                using (OleDbDataReader dr = command.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        using (SGSDBEntities db = new SGSDBEntities())
                        {
                            string   empId    = GetValueString(dr["ID"]);
                            DateTime?workDate = GetValueDate(dr["Date"]);

                            if (workDate != null && empId != "")
                            {
                                TimeSheet item = db.TimeSheets.SingleOrDefault(x => x.EmpId == empId && x.WorkDate == workDate);

                                if (item == null)
                                {
                                    item = new TimeSheet();
                                }

                                item.EmpId                    = empId;
                                item.Name                     = GetValueString(dr["Name"]);
                                item.Position                 = GetValueString(dr["Position"]);
                                item.Client                   = GetValueString(dr["Client"]);
                                item.BasicRate                = GetValueNum(dr["BasicRate"]);
                                item.WorkDate                 = workDate;
                                item.TimeIn                   = GetValueTime(dr["TimeIn"]);
                                item.TimeOut                  = GetValueTime(dr["TimeOut"]);
                                item.RegularHours             = GetValueNum(dr["RegularHours"]);
                                item.Late                     = GetValueNum(dr["Late"]);
                                item.LegalHolidayNotWorked    = GetValueNum(dr["LegalHolidayNotWorked"]);
                                item.LegalHolidayOT           = GetValueNum(dr["LegalHolidayOT"]);
                                item.ExcessOfLegalHolidayOT   = GetValueNum(dr["ExcessOfLegalHolidayOT"]);
                                item.SpecialHolidayNotWorked  = GetValueNum(dr["SpecialHolidayNotWorked"]);
                                item.SpecialHolidayOT         = GetValueNum(dr["SpecialHolidayOT"]);
                                item.ExcessOfSpecialHolidayOT = GetValueNum(dr["ExcessOfSpecialHolidayOT"]);
                                item.AuthorizedOT             = GetValueNum(dr["AuthorizedOT"]);
                                item.RestDayOT                = GetValueNum(dr["RestDayOT"]);
                                item.ExcessOfRestDayOT        = GetValueNum(dr["ExcessOfRestDayOT"]);
                                item.NightDiff                = GetValueNum(dr["NightDiff"]);
                                item.SSSLoan                  = GetValueNum(dr["SSSLoan"]);
                                item.PagibigLoan              = GetValueNum(dr["PagibigLoan"]);
                                item.Allowance                = GetValueNum(dr["Allowance"]);
                                item.Adjustment               = GetValueNum(dr["Adjustment"]);

                                if (item.LegalHolidayOT > 0 || item.SpecialHolidayOT > 0 || item.RestDayOT > 0)
                                {
                                    item.RegularHours = 0;
                                }

                                if (item.Id == 0)
                                {
                                    item.CreatedBy   = UploadedBy;
                                    item.CreatedDate = DateTime.UtcNow;
                                    db.TimeSheets.Add(item);
                                }
                                else
                                {
                                    item.ModifiedBy   = UploadedBy;
                                    item.ModifiedDate = DateTime.UtcNow;
                                }

                                db.SaveChanges();
                            }
                        }
                    }
                }
            }
        }
コード例 #4
0
        public int SaveUser(User user)
        {
            int memberId = user.UserId;

            using (SGSDBEntities db = new SGSDBEntities())
            {
                int  nextId = db.Users.Where(x => x.Client == user.Client).Count() + 1;
                User item   = db.Users.SingleOrDefault(x => x.UserId == user.UserId);

                if (item == null)
                {
                    item = new User();
                }

                item.FirstName         = user.FirstName;
                item.MiddleName        = user.MiddleName;
                item.LastName          = user.LastName;
                item.NickName          = user.NickName;
                item.Gender            = user.Gender;
                item.MaritalStatus     = user.MaritalStatus;
                item.DateOfBirth       = user.DateOfBirth;
                item.PlaceOfBirth      = user.PlaceOfBirth;
                item.PresentAddress    = user.PresentAddress;
                item.ProvincialAddress = user.ProvincialAddress;
                item.LandlineNo        = user.LandlineNo;
                item.MobileNo          = user.MobileNo;
                item.Email             = user.Email;
                item.Nationality       = user.Nationality;
                item.Ref_Name          = user.Ref_Name;
                item.Ref_Relationship  = user.Ref_Relationship;
                item.Ref_Address       = user.Ref_Address;
                item.Ref_ContactNo     = user.Ref_ContactNo;
                item.TaxIdNo           = user.TaxIdNo;
                item.SSSNo             = user.SSSNo;
                item.HDMFNo            = user.HDMFNo;
                item.PhilHealthNo      = user.PhilHealthNo;
                item.Status            = user.Status;
                item.EmploymentType    = user.EmploymentType;
                item.Position          = user.Position;
                item.Client            = user.Client;
                item.DateHired         = user.DateHired;

                if (user.Picture != null)
                {
                    item.Picture = user.Picture;
                }

                if (item.UserId == 0)
                {
                    item.RoleId = GetDefaultRole();

                    if (item.Client == "HO")
                    {
                        item.EmployeeId = String.Format("E-{0:D4}", nextId);
                    }
                    else
                    {
                        item.EmployeeId = String.Format("C-" + item.Client + "-{0:D3}", nextId);
                    }

                    item.Password    = user.Password;
                    item.CreatedDate = DateHelper.DateTimeNow;
                    item.CreatedBy   = user.CreatedBy;
                    item.RecState    = "A";
                    db.Users.Add(item);
                }
                else
                {
                    item.ModifiedBy   = user.ModifiedBy;
                    item.ModifiedDate = DateHelper.DateTimeNow;
                }

                db.SaveChanges();
                memberId = item.UserId;
            }

            return(memberId);
        }