Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static RewardModel Create(RewardModel model)
        {
            // init entity
            var entity = new hr_Reward();

            // fill entity
            model.FillEntity(ref entity);

            // create
            return(new RewardModel(hr_RewardServices.Create(entity)));
        }
        private void Create(DirectEventArgs e)
        {
            try
            {
                var path = string.Empty;
                var util = new Util();
                if (fufTepTinHangLoat.HasFile)
                {
                    path = UploadFile(fufTepTinHangLoat,
                                      hdfTypePage.Text.Equals("KhenThuong") ? Constant.PathReward : Constant.PathDiscipline);
                }

                var listId = e.ExtraParams["ListId"].Split(',');
                if (listId.Length <= 1)
                {
                    Dialog.Alert("Bạn chưa chọn cán bộ nào!");
                    return;
                }

                for (var i = 0; i < listId.Length - 1; i++)
                {
                    var id = listId[i];
                    if (hdfTypePage.Text.Equals("KhenThuong"))
                    {
                        string reasonReward;
                        if (hdfIsDanhMuc2.Text == @"0")
                        {
                            var reason = new cat_ReasonReward {
                                Name = cbbLyDoHangLoat.Text
                            };
                            cat_ReasonRewardServices.Create(reason);
                            reasonReward = cbbLyDoHangLoat.Text;
                        }
                        else
                        {
                            reasonReward = cbbLyDoHangLoat.SelectedItem.Text;
                        }

                        if (string.IsNullOrEmpty(reasonReward))
                        {
                            ExtNet.Msg.Alert("Thông báo", "Không tìm thấy lý do khen thưởng. Vui lòng thử lại!").Show();
                            return;
                        }

                        if (txtSoQuyetDinhHangLoat.Text == "")
                        {
                            GenerateRewardDecisionNumber();
                        }

                        var record = new hr_Reward
                        {
                            RecordId         = int.Parse(id),
                            DecisionNumber   = txtSoQuyetDinhHangLoat.Text.Trim(),
                            DecisionMaker    = tgfNguoiQuyetDinhHangLoat.Text.Trim(),
                            FormRewardId     = int.Parse(hdfHinhThucHangLoat.Text),
                            LevelRewardId    = int.Parse(hdfCapKhenThuongKyLuatHangLoat.Text),
                            Reason           = reasonReward,
                            SourceDepartment = txtSourceDepartment.Text,
                            Note             = txtGhuChuHangLoat.Text.Trim()
                        };
                        var makerPosition = hdfIsMakerPosition.Text == @"0"
                            ? cbxMakerPosition.Text
                            : cbxMakerPosition.SelectedItem.Text;
                        record.MakerPosition = makerPosition;
                        if (!string.IsNullOrEmpty(txtMoneyAmount.Text))
                        {
                            record.MoneyAmount = decimal.Parse("0" + txtMoneyAmount.Text);
                        }
                        record.CreatedDate = DateTime.Now;
                        if (!util.IsDateNull(dfNgayQuyetDinhHangLoat.SelectedDate))
                        {
                            record.DecisionDate = dfNgayQuyetDinhHangLoat.SelectedDate;
                        }

                        if (!util.IsDateNull(dfNgayHieuLuc.SelectedDate))
                        {
                            record.EffectiveDate = dfNgayHieuLuc.SelectedDate;
                        }

                        record.AttachFileName = path != "" ? path : hdfTepDinhKemHangLoat.Text;
                        hr_RewardServices.Create(record);
                    }
                    else
                    {
                        string reasonDiscipline;
                        if (hdfIsDanhMuc2.Text == @"0")
                        {
                            var reason = new cat_ReasonDiscipline()
                            {
                                Name = cbbLyDoHangLoat.Text
                            };
                            cat_ReasonDisciplineServices.Create(reason);
                            reasonDiscipline = cbbLyDoHangLoat.Text;
                        }
                        else
                        {
                            reasonDiscipline = cbbLyDoHangLoat.SelectedItem.Text;
                        }

                        if (string.IsNullOrEmpty(reasonDiscipline))
                        {
                            ExtNet.Msg.Alert("Thông báo", "Không tìm thấy lý do khen thưởng. Vui lòng thử lại!").Show();
                            return;
                        }

                        if (txtSoQuyetDinhHangLoat.Text == "")
                        {
                            GenerateRewardDecisionNumber();
                        }

                        var record = new hr_Discipline
                        {
                            RecordId          = int.Parse(id),
                            DecisionNumber    = txtSoQuyetDinhHangLoat.Text.Trim(),
                            DecisionMaker     = tgfNguoiQuyetDinhHangLoat.Text.Trim(),
                            FormDisciplineId  = int.Parse(hdfHinhThucHangLoat.Text),
                            LevelDisciplineId = int.Parse(hdfCapKhenThuongKyLuatHangLoat.Text),
                            Reason            = reasonDiscipline,
                            SourceDepartment  = txtSourceDepartment.Text,
                            Note = txtGhuChuHangLoat.Text.Trim()
                        };
                        var makerPosition = hdfIsMakerPosition.Text == @"0"
                            ? cbxMakerPosition.Text
                            : cbxMakerPosition.SelectedItem.Text;
                        record.MakerPosition = makerPosition;
                        record.CreatedDate   = DateTime.Now;
                        if (!util.IsDateNull(dfNgayQuyetDinhHangLoat.SelectedDate))
                        {
                            record.DecisionDate = dfNgayQuyetDinhHangLoat.SelectedDate;
                        }

                        if (!util.IsDateNull(dfExpireDate.SelectedDate))
                        {
                            record.ExpireDate = dfExpireDate.SelectedDate;
                        }
                        record.AttachFileName = path != "" ? path : hdfTepDinhKemHangLoat.Text;
                        hr_DisciplineServices.Create(record);
                    }
                }

                grp_KhenThuongKyLuat.Reload();
                ResetForm();
                wdKhenThuongKyLuatHangLoat.Hide();
            }
            catch (Exception ex)
            {
                Dialog.Alert("Có lỗi xảy ra trong quá trình tạo quyết định: {0}".FormatWith(ex.Message));
            }
        }