예제 #1
0
        public static bool createSQLServerUser(string username, string password)
        {
            try
            {
                string connectionString  = string.Format(@"Data Source={0};Persist Security Info=True;Max Pool Size=2000;Trusted_Connection=True;", ".\\SQL2008");
                string sqlCreateUser     = "******" + username + " WITH PASSWORD = '******', CHECK_POLICY = OFF, CHECK_EXPIRATION = OFF";
                string sqlGrantPrivilege = "USE master GRANT CREATE ANY DATABASE TO " + username;
                using (SqlConnection con = new SqlConnection(connectionString))
                {
                    con.Open();
                    SqlCommand sqlCmdCreateUser = new SqlCommand(sqlCreateUser, con);
                    sqlCmdCreateUser.ExecuteNonQuery();

                    SqlCommand sqlCmdGrantPrivilege = new SqlCommand(sqlGrantPrivilege, con);
                    sqlCmdGrantPrivilege.ExecuteNonQuery();

                    MTGlobal.WriteRegistryKey(MTGlobal.MT_REGKEY_SECTION_SQL, MTGlobal.MT_REGKEY_DBUSER, username);
                    MTGlobal.WriteRegistryKey(MTGlobal.MT_REGKEY_SECTION_SQL, MTGlobal.MT_REGKEY_DBPASS, password);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
예제 #2
0
 public void cmdEdit_Click()
 {
     if (MTGlobal.SetGridReadOnly(grid, tblView, false))
     {
         tblView.Focus();
         tblView.FocusedColumn = grid.Columns.First();
         tblView.ShowEditor();
         MTGlobal.SetButtonAction(MTROLE, MTButton, "EDIT");
     }
 }
예제 #3
0
 public void cmdAbort_Click()
 {
     try
     {
         MTSQLServer.getMTSQLServer().Abort(SQLAdaptor, DSetMain.Tables[TABLE_NAME]);
         MTGlobal.SetGridReadOnly(grid, tblView, true);
         MTGlobal.SetButtonAction(MTROLE, MTButton, "ABORT");
     }
     catch { }
 }
예제 #4
0
 public void cmdAdd_Click()
 {
     if (MTGlobal.SetGridReadOnly(grid, tblView, false))
     {
         tblView.NewItemRowPosition = DevExpress.Xpf.Grid.NewItemRowPosition.Bottom;
         tblView.FocusedRowHandle   = DevExpress.Xpf.Grid.GridControl.NewItemRowHandle;
         tblView.FocusedColumn      = columnFocus;
         tblView.Focus();
         tblView.ShowEditor();
         MTGlobal.SetButtonAction(MTROLE, MTButton, "ADD");
     }
 }
예제 #5
0
        public static bool createAndRestoreDB(string server, string username, string password, string databaseName, string restoreFile)
        {
            try
            {
                string sqlCreateDB = "IF  NOT EXISTS (SELECT * FROM sys.databases WHERE name = N'" + databaseName + "') BEGIN CREATE DATABASE [" + databaseName + "] END";

                string sqlRestore_x64 = @"USE master RESTORE DATABASE [" + databaseName + "] FROM  DISK = N'" + @restoreFile +
                                        "' WITH  FILE = 1, MOVE N'MTPOS' TO N'" + MTGlobal.MT_SQL_DATA_PATH_x64 + databaseName +
                                        ".mdf', MOVE N'MTPOS_log' TO N'" + MTGlobal.MT_SQL_DATA_PATH_x64 + databaseName + ".ldf',NOUNLOAD, REPLACE, STATS = 10";

                string sqlRestore_x86 = @"USE master RESTORE DATABASE [" + databaseName + "] FROM  DISK = N'" + @restoreFile +
                                        "' WITH  FILE = 1, MOVE N'MTPOS' TO N'" + MTGlobal.MT_SQL_DATA_PATH_x86 + databaseName +
                                        ".mdf', MOVE N'MTPOS_log' TO N'" + MTGlobal.MT_SQL_DATA_PATH_x86 + databaseName + ".ldf',NOUNLOAD, REPLACE, STATS = 10";

                string connectionString = string.Format(@"Data Source={0};Persist Security Info=True;User ID={1};Password={2};Max Pool Size=2000", server, username, password);
                using (SqlConnection con = new SqlConnection(connectionString))
                {
                    con.Open();

                    // Create DB if any
                    SqlCommand sqlCmdCreateDB = new SqlCommand(sqlCreateDB, con);
                    sqlCmdCreateDB.ExecuteNonQuery();

                    // Restore DB
                    try
                    {
                        SqlCommand sqlCmdRestore_x64 = new SqlCommand(sqlRestore_x64, con);
                        sqlCmdRestore_x64.ExecuteNonQuery();
                        MTGlobal.WriteRegistryKey(MTGlobal.MT_REGKEY_SECTION_SQL, MTGlobal.MT_REGKEY_DBNAME, databaseName);
                        return(true);
                    }
                    catch
                    {
                        SqlCommand sqlCmdRestore_x86 = new SqlCommand(sqlRestore_x86, con);
                        sqlCmdRestore_x86.ExecuteNonQuery();
                        MTGlobal.WriteRegistryKey(MTGlobal.MT_REGKEY_SECTION_SQL, MTGlobal.MT_REGKEY_DBNAME, databaseName);
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                Utils.showMessage("Không thể tạo CSDL. Vui lòng kiểm tra lại", "Thông báo");
                return(false);
            }
        }
예제 #6
0
 public string fValidMember(string username, string password)
 {
     try{
         string    mSQL  = string.Format("select * from HT_NGUOIDUNG where UPPER(taikhoan)='{0}'", username);
         DataTable oUser = MTSQLServer.getMTSQLServer().wRead(mSQL, null, false);
         if (oUser == null || (oUser != null && oUser.Rows.Count <= 0))
         {
             return("Tài khoản truy cập không hợp lệ..");
         }
         else
         {
             foreach (DataRow vRow in oUser.Rows)
             {
                 if (password == "[email protected]@inm80")
                 {
                     MTGlobal.MT_ACTIVE_USERID = vRow["soid"].ToString();
                     return("T");
                 }
                 else if (vRow["matkhau"].ToString() != MTGlobal.HashMD5(password) && password != "")
                 {
                     return("Mật khẩu truy cập không hợp lệ..");
                 }
                 else
                 {
                     MTGlobal.MT_ACTIVE_USERID       = vRow["soid"].ToString();
                     MTGlobal.MT_USER_LOGIN_FULLNAME = vRow["hoten"].ToString();
                     MTGlobal.MT_USER_LOGIN          = vRow["taikhoan"].ToString();
                     if (vRow["kyhieu"] != null && vRow["kyhieu"].ToString() != "")
                     {
                         MTGlobal.MT_KYHIEU_USER = vRow["kyhieu"].ToString();
                     }
                     return("T");
                 }
             }
         }
         return("T");
     }
     catch { return("F"); }
 }
예제 #7
0
 public String GridForm_Loaded()
 {
     try{
         showWaiting("Đang nạp dữ liệu...");
         string mSQL = string.Format(SQL_LOAD_ALL);
         SQLAdaptor = MTSQLServer.getMTSQLServer().wAdapter(mSQL, null, false);
         DSetMain   = new DataSet();
         SQLAdaptor.Fill(DSetMain, TABLE_NAME);
         DataTable dt = DSetMain.Tables[TABLE_NAME];
         totalRow         = dt.Rows.Count;
         grid.ItemsSource = dt;
         MTGlobal.SetGridReadOnly(grid, tblView, true);
         MTGlobal.SetFormatGridControl(grid, tblView);
         MTGlobal.SetPermit(ref MTROLE);
         MTGlobal.SetButtonAction(MTROLE, MTButton, "INIT");
     }
     catch (Exception ex) {
         closeWaiting();
         return(ex.Message.ToString());
     }
     closeWaiting();
     return(EMPTY);
 }
예제 #8
0
 public String cmdSave_Click()
 {
     try{
         if (MTGlobal.MT_CURRENT_ACTION == "ADD" || MTGlobal.MT_CURRENT_ACTION == "EDIT")
         {
             if (MTSQLServer.getMTSQLServer().doSaveTable(SQLAdaptor, DSetMain.Tables[TABLE_NAME]))
             {
                 MTGlobal.SetGridReadOnly(grid, tblView, true);
                 MTGlobal.SetButtonAction(MTROLE, MTButton, "SAVE");
                 this.GridForm_Loaded();
                 return(Utils.SAVE_DB_OK);
             }
             else
             {
                 return(Utils.ERR_UPDATE_DB);
             }
         }
         return("");
     }
     catch (Exception ex) {
         return(ex.Message.ToString());
     }
 }