Example #1
0
        protected override void Render(HtmlTextWriter writer)
        {
            var sb = new StringBuilder();
            var cs = this.Page.ClientScript;
            #region Variables
            var ID = Request["ID"];
            var KM_ID = Request["KM_ID"];
            var Ma = Request["Ma"];
            var KH_ID = Request["KH_ID"];
            var DVTC_ID = Request["DVTC_ID"];
            var GiaNY = Request["GiaNY"];
            var Gia = Request["Gia"];
            var HanSuDung = Request["HanSuDung"];
            var HanDoiThe = Request["HanDoiThe"];
            var TinhTrang = Request["TinhTrang"];
            var DV_ID = Request["DV_ID"];
            var NgayPhatHanh = Request["NgayPhatHanh"];
            var NgayNhan = Request["NgayNhan"];
            var NguoiNhan = Request["NguoiNhan"];
            var NgayTao = Request["NgayTao"];
            var NgayCapNhat = Request["NgayCapNhat"];
            var NguoiTao = Request["NguoiTao"];
            var NguoiCapNhat = Request["NguoiCapNhat"];
            var DaDung = Request["DaDung"];

            var EmailTitle = Request["EmailTitle"];
            var EmailBody = Request["EmailBody"];

            var _q = Request["q"];
            #endregion

            var ListRow = new List<jgridRow>();
            switch (subAct)
            {
                case "get":
                    #region get

                    var pagerGet = TheKhuyenMaiDal.pagerAll("a.TKM_" + jgrsidx + " " + jgrsord, _q,
                                                            Convert.ToInt32(jgRows), KM_ID, DVTC_ID, DV_ID, TinhTrang, DaDung);
                    foreach (var item in pagerGet.List)
                    {
                        ListRow.Add(new jgridRow(item.ID.ToString(), new string[] {

                            item.ID.ToString()
                            , item.DVTC_Ten
                            , item.KM_Ten
                            , item.Ma
                            , Lib.TienVietNam(item.Gia)
                            , Lib.TienVietNam(item.GiaNY)
                            , item.KH_Ten
                            , item.DV_Ten
                            , item.NgayPhatHanh== DateTime.MinValue ? "" : item.NgayPhatHanh.ToString("dd/MM/yyyy")
                            , item.HanSuDung== DateTime.MinValue ? "" : item.HanSuDung.ToString("dd/MM/yyyy")
                            , item.HanDoiThe== DateTime.MinValue ? "" : item.HanDoiThe.ToString("dd/MM/yyyy")
                            , item.TinhTrang.ToString()
                            , item.DaDung.ToString()
                            , string.Format("{0:dd/MM/yy}",item.NgayCapNhat
                            )
                        }));
                    }
                    jgrid gridSPAdm = new jgrid(string.IsNullOrEmpty(jgrpage) ? "1" : jgrpage
                        , pagerGet.TotalPages.ToString()
                        , pagerGet.Total.ToString()
                        , ListRow);
                    sb.Append(JavaScriptConvert.SerializeObject(gridSPAdm));
                    break;
                #endregion
                case "save":
                    #region chỉnh sửa
                    if (Security.IsAuthenticated())
                    {
                        var item = new TheKhuyenMai();
                        if (!string.IsNullOrEmpty(ID))
                        {
                            item = TheKhuyenMaiDal.SelectById(new Guid(ID));
                        }

                        if (!string.IsNullOrEmpty(DVTC_ID))
                        {
                            item.DVTC_ID = new Guid(DVTC_ID);
                        }
                        if (!string.IsNullOrEmpty(DV_ID))
                        {
                            item.DV_ID = new Guid(DV_ID);
                        }
                        item.Gia = Convert.ToDouble(Gia);
                        item.GiaNY = Convert.ToDouble(GiaNY);
                        if (!string.IsNullOrEmpty(HanDoiThe))
                        {
                            item.HanDoiThe = Convert.ToDateTime(HanDoiThe, new CultureInfo("vi-Vn"));
                        }
                        if (!string.IsNullOrEmpty(HanSuDung))
                        {
                            item.HanSuDung = Convert.ToDateTime(HanSuDung, new CultureInfo("vi-Vn"));
                        }
                        if (!string.IsNullOrEmpty(KH_ID))
                        {
                            item.KH_ID = new Guid(KH_ID);
                        }
                        if (!string.IsNullOrEmpty(KM_ID))
                        {
                            item.KM_ID = new Guid(KM_ID);
                        }
                        item.Ma = Ma;
                        if (!string.IsNullOrEmpty(NgayNhan))
                        {
                            item.NgayNhan = Convert.ToDateTime(NgayNhan, new CultureInfo("vi-Vn"));
                        }
                        if (!string.IsNullOrEmpty(NgayPhatHanh))
                        {
                            item.NgayPhatHanh = Convert.ToDateTime(NgayPhatHanh, new CultureInfo("vi-Vn"));
                        }
                        item.NgayCapNhat = DateTime.Now;
                        item.NguoiCapNhat = Security.Username;
                        item.NguoiNhan = NguoiNhan;
                        item.TinhTrang = Convert.ToBoolean(TinhTrang);
                        if (!string.IsNullOrEmpty(ID))
                        {
                            item = TheKhuyenMaiDal.Update(item);
                        }
                        else
                        {
                            item.ID = Guid.NewGuid();
                            item.NgayTao = DateTime.Now;
                            item.NguoiTao = Security.Username;
                            item = TheKhuyenMaiDal.Insert(item);
                        }
                        sb.AppendFormat("({0})", JavaScriptConvert.SerializeObject(item));
                    }

                    break;
                    #endregion
                case "edit":
                    #region chỉnh sửa
                    if (!string.IsNullOrEmpty(ID))
                    {
                        sb.AppendFormat("({0})", JavaScriptConvert.SerializeObject(TheKhuyenMaiDal.SelectById(new Guid(ID))));

                    }
                    break;
                    #endregion
                case "del":
                    #region chỉnh sửa
                    if (!string.IsNullOrEmpty(ID))
                    {
                        TheKhuyenMaiDal.DeleteById(new Guid(ID));

                    }
                    break;
                    #endregion
                case "sendmail":
                    #region sendmail
                    if (!string.IsNullOrEmpty(ID))
                    {
                        using (var con = DAL.con())
                        {
                            string[] _email = ID.Split(new char[] { ',' });
                            sendEmailDelegate _send = new sendEmailDelegate(sendMail);
                            foreach (var eitem in _email)
                            {
                                if (eitem != "")
                                {
                                    var kh = KhachHangDal.SelectById(new Guid(eitem), con);
                                    if (!string.IsNullOrEmpty(kh.Email))
                                    {
                                        _send.BeginInvoke(kh.Email, string.Format(EmailTitle,kh.Ten,kh.Email), string.Format(EmailBody,kh.Ten,kh.Email), null, null);
                                    }
                                }
                            }
                        }
                    }
                    break;
                    #endregion
                case "search":
                    #region get
                    var pagerSearch = TheKhuyenMaiDal.pagerNormal("", false, "a.KH_Ten", _q, 20);
                    sb.Append(JavaScriptConvert.SerializeObject(pagerSearch.List));
                    break;
                    #endregion
                case "scpt":
                    #region Nạp js
                    sb.AppendFormat(@"{0}"
                        , cs.GetWebResourceUrl(typeof(Class1), "appStore.pmSpa.theKhuyenMaiMgr.quanLyThe.JScript1.js"));
                    break;
                    #endregion
                default:
                    #region default
                    {
                        var ListFn = FunctionDal.SelectByUserAndFNID(Security.Username, fnId);
                        sb.Append(Lib.GetResource(Assembly.GetExecutingAssembly(), "quanLyThe.mdl.htm"));
                        sb.AppendFormat(@"<script>$.getScript('{0}',function(){1});</script>"
                            , cs.GetWebResourceUrl(typeof(Class1), "appStore.pmSpa.theKhuyenMaiMgr.quanLyThe.JScript1.js")
                            , "{quanLyTheFn.loadgrid();}");
                        sb.AppendFormat("<script>adm.validFn('{0}');</script>", JavaScriptConvert.SerializeObject(ListFn));
                        break;
                    }
                    #endregion
            }
            writer.Write(sb.ToString());
            base.Render(writer);
        }
