示例#1
0
        public static bool Ketnoi()
        {
            // show wait form

            // lấy chuỗi kết nối trong file app config

            string        s    = AppConfig.GetConnectionString(HeThong.AppConfigConnectionStringName);
            SqlConnection conn = null;

            // thử kết nối CSDL, nếu thành công thì gán ChuoiKetNoi -> sau này dùng
            try
            {
                string chuoiKetnoi = s;
                if (HeThong.MaHoaChuoiKetNoi)
                {
                    chuoiKetnoi = LotusEncoding.Descrypt(s, "nh@ntr@n");
                }

                conn = new SqlConnection(chuoiKetnoi);
                conn.Open();
                ChuoiKetNoi = chuoiKetnoi;
                SQLHelper.Connectionstring = chuoiKetnoi;
                Lotus.Libraries.Settings.Default.ConnectionString = chuoiKetnoi;

                HeThong.ConnectionString = chuoiKetnoi;

                var connStringBuilder = new SqlConnectionStringBuilder(chuoiKetnoi);
                DBName = connStringBuilder.InitialCatalog;
            }
            catch (Exception ex)
            {
                FrmThietLapKetnoi f = new FrmThietLapKetnoi();
                if (HeThong.DaNgonNgu)
                {
                    LanguageHelper.Translate(f);
                }
                if (f.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    return(true);
                }

                Console.WriteLine(ex.Message);
                return(false);
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
            return(true);
        }
        public FrmThietLapKetnoi()
        {
            InitializeComponent();
            string s = AppConfig.GetConnectionString(HeThong.AppConfigConnectionStringName);

            string chuoiKetnoi = s;

            if (HeThong.MaHoaChuoiKetNoi)
            {
                chuoiKetnoi = LotusEncoding.Descrypt(s, "nh@ntr@n");
            }


            var connStringBuilder = new SqlConnectionStringBuilder(chuoiKetnoi);

            txtMayChu.Text      = connStringBuilder.DataSource;
            txtTenDangNhap.Text = connStringBuilder.UserID;
            txtMatKhau.Text     = connStringBuilder.Password;
            txtCSDL.Text        = connStringBuilder.InitialCatalog;

            cboCheDo.SelectedIndex = 1;
        }