Beispiel #1
0
    protected void btnCapNhat_Click(object sender, DirectEventArgs e)
    {
        try
        {
            LinqProvider         linq         = new LinqProvider();
            DanhSachCaController dsController = new DanhSachCaController();
            DAL.DanhSachCa       ca           = new DAL.DanhSachCa();
            if (e.ExtraParams["Command"] == "Edit")
            {
                ca = linq.GetDataContext().DanhSachCas.Where(t => t.ID == int.Parse(hdfRecordID.Text)).FirstOrDefault();
            }
            else
            {
                string lyDo = "";
                if (KiemTraTrungNgayNghiLe(txtMaCa.Text, ref lyDo))
                {
                    X.Msg.Alert("Thông báo từ hệ thống", lyDo + " Vui lòng nhập mã ca khác!").Show();
                    return;
                }
            }
            ca.MaCa  = txtMaCa.Text;
            ca.TenCa = txtTenCa.Text;
            if (txtPhuCapCa.Text != "")
            {
                ca.PhuCapCa = double.Parse(txtPhuCapCa.Text.Replace('.', ','));
            }
            if (txtLuongCuaCa.Text != "")
            {
                ca.TienLuongCa = double.Parse(txtLuongCuaCa.Text.Replace('.', ','));
            }
            if (txtTongSoGio.Text != "")
            {
                ca.TongGio = double.Parse(txtTongSoGio.Text.Replace('.', ','));
            }
            ca.LoaiCa = int.Parse("0" + hdfLoaiCa.Text);
            //   ca.NgayApDung = cbxNgayApDung.SelectedItem.Value;
            //
            ca.GioVao     = GetTime(tfBatDauCa.Text);
            ca.GioRa      = GetTime(tfKetThucCaSau.Text);
            ca.NghiGiuaCa = GetTime(tfNghiNuaCaDau.Text);
            ca.VaoGiuaCa  = GetTime(tfBatDauCaSau.Text);
            //ca.BatDauTinhLamThemDauGio = GetTime(tfBatDauLamThemDauGio.Text);
            //ca.BatDauTinhLamThemCuoiGio = GetTime(tfBatDauLamThemCuoiGio.Text);
            //
            ca.RaNgoaiKhongBiTruGio = chkRaNgoaiKhongBiTruGio.Checked;
            //
            ca.BatDauQuetTheLan1  = GetTime(tfDauCaTu.Text);
            ca.KetThucQuetTheLan1 = GetTime(tfDauCaDen.Text);
            ca.BatDauQuetTheLan2  = GetTime(tfGiuaCaRaTu.Text);
            ca.KetThucQuetTheLan2 = GetTime(tfGiuaCaRaDen.Text);
            ca.BatDauQuetTheLan3  = GetTime(tfGiuaCaVaoTu.Text);
            ca.KetThucQuetTheLan3 = GetTime(tfGiuaCaVaoDen.Text);
            ca.BatDauQuetTheLan4  = GetTime(tfCuoiCaTu.Text);
            ca.KetThucQuetTheLan4 = GetTime(tfCuoiCaDen.Text);
            //
            //if (!SoftCore.Util.GetInstance().IsDateNull(dfApDungTu.SelectedDate))
            //    ca.ThoiGianApDungTu = dfApDungTu.SelectedDate;
            //if (!SoftCore.Util.GetInstance().IsDateNull(dfApDungDen.SelectedDate))
            //    ca.ThoiGianApDungDen = dfApDungDen.SelectedDate;
            //
            if (txtSoPhutChoPhepDiMuon.Text != "")
            {
                ca.SoPhutChoPhepDiMuon = double.Parse(txtSoPhutChoPhepDiMuon.Text);
            }
            if (txtSoPhutChoPhepVeSom.Text != "")
            {
                ca.SoPhutChoPhepVeSom = double.Parse(txtSoPhutChoPhepVeSom.Text);
            }
            ca.DangSuDung = chkDangSuDung.Checked;
            //
            ca.MaDonVi     = Session["MaDonVi"].ToString();
            ca.CreatedBy   = CurrentUser.ID;
            ca.CreatedDate = DateTime.Now;

            if (e.ExtraParams["Command"] == "Edit")
            {
                ca.ID = int.Parse(hdfRecordID.Text);
                dsController.Update(ca);
                Dialog.ShowNotification("Cập nhật dữ liệu thành công!");
                grp_DanhSachCa.Reload();
                wdThemCaLamViec.Hide();
            }
            else
            {
                DAL.DanhSachCa tmp = dsController.GetOneByMaCa(ca.MaCa);
                if (tmp != null)
                {
                    X.Msg.Alert("Thông báo", "Mã ca đã tồn tại. Vui lòng nhập mã ca khác!").Show();
                    return;
                }
                dsController.Insert(ca);
                Dialog.ShowNotification("Thêm mới thành công ca!");
                grp_DanhSachCa.Reload();
            }
            if (e.ExtraParams["Closed"] == "True")
            {
                wdThemCaLamViec.Hide();
            }
            else
            {
                ResourceManager1.RegisterClientScriptBlock("rl1f", "resetForm();");
            }
        }
        catch (Exception ex)
        {
            X.Msg.Alert("Thông báo", "Có lỗi xảy ra: " + ex.Message).Show();
        }
    }
