/// <summary>
        ///
        /// </summary>
        private void Insert()
        {
            var timeSheetReportModel = new TimeSheetReportModel
            {
                CreatedBy   = CurrentUser.User.UserName,
                CreatedDate = DateTime.Now,
            };

            //edit data
            EditData(timeSheetReportModel);
            var newTimeSheetReport = TimeSheetReportController.Create(timeSheetReportModel);

            //create employeeReport
            foreach (var employee in chkEmployeeRowSelection.SelectedRows)
            {
                var timeSheetEmployeeReport = new TimeSheetEmployeeReportModel
                {
                    RecordId = int.Parse(employee.RecordID),
                    ReportId = newTimeSheetReport.Id
                };
                TimeSheetEmployeeReportController.Create(timeSheetEmployeeReport);
            }

            // create time sheet employee report
            Dialog.ShowNotification("Lưu thành công");
        }
        public void InitWindowTimeSheet(string day, string recordId)
        {
            var startDate = ConvertUtils.GetStartDayOfMonth();

            if (DateTime.TryParse(day, out var date))
            {
                hdfStartDateEmployee.Text = date.ToString("dd/MM/yyyy");
                hdfEndDateEmployee.Text   = date.ToString("dd/MM/yyyy");
                cbxDay.Text = date.ToString("dd/MM/yyyy");
                startDate   = date;
            }

            _timeSheetReport = TimeSheetReportController.GetById(Convert.ToInt32(hdfTimeSheetReportId.Text));
            if (_timeSheetReport != null)
            {
                var timeSheet = TimeSheetController.GetTimeSheet(Convert.ToInt32(recordId), startDate, startDate);
                if (timeSheet != null)
                {
                    txtTimeLogs.Text = timeSheet.TimeLogs;
                }
            }
            if (_timeSheetReport.Status == TimeSheetStatus.Locked)
            {
                return;
            }
            gridUpdateTimeSheet.Reload();
            btnDeleteUpdateTimeSheet.Disabled = true;
            wdUpdateTimeSheet.Show();
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="timeSheetReportModel"></param>
 private void EditData(TimeSheetReportModel timeSheetReportModel)
 {
     timeSheetReportModel.Name = txtName.Text;
     if (!DatetimeHelper.IsNull(dfFromDate.SelectedDate))
     {
         timeSheetReportModel.StartDate = dfFromDate.SelectedDate;
     }
     if (!DatetimeHelper.IsNull(dfToDate.SelectedDate))
     {
         timeSheetReportModel.EndDate = dfToDate.SelectedDate;
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!ExtNet.IsAjaxRequest)
            {
                hdfTimeSheetReportId.Text = Request.QueryString["id"];
                hdfTypeTimeSheet.Text     = Constant.TimesheetTypeTimeSheet;
                hdfDepartments.Text       = string.Join(",", CurrentUser.Departments.Select(d => d.Id));
                if (!string.IsNullOrEmpty(hdfTimeSheetReportId.Text))
                {
                    // get time sheet report
                    _timeSheetReport = TimeSheetReportController.GetById(Convert.ToInt32(hdfTimeSheetReportId.Text));
                    if (_timeSheetReport != null)
                    {
                        // set title for grid
                        gridTimeSheet.Title = _timeSheetReport.Name;
                        // set start date
                        if (_timeSheetReport.StartDate != null)
                        {
                            dfFromDateSearch.MinDate      = (DateTime)_timeSheetReport.StartDate;
                            dfToDateSearch.MinDate        = (DateTime)_timeSheetReport.StartDate;
                            dfFromDateSearch.SelectedDate = (DateTime)_timeSheetReport.StartDate;
                            hdfStartDate.Text             = _timeSheetReport.StartDate.ToString();
                        }
                        // set end date
                        if (_timeSheetReport.EndDate != null)
                        {
                            dfToDateSearch.MinDate      = (DateTime)_timeSheetReport.EndDate;
                            dfToDateSearch.MaxDate      = (DateTime)_timeSheetReport.EndDate;
                            dfToDateSearch.SelectedDate = (DateTime)_timeSheetReport.EndDate;
                            hdfEndDate.Text             = _timeSheetReport.EndDate.ToString();
                        }

                        ReloadGrid();
                    }

                    var timeSheetEmployeeReports = TimeSheetEmployeeReportController.GetAll(null, null, null,
                                                                                            Convert.ToInt32(hdfTimeSheetReportId.Text), null, null);
                    if (timeSheetEmployeeReports != null)
                    {
                        hdfRecordIds.Text = string.Join(",", timeSheetEmployeeReports.Select(tser => tser.RecordId));
                    }
                }

                // init department
                storeDepartment.DataSource = CurrentUser.DepartmentsTree;
                storeDepartment.DataBind();

                // generate dynamic column by day
                AddDayColumnToGrid(dfFromDateSearch.SelectedDate, dfToDateSearch.SelectedDate);
            }
        }
 /// <summary>
 /// Mở bảng công
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void btnUnlockTimeSheetReportClick(object sender, DirectEventArgs e)
 {
     try
     {
         _timeSheetReport        = TimeSheetReportController.GetById(Convert.ToInt32(hdfTimeSheetReportId.Text));
         _timeSheetReport.Status = TimeSheetStatus.Active;
         TimeSheetReportController.Update(_timeSheetReport);
         ReloadGrid();
     }
     catch (Exception ex)
     {
         Dialog.ShowError(ex.Message);
     }
 }
        public TimeSheetReportModel GetReportTimeSheetList(int userID, long startTimeStamp, long endTimeStamp,
                                                           List <int> selectTeamIDList, List <int> selectUserIDList, List <int> selectProjectIDList,
                                                           int from, int to, out long total)
        {
            total = 0;
            TimeSheetReportModel model = new TimeSheetReportModel();
            var tuple = this.checkQueryTeamIDAndUserIDAndProjectID(userID, selectTeamIDList, selectUserIDList, selectProjectIDList);

            selectTeamIDList    = tuple.Item1;
            selectUserIDList    = tuple.Item2;
            selectProjectIDList = tuple.Item3;

            model.totalTime = this._timeSheetTaskBll.GetReportTotalTime(startTimeStamp, endTimeStamp, selectTeamIDList,
                                                                        selectUserIDList, selectProjectIDList);
            model.projectCount    = selectProjectIDList.Count;
            model.teamMemberCount = selectUserIDList.Count;
            var userList = this._timeSheetTaskBll.GetReportPageList(selectTeamIDList, selectUserIDList, selectProjectIDList, from, to, out total);
            List <T_TIME_SHEET_TASK> userProjectTimeList = new List <T_TIME_SHEET_TASK>();

            if (userList.Count > 0)
            {
                userProjectTimeList = this._timeSheetTaskBll.GetReportUserProjectTime(
                    startTimeStamp, endTimeStamp, userList.Select(s => s.ID).Distinct().ToList(), selectProjectIDList);
            }
            model.userInfos = userList.Select(s => new TimeSheetReportUserModel()
            {
                userID             = s.ID,
                userMail           = s.U_EMAIL,
                userName           = s.U_USER_NAME,
                timeSheetTimeInfos = userProjectTimeList.Where(m => m.TST_USER_ID.Equals(s.ID)).Select(m => new TimeSheetReportProjectModel()
                {
                    projectID   = m.P_ID,
                    projectName = m.P_NAME,
                    totalTime   = m.TST_TIME
                }).ToList()
            }).ToList();

            return(model);
        }