Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static TimeSheetCodeModel Create(TimeSheetCodeModel model)
        {
            var entity = new hr_TimeSheetCode();

            model.FillEntity(ref entity);
            return(new TimeSheetCodeModel(hr_TimeSheetCodeServices.Create(entity)));
        }
        private void Insert(DirectEventArgs e)
        {
            try
            {
                var util      = new Util();
                var startTime = string.Empty;
                var endTime   = string.Empty;

                var timeSheet = new hr_TimeSheetCode()
                {
                    Code        = txtTimeSheetCode.Text,
                    CreatedDate = DateTime.Now,
                };
                if (!string.IsNullOrEmpty(hdfEmployeeSelectedId.Text))
                {
                    timeSheet.RecordId = Convert.ToInt32(hdfEmployeeSelectedId.Text);
                }
                if (!util.IsDateNull(dfStartTime.SelectedDate))
                {
                    timeSheet.StartTime = dfStartTime.SelectedDate;
                    startTime           = dfStartTime.SelectedDate.ToString("yyyy-MM-dd");
                }

                if (!util.IsDateNull(dfEndTime.SelectedDate))
                {
                    timeSheet.EndTime = dfEndTime.SelectedDate;
                    endTime           = dfEndTime.SelectedDate.ToString("yyyy-MM-dd");
                }

                timeSheet.IsActive = chk_IsActive.Checked;
                var checkTime =
                    hr_TimeSheetCodeServices.CheckExitTimeSheetCode(txtTimeSheetCode.Text, startTime, endTime);
                if (checkTime != null && checkTime.Count > 0)
                {
                    Dialog.Alert("Mã chấm công đã tồn tại. Vui lòng nhập mã chấm công khác!");
                    return;
                }
                else
                {
                    hr_TimeSheetCodeServices.Create(timeSheet);
                }

                if (e.ExtraParams["Close"] == "True")
                {
                    wdTimeSheetCode.Hide();
                    ResetForm();
                }
            }
            catch (Exception ex)
            {
                Dialog.Alert("Có lỗi xảy ra trong quá trình thêm mới: {0}".FormatWith(ex.Message));
            }
        }