Beispiel #2
0
    protected void btnTaoTaiKhoan_Click(object sender, DirectEventArgs e)
    {
        try
        {
            string[]       tmp          = hdfJsonData.Text.Replace("[", "").Replace("]", "").Replace("},", "#").Split('#');
            HoSoController hsController = new HoSoController();
            LinqProvider   linq         = new LinqProvider();
            string         email        = string.Empty;
            string         password     = string.Empty;
            if (Checkbox1.Checked)
            {
                HeThongController ht          = new HeThongController();
                object            objEmail    = ht.GetValueByName(SystemConfigParameter.EMAIL, Session["MaDonVi"].ToString());
                object            objPassword = ht.GetValueByName(SystemConfigParameter.PASSWORD_EMAIL, Session["MaDonVi"].ToString());
                if (objEmail != null)
                {
                    email = objEmail.ToString();
                }
                if (objPassword != null)
                {
                    password = objPassword.ToString();
                }
            }
            int countDuplicate = 0;
            int success        = 0;
            foreach (var item in tmp)
            {
                try
                {
                    DAL.HOSO hs = linq.GetDataContext().HOSOs.Where(t => t.MA_CB == Util.GetInstance().Getproperties(item, "UserID")).FirstOrDefault();//hsController.GetByMaCB(Util.GetInstance().Getproperties(item, "UserID"));
                    if (hs == null)
                    {
                        continue;
                    }
                    UserInfo uInfo = new UserInfo()
                    {
                        Gender      = hs.MA_GIOITINH == "M" ? true : false,
                        Address     = hs.DIA_CHI_LH,
                        Birthday    = hs.NGAY_SINH,
                        DisplayName = hs.HO_TEN,
                        Image       = "",
                        CreatedBy   = CurrentUser.ID,
                        CreatedOn   = DateTime.Now,
                        EdittedBy   = CurrentUser.ID,
                        EdittedOn   = DateTime.Now,
                        IsLock      = false,
                        Email       = hs.EMAIL,
                        IsSuperUser = false,
                        Phone       = hs.DI_DONG,
                        FirstName   = hs.HO_CB,
                        LastName    = hs.TEN_CB,
                        Password    = Util.GetInstance().Getproperties(item, "Password"),
                        UserName    = Util.GetInstance().Getproperties(item, "UserName"),
                    };
                    int uID = UsersController.GetInstance().CreateUser(uInfo);
                    if (uID > 0)
                    {
                        hs.UserID = uID;
                        linq.Save();

                        //Gán quyền cho người dùng
                        foreach (var roleItem in CheckboxSelectionModelRoleList.SelectedRows)
                        {
                            UsersController.GetInstance().SetRoles(uID, int.Parse(roleItem.RecordID));
                        }

                        new DM_DONVIController().AddUserIntoDonVi(hdfMaDonViOfCurrentUser.Text, uID);

                        //Gửi email thông báo
                        if (Checkbox1.Checked && string.IsNullOrEmpty(hs.EMAIL) == false)
                        {
                            string content = GlobalResourceManager.GetInstance().GetLanguageValue("NotifyUserName");
                            Email.SendEmail(email, password, "Thông báo mật khẩu", hs.EMAIL, "Thông báo mật khẩu", string.Format(content, uInfo.UserName, uInfo.Password));
                        }
                    }
                    success++;
                }
                catch (Exception ex)
                {
                    if (ex.Message.ToLower().Contains("duplicate key"))
                    {
                        countDuplicate++;
                    }
                }
            }
            wdTaoTaiKhoanNhanVien.Hide();
            string notifies = "";
            if (success > 0)
            {
                notifies += "Tạo tài khoản thành công cho " + success + " cán bộ.";
            }
            if (countDuplicate > 0)
            {
                notifies += " Có " + countDuplicate + " tài khoản đã tồn tại.";
            }
            X.Msg.Alert("Thông báo từ hệ thống", notifies).Show();
            ReloadStore();
        }
        catch (Exception ex)
        {
            Dialog.ShowError(ex.Message);
        }
    }