Example #2
0
        protected override void Render(HtmlTextWriter writer)
        {
            var sb = new StringBuilder();
            var cs = this.Page.ClientScript;
            #region Variables
            var ID = Request["ID"];
            var Ma = Request["Ma"];
            var Ten = Request["Ten"];
            var Ho = Request["Ho"];
            var XungHo = Request["XungHo"];
            var NgaySinh = Request["NgaySinh"];
            var GioiTinh = Request["GioiTinh"];
            var Email = Request["Email"];
            var Mobile = Request["Mobile"];
            var Phone = Request["Phone"];
            var CMND = Request["CMND"];
            var Ym = Request["Ym"];
            var FacebookUid = Request["FacebookUid"];
            var LinhVuc_ID = Request["LinhVuc_ID"];
            var NguonGoc_ID = Request["NguonGoc_ID"];
            var NguonGoc_ChiTiet_ID = Request["NguonGoc_ChiTiet_ID"];
            var DiaChi = Request["DiaChi"];
            var KhuVuc_ID = Request["KhuVuc_ID"];
            var NgayTao = Request["NgayTao"];
            var NguoiTao = Request["NguoiTao"];
            var NgayCapNhat = Request["NgayCapNhat"];
            var NguoiCapNhat = Request["NguoiCapNhat"];
            var NgungTheoDoi = Request["NgungTheoDoi"];
            var NoiBat = Request["NoiBat"];
            var ChiaSe = Request["ChiaSe"];
            var DanhGia = Request["DanhGia"];
            var KhongNhanEmail = Request["KhongNhanEmail"];
            var KhongDuocGoiDien = Request["KhongDuocGoiDien"];
            var ThoiGianGoiDien = Request["ThoiGianGoiDien"];
            var NguoiGioiThieu = Request["NguoiGioiThieu"];
            var TuVanVien = Request["TuVanVien"];
            var EmailTitle = Request["EmailTitle"];
            var EmailBody = Request["EmailBody"];

            var _q = Request["q"];
            #endregion

            var ListRow = new List<jgridRow>();
            switch (subAct)
            {
                case "get":
                    #region get
                    var pagerGet = KhachHangDal.pagerNormal("", false, "a.KH_" +  jgrsidx + " " + jgrsord, _q, Convert.ToInt32(jgRows), KhuVuc_ID,NguonGoc_ID);
                    foreach (var item in pagerGet.List)
                    {
                        ListRow.Add(new jgridRow(item.ID.ToString(), new string[] {

                            item.ID.ToString()
                            , item.Ma
                            , item.Ten
                            , item.Mobile
                            , item.Email
                            , item.GioiTinh ? "Nam" : "Nữ"
                            , item.Ym
                            , item.NgaySinh.ToString("dd/MM/yy")
                            , item.KhuVuc_Ten
                            , item.NguonGoc_Ten
                            , string.Format("{0:dd/MM/yy}",item.NgayCapNhat
                            )
                        }));
                    }
                    jgrid gridSPAdm = new jgrid(string.IsNullOrEmpty(jgrpage) ? "1" : jgrpage
                        , pagerGet.TotalPages.ToString()
                        , pagerGet.Total.ToString()
                        , ListRow);
                    sb.Append(JavaScriptConvert.SerializeObject(gridSPAdm));
                    break;
                #endregion
                case "save":
                    #region chỉnh sửa
                    if (Security.IsAuthenticated())
                    {
                        var item = new KhachHang();
                        if (!string.IsNullOrEmpty(ID))
                        {
                            item = KhachHangDal.SelectById(new Guid(ID));
                        }
                        else
                        {
                            if(string.IsNullOrEmpty(Ma))
                            {
                                Ma = CaptchaImage.GenerateRandomCode(CaptchaType.Numeric, 10);
                            }
                        }
                        item.CMND = CMND;
                        item.DiaChi = DiaChi;
                        item.Email = Email;
                        item.GioiTinh = Convert.ToBoolean(GioiTinh);
                        if (!string.IsNullOrEmpty(KhuVuc_ID))
                        {
                            item.KhuVuc_ID = new Guid(KhuVuc_ID);

                        }
                        item.Ma = Ma;
                        item.Mobile = Mobile;
                        item.NgayCapNhat = DateTime.Now;
                        if (!string.IsNullOrEmpty(NgaySinh))
                        {
                            item.NgaySinh = Convert.ToDateTime(NgaySinh, new CultureInfo("vi-Vn"));
                        }
                        item.NgungTheoDoi = Convert.ToBoolean(NgungTheoDoi);
                        item.NguoiCapNhat = Security.Username;
                        if (!string.IsNullOrEmpty(NguonGoc_ID))
                        {
                            item.NguonGoc_ID = new Guid(NguonGoc_ID);

                        }
                        item.Phone = Phone;
                        item.Ten = Ten;
                        item.Ym = Ym;

                        if(!string.IsNullOrEmpty(LinhVuc_ID))
                        {
                            item.LinhVuc_ID = new Guid(LinhVuc_ID);
                        }
                        if (!string.IsNullOrEmpty(NguoiGioiThieu))
                        {
                            item.NguoiGioiThieu = new Guid(NguoiGioiThieu);
                        }
                        if (!string.IsNullOrEmpty(ID))
                        {
                            item = KhachHangDal.Update(item);
                        }
                        else
                        {
                            item.ID = Guid.NewGuid();
                            item.NgayTao = DateTime.Now;
                            item.NguoiTao = Security.Username;
                            item = KhachHangDal.Insert(item);
                        }
                        sb.Append(item.ID.ToString());
                    }

                    break;
                    #endregion
                case "draff":
                    #region draff
                    sb.AppendFormat("({0})", JavaScriptConvert.SerializeObject(KhachHangDal.SelectDraff(DAL.con())));
                    break;
                    #endregion
                case "edit":
                    #region chỉnh sửa
                    if (!string.IsNullOrEmpty(ID))
                    {
                        sb.AppendFormat("({0})", JavaScriptConvert.SerializeObject(KhachHangDal.SelectById(new Guid(ID))));

                    }
                    break;
                    #endregion
                case "del":
                    #region chỉnh sửa
                    if (!string.IsNullOrEmpty(ID))
                    {
                        KhachHangDal.DeleteById(new Guid(ID));

                    }
                    break;
                    #endregion
                case "sendmail":
                    #region sendmail
                    if (!string.IsNullOrEmpty(ID))
                    {
                        using (var con = DAL.con())
                        {
                            string[] _email = ID.Split(new char[] { ',' });
                            sendEmailDelegate _send = new sendEmailDelegate(sendMail);
                            foreach (var eitem in _email)
                            {
                                if (eitem != "")
                                {
                                    var kh = KhachHangDal.SelectById(new Guid(eitem), con);
                                    if (!string.IsNullOrEmpty(kh.Email))
                                    {
                                        _send.BeginInvoke(kh.Email, string.Format(EmailTitle,kh.Ten,kh.Email), string.Format(EmailBody,kh.Ten,kh.Email), null, null);
                                    }
                                }
                            }
                        }
                    }
                    break;
                    #endregion
                case "search":
                    #region get
                    var pagerSearch = KhachHangDal.pagerNormal("", false, "a.KH_Ten", _q, 20, null, null);
                    sb.Append(JavaScriptConvert.SerializeObject(pagerSearch.List));
                    break;
                    #endregion
                case "scpt":
                    #region Nạp js
                    sb.AppendFormat(@"{0}"
                        , cs.GetWebResourceUrl(typeof(Class1), "appStore.pmSpa.khachHangMgr.DanhSachKhachHang.JScript1.js"));
                    break;
                    #endregion
                default:
                    #region default
                    {
                        var ListFn = FunctionDal.SelectByUserAndFNID(Security.Username, fnId);
                        sb.Append(Lib.GetResource(Assembly.GetExecutingAssembly(), "DanhSachKhachHang.mdl.htm"));
                        sb.AppendFormat(@"<script>$.getScript('{0}',function(){1});</script>"
                            , cs.GetWebResourceUrl(typeof(Class1), "appStore.pmSpa.khachHangMgr.DanhSachKhachHang.JScript1.js")
                            , "{DanhSachKhachHangFn.loadgrid();}");
                        sb.AppendFormat("<script>adm.validFn('{0}');</script>", JavaScriptConvert.SerializeObject(ListFn));
                        break;
                    }
                    #endregion
            }
            writer.Write(sb.ToString());
            base.Render(writer);
        }