Example #3
0
 private void EditDataTimeSheet(hr_TimeSheet timeSheet, hr_TimeSheetCode code)
 {
     if (!string.IsNullOrEmpty(hdfMonth.Text))
     {
         timeSheet.Month = Convert.ToInt32(hdfMonth.Text);
     }
     if (!string.IsNullOrEmpty(hdfYear.Text))
     {
         timeSheet.Year = Convert.ToInt32(hdfYear.Text);
     }
     timeSheet.RecordId      = code.RecordId;
     timeSheet.TimeSheetCode = code.Code;
     timeSheet.CreatedDate   = DateTime.Now;
     timeSheet.Detail        = "Bình thường";
 }
        /// <summary>
        /// Read data from excel file and save to db
        /// </summary>
        /// <param name="dataTable"></param>
        /// <param name="currentRow"></param>
        private void MainProcess(DataTable dataTable, int currentRow)
        {
            // Finish import file
            if (currentRow >= dataTable.Rows.Count)
            {
                Dialog.Alert("Success");
                gridTimeSheetCode.Reload();
                txtSheetName.Clear();
                txtFromRow.Clear();
                txtToRow.Clear();
                return;
            }

            count++;

            var listRecordId = TimeSheetCodeController.GetAll(null, null, null, null, null, true, null, null, null, null);

            var timeSheetCode = new hr_TimeSheetCode()
            {
                StartTime   = DateTime.Now,
                IsActive    = true,
                CreatedDate = DateTime.Now,
                CreatedBy   = CurrentUser.User.DisplayName,
            };

            foreach (DataColumn col in dataTable.Columns)
            {
                switch (col.ColumnName)
                {
                case nameof(TimeSheetCodeModel.EmployeeCode):
                    var record = RecordController.GetByEmployeeCode(dataTable.Rows[currentRow][col].ToString());
                    if (record != null)
                    {
                        timeSheetCode.RecordId = record.Id;
                    }
                    break;

                default:
                    var reg     = @"\(([^)]*)\)";
                    var propVal = dataTable.Rows[currentRow][col];
                    if (Regex.IsMatch(propVal.ToString(), reg))
                    {
                        propVal = Regex.Match(propVal.ToString(), reg).Groups[1].Value;
                    }
                    //get the property information based on the type
                    var propInfo = timeSheetCode.GetType().GetProperty(col.ColumnName);
                    //find the property type
                    if (propInfo == null)
                    {
                        continue;
                    }
                    if (!propInfo.CanWrite)
                    {
                        continue;
                    }
                    var propType = propInfo.PropertyType;

                    //equivalent to the specified object.
                    if (propType.IsEnum)
                    {
                        propVal = Enum.ToObject(propType, int.Parse(propVal.ToString()));
                    }
                    if (propType.Name == typeof(Nullable <>).Name)
                    {
                        if (Nullable.GetUnderlyingType(propType) == typeof(DateTime))
                        {
                            if (!DateTime.TryParseExact(propVal.ToString(), "dd/MM/yyyy",
                                                        CultureInfo.CurrentCulture, DateTimeStyles.None, out var date))
                            {
                                break;
                            }
                            propVal = Convert.ChangeType(date, typeof(DateTime));
                        }
                        else
                        {
                            propVal = Convert.ChangeType(propVal, Nullable.GetUnderlyingType(propType));
                        }
                    }
                    else
                    {
                        propVal = Convert.ChangeType(propVal, propType);
                    }
                    //Set the value of the property
                    propInfo.SetValue(timeSheetCode, propVal, null);
                    break;
                }
            }

            // Check if RecordId exists in TimeSheetCode table
            if (!string.IsNullOrEmpty(timeSheetCode.Code))
            {
                // create model
                var timeSheetCodeMode = new TimeSheetCodeModel(timeSheetCode);
                if (listRecordId.All(tsc => tsc.RecordId != timeSheetCode.RecordId))
                {
                    TimeSheetCodeController.Create(timeSheetCodeMode);
                    ContinueProcess(count);
                }
                else
                {
                    var timeSheetCodeJson = JSON.Serialize(timeSheetCode);

                    hdfTimeSheetCode.Text = timeSheetCodeJson;

                    // Open Messagebox
                    RM.RegisterClientScriptBlock("confirm",
                                                 "showResult(" + count + ", '" + (string.IsNullOrEmpty(timeSheetCodeMode.EmployeeCode) ? "0" : timeSheetCodeMode.EmployeeCode) +
                                                 "', '" + (string.IsNullOrEmpty(timeSheetCodeMode.FullName) ? "0" : timeSheetCodeMode.FullName) + "');");
                }
            }
        }
        // Read data from excel file and save to db
        private void MainProcess(DataTable dataTable, int currentRow)
        {
            // Finish import file
            if (currentRow >= dataTable.Rows.Count)
            {
                Dialog.Alert("Success");
                gridTimeSheetCode.Reload();
                txtSheetName.Clear();
                txtFromRow.Clear();
                txtToRow.Clear();
                return;
            }

            count++;

            var    listRecordId = hr_TimeSheetCodeServices.GetListRecordIds();
            string employeeCode = string.Empty;
            string fullname     = string.Empty;

            var timeSheetCode = new hr_TimeSheetCode()
            {
                StartTime   = DateTime.Now,
                IsActive    = true,
                CreatedDate = DateTime.Now,
                CreatedBy   = CurrentUser.User.DisplayName,
            };
            var recordId = 0;

            foreach (DataColumn col in dataTable.Columns)
            {
                var item = dataTable.Rows[currentRow][col];

                if (item != DBNull.Value)
                {
                    switch (col.Ordinal)
                    {
                    case 1:
                        employeeCode           = item.ToString();
                        recordId               = hr_RecordServices.GetRecordIdByEmployeeCode(employeeCode);
                        timeSheetCode.RecordId = recordId;
                        break;

                    case 2:
                        fullname = item.ToString();
                        break;

                    case 3:
                        timeSheetCode.Code = item.ToString();
                        break;

                    case 4:
                        timeSheetCode.MachineSerialNumber = item.ToString();
                        break;

                    case 5:
                        timeSheetCode.MachineName = item.ToString();
                        break;

                    case 6:
                        timeSheetCode.LocationName = item.ToString();
                        break;

                    case 7:
                        timeSheetCode.IPAddress = item.ToString();
                        break;
                    }
                }
            }

            // Check if RecordId exists in TimeSheetCode table
            if (!string.IsNullOrEmpty(timeSheetCode.Code))
            {
                if (!listRecordId.Any(tsc => tsc.RecordId == recordId))
                {
                    hr_TimeSheetCodeServices.Create(timeSheetCode);
                    ContinueProcess(count);
                }
                else
                {
                    // Find TimeSheetCode to edit
                    var editTimeSheetCode = hr_TimeSheetCodeServices.GetTimeSheetCodeByRecordId(recordId);

                    string timeSheetCodeJson = JSON.Serialize(timeSheetCode);

                    hdfTimeSheetCode.Text = timeSheetCodeJson;

                    // Open Messagebox
                    RM.RegisterClientScriptBlock("confirm",
                                                 "showResult(" + count + ", '" + (string.IsNullOrEmpty(employeeCode) ? "0" : employeeCode) +
                                                 "', '" + (string.IsNullOrEmpty(fullname) ? "0" : fullname) + "');");

                    // Update is accepted
                    //if (editTimeSheetCode != null && hdfIsAgree.Text == "1")
                    //{
                    //    timeSheetCode.Id = editTimeSheetCode.Id;
                    //    timeSheetCode.CreatedDate = editTimeSheetCode.CreatedDate;
                    //    timeSheetCode.CreatedBy = editTimeSheetCode.CreatedBy;
                    //    timeSheetCode.EditedDate = DateTime.Now;
                    //    timeSheetCode.EditedBy = CurrentUser.User.DisplayName;
                    //    hr_TimeSheetCodeServices.Update(timeSheetCode);
                    //}
                }
            }
        }