private bool AddTimeSheetsWithEvent(EventEntity entity)
        {
            TimeSheetsEntity TimeSheet = new TimeSheetsEntity();

            TimeSheet.Description = entity.Details;
            if (entity.AllDay)
            {
                TimeSheet.Hours = 8;
                //删除之前用户当天的TimeSheet
                tsp.DeleteByUserAndDate(entity.CreatedBy, entity.FromDay.Date);
            }
            else
            {
                DateTime FromDay = DateTime.Parse(string.Format("{0}/{1}/{2} {3} {4}"
                                                                , entity.FromDay.Month, entity.FromDay.Day, entity.FromDay.Year, entity.FromTime, entity.FromTimeType == 1 ? "AM" : "PM"));
                DateTime EndDay = DateTime.Parse(string.Format("{0}/{1}/{2} {3} {4}"
                                                               , entity.ToDay.Month, entity.ToDay.Day, entity.ToDay.Year, entity.ToTime, entity.ToTimeType == 1 ? "AM" : "PM"));
                string Hours = EndDay.Subtract(FromDay).TotalHours.ToString();
                TimeSheet.Hours = decimal.Parse(Hours);
            }
            TimeSheet.IsMeeting   = false;
            TimeSheet.IsSubmitted = entity.AllDay ? true : false;
            TimeSheet.Percentage  = 0;
            TimeSheet.ProjectID   = entity.ProjectID;
            TimeSheet.TicketID    = string.IsNullOrEmpty(Config.HRTicketID) ? 0 : int.Parse(Config.HRTicketID);
            TimeSheet.SheetDate   = entity.FromDay.Date;
            TimeSheet.UserID      = entity.CreatedBy;
            TimeSheet.CreatedOn   = DateTime.Now;
            TimeSheet.CreatedBy   = entity.CreatedBy;
            TimeSheet.ModifiedOn  = DateTime.Now;
            TimeSheet.ModifiedBy  = entity.CreatedBy;
            TimeSheet.EventID     = entity.ID;
            return(tsp.AddTimeSheet(TimeSheet) > 0);
        }
Exemple #2
0
        private TimeSheetsEntity GetEntity(HttpContext context, out string msg)
        {
            msg = string.Empty;
            HttpRequest request = context.Request;

            try
            {
                TimeSheetsEntity timesheet = TimeSheetFactory.CreateTimeSheet(IdentityContext.UserID, ObjectFactory.GetInstance <ISystemDateTime>());

                timesheet.Description = request.Params["WorkDetail"];
                decimal decValue;
                if (!decimal.TryParse(request.Params["Hours"], out decValue))
                {
                    msg = "Hours must be a number little than 24.";
                    return(null);
                }
                if (!decimal.TryParse(request.Params["Percentage"], out decValue))
                {
                    msg = "Percentage must be a number little than 100.";
                    return(null);
                }
                bool booValue = false;
                if (!bool.TryParse(request.Params["IsMeeting"], out booValue))
                {
                    msg = "IsMeeting must be a bool value or bit value.";
                    return(null);
                }
                if (!bool.TryParse(request.Params["IsSubmitted"], out booValue))
                {
                    msg = "IsSubmitted must be a bool value or bit value.";
                    return(null);
                }
                int intValue;
                if (!int.TryParse(request.Params["ProjectID"], out intValue))
                {
                    msg = "Project can not be null.";
                    return(null);
                }
                if (!int.TryParse(request.Params["TicketID"], out intValue))
                {
                    msg = "Ticket can not be null.";
                    return(null);
                }
                timesheet.Hours       = decimal.Parse(request.Params["Hours"]);
                timesheet.IsMeeting   = bool.Parse(request.Params["IsMeeting"]);
                timesheet.IsSubmitted = bool.Parse(request.Params["IsSubmitted"]);
                timesheet.Percentage  = decimal.Parse(request.Params["Percentage"]);
                timesheet.ProjectID   = int.Parse(request.Params["ProjectID"]);
                timesheet.SheetDate   = Convert.ToDateTime(context.Server.UrlDecode(request.Params["SheetDate"]));
                timesheet.TicketID    = int.Parse(request.Params["TicketID"]);
                timesheet.UserID      = IdentityContext.UserID;
                timesheet.ID          = int.Parse(request.Params["TimeSheetID"]);
                return(timesheet);
            }
            catch (Exception ex)
            {
                msg = string.Format("Input Error:{0}", ex.Message);
                return(null);
            }
        }
