Exemple #1
0
        protected void RadToolBar1_ButtonClick(object sender, RadToolBarEventArgs e)
        {
            switch (e.Item.Value)
            {
            case "Save":
                if (idHopDong == null)
                {
                    HopDongLD hd = new HopDongLD();
                    if (idNhanVien == null)
                    {
                        hd.IDNhanVien = Convert.ToInt32(cboNguoiLD.SelectedValue);
                    }
                    else
                    {
                        hd.IDNhanVien = idNhanVien;
                    }
                    if (_entities.HopDongLDs.Where(h => h.SoHD == txtSoHD.Text).FirstOrDefault() == null)
                    {
                        hd.SoHD               = txtSoHD.Text;
                        hd.NgayKyHD           = txtNgayKyHD.SelectedDate;
                        hd.IDLoaiHD           = Convert.ToInt32(cboLoaiHD.SelectedValue);
                        hd.TuNgay             = txtTuNgayKyHD.SelectedDate;
                        hd.DenNgay            = txtDenNgayKyHD.SelectedDate;
                        hd.IDNguoiDaiDien     = Convert.ToInt32(cboNguoiDaiDien.SelectedValue);
                        hd.IDCoCauToChuc      = Convert.ToInt32(cboDonViLamViec.SelectedValue);
                        hd.DiaDiemLamViec     = txtDiaDiemLamViec.Text;
                        hd.TrinhDoChuyenMon   = txtTrinhDoChuyenMon.Text;
                        hd.IDChucDanhNghiepVu = Convert.ToInt32(cboChucDanhNghiepVu.SelectedValue);
                        hd.IDChucDanhCongViec = Convert.ToInt32(cboChucDanhCongViec.SelectedValue);
                        hd.MucHuong           = Convert.ToInt32(txtMucHuong.Text);
                        hd.IDBacNgach         = Convert.ToInt32(cboBac.SelectedValue);
                        if (txtPhuCapCV.Text != "")
                        {
                            hd.PhuCapCV = Convert.ToDecimal(txtPhuCapCV.Text);
                        }
                        else
                        {
                            hd.PhuCapCV = null;
                        }
                        if (txtMucLuongToiThieu.Text != "")
                        {
                            hd.MucLuongToiThieu = Convert.ToDecimal(txtMucLuongToiThieu.Text);
                        }
                        else
                        {
                            hd.MucLuongToiThieu = null;
                        }
                        if (txtTepDinhKem.UploadedFiles.Count > 0)
                        {
                            string targetFolder = txtTepDinhKem.TargetFolder;
                            hd.TepDinhKem = Path.Combine(Server.MapPath(targetFolder), txtSoHD.Text.Replace("/", "_") + "_" + txtTepDinhKem.UploadedFiles[0].FileName.Replace(" ", "_"));
                        }
                        hd.GhiChu   = txtGhiChu.Text;
                        hd.NguoiTao = hd.NguoiCapNhat = idUser;
                        hd.NgayTao  = hd.NgayCapNhat = DateTime.Now;
                        _entities.AddToHopDongLDs(hd);
                        try
                        {
                            _entities.SaveChanges();
                            LoadGrid();
                            RadWindowManager1.RadAlert("Thêm thông tin thành công", 285, 100, "Thông báo", "");
                        }
                        catch (Exception ex)
                        {
                            RadWindowManager1.RadAlert("Thêm thông tin thất bại", 285, 100, "Lỗi", "");
                            throw ex;
                        }
                    }
                    else
                    {
                        RadWindowManager1.RadAlert("Đã tồn tại số hợp đồng này", 285, 100, "Lỗi", "");
                    }
                }
                else
                {
                    cboNguoiLD.ShowDropDownOnTextboxClick = false;
                    cboNguoiLD.ShowToggleImage            = false;
                    HopDongLD hopDongLD = _entities.HopDongLDs.Where(h => h.IDHopDongLD == idHopDong).FirstOrDefault();
                    hopDongLD.SoHD               = txtSoHD.Text;
                    hopDongLD.NgayKyHD           = txtNgayKyHD.SelectedDate;
                    hopDongLD.IDLoaiHD           = Convert.ToInt32(cboLoaiHD.SelectedValue);
                    hopDongLD.TuNgay             = txtTuNgayKyHD.SelectedDate;
                    hopDongLD.DenNgay            = txtDenNgayKyHD.SelectedDate;
                    hopDongLD.IDNguoiDaiDien     = Convert.ToInt32(cboNguoiDaiDien.SelectedValue);
                    hopDongLD.IDCoCauToChuc      = Convert.ToInt32(cboDonViLamViec.SelectedValue);
                    hopDongLD.DiaDiemLamViec     = txtDiaDiemLamViec.Text;
                    hopDongLD.TrinhDoChuyenMon   = txtTrinhDoChuyenMon.Text;
                    hopDongLD.IDChucDanhNghiepVu = Convert.ToInt32(cboChucDanhNghiepVu.SelectedValue);
                    hopDongLD.IDChucDanhCongViec = Convert.ToInt32(cboChucDanhCongViec.SelectedValue);
                    hopDongLD.MucHuong           = Convert.ToInt32(txtMucHuong.Text);
                    hopDongLD.IDBacNgach         = Convert.ToInt32(cboBac.SelectedValue);
                    if (txtPhuCapCV.Text != "")
                    {
                        hopDongLD.PhuCapCV = Convert.ToDecimal(txtPhuCapCV.Text);
                    }
                    if (txtMucLuongToiThieu.Text != "")
                    {
                        hopDongLD.MucLuongToiThieu = Convert.ToDecimal(txtMucLuongToiThieu.Text);
                    }
                    hopDongLD.GhiChu = txtGhiChu.Text;
                    if (txtTepDinhKem.UploadedFiles.Count > 0)
                    {
                        string targetFolder = txtTepDinhKem.TargetFolder;
                        hopDongLD.TepDinhKem = Path.Combine(Server.MapPath(targetFolder), txtSoHD.Text.Replace("/", "_") + "_" + txtTepDinhKem.UploadedFiles[0].FileName.Replace(" ", "_"));
                    }
                    hopDongLD.NgayCapNhat  = DateTime.Now;
                    hopDongLD.NguoiCapNhat = idUser;
                    try
                    {
                        _entities.SaveChanges();
                        RadWindowManager1.RadAlert("Sửa thông tin thành công", 285, 100, "Thông báo", "");
                        LoadGrid();
                    }
                    catch (Exception ex)
                    {
                        RadWindowManager1.RadAlert("Sửa thông tin thất bại", 285, 100, "Lỗi", "");
                        throw ex;
                    }
                }
                break;

            case "Reset":
                txtSoHD.Text = "/" + DateTime.Now.Year.ToString() + "/HĐLĐ/AITS.";
                txtNgayKyHD.Clear();
                cboLoaiHD.SelectedIndex = -1;
                txtTuNgayKyHD.Clear();
                txtDenNgayKyHD.Clear();
                cboNguoiLD.SelectedIndex          = -1;
                cboChucDanhNghiepVu.SelectedIndex = -1;
                cboChucDanhCongViec.SelectedIndex = -1;
                cboNgach.SelectedIndex            = -1;
                LoadBacNgach(Convert.ToInt32(cboNgach.SelectedValue));
                LoadHeSoBacNgach();
                txtTrinhDoChuyenMon.Text      = "";
                cboDonViLamViec.SelectedIndex = -1;
                txtMucLuongBHXH.Text          = "";
                txtMucHuong.Text              = "100";
                txtPhuCapCV.Text              = "";
                txtMucLuongToiThieu.Text      = "";
                cboNguoiDaiDien.SelectedIndex = -1;
                txtGhiChu.Text = "";
                txtTepDinhKem.UploadedFiles.Clear();
                idHopDong = null;
                break;

            case "Report":
                Session["PrintType"] = "HopDong";
                Response.Redirect("InHD.aspx");
                break;

            case "PhuLuc":
                if (Session["idHD"] != null)
                {
                    Response.Redirect("ThemPhuLucHD.aspx");
                }
                else
                {
                    RadWindowManager1.RadAlert("Chưa chọn hợp đồng", 285, 100, "Lưu ý", null);
                }
                break;
            }
        }