/// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        private void Insert(DirectEventArgs e)
        {
            DateTime?startTime = null;
            DateTime?endTime   = null;

            var modelTimeSheet = new TimeSheetCodeModel(null)
            {
                CreatedDate = DateTime.Now
            };

            //Edit data
            EditData(modelTimeSheet, ref startTime, ref endTime);

            var checkTime = TimeSheetCodeController.GetAll(null, null, null, txtTimeSheetCode.Text, null, true, startTime, endTime, null, null);

            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;
            }

            TimeSheetCodeController.Create(modelTimeSheet);

            if (e.ExtraParams["Close"] == "True")
            {
                wdTimeSheetCode.Hide();
                ResetForm();
            }
        }
        /// <summary>
        /// Edit data
        /// </summary>
        /// <param name="modelTimeSheet"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        private void EditData(TimeSheetCodeModel modelTimeSheet, ref DateTime?startTime, ref DateTime?endTime)
        {
            var util = new Util();

            if (!string.IsNullOrEmpty(hdfEmployeeSelectedId.Text))
            {
                modelTimeSheet.RecordId = Convert.ToInt32(hdfEmployeeSelectedId.Text);
            }

            if (!string.IsNullOrEmpty(hdfTimeMachineId.Text))
            {
                modelTimeSheet.MachineId = Convert.ToInt32(hdfTimeMachineId.Text);
            }

            modelTimeSheet.Code = txtTimeSheetCode.Text;
            if (!util.IsDateNull(dfStartTime.SelectedDate))
            {
                modelTimeSheet.StartTime = dfStartTime.SelectedDate;
                startTime = dfStartTime.SelectedDate;
            }

            if (!util.IsDateNull(dfEndTime.SelectedDate))
            {
                modelTimeSheet.EndTime = dfEndTime.SelectedDate;
                endTime = dfEndTime.SelectedDate;
            }

            modelTimeSheet.IsActive = chk_IsActive.Checked;
        }
Example #3
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)));
        }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static void Update(TimeSheetCodeModel model)
        {
            var record = hr_TimeSheetCodeServices.GetById(model.Id);

            if (record == null)
            {
                return;
            }
            model.FillEntity(ref record);
            record.EditedDate = DateTime.Now;

            hr_TimeSheetCodeServices.Update(record);
        }
        /// <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) + "');");
                }
            }
        }
Example #6
0
 /// <summary>
 /// lay du lieu luong co dinh
 /// </summary>
 /// <param name="item"></param>
 /// <param name="salaryInfo"></param>
 private static void GetDataFromSalary(TimeSheetCodeModel item, hr_SalaryBoardInfo salaryInfo)
 {
     //Edit data salary
     EditDataSalary(item.RecordId, salaryInfo);
 }