Exemple #3
0
        public bool UpdateTimeSheet(TimeSheetsEntity model)
        {
            this.ClearBrokenRuleMessages();
            bool result = mgr.UpdateTimeSheet(model);

            this.AddBrokenRuleMessages(mgr.BrokenRuleMessages);
            return(result);
        }
Exemple #4
0
        public int AddTimeSheet(TimeSheetsEntity model)
        {
            this.ClearBrokenRuleMessages();
            int id = mgr.AddTimeSheet(model);

            this.AddBrokenRuleMessages(mgr.BrokenRuleMessages);
            return(id);
        }
Exemple #5
0
        private bool UpdateTimeSheet(TimeSheetsEntity model, out string msg)
        {
            msg = string.Empty;
            TimeSheetApplication tsApp = new TimeSheetApplication();
            bool result = tsApp.UpdateTimeSheet(model);

            msg = tsApp.BrokenRuleMessages.Count > 0 ? tsApp.BrokenRuleMessages[0].Message : SuccessMessage;
            return(result);
        }
        private bool UpdateTimeSheet(TimeSheetsEntity model, out string msg)
        {
            msg = string.Empty;
            var result = tsApp.UpdateTimeSheet(model);

            if (tsApp.BrokenRuleMessages.Count > 0)
            {
                msg = tsApp.BrokenRuleMessages[0].Message;
            }
            return(result);
        }
        private int AddTimeSheet(TimeSheetsEntity model, out string msg)
        {
            msg = string.Empty;
            int id = tsApp.AddTimeSheet(model);

            if (tsApp.BrokenRuleMessages.Count > 0 || id <= 0)
            {
                msg = tsApp.BrokenRuleMessages[0].Message;
            }
            return(id);
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            int  id    = -1;
            bool isInt = int.TryParse(TimeSheetId, out id);

            if (isInt)
            {
                if (id > 0)
                {
                    TimeSheetsEntity timesheet = tsRepository.Get(id);
                    if (timesheet != null)
                    {
                        DateTime         sheetdate_old = timesheet.SheetDate;
                        TimeSheetsEntity moveTimesheet = tsApp.GetByUserId(UserInfo.UserID, DateTime.Parse(txtFrom.Text));
                        if (moveTimesheet == null) //当天没有写时,可直接更改
                        {
                            MoveTimeSheets(timesheet, sheetdate_old);
                        }
                        else
                        {
                            if (moveTimesheet.IsSubmitted)//当前TimeSheet已提交时,不可更改
                            {
                                ClientScript.RegisterStartupScript(this.GetType(), Request.Url.AbsolutePath
                                                                   , "<p style='color:red;text-align: center;line-height: 30px;margin: 3px;'>Warning:The timesheet of the selected day has been submitted!</p>");
                            }
                            else
                            {
                                MoveTimeSheets(timesheet, sheetdate_old);
                            }
                        }
                    }
                    else
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), Request.Url.AbsolutePath
                                                           , "<p style='color:red;text-align: center;line-height: 30px;margin: 3px;'>Warning:Paramter is error!</p>");
                    }
                }
                else
                {
                    ClientScript.RegisterStartupScript(this.GetType(), Request.Url.AbsolutePath
                                                       , "<p style='color:red;text-align: center;line-height: 30px;margin: 3px;'>Warning:Paramter is error!</p>");
                }
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), Request.Url.AbsolutePath
                                                   , "<p style='color:red;text-align: center;line-height: 30px;margin: 3px;'>Warning:Paramter is error!</p>");
            }
        }
 private void MoveTimeSheets(TimeSheetsEntity timesheet, DateTime sheetdate_old)
 {
     timesheet.SheetDate  = DateTime.Parse(txtFrom.Text);
     timesheet.ModifiedBy = UserInfo.UserID;
     timesheet.ModifiedOn = DateTime.Now;
     tsApp.UpdateTimeSheet(timesheet);
     if (timesheet.SheetDate > DateTime.Now) //更改Change后的WeekPlan
     {
         ts.SyncWeekPlan(timesheet);
     }
     if (sheetdate_old > DateTime.Now) //更改之前的WeekPlan
     {
         timesheet.SheetDate = sheetdate_old;
         ts.SyncWeekPlan(timesheet);
     }
     Redirect(Request.RawUrl, false, true);
 }
        private void UpdateTimeSheetsByWeekPlan(DateTime weekDay)
        {
            Dictionary <DateTime, List <int> > dic_Ticket = new Dictionary <DateTime, List <int> >();

            dic_Ticket.Add(weekDay.AddDays(-6), GetTickets(mondayTicketIds.Value));
            dic_Ticket.Add(weekDay.AddDays(-5), GetTickets(tuesdayTicketIds.Value));
            dic_Ticket.Add(weekDay.AddDays(-4), GetTickets(wednesdayTicketIds.Value));
            dic_Ticket.Add(weekDay.AddDays(-3), GetTickets(thursdayTicketIds.Value));
            dic_Ticket.Add(weekDay.AddDays(-2), GetTickets(fridayTicketIds.Value));
            dic_Ticket.Add(weekDay.AddDays(-1), GetTickets(saturdayTicketIds.Value));
            dic_Ticket.Add(weekDay, GetTickets(sundayTicketIds.Value));

            if (dic_Ticket.Count > 0)
            {
                DataTable TimeSheets = tsp.GetAllTimeSheetRecord(UserInfo.UserID, weekDay.AddDays(-6), weekDay);
                List <TimeSheetsEntity> list_TimeSheets = new List <TimeSheetsEntity>();
                foreach (DataRow item in TimeSheets.Rows)
                {
                    TimeSheetsEntity TimeSheet = new TimeSheetsEntity();
                    TimeSheet.ID        = (int)item["ID"];
                    TimeSheet.SheetDate = (DateTime)item["SheetDate"];
                    TimeSheet.TicketID  = (int)item["TicketID"];
                    list_TimeSheets.Add(TimeSheet);
                }

                List <int> List_allTicketIds = new List <int>();
                foreach (List <int> item in dic_Ticket.Values)
                {
                    foreach (int item2 in item)
                    {
                        List_allTicketIds.Add(item2);
                    }
                }
                List <TicketsEntity> list_Tickets = tkapp.GetTicketsByIds(List_allTicketIds);

                StringBuilder sb             = new StringBuilder();
                List <int>    List_addIds    = new List <int>(); //要添加的TicketID集合
                List <int>    List_removeIds = new List <int>(); //要删除的TicketID集合

                foreach (var item in dic_Ticket)
                {
                    //获取要删除的TimeSheet的TickeID集合
                    List_removeIds.AddRange(list_TimeSheets.Where(r => r.SheetDate == item.Key)
                                            .Select(r => r.TicketID).Except(item.Value));
                    if (List_removeIds.Count > 0)
                    {
                        foreach (int item_remove in List_removeIds)
                        {
                            sb = sb.AppendFormat("delete TimeSheets where SheetDate={0} and TicketID={1} and UserID={2} and IsSumbitted=0;"
                                                 , item.Key, item_remove, UserInfo.UserID);
                        }
                    }

                    //获取要添加的TimeSheet的TickeID集合
                    List_addIds.AddRange(item.Value.Except(list_TimeSheets.Where(r => r.SheetDate == item.Key)
                                                           .Select(r => r.TicketID)));
                    if (List_addIds.Count > 0)
                    {
                        TimeSheetsEntity moveTimesheet = tsApp.GetByUserId(UserInfo.UserID, item.Key);
                        foreach (int item_add in List_addIds)
                        {
                            if (moveTimesheet == null)
                            {
                                int projectId = list_Tickets.Find(r => r.TicketID == item_add).ProjectID;
                                sb = sb.Append(" insert into TimeSheets([SheetDate],[ProjectID],[TicketID],[UserID],[Hours],[Percentage],[Description],");
                                sb = sb.Append("[IsSubmitted],[CreatedOn],[CreatedBy],[ModifiedOn],[ModifiedBy],[IsMeeting],[EventID])");
                                sb = sb.AppendFormat("Values({0},{1},{2},{3},0,0.00,'',0,{4},{3},{4},{3},0,0)"
                                                     , item.Key, projectId, item_add, UserInfo.UserID, DateTime.Now);
                            }
                            else
                            {
                                if (moveTimesheet.IsSubmitted == false)
                                {
                                    int projectId = list_Tickets.Find(r => r.TicketID == item_add).ProjectID;
                                    sb = sb.Append(" insert into TimeSheets([SheetDate],[ProjectID],[TicketID],[UserID],[Hours],[Percentage],[Description],");
                                    sb = sb.Append("[IsSubmitted],[CreatedOn],[CreatedBy],[ModifiedOn],[ModifiedBy],[IsMeeting],[EventID])");
                                    sb = sb.AppendFormat("Values({0},{1},{2},{3},0,0.00,'',0,{4},{3},{4},{3},0,0)"
                                                         , item.Key, projectId, item_add, UserInfo.UserID, DateTime.Now);
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                    }
                }

                if (sb.Length > 0)
                {
                    //Database db = DatabaseFactory.CreateDatabase();
                    //string sql = string.Format("update Tickets set ConfirmEstmateUserId={0} where TicketID={1}"
                    //    , userId, ticketId);
                    //using (DbCommand dbCommand = db.GetSqlStringCommand(sql))
                    //{
                    //    return db.ExecuteNonQuery(dbCommand) > 0;
                    //}
                }
            }
            else //删除当前日期内该用户所有的TimeSheets
            {
            }
        }
Exemple #11
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            try
            {
                if (IdentityContext.UserID <= 0)
                {
                    return;
                }
                HttpRequest request = context.Request;
                if (string.IsNullOrEmpty(request.Params["type"]))
                {
                    context.Response.Write("");
                }
                else
                {
                    DateTime date      = Convert.ToDateTime(request.Params["date"]);
                    DateTime startDate = date.Date;
                    DateTime endDate   = date.Date;
                    int      projectID = 0;
                    switch (request.Params["type"])
                    {
                    case "GetTicketsByCategory":
                        //int id = 0;
                        //if (int.TryParse(request.Params["cagegoryid"], out id) && id > 0)
                        //{
                        //    context.Response.Write(GetTicketsJsonByCategory(id));
                        //    break;
                        //}
                        //else
                        //{
                        //    context.Response.Write("");
                        //    break;
                        //}
                        context.Response.Write("");
                        break;

                    case "GetTimeSheetsByWeek":
                        if (string.IsNullOrEmpty(request["date"]))
                        {
                            context.Response.Write("");
                            break;
                        }
                        int.TryParse(request.Params["project"], out projectID);

                        if (string.IsNullOrEmpty(request.Params["category"]))
                        {
                            context.Response.Write(GetTimesheetTicketJson(0, startDate, endDate, true, IdentityContext.UserID, projectID));
                            break;
                        }
                        else
                        {
                            int category = 0;
                            if (int.TryParse(request.Params["category"], out category))
                            {
                                context.Response.Write(GetTimesheetTicketJson(category, date, date, true, IdentityContext.UserID, projectID));
                                break;
                            }
                        }
                        break;

                    case "GetTimeSheetsByDate":
                        if (string.IsNullOrEmpty(request["date"]))
                        {
                            context.Response.Write("");
                            break;
                        }
                        int.TryParse(request.Params["project"], out projectID);

                        int userID = IdentityContext.UserID;
                        if (!string.IsNullOrEmpty(request.Params["userid"]))
                        {
                            int.TryParse(request.Params["userid"], out userID);
                        }
                        if (string.IsNullOrEmpty(request.Params["category"]))
                        {
                            context.Response.Write(GetTimesheetTicketJson(0, startDate, endDate, false, userID, projectID));
                            break;
                        }
                        else
                        {
                            int category = 0;
                            if (int.TryParse(request.Params["category"], out category))
                            {
                                context.Response.Write(GetTimesheetTicketJson(category, date, date, false, userID, projectID));
                                break;
                            }
                        }
                        break;

                    case "update":
                        int updateID = 0;
                        if (int.TryParse(request.Params["TimeSheetID"], out updateID))
                        {
                            string           response = string.Empty;
                            string           msg      = string.Empty;
                            TimeSheetsEntity model    = GetEntity(context, out msg);
                            if (model == null)
                            {
                                response = GetResponse(false, msg, 0);
                                context.Response.Write(response);
                                break;
                            }

                            if (updateID == 0)
                            {
                                model.ID = AddTimeSheet(model, out msg);
                                if (model.ID > 0)
                                {
                                    response = GetResponse(true, SuccessMessage, model.ID);
                                    context.Response.Write(response);
                                    break;
                                }
                                else
                                {
                                    response = GetResponse(false, msg, model.ID);
                                    context.Response.Write(response);
                                    break;
                                }
                            }
                            if (model.IsSubmitted == false)
                            {
                                bool update = UpdateTimeSheet(model, out msg);
                                if (update)
                                {
                                    response = GetResponse(true, SuccessMessage, model.ID);
                                    context.Response.Write(response);
                                    break;
                                }
                                else
                                {
                                    response = GetResponse(false, msg, model.ID);
                                    context.Response.Write(response);
                                    break;
                                }
                            }
                            else
                            {
                                response = GetResponse(false, "Current item has submitted.", model.ID);
                                context.Response.Write(response);
                                break;
                            }
                        }
                        context.Response.Write("false");
                        break;

                    case "add":
                        string           msgAdd      = string.Empty;
                        TimeSheetsEntity modelAdd    = GetEntity(context, out msgAdd);
                        string           responseAdd = string.Empty;
                        if (modelAdd == null)
                        {
                            responseAdd = GetResponse(false, msgAdd, 0);
                            context.Response.Write(responseAdd);
                            break;
                        }
                        modelAdd.ID = AddTimeSheet(modelAdd, out msgAdd);
                        if (modelAdd.ID > 0)
                        {
                            responseAdd = GetResponse(true, SuccessMessage, modelAdd.ID);
                            context.Response.Write(responseAdd);
                            break;
                        }
                        else
                        {
                            responseAdd = GetResponse(false, msgAdd, modelAdd.ID);
                            context.Response.Write(responseAdd);
                            break;
                        }

                    case "delete":
                        int    deleteID       = 0;
                        string responseDelete = string.Empty;
                        if (int.TryParse(request.Params["id"], out deleteID) && deleteID > 0)
                        {
                            if (DeleteTimeSheet(deleteID))
                            {
                                responseDelete = GetResponse(true, SuccessMessage, deleteID);
                                context.Response.Write(responseDelete);
                                break;
                            }
                            else
                            {
                                responseDelete = GetResponse(false, FailMessage, deleteID);
                                context.Response.Write(responseDelete);
                                break;
                            }
                        }
                        responseDelete = GetResponse(true, SuccessMessage, deleteID);
                        context.Response.Write(responseDelete);
                        break;

                    case "cancelsubmit":
                        string sheeddate   = request.Params["sheetdate"];
                        string userid      = request.Params["userid"];
                        string responseMsg = string.Empty;
                        string msgcancel   = string.Empty;
                        if (string.IsNullOrEmpty(sheeddate) || string.IsNullOrEmpty(userid))
                        {
                            responseMsg = GetResponse(false, FailMessage, 0);
                        }
                        else
                        {
                            if (CancelSubmit(sheeddate, userid, out msgcancel))
                            {
                                responseMsg = GetResponse(true, SuccessMessage, 0);
                            }
                            else
                            {
                                responseMsg = GetResponse(false, msgcancel, 0);
                            }
                        }
                        context.Response.Write(responseMsg);
                        break;

                    default:
                        responseDelete = GetResponse(false, FailMessage, 0);
                        context.Response.Write(responseDelete);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                context.Response.Write("para error!");
                WebLogAgent.Write(string.Format("Error Ashx:TimeSheet.ashx Messages:\r\n{0}", ex));
                return;
            }
        }
        /// <summary>
        /// 修改Event时
        /// </summary>
        public bool UpdateEvent(EventsView entity, EventEntity oldEvent, List <EventInviteEntity> inviteUserList)
        {
            bool result = false;

            entity.UpdatedOn = DateTime.Now;

            if (!entity.AllDay)
            {
                entity.FromDay = DateTime.Parse(string.Format("{0}/{1}/{2} {3} {4}"
                                                              , entity.FromDay.Month, entity.FromDay.Day, entity.FromDay.Year, entity.FromTime, entity.FromTimeType == 1 ? "AM" : "PM"));
            }

#if !DEBUG
            using (TransactionScope tran = new TransactionScope())
#endif
            {
                result = mgr.EditEvents(entity);

                if (entity.FromDay >= DateTime.Now.Date)                   //当天之前的TimeSheet不做修改
                {
                    if (entity.ProjectID.ToString() == Config.HRProjectID) //项目为HR时,需要处理TimeSheets
                    {
                        if (!(oldEvent.IsOff) && entity.IsOff)             //如果之前没有选择OFF的ticket,修改后选择了,则添加TimeSheets
                        {
                            result = AddTimeSheetsWithEvent(entity);
                        }
                        if (oldEvent.IsOff && entity.IsOff)//如果两次都选择了OFF的ticket,则修改Timesheet时间
                        {
                            TimeSheetsEntity timeSheetEntity = tsp.GetByEventId(entity.ID, entity.FromDay.Date);
                            if (entity.AllDay)
                            {
                                timeSheetEntity.Hours = 8;
                            }
                            else
                            {
                                DateTime FromDay = DateTime.Parse(string.Format("{0}/{1}/{2} {3} {4}"
                                                                                , entity.FromDay.Month, entity.FromDay.Day, entity.FromDay.Year, entity.FromTime, entity.FromTimeType == 1 ? "AM" : "PM"));
                                DateTime EndDay = DateTime.Parse(string.Format("{0}/{1}/{2} {3} {4}"
                                                                               , entity.ToDay.Month, entity.ToDay.Day, entity.ToDay.Year, entity.ToTime, entity.ToTimeType == 1 ? "AM" : "PM"));
                                string Hours = EndDay.Subtract(FromDay).TotalHours.ToString();
                                timeSheetEntity.Hours = decimal.Parse(Hours);
                            }
                            timeSheetEntity.IsSubmitted = entity.AllDay ? true : false;
                            timeSheetEntity.ModifiedOn  = DateTime.Now;
                            result = tsp.UpdateTimeSheet(timeSheetEntity);
                        }
                        if (oldEvent.IsOff && !(entity.IsOff))//如果之前选择了OFF的ticket,修改后没有选择,则删除TimeSheets
                        {
                            result = tsp.DeleteByEventId(entity.ID, entity.FromDay.Date);
                        }
                    }
                }

                if (result)
                {
                    RemoveInviteUser(inviteUserList);
                    inviteUserList.RemoveAll(r => (r.UserID > 0 && (r.OptionStatus == 1 || r.OptionStatus == 3)) ||
                                             (r.UserID == 0 && r.OptionStatus == 3));
                    mgr.AddEventInvites(entity, inviteUserList);
                }
#if !DEBUG
                if (result)
                {
                    tran.Complete();
                    return(true);
                }
#endif
            }
            return(result);
        }
Exemple #13
0
        public void ProcessRequest(HttpContext context)
        {
            var Request = context.Request;

            context.Response.ContentType = "application/json";
            if (UserID < 1 || UserInfo == null || UserInfo.Role == Entity.UserModel.RolesEnum.CLIENT)
            {
                context.Response.Write("[]");
                context.Response.End();
            }
            DateTime date = DateTime.MinValue, startDate = DateTime.Now, endDate = DateTime.Now;
            int      projectId, category;
            string   action     = context.Request.Params["action"].ToLower();
            var      list       = new object();
            string   msg        = "";
            bool     boolResult = false;
            int      deleteID   = 0;

            switch (action)
            {
            case "gettimesheetsbyweek":
                if (DateTime.TryParse(Request.Params["date"], out date))
                {
                    startDate = date;
                    endDate   = date;
                    var list2 = GetTimesheetTicket(0, startDate, endDate, false, UserID, 0);
                    if (list2 != null && list2.Count > 0)
                    {
                        list = new
                        {
                            date       = date,
                            totalHours = list2.Select(x => x.Hours).Sum(),
                            timesheets = list2.Select(x => new
                            {
                                ticket     = new { title = x.TicketTitle, id = x.TicketID, description = x.TicketDescription, pct = x.Percentage },
                                project    = new { id = x.ProjectID, title = x.ProjectTitle },
                                id         = x.TimeSheetID,
                                workDetail = x.WorkDetail,
                                hours      = x.Hours,
                                isMeeting  = x.IsMeeting,
                                submitted  = x.IsSubmitted
                            })
                        }
                    }
                    ;
                    else
                    {
                        list = new List <int>();
                    }
                    context.Response.Write(JsonConvert.SerializeObject(list, new IsoDateTimeConverter {
                        DateTimeFormat = "yyyy-MM-dd"
                    }));
                }
                else
                {
                    context.Response.Write("[]");
                }
                break;

            case "gettimesheetsbydate":
                DateTime.TryParse(Request.Params["date"], out date);
                startDate = date;
                endDate   = date;
                int.TryParse(Request.Params["project"], out projectId);
                int.TryParse(Request.Params["category"], out category);
                var list1 = GetTimesheetTicket(category, startDate, endDate, false, UserID, projectId);
                if (list1 != null && list1.Count > 0)
                {
                    list = list1.Select(x => new
                    {
                        ticket     = new { title = x.TicketTitle, id = x.TicketID, description = x.TicketDescription, pct = x.Percentage },
                        project    = new { id = x.ProjectID, title = x.ProjectTitle },
                        id         = x.TimeSheetID,
                        workDetail = x.WorkDetail,
                        hours      = x.Hours,
                        isMeeting  = x.IsMeeting,
                        submitted  = x.IsSubmitted
                    });
                }
                else
                {
                    list = new List <int>();
                }
                context.Response.Write(JsonConvert.SerializeObject(list, DateConverter));
                break;

            case "getticketslistbyproject":
                int.TryParse(Request["project"], out projectId);
                DateTime.TryParse(Request.Params["date"], out date);
                var result = GetTicketsByProject(projectId, date);
                if (result != null && result.ResultList != null)
                {
                    list = result.ResultList.OrderByDescending(x => x.TicketID).Select(x => new { title = x.Title, description = x.FullDescription, id = x.ID, pct = x.Percentage });
                }
                else
                {
                    list = new List <int>();
                }
                context.Response.Write(JsonConvert.SerializeObject(list, DateConverter));
                break;

            case "addtimesheet":
                TimeSheetsEntity modelAdd = GetEntity(context, out msg);
                if (modelAdd == null)
                {
                    context.Response.Write(ResponseMessage.GetResponse(false, msg, 0));
                }
                else
                {
                    modelAdd.ID = AddTimeSheet(modelAdd, out msg);
                    if (modelAdd.SheetDate > DateTime.Now)
                    {
                        SyncWeekPlan(modelAdd);
                    }
                    context.Response.Write(modelAdd.ID > 0
                            ? ResponseMessage.GetResponse(true, "", modelAdd.ID)
                            : ResponseMessage.GetResponse(false, msg, modelAdd.ID));
                }
                break;

            case "updatetimesheet":
                TimeSheetsEntity modelUpdate = GetEntity(context, out msg);
                if (modelUpdate == null)
                {
                    context.Response.Write(ResponseMessage.GetResponse(false, msg, 0));
                }
                else
                {
                    boolResult = UpdateTimeSheet(modelUpdate, out msg);
                    if (modelUpdate.SheetDate > DateTime.Now)
                    {
                        SyncWeekPlan(modelUpdate);
                    }
                    context.Response.Write(boolResult
                            ? ResponseMessage.GetResponse(true, "", modelUpdate.ID)
                            : ResponseMessage.GetResponse(false, msg, modelUpdate.ID));
                }
                break;

            case "deletetimesheet":
                if (int.TryParse(Request["id"], out deleteID) && deleteID > 0)
                {
                    if (DeleteTimeSheet(deleteID))
                    {
                        msg = ResponseMessage.GetResponse(true, "", deleteID);
                    }
                    else
                    {
                        msg = ResponseMessage.GetResponse(false, "", deleteID);
                    }
                    if (Convert.ToDateTime(context.Server.UrlDecode(context.Request.Params["SheetDate"])) >
                        DateTime.Now)
                    {
                        SyncWeekPlan(new TimeSheetsEntity()
                        {
                            SheetDate =
                                Convert.ToDateTime(context.Server.UrlDecode(context.Request.Params["SheetDate"]))
                        });
                    }
                }
                context.Response.Write(msg);
                break;

            case "cancelsubmit":
                string sheeddate   = Request.Params["sheetdate"];
                string userid      = Request.Params["userid"];
                string responseMsg = string.Empty;
                string msgcancel   = string.Empty;
                if (string.IsNullOrEmpty(sheeddate) || string.IsNullOrEmpty(userid))
                {
                    responseMsg = ResponseMessage.GetResponse(false);
                }
                else
                {
                    if (CancelSubmit(sheeddate, userid, out msgcancel))
                    {
                        responseMsg = ResponseMessage.GetResponse(true);
                    }
                    else
                    {
                        responseMsg = ResponseMessage.GetResponse(false, msgcancel, 0);
                    }
                }
                context.Response.Write(responseMsg);
                break;

            case "getweekhours":
                int userId = int.Parse(context.Request.Params["userID"]);
                context.Response.Write(getWeekHours(userId));
                break;

            default:
                context.Response.Write("[]");
                break;
            }
        }
Exemple #14
0
        public bool SyncWeekPlan(TimeSheetsEntity model)
        {
            WeekPlanApplication planApp = new WeekPlanApplication();

            DateTime weekDay = model.SheetDate;

            //DateTime weekDay = DateTime.Now.AddDays(7);
            int weekOfDay = (int)weekDay.DayOfWeek;

            weekOfDay = weekOfDay == 0 ? 7 : weekOfDay;
            weekDay   = weekDay.AddDays(-weekOfDay).AddDays(7);
            List <TimeSheetTicket> listTimeSheetTicket = GetTimesheetTicket(0, model.SheetDate, model.SheetDate, false,
                                                                            UserID, 0);

            string  description = "";
            string  tickets     = "";
            decimal hours       = 0;

            foreach (var timeSheet in listTimeSheetTicket)
            {
                description += timeSheet.TicketID + ": " + timeSheet.TicketTitle + "\r\n";
                tickets     += timeSheet.TicketID + "_";
                hours       += timeSheet.Hours;
            }
            WeekPlanEntity entity = planApp.GetInfo(UserID, weekDay);

            if (entity == null)
            {
                entity = new WeekPlanEntity();

                entity.WeekDay           = weekDay.Date;
                entity.UserID            = UserInfo.UserID;
                entity.CreateDate        = DateTime.Now;
                entity.UpdateDate        = DateTime.Now;
                entity.UpdateUserID      = UserInfo.UserID;
                entity.IsDeleted         = false;
                entity.Monday            = "";
                entity.MondayTickets     = "";
                entity.MondayEstimate    = 0;
                entity.Tuesday           = "";
                entity.TuesdayTickets    = "";
                entity.TuesdayEstimate   = 0;
                entity.Wednesday         = "";
                entity.WednesdayTickets  = "";
                entity.WednesdayEstimate = 0;
                entity.Thursday          = "";
                entity.ThursdayTickets   = "";
                entity.ThursdayEstimate  = 0;
                entity.Friday            = "";
                entity.FridayTickets     = "";
                entity.FridayEstimate    = 0;
                entity.Saturday          = "";
                entity.SaturdayTickets   = "";
                entity.SaturdayEstimate  = 0;
                entity.Sunday            = "";
                entity.SundayTickets     = "";
                entity.SundayEstimate    = 0;
            }
            switch (weekOfDay)
            {
            case 1:
                entity.Monday         = description;
                entity.MondayTickets  = tickets;
                entity.MondayEstimate = (int)hours;
                break;

            case 2:
                entity.Tuesday         = description;
                entity.TuesdayTickets  = tickets;
                entity.TuesdayEstimate = (int)hours;
                break;

            case 3:
                entity.Wednesday         = description;
                entity.WednesdayTickets  = tickets;
                entity.WednesdayEstimate = (int)hours;
                break;

            case 4:
                entity.Thursday         = description;
                entity.ThursdayTickets  = tickets;
                entity.ThursdayEstimate = (int)hours;
                break;

            case 5:
                entity.Friday         = description;
                entity.FridayTickets  = tickets;
                entity.FridayEstimate = (int)hours;
                break;

            case 6:
                entity.Saturday         = description;
                entity.SaturdayTickets  = tickets;
                entity.SaturdayEstimate = (int)hours;
                break;

            case 7:
                entity.Sunday         = description;
                entity.SundayTickets  = tickets;
                entity.SundayEstimate = (int)hours;
                break;
            }

            if (entity.ID > 0)
            {
                return(planApp.Update(entity, true));
            }
            else
            {
                return(planApp.Add(entity) > 0);
            }
        }