コード例 #1
0
        private void Login()
        {
            try
            {
                // @TrườngNX on 20120905
                // Lựa chọn ngôn ngữ của phiên làm việc
                // Căn cứ vào ngôn ngữ, load file language resources tương ứng
                //this.Cursor = Cursors.Wait;

                //var process = new ZAMainAppProcess();
                string userName = txtUsername.Text;
                string txtMD5   = LSecurity.MD5Encrypt(txtPassword.Password);
                //process.createSession();
                string       responseMessage = "";
                NGON_NGU_DTO ngonNguDTO      = null;
                bool         ret             = process.doLoginWithSession(userName, txtMD5, ref ngonNguDTO, ref responseMessage);

                // Nếu thành công
                if (ret)
                {
                    // Nếu yêu cầu cập nhật phiên bản
                    if (responseMessage != null &&
                        responseMessage.Equals(ApplicationConstant.CommonResponseMessage.M_ResponseMessage_Common_NotLatestVersion.layGiaTri())
                        )
                    {
                        //MessageBoxResult retQuestion = LMessage.ShowMessage(responseMessage, LMessage.MessageBoxType.Question);
                        //if (retQuestion == MessageBoxResult.Yes)
                        //{
                        //    // Cập nhật phiên bản
                        //}
                        //else
                        //{
                        //}

                        MessageBoxResult retMessage = LMessage.ShowMessage(responseMessage, LMessage.MessageBoxType.Question);
                        if (retMessage == MessageBoxResult.Yes)
                        {
                            UserControl p             = null;
                            bool        stretchWindow = false;
                            p = new PresentationWPF.QuanTriHeThong.PhienBan.ucPhienBanCapNhat();

                            if (p != null)
                            {
                                Window window = new Window
                                {
                                    Title = LLanguage.SearchResourceByKey("MENU.152_CAP_NHAT_PB"),
                                    WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen,
                                    //Icon = (rmb.ImageSource == null ? this.Icon : rmb.ImageSource),
                                    Width   = (Double.IsNaN(p.Width) ? 1024 : p.Width),
                                    Height  = (Double.IsNaN(p.Height) ? 700 : p.Height),
                                    Content = p,
                                };
                                if (stretchWindow == true)
                                {
                                    window.WindowState = WindowState.Maximized;
                                }
                                window.Width      = 500;
                                window.Height     = 150;
                                window.ResizeMode = ResizeMode.NoResize;

                                //Mouse.OverrideCursor = Cursors.Arrow;
                                this.Close();
                                window.ShowDialog();
                            }
                            else
                            {
                                Mouse.OverrideCursor = Cursors.Arrow;
                                LMessage.ShowMessage("Không tìm thấy chức năng này", LMessage.MessageBoxType.Warning);
                            }
                        }
                    }

                    ClientInformation.NgonNgu = ((RadComboBoxItem)cboLanguage.SelectedItem).Tag.ToString();

                    // @Truonglq set Culture ngôn ngữ cho  Coltrol (telerik)
                    //CultureInfo culture = new CultureInfo(((RadComboBoxItem)cboLanguage.SelectedItem).Tag.ToString());
                    //System.Threading.Thread.CurrentThread.CurrentCulture = culture;
                    //System.Threading.Thread.CurrentThread.CurrentUICulture = culture;
                    InitializeCultures();
                    //InitializeCulturesTelerik();
                    LocalizationManager.Manager = new LocalizationManager()
                    {
                        ResourceManager = LocalizationRadControl.ResourceManager
                    };

                    // Khởi tạo phiên làm việc, chọn đơn vị nghiệp vụ cần thao tác dữ liệu
                    if (!ClientInformation.LoaiNguoiSuDung.Equals(BusinessConstant.LoaiNguoiSuDung.CAP_SA.layGiaTri()))
                    {
                        InitSession initSession = new InitSession(ClientInformation.ListPhongGD);

                        initSession.ResizeMode            = ResizeMode.NoResize;
                        initSession.Height                = 250;
                        initSession.Width                 = 600;
                        initSession.WindowStartupLocation = WindowStartupLocation.CenterScreen;

                        initSession.lblNguoiDungValue.Content = "(" + ClientInformation.TenDangNhap + ") " + ClientInformation.HoTen;
                        initSession.lblChiNhanhValue.Content  = "(" + ClientInformation.MaDonVi + ") " + ClientInformation.TenDonVi;
                        //initSession.ListPhongGD = ClientInformation.ListPhongGD;

                        initSession.Show();
                        this.Cursor = Cursors.Arrow;
                        Close();
                    }
                    else
                    {
                        ClientInformation.TenDonViGiaoDich   = ClientInformation.TenDonVi;
                        ClientInformation.MaDonViGiaoDich    = ClientInformation.MaDonVi;
                        ClientInformation.IdDonViGiaoDich    = ClientInformation.IdDonVi;
                        ClientInformation.PhuongPhapHachToan = null;

                        MainWindow mainwindow = new MainWindow();
                        mainwindow.Show();
                        this.Cursor = Cursors.Arrow;
                        Close();
                    }
                }
                else
                {
                    ImageBehavior.SetAnimatedSource(imgWaiting, null);

                    // Nếu yêu cầu đổi mật khẩu
                    if (responseMessage != null &&
                        (
                            responseMessage.Equals(ApplicationConstant.LoginResponseMessage.M_ResponseMessage_Login_YeuCauDoiMatKhauLanDau.layGiaTri()) ||
                            responseMessage.Equals(ApplicationConstant.LoginResponseMessage.M_ResponseMessage_Login_YeuCauDoiMatKhau.layGiaTri())
                        )
                        )
                    {
                        MessageBoxResult retQuestion = LMessage.ShowMessage(responseMessage, LMessage.MessageBoxType.Question);
                        if (retQuestion == MessageBoxResult.Yes)
                        {
                            txtPassword.Clear();

                            ChangePassword changePassword = new ChangePassword();
                            Window         window         = new Window();

                            window.ResizeMode            = ResizeMode.NoResize;
                            window.Height                = 180;
                            window.Width                 = 500;
                            window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                            window.Title                 = LLanguage.SearchResourceByKey("U.ZAMainApp.ChangePassword.Title");
                            window.Content               = changePassword;

                            changePassword.userName = userName;
                            window.ShowDialog();
                            //LMessage.ShowMessage("Change pass", LMessage.MessageBoxType.Warning);
                        }
                        else
                        {
                            return;
                        }
                    }
                    else
                    {
                        LMessage.ShowMessage(responseMessage, LMessage.MessageBoxType.Warning);
                    }
                }
            }
            //else
            catch (Exception ex)
            {
                ImageBehavior.SetAnimatedSource(imgWaiting, null);

                //this.Close();
                //Application.Current.Shutdown();
                this.Cursor = Cursors.Arrow;
                if (ex.GetType() == typeof(CustomException))
                {
                    new frmThongBaoLoi(ex.Message, ex.InnerException).ShowDialog();
                }
                else
                {
                    if (ex.InnerException != null)
                    {
                        if (ex.InnerException.GetType() == typeof(CustomException))
                        {
                            new frmThongBaoLoi(ex.InnerException.Message, ex.InnerException).ShowDialog();
                        }
                        else
                        {
                            new frmThongBaoLoi("M.ResponseMessage.Login.KhongThanhCong", ex).ShowDialog();
                        }
                    }
                    else
                    {
                        new frmThongBaoLoi("M.ResponseMessage.Login.KhongThanhCong", ex).ShowDialog();
                    }
                }
                LLogging.WriteLog(System.Reflection.MethodInfo.GetCurrentMethod().ToString(), LLogging.LogType.ERR, ex);
            }
        }