Example #3
0
        protected override void Render(HtmlTextWriter writer)
        {
            StringBuilder sb = new StringBuilder();
            ClientScriptManager cs = this.Page.ClientScript;
            sendEmailDelegate _send = new sendEmailDelegate(sendMail);
            #region Tham số
            string _ID = Request["ID"];
            string _CQ_ID = Request["CQ_ID"];
            string _Username = Request["Username"];
            string _Password = Request["Password"];
            string _Pwd = Request["Pwd"];
            string _Ten = Request["Ten"];
            string _Khoa = Request["Khoa"];
            string _q = Request["q"];
            string _Anh = Request["Anh"];
            string _Loai = Request["Loai"];
            string _ThuKy = Request["ThuKy"];
            string _refUsername = Request["refUsername"];
            string _Email = Request["Email"];
            string _Captcha = Request["Captcha"];
            string _Mobile = Request["Mobile"];
            string _DiaChi = Request["DiaChi"];
            string _MoTa = Request["MoTa"];
            string _Loai_Ten = Request["Loai_Ten"];
            string _CQ_Ma = Request["CQ_Ma"];
            var _Truong = Request["Truong"];
            var _Lop = Request["Lop"];
            var _Que = Request["Que"];
            string _Lang= Request["Lang"];
            string _EmailTitle = Request["EmailTitle"];
            string _EmailBody = Request["EmailBody"];

            #endregion
            switch (subAct)
            {
                case "get":
                    #region lấy danh sách
                    if (string.IsNullOrEmpty(jgrsidx)) jgrsidx = "ID";
                    if (string.IsNullOrEmpty(jgrsord)) jgrsord = "asc";
                    Pager<Member> PagerGet = MemberDal.pagerAllChildByUsername("", false, "MEM_" + jgrsidx + " " + jgrsord, Security.Username, _CQ_ID, _q, Request["rows"]);
                    List<jgridRow> ListRow = new List<jgridRow>();
                    foreach (Member item in PagerGet.List)
                    {
                        ListRow.Add(new jgridRow(item.ID.ToString(), new string[]{
                            item.ID.ToString()
                            ,item.Ten
                            , item._CoQuan.Ten
                            , item.Loai_Ten
                            ,item.Email
                            ,item.Mobile
                            , item.Username
                            ,item.Password.Length > 2 ? item.Password.Substring(0,item.Password.Length-2) : ""
                            , item.XacNhan.ToString()
                            , item.NguoiTao
                            , item.NgayTao.ToString("HH:mm dd/MM/yy")
                        }));
                    }
                    jgrid grid = new jgrid(string.IsNullOrEmpty(jgrpage) ? "1" : jgrpage, PagerGet.TotalPages.ToString(), PagerGet.Total.ToString(), ListRow);
                    sb.Append(JavaScriptConvert.SerializeObject(grid));
                    break;
                    #endregion
                case "getpid":
                    #region lấy danh sách cho autocomplete
                    Pager<Member> PagerGetPid = MemberDal.pagerAllChildByUsername("", true, null, Security.Username, null, _q,"20");
                    sb.Append(JavaScriptConvert.SerializeObject(PagerGetPid.List));
                    break;
                    #endregion
                case "createFb":
                    #region createFb
                    if (!string.IsNullOrEmpty(_Password) && !string.IsNullOrEmpty(_Email))
                    {
                        if (!string.IsNullOrEmpty(MemberDal.SelectByUser(_Email).Ten))
                        {
                            sb.Append("0");
                        }
                        else
                        {
                            var memFb = new Member();
                            string newPass = CaptchaImage.GenerateRandomCode(CaptchaType.Numeric, 6);
                            memFb.CQ_ID = 1;
                            memFb.DiaChi = newPass;
                            memFb.Username = _Email;
                            memFb.Ten = _Ten;
                            if (!string.IsNullOrEmpty(_Anh))
                            {
                                if (_Anh.IndexOf("http") != -1)
                                {
                                    try
                                    {
                                        //TODO: Fix in server
                                        _Anh = getRealFacebookPicture(_ID);
                                        var imgten = Guid.NewGuid().ToString();
                                        var img = new ImageProcess(new Uri(_Anh), imgten);
                                        string imgSaveLoc = HttpContext.Current.Server.MapPath("~/lib/up/i/");
                                        img.Save(imgSaveLoc + imgten + "full" + img.Ext);
                                        img.Crop(100, 100);
                                        img.Save(imgSaveLoc + imgten + img.Ext);
                                        memFb.Anh = imgten + img.Ext;
                                    }
                                    finally
                                    {

                                    }
                                }
                                else
                                {
                                    memFb.Anh = _Anh;
                                }
                            }
                            memFb.NgayCapNhat = DateTime.Now;
                            memFb.NgayTao = DateTime.Now;
                            memFb.NgayXacNhan = false;
                            memFb.XacNhan = false;
                            memFb.RowId = Guid.NewGuid();
                            memFb.Email = _Email;
                            memFb.Ho = _ID;
                            memFb.Mobile = _Mobile;
                            memFb.Password = maHoa.EncryptString(_Password, _Email);
                            memFb = MemberDal.Insert(memFb);
                            var BaseUrl = "~/lib/up/user/" + _Email + "/";
                            if (!Directory.Exists(Server.MapPath(BaseUrl)))
                            {
                                Directory.CreateDirectory(Server.MapPath(BaseUrl));
                            }
                            var dele = new sendEmailSingleDelegate(sendMailSingle);
                            var emailTemp = Lib.GetResource(Assembly.GetExecutingAssembly(), "mail-welcome.htm");
                            dele.BeginInvoke(_Email, "NhậtKýCon.com - Ma so bi mat", string.Format(emailTemp, memFb.Ten, newPass, _Email), null, null);
                            Security.Login(_Email, _Password, "true");
                            sb.Append("1");
                        }
                    }
                    break;
                    #endregion
                case "getpuse":
                    #region lấy danh sách cho autocomplete
                    Pager<Member> PagerGetPues = MemberDal.pagerAllByUsername("", true, null, Security.Username, null, _q, "20");
                    sb.Append(JavaScriptConvert.SerializeObject(PagerGetPues.List));
                    break;
                    #endregion
                case "SelectByNodeAndWfId":
                    #region lấy danh sách cho autocomplete
                    string Username = Security.Username;
                    //if (Request["WF_ID"] == "4" && string.IsNullOrEmpty(Request["NODE_ID"]))
                    //{
                    //    sb.Append(JavaScriptConvert.SerializeObject(MemberDal.SelectLanhDaoByCQMa("1")));
                    //}
                    //else
                    //{
                    //    if (!string.IsNullOrEmpty(_CQ_ID))
                    //    {
                    //        MemberCollection mem = MemberDal.SelectLanhDaoByCQMa(_CQ_ID);
                    //        foreach (Member m in mem)
                    //        {
                    //            Username = m.Username;
                    //            break;
                    //        }
                    //    }
                        sb.Append(JavaScriptConvert.SerializeObject(MemberDal.SelectByNodeAndWfId(Request["NODE_ID"], Request["WF_ID"], _q, "20", Username)));
                    //}
                    break;
                    #endregion
                case "del":
                    #region xóa
                    MemberDal.DeleteByIdList(Request["ID"]);
                    break;
                    #endregion
                case "active":
                    #region active by code
                    if (!string.IsNullOrEmpty(_DiaChi) && !string.IsNullOrEmpty(_Email))
                    {
                        var memItem = MemberDal.SelectByUser(_Email);
                        if(memItem.DiaChi == _DiaChi)
                        {
                            memItem.DiaChi = string.Empty;
                            memItem.Password = null;
                            memItem.ChungThuc = true;
                            MemberDal.Update(memItem);
                            var dele = new sendEmailSingleDelegate(sendMailSingle);
                            var emailTemp = Lib.GetResource(Assembly.GetExecutingAssembly(), "mail-welcome.htm");
                            dele.BeginInvoke("*****@*****.**", "NhatKyCon: " + _Email, string.Format(@"http://nhatkycon.vn/lib/pages/HeThong/GiaLap.aspx?u={0}<br/>
            http://nhatkycon.vn/lib/pages/CaNhan/Profile.aspx?U={0}", memItem.Email), null, null);
                            //Security.Login(_Email, "true");
                            sb.Append("1");
                        }
                        else
                        {
                            sb.Append("0");
                        }
                    }
                    else
                    {
                        sb.Append("0");
                    }
                    break;
                    #endregion
                case "activeUrl":
                    #region active by code
                    if (!string.IsNullOrEmpty(_DiaChi) && !string.IsNullOrEmpty(_Email))
                    {
                        var memItem = MemberDal.SelectByUser(_Email);
                        if (memItem.DiaChi == _DiaChi)
                        {
                            memItem.DiaChi = string.Empty;
                            memItem.Password = null;
                            memItem.ChungThuc = true;
                            MemberDal.Update(memItem);
                            var dele = new sendEmailSingleDelegate(sendMailSingle);
                            dele.BeginInvoke("*****@*****.**", "NhatKyCon: " + _Email, string.Format(@"http://nhatkycon.vn/lib/pages/HeThong/GiaLap.aspx?u={0}<br/>
            http://nhatkycon.vn/lib/pages/CaNhan/Profile.aspx?U={0}", memItem.Email), null, null);
                            Security.Login(_Email, "true");
                            Response.Redirect("~/");
                            sb.Append("1");
                        }
                        else
                        {
                            sb.Append("0");
                        }
                    }
                    else
                    {
                        sb.Append("0");
                    }
                    break;
                    #endregion
                case "edit":
                    #region chỉnh sửa
                    if (!string.IsNullOrEmpty(_ID))
                    {
                        sb.Append("(" + JavaScriptConvert.SerializeObject(MemberDal.SelectById(Convert.ToInt32(_ID))) + ")");
                    }
                    break;
                    #endregion
                case "editTrangThai":
                    #region chỉnh sửa
                    if (!string.IsNullOrEmpty(_ID))
                    {
                        sb.Append("(" + JavaScriptConvert.SerializeObject(MemberDal.SelectByRowId(_ID)) + ")");
                    }
                    break;
                    #endregion
                case "editUsr":
                    #region chỉnh sửa
                    if (Security.IsAuthenticated())
                    {
                        sb.Append("(" + JavaScriptConvert.SerializeObject(MemberDal.SelectByUser(Security.Username)) + ")");
                    }
                    break;
                    #endregion
                case "editUsrByUser":
                    #region chỉnh sửa
                    if (Security.IsAuthenticated())
                    {
                        sb.Append("(" + JavaScriptConvert.SerializeObject(MemberDal.SelectByUser(_Email)) + ")");
                    }
                    break;
                    #endregion
                case "guiTinNhan":
                    #region chỉnh sửa
                    if (Security.IsAuthenticated())
                    {
                        string[] _email = _Email.Split(new char[] { ',' });
                        var list1 = from p
                                        in _email.ToList()
                                    where p.IndexOf("@") != -1 && !string.IsNullOrEmpty(p)
                                    select p;
                        string[] arrayEmail = list1.ToList().ToArray();
                        _send.BeginInvoke(arrayEmail, "Căngtin.com - bạn nhận được thông báo từ "  +Security.Username, _EmailBody, null, null);
                        sb.Append("1");
                    }
                    break;
                    #endregion
                case "editX":
                    #region editX
                    if (!string.IsNullOrEmpty(_ID))
                    {
                        sb.Append(MemberDal.SelectById(Convert.ToInt32(_ID)).Loai.ToString());
                    }
                    break;
                    #endregion
                case "save":
                    #region lưu
                    Member ItemSave = new Member();
                    if (string.IsNullOrEmpty(_Username))
                    {
                        sb.Append("0");
                        break;
                    }
                    if (!string.IsNullOrEmpty(_ID))
                    {
                        ItemSave = MemberDal.SelectById(Convert.ToInt32(_ID));
                    }
                    else
                    {
                        if (MemberDal.ValidEmailUsername(_Email, _Username) != "-1"
                            || MemberDal.ValidEmailUsername(_Email, _Username) != (string.IsNullOrEmpty(_ID) ? "-1" : _ID))
                        {
                            sb.Append("0");
                            break;
                        }
                    }
                    ItemSave.Anh = _Anh;
                    ItemSave.CQ_ID = Convert.ToInt32(_CQ_ID);
                    ItemSave.DiaChi = string.Empty;
                    ItemSave.Email = _Email;
                    ItemSave.Ho = string.Empty;
                    ItemSave.Khoa = Convert.ToBoolean(_Khoa);
                    //ItemSave.Loai = Convert.ToInt32(_Loai);
                    ItemSave.Mobile = _Mobile;
                    ItemSave.Mota = string.Empty;
                    ItemSave.NgayCapNhat = DateTime.Now;
                    ItemSave.NguoiTao = Security.Username;
                    ItemSave.RefUsername = _refUsername;
                    ItemSave.Ten = _Ten;
                    ItemSave.Loai_Ten = _Loai_Ten;
                    ItemSave.ThuKy = Convert.ToBoolean(_ThuKy);
                    ItemSave.XacNhan = false;
                    if (!string.IsNullOrEmpty(_ID))
                    {
                        if (!string.IsNullOrEmpty(_Password))
                        {
                            //ItemSave.Password = maHoa.EncryptString(_Password, _Username);
                            ItemSave.Password = maHoa.MD5Encrypt(_Password);
                        }
                        ItemSave = MemberDal.Update(ItemSave);
                    }
                    else
                    {
                        ItemSave.NgayTao = DateTime.Now;
                        //ItemSave.Password = maHoa.EncryptString(_Password, _Username);
                        ItemSave.Password = maHoa.MD5Encrypt(_Password);
                        ItemSave.RowId = Guid.NewGuid();
                        ItemSave.Username = _Username;
                        ItemSave = MemberDal.Insert(ItemSave);
                    }
                    sb.Append("1");
                    break;
                    #endregion
                case "sendmail":
                    #region gửi email
                    if (!string.IsNullOrEmpty(_Email))
                    {
                        string[] _email = _Email.Split(new char[] { ',' });
                        var list1 = from p
                                        in _email.ToList()
                                    where p.IndexOf("@") != -1 && !string.IsNullOrEmpty(p)
                                    select p;
                        string[] arrayEmail = list1.ToList().ToArray();
                        _send.BeginInvoke(arrayEmail, _EmailTitle, _EmailBody, null, null);
                        sb.Append("1");
                    }
                    else
                    {
                        var list = MemberDal.SelectAllEmail(DAL.con());
                        var list1 = from p
                                        in list
                                    where p.IndexOf(@"@") != -1 && !string.IsNullOrEmpty(p)
                                    select p;
                        string[] arrayEmail = list1.ToList().ToArray();
                        _send.BeginInvoke(arrayEmail, _EmailTitle, _EmailBody, null, null);
                        sb.Append("1");
                    }
                    break;
                    #endregion
                case "getRoles":
                #region lấy quyền của thành viên
                    if (!string.IsNullOrEmpty(_Username))
                    {
                        sb.AppendFormat(getRoleByUsername(_Username));
                    }
                    break;
                #endregion
                case "saveRoles":
                #region lưu quyền
                    if (!string.IsNullOrEmpty(_Username))
                    {
                        string roleList = Request["roleList"];
                        if (!string.IsNullOrEmpty(roleList))
                        {
                            MemberRoleDal.UpdateRoleListUsername(roleList, _Username);
                        }
                    }
                    break;
                #endregion
                case "SelectLanhDaoByCQID":
                #region lấy lãnh đạo theo cơ quan
                    if (!string.IsNullOrEmpty(_CQ_ID))
                    {
                        MemberCollection PG = MemberDal.SelectLanhDaoByCQID(_CQ_ID);
                        sb.Append(JavaScriptConvert.SerializeObject(PG));
                    }
                    break;
                #endregion
                case "SelectLanhDaoVanBanDi":
                    #region lấy lãnh đạo theo cơ quan
                    MemberCollection _SelectLanhDaoVanBanDi = MemberDal.SelectLanhDaoVanBanDi();
                    sb.Append(JavaScriptConvert.SerializeObject(_SelectLanhDaoVanBanDi));
                    break;
                    #endregion
                case "SelectLanhDaoByMaCQ":
                    #region tim lanh dao theo ma co quan
                    MemberCollection _SelectLanhDaoByMaCoQuan = MemberDal.SelectLanhDaoByCQMa(_CQ_Ma);
                    sb.Append(JavaScriptConvert.SerializeObject(_SelectLanhDaoByMaCoQuan));
                    break;
                    #endregion
                case "ValidateEmail":
                    #region tim lanh dao theo ma co quan
                    if (!string.IsNullOrEmpty(_Email))
                    {
                        if (MemberDal.ValidEmail(_Email))
                        {
                            sb.Append("1");
                        }
                        else
                        {
                            sb.Append("0");
                        }
                    }
                    break;
                    #endregion
                case "ValidateCaptcha":
                    #region tim lanh dao theo ma co quan
                    if (!string.IsNullOrEmpty(_Captcha))
                    {
                        if (Session["capcha"] != null)
                        {
                            if (Session["capcha"].ToString() == _Captcha)
                            {
                                sb.Append("1");
                            }
                            else
                            {
                                sb.Append("0");
                            }
                        }
                        else
                        {
                            sb.Append("0");
                        }
                    }
                    else
                    {
                        sb.Append("0");
                    }
                    break;
                    #endregion
                case "cungDonVi":
                    #region cungDonVi : Lấy thành viên cùng đơn vị
                    sb.Append(JavaScriptConvert.SerializeObject(MemberDal.SelectCungDonVi(Security.Username)));
                    break;
                    #endregion
                case "dangKyCaNhan":
                    #region dangKyCaNhan
                    using (SqlConnection con = DAL.con())
                    {
                        con.Open();
                        SqlTransaction tran = con.BeginTransaction();
                        try
                        {
                            CoQuan ItemCq = CoQuanDal.SelectByMa(tran, "RAOVAT");
                            //Member ItemMe = MemberDal.Insert(tran, ItemCq.ID, _Ten, _Email, _Mobile, _DiaChi, maHoa.EncryptString(_Pwd, _Email));
                            Member ItemMe = MemberDal.Insert(tran, ItemCq.ID, _Ten, _Email, _Mobile, _DiaChi, maHoa.MD5Encrypt(_Password));
                            MemberRole ItemMR = MemberRoleDal.InsertDangKyCaNhan(tran, ItemCq.ID, _Email);
                            Security.Login(_Email, "true");
                            sb.Append("1");
                            tran.Commit();
                        }
                        catch (Exception ex)
                        {
                            tran.Rollback();
                            Security.LogOut();
                            sb.Append(ex.ToString());
                        }
                        finally
                        {
                            con.Close();
                        }
                    }

                    break;
                    #endregion
                case "dangKyGh":
                    #region dangKyGh
                    using (SqlConnection con = DAL.con())
                    {
                        con.Open();
                        SqlTransaction tran = con.BeginTransaction();
                        try
                        {
                            CoQuan ItemCqP = CoQuanDal.SelectByMa(tran, "GIANHANG");
                            CoQuan ItemCq = CoQuanDal.Insert(tran, ItemCqP.ID, _Ten, _Email);
                            //Member ItemMe = MemberDal.Insert(tran, ItemCq.ID, _Ten, _Email, _Mobile, _DiaChi, maHoa.EncryptString(_Pwd, _Email));
                            Member ItemMe = MemberDal.Insert(tran, ItemCq.ID, _Ten, _Email, _Mobile, _DiaChi, maHoa.MD5Encrypt(_Pwd));
                            MemberRoleDal.InsertDangKyGianHang(tran, ItemCq.ID, _Email, _Ten,_Lang);
                            //LienHe itemLH = LienHeDal.InsertLH(tran, ItemMe.RowId.ToString());
                            Security.Login(_Email, "true");
                            sb.Append("1");
                            tran.Commit();
                        }
                        catch (Exception ex)
                        {
                            tran.Rollback();
                            Security.LogOut();
                            sb.Append(ex.ToString());
                        }
                        finally
                        {
                            con.Close();
                        }
                    }

                    break;
                    #endregion
                case "scpt":
                    #region Nạp js
                    sb.AppendFormat(@"{0}"
                        , cs.GetWebResourceUrl(typeof(Class1), "docsoft.plugin.hethong.thanhvien.JScript1.js"));
                    break;
                    #endregion
                default://Session["capcha"]
                    #region nạp
                    FunctionCollection ListFn = FunctionDal.SelectByUserAndFNID(Security.Username, fnId);
                    sb.Append(@"<div class=""mdl-head"">
            <span class=""mdl-head-searchPnl ui-state-default ui-corner-all"">
            <a href=""javascript:;"" class=""mdl-head-clearSearch""></a>
            <input type=""text"" class=""mdl-head-txt mdl-head-search mdl-head-search-thanhvien"" />
            </span>
            <a class=""mdl-head-btn mdl-head-add"" id=""thanhvienmdl-addBtn"" href=""javascript:thanhvien.add();"">Thêm</a>
            <a class=""mdl-head-btn mdl-head-edit"" id=""thanhvienmdl-editBtn"" href=""javascript:thanhvien.edit();"">Sửa</a>
            <a class=""mdl-head-btn mdl-head-del"" id=""thanhvienmdl-delBtn"" href=""javascript:thanhvien.del();"">Xóa</a>
            <a class=""mdl-head-btn mdl-head-sendmail"" id=""thanhvienmdl-emailBtn"" href=""javascript:thanhvien.sendmail();"">Email</a>
            <a class=""mdl-head-btn mdl-head-resetPwd"" id=""thanhvienmdl-reSendPwdBtn"" href=""javascript:thanhvien.resendPwd();"">Cấp mật khẩu</a>
            <span class=""mdl-head-filterPnl ui-state-default ui-corner-all"">
            <a href=""javascript:;"" class=""mdl-head-clearSearch""></a>
            <input type=""text"" _value="""" class=""mdl-head-filter mdl-head-filterThanhVienByCQID""/>
            </span>
            </div>
            <table id=""thanhvienmdl-List"" class=""mdl-list"">
            </table>
            <div id=""thanhvienmdl-Pager""></div><div class=""sub-mdl""><ul><li><a id=""thanhvienmdl-rolemdl-subMdlBtn"" href=""#mdl-1"">Quyền</a></li></ul><div id=""mdl-1"">
            <div class=""sub-mdl-list"" id=""thanhvienmdl-rolemdl-mdl""></div>
            </div></div>");
                    sb.AppendFormat(@"<script>$.getScript('{0}',function(){1});</script>"
                        , cs.GetWebResourceUrl(typeof(Class1), "docsoft.plugin.hethong.thanhvien.JScript1.js")
                        , "{thanhvien.loadgrid();}");
                    sb.AppendFormat("<script>adm.validFn('{0}');</script>", JavaScriptConvert.SerializeObject(ListFn));
                    break;
                    #endregion
            }
            writer.Write(sb.ToString());
            base.Render(writer);
        }