コード例 #2
0
        private void Login()
        {
            try
            {
                // @TrườngNX on 20120905
                // Lựa chọn ngôn ngữ của phiên làm việc
                // Căn cứ vào ngôn ngữ, load file language resources tương ứng
                //this.Cursor = Cursors.Wait;

                //var process = new ZAMainAppProcess();
                string userName = txtUsername.Text;
                string txtMD5   = LSecurity.MD5Encrypt(txtPassword.Password);
                //process.createSession();
                string       responseMessage = "";
                NGON_NGU_DTO ngonNguDTO      = null;
                bool         ret             = process.doLoginWithSession(userName, txtMD5, ref ngonNguDTO, ref responseMessage);

                LLogging.WriteLog(System.Reflection.MethodInfo.GetCurrentMethod().ToString(), LLogging.LogType.ERR, "ret value: " + ret.ToString());
                LLogging.WriteLog(System.Reflection.MethodInfo.GetCurrentMethod().ToString(), LLogging.LogType.ERR, "responseMessage value: " + responseMessage);
                // Nếu thành công
                if (ret)
                {
                    // Nếu yêu cầu cập nhật phiên bản
                    if (responseMessage != null &&
                        responseMessage.Equals(ApplicationConstant.CommonResponseMessage.M_ResponseMessage_Common_NotLatestVersion.layGiaTri())
                        )
                    {
                        //MessageBoxResult retQuestion = LMessage.ShowMessage(responseMessage, LMessage.MessageBoxType.Question);
                        //if (retQuestion == MessageBoxResult.Yes)
                        //{
                        //    // Cập nhật phiên bản
                        //}
                        //else
                        //{
                        //}

                        MessageBoxResult retMessage = LMessage.ShowMessage(responseMessage, LMessage.MessageBoxType.Question);
                        if (retMessage == MessageBoxResult.Yes)
                        {
                            UserControl p             = null;
                            bool        stretchWindow = false;
                            p = new PresentationWPF.QuanTriHeThong.PhienBan.ucPhienBanCapNhat();

                            if (p != null)
                            {
                                Window window = new Window
                                {
                                    Title = LLanguage.SearchResourceByKey("MENU.152_CAP_NHAT_PB"),
                                    WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen,
                                    //Icon = (rmb.ImageSource == null ? this.Icon : rmb.ImageSource),
                                    Width   = (Double.IsNaN(p.Width) ? 1024 : p.Width),
                                    Height  = (Double.IsNaN(p.Height) ? 700 : p.Height),
                                    Content = p,
                                };
                                if (stretchWindow == true)
                                {
                                    window.WindowState = WindowState.Maximized;
                                }
                                window.Width      = 500;
                                window.Height     = 150;
                                window.ResizeMode = ResizeMode.NoResize;

                                //Mouse.OverrideCursor = Cursors.Arrow;
                                this.Close();
                                window.ShowDialog();
                            }
                            else
                            {
                                Mouse.OverrideCursor = Cursors.Arrow;
                                LMessage.ShowMessage("Không tìm thấy chức năng này", LMessage.MessageBoxType.Warning);
                            }
                        }
                    }


                    #region Ghi ngôn ngữ ra file UIResources
                    if (ngonNguDTO != null)
                    {
                        List <string> lstResource_vi = new List <string>();
                        List <string> lstResource_en = new List <string>();
                        List <string> lstResource_gl = new List <string>();
                        List <string> lstMessage_vi  = new List <string>();
                        List <string> lstMessage_en  = new List <string>();
                        List <string> lstMessage_gl  = new List <string>();

                        string pathFileResource_vi = ClientInformation.LanguagesDir + "\\UIResources_vi.xaml";
                        string pathFileResource_en = ClientInformation.LanguagesDir + "\\UIResources_en.xaml";
                        string pathFileResource_gl = ClientInformation.LanguagesDir + "\\UIResources_gl.xaml";
                        string pathFileMessage_vi  = ClientInformation.LanguagesDir + "\\MessageResources_vi.xaml";
                        string pathFileMessage_en  = ClientInformation.LanguagesDir + "\\MessageResources_en.xaml";
                        string pathFileMessage_gl  = ClientInformation.LanguagesDir + "\\MessageResources_gl.xaml";


                        string begin = "<ResourceDictionary xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\""
                                       + "\n                " + "xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\""
                                       + "\n                " + "xmlns:my=\"clr-namespace:System;assembly=mscorlib\">";
                        string end = "\n\n</ResourceDictionary>";



                        if (!ngonNguDTO.checkResource && ngonNguDTO.lstResource != null)
                        {
                            lstResource_vi.Add(begin);
                            lstResource_en.Add(begin);
                            lstResource_gl.Add(begin);

                            foreach (var item in ngonNguDTO.lstResource)
                            {
                                lstResource_vi.Add("\n    <my:String x:Key=\"" + item.MA + "\">" + item.VIET_NAM + "</my:String>");
                                lstResource_en.Add("\n    <my:String x:Key=\"" + item.MA + "\">" + item.ENGLISH + "</my:String>");
                                lstResource_gl.Add("\n    <my:String x:Key=\"" + item.MA + "\">" + item.GLOBAL + "</my:String>");
                            }

                            lstResource_vi.Add(end);
                            lstResource_en.Add(end);
                            lstResource_gl.Add(end);

                            LFile.DeleteFile(pathFileResource_vi);
                            LFile.DeleteFile(pathFileResource_en);
                            LFile.DeleteFile(pathFileResource_gl);

                            LFile.WriteListTextToFile(pathFileResource_vi, true, lstResource_vi);
                            LFile.WriteListTextToFile(pathFileResource_en, true, lstResource_en);
                            LFile.WriteListTextToFile(pathFileResource_gl, true, lstResource_gl);
                        }

                        if (!ngonNguDTO.checkMessage && ngonNguDTO.lstMessage != null)
                        {
                            lstMessage_vi.Add(begin);
                            lstMessage_en.Add(begin);
                            lstMessage_gl.Add(begin);

                            foreach (var item in ngonNguDTO.lstMessage)
                            {
                                lstMessage_vi.Add("\n    <my:String x:Key=\"" + item.MA + "\">" + item.VIET_NAM + "</my:String>");
                                lstMessage_en.Add("\n    <my:String x:Key=\"" + item.MA + "\">" + item.ENGLISH + "</my:String>");
                                lstMessage_gl.Add("\n    <my:String x:Key=\"" + item.MA + "\">" + item.GLOBAL + "</my:String>");
                            }

                            lstMessage_vi.Add(end);
                            lstMessage_en.Add(end);
                            lstMessage_gl.Add(end);

                            LFile.DeleteFile(pathFileMessage_vi);
                            LFile.DeleteFile(pathFileMessage_en);
                            LFile.DeleteFile(pathFileMessage_gl);

                            LFile.WriteListTextToFile(pathFileMessage_vi, true, lstMessage_vi);
                            LFile.WriteListTextToFile(pathFileMessage_en, true, lstMessage_en);
                            LFile.WriteListTextToFile(pathFileMessage_gl, true, lstMessage_gl);
                        }

                        ChangeLanguage();
                    }
                    #endregion


                    ClientInformation.NgonNgu = ((RadComboBoxItem)cboLanguage.SelectedItem).Tag.ToString();

                    // @Truonglq set Culture ngôn ngữ cho  Coltrol (telerik)
                    //CultureInfo culture = new CultureInfo(((RadComboBoxItem)cboLanguage.SelectedItem).Tag.ToString());
                    //System.Threading.Thread.CurrentThread.CurrentCulture = culture;
                    //System.Threading.Thread.CurrentThread.CurrentUICulture = culture;
                    InitializeCultures();
                    //InitializeCulturesTelerik();
                    LocalizationManager.Manager = new LocalizationManager()
                    {
                        ResourceManager = LocalizationRadControl.ResourceManager
                    };

                    // Khởi tạo phiên làm việc, chọn đơn vị nghiệp vụ cần thao tác dữ liệu
                    if (!ClientInformation.LoaiNguoiSuDung.Equals(BusinessConstant.LoaiNguoiSuDung.CAP_SA.layGiaTri()))
                    {
                        LLogging.WriteLog(System.Reflection.MethodInfo.GetCurrentMethod().ToString(), LLogging.LogType.ERR, "BeforeInitSession");
                        InitSession initSession = new InitSession(ClientInformation.ListPhongGD);
                        LLogging.WriteLog(System.Reflection.MethodInfo.GetCurrentMethod().ToString(), LLogging.LogType.ERR, "AfterInitSession");

                        initSession.ResizeMode            = ResizeMode.NoResize;
                        initSession.Height                = 250;
                        initSession.Width                 = 600;
                        initSession.WindowStartupLocation = WindowStartupLocation.CenterScreen;

                        initSession.lblNguoiDungValue.Content = "(" + ClientInformation.TenDangNhap + ") " + ClientInformation.HoTen;
                        initSession.lblChiNhanhValue.Content  = "(" + ClientInformation.MaDonVi + ") " + ClientInformation.TenDonVi;
                        //initSession.ListPhongGD = ClientInformation.ListPhongGD;

                        LLogging.WriteLog(System.Reflection.MethodInfo.GetCurrentMethod().ToString(), LLogging.LogType.ERR, "BeforeInitSession Show");
                        initSession.Show();
                        LLogging.WriteLog(System.Reflection.MethodInfo.GetCurrentMethod().ToString(), LLogging.LogType.ERR, "AfterInitSession Show");
                        this.Cursor = Cursors.Arrow;
                        Close();
                    }
                    else
                    {
                        ClientInformation.TenDonViGiaoDich   = ClientInformation.TenDonVi;
                        ClientInformation.MaDonViGiaoDich    = ClientInformation.MaDonVi;
                        ClientInformation.IdDonViGiaoDich    = ClientInformation.IdDonVi;
                        ClientInformation.PhuongPhapHachToan = null;

                        MainWindow mainwindow = new MainWindow();
                        mainwindow.Show();
                        this.Cursor = Cursors.Arrow;
                        Close();
                    }
                }
                else
                {
                    ImageBehavior.SetAnimatedSource(imgWaiting, null);

                    // Nếu yêu cầu đổi mật khẩu
                    if (responseMessage != null &&
                        (
                            responseMessage.Equals(ApplicationConstant.LoginResponseMessage.M_ResponseMessage_Login_YeuCauDoiMatKhauLanDau.layGiaTri()) ||
                            responseMessage.Equals(ApplicationConstant.LoginResponseMessage.M_ResponseMessage_Login_YeuCauDoiMatKhau.layGiaTri())
                        )
                        )
                    {
                        LLogging.WriteLog(System.Reflection.MethodInfo.GetCurrentMethod().ToString(), LLogging.LogType.ERR, "IF M_ResponseMessage_Login_YeuCauDoiMatKhau");
                        MessageBoxResult retQuestion = LMessage.ShowMessage(responseMessage, LMessage.MessageBoxType.Question);
                        if (retQuestion == MessageBoxResult.Yes)
                        {
                            txtPassword.Clear();

                            ChangePassword changePassword = new ChangePassword();
                            Window         window         = new Window();

                            window.ResizeMode            = ResizeMode.NoResize;
                            window.Height                = 180;
                            window.Width                 = 500;
                            window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                            window.Title                 = LLanguage.SearchResourceByKey("U.ZAMainApp.ChangePassword.Title");
                            window.Content               = changePassword;

                            changePassword.userName = userName;
                            window.ShowDialog();
                            //LMessage.ShowMessage("Change pass", LMessage.MessageBoxType.Warning);
                        }
                        else
                        {
                            return;
                        }
                    }
                    else
                    {
                        LLogging.WriteLog(System.Reflection.MethodInfo.GetCurrentMethod().ToString(), LLogging.LogType.ERR, "ELSE M_ResponseMessage_Login_YeuCauDoiMatKhau");
                        LMessage.ShowMessage(responseMessage, LMessage.MessageBoxType.Warning);
                    }
                }
            }
            //else
            catch (Exception ex)
            {
                LLogging.WriteLog(System.Reflection.MethodInfo.GetCurrentMethod().ToString(), LLogging.LogType.ERR, "Login() Exception");
                ImageBehavior.SetAnimatedSource(imgWaiting, null);

                //this.Close();
                //Application.Current.Shutdown();
                this.Cursor = Cursors.Arrow;
                if (ex.GetType() == typeof(CustomException))
                {
                    new frmThongBaoLoi(ex.Message, ex.InnerException).ShowDialog();
                }
                else
                {
                    if (ex.InnerException != null)
                    {
                        if (ex.InnerException.GetType() == typeof(CustomException))
                        {
                            new frmThongBaoLoi(ex.InnerException.Message, ex.InnerException).ShowDialog();
                        }
                        else
                        {
                            new frmThongBaoLoi("M.ResponseMessage.Login.KhongThanhCong", ex).ShowDialog();
                        }
                    }
                    else
                    {
                        new frmThongBaoLoi("M.ResponseMessage.Login.KhongThanhCong", ex).ShowDialog();
                    }
                }
                LLogging.WriteLog(System.Reflection.MethodInfo.GetCurrentMethod().ToString(), LLogging.LogType.ERR, ex);
            }
        }