public DataSettingList(string ctrName) { InitializeComponent(); tableName = ctrName; string strServer, strDatabase, strUser, strPassword; DBConnection dbCon = new DBConnection(); dbCon.getDBConnectionInfo(out strServer, out strDatabase, out strUser, out strPassword); m_objManager.Parent = this; m_objManager.DBEngine = new EzSql2(strServer, strDatabase, strUser, strPassword); m_objManager.DBEngine.open(); }
private static void LoadMainData() { string strServer, strDatabase, strUser, strPassword; bool nReturn = false; try { DBConnection dbCon = new DBConnection(); dbCon.getDBConnectionInfo(out strServer, out strDatabase, out strUser, out strPassword); m_objManager.Parent = null; m_objManager.DBEngine = new EzSql2(strServer, strDatabase, strUser, strPassword); m_objManager.DBEngine.open(); nReturn = true; UIMessage.ENTER_TO_TAB = HPA.Properties.Settings.Default.EnterToTab; UIMessage.DBEngine = m_objManager.DBEngine; UIMessage.StoreProcName = "MST_Message_Get"; UIMessage.StoreProcParamMessageID = "@MessageID"; UIMessage.StoreProcParamLanguage = "@Language"; UIMessage.StoreProcParamOutName = "@Content"; UIMessage.MessageBoxTitle = "Paradise-HPA"; //UIMessage.TA_LoadLogTimeWhenOpen = true; UIMessage.LoginWallpaper = HPA.Properties.Settings.Default.LoginWallpaper; m_objManager.UserID = 3; return; } catch { if (nReturn == false) { object obj; SetConnection frmCn = new SetConnection() { AssemblyName = "HPA.Component.SystemAdmin", ClassName = "SetConnection" }; m_objManager.OpenObject(frmCn, true, null, out obj); } return; } }
public override bool Commit() { // remember current Action State HPA.Component.Framework.Base.EActionState eOldActionState = ActionState; try { // switch to COMMITING state ActionState = HPA.Component.Framework.Base.EActionState.BUSY; // wait-cursor this.Cursor = Cursors.WaitCursor; try { if (DBEngine == null) { string strServer, strDatabase, strUser, strPassword; try { DBConnection dbCon = new DBConnection(); dbCon.getDBConnectionInfo(out strServer, out strDatabase, out strUser, out strPassword); DBEngine = new EzSql2(strServer, strDatabase, strUser, strPassword); DBEngine.open(); } catch(Exception ex) { HPA.Common.Helper.ShowException(ex, ex.Message, "Commit"); } } object objRetVal = DBEngine.execReturnValue("SC_UserPassword_Update", "@p_UserName", xteUserID.Text, "@p_OldPassword", Encryption.EncryptText(xteOldPass.Text,true), "@p_NewPassword", Encryption.EncryptText(xteNewPass.Text,true)); int iRetVal = Convert.ToInt32(objRetVal); switch (iRetVal) { case 0: UIMessage.ShowMessage("PASS_CHANGED_SUCCESSFULL", MessageBoxButtons.OK, MessageBoxIcon.Information); break; case 1: UIMessage.ShowMessage("USER_NOT_EXISTS", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); xteUserID.Focus(); break; case 2: UIMessage.ShowMessage("PASS_WRONG", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); xteOldPass.Focus(); break; } } catch (Exception ex) { throw (ex); } // restore cursor this.Cursor = Cursors.Default; // restore action state ActionState = eOldActionState; } catch (Exception e) { // restore cursor this.Cursor = Cursors.Default; // show error HPA.Common.Helper.ShowException(e, this.Name + ".Commit()", null); // restore action state ActionState = eOldActionState; // unable to commit return false; } // commit successfully return true; }
private void SetConnection_Load(object sender, EventArgs e) { string strConnection = ""; SqlConnection connection; SqlCommand cmd; string strCreateUser = ""; string strAttachDB = ""; string strServer, strDatabase, strUser, strPassword, strEncrypted; DBConnection dbCon = null; try { //Connect to Master Database //strConnection = @"Data Source=.\SQLExpress;Initial Catalog=master;User Id=sa;Password=123;"; // register dll for zk SDK if (!System.IO.File.Exists("Paradise.ini")) { Process.Start(@"C:\windows\system32\RegiszkDll.bat"); strConnection = @"Data Source=.\SQLEXPRESS;Initial Catalog=master;Integrated Security=True"; connection = new SqlConnection(strConnection); connection.Open(); //Attach Database file cmd = new SqlCommand("if exists (select 1 from sys.databases where Name = 'Att_VTS') EXEC master.dbo.sp_detach_db N'Att_VTS','true'", connection); cmd.ExecuteNonQuery(); strAttachDB = @"if not exists (select 1 from sys.databases where name = 'Att_VTS') CREATE DATABASE [Att_VTS] ON ( FILENAME = N'C:\Windows\Att_VTS.mdf' ),( FILENAME = N'C:\Windows\Att_VTS_log.ldf' ) FOR ATTACH "; cmd = new SqlCommand(strAttachDB, connection); cmd.ExecuteNonQuery(); //Create new login name saFree, Pass:LuaThiengFree //Retry to connect new SQL String again strCreateUser = @"if not exists (select 1 from master.dbo.syslogins where name = 'SaFree') CREATE LOGIN saFree WITH PASSWORD=N'LuaThiengFree', DEFAULT_DATABASE=[Att_VTS], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF;"; cmd = new SqlCommand(strCreateUser, connection); cmd.ExecuteNonQuery(); cmd = new SqlCommand("EXEC master..sp_addsrvrolemember @loginame = N'saFree', @rolename = N'sysadmin'", connection); cmd.ExecuteNonQuery(); try { cmd = new SqlCommand(@"xp_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\Microsoft SQL Server\MSSQL.1\MSSQLServer', N'LoginMode', REG_DWORD, 2", connection); cmd.ExecuteNonQuery(); } catch { } try { cmd = new SqlCommand(@"xp_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\Microsoft SQL Server\MSSQL.2\MSSQLServer', N'LoginMode', REG_DWORD, 2", connection); cmd.ExecuteNonQuery(); } catch { } try { cmd = new SqlCommand(@"xp_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\Microsoft SQL Server\MSSQL.3\MSSQLServer', N'LoginMode', REG_DWORD, 2", connection); cmd.ExecuteNonQuery(); } catch { } connection.Close(); strServer = @".\SQLEXPRESS"; strDatabase = "Att_VTS"; strUser = "******"; strPassword = "******"; strEncrypted = DBConnection.NO_ENCRYPTED; dbCon = new DBConnection(); dbCon.saveConnectionInfo(strServer, strDatabase, strUser, strPassword, DBConnection.ENCRYPTED); //Reset computer if (MessageBox.Show("Need restart compurter to complete the First configuration. Do you want to restart your computer?", "Vietinsoft", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) Process.Start("ShutDown", "/r /t 000"); else Application.Exit(); } dbCon = new DBConnection(); dbCon.getDBConnectionInfo(out strServer, out strDatabase, out strUser, out strPassword, out strEncrypted); } catch { strServer = @".\SQLEXPRESS"; strDatabase = "Att_VTS"; strUser = "******"; strPassword = "******"; strEncrypted = DBConnection.NO_ENCRYPTED; dbCon = new DBConnection(); dbCon.saveConnectionInfo(strServer, strDatabase, strUser, strPassword, DBConnection.ENCRYPTED); } // ConnectionString cs = new ConnectionString(); // cs.GetConnectParam(); // cs.GetParam(out strServer, out strDatabase, out strUser, out strPassword, out strEncrypted); // txeServer.Text = strServer; txeDatabase.Text = strDatabase; txeUsername.Text = strUser; txePassword.Text = strPassword; if (strEncrypted.Trim() == DBConnection.ENCRYPTED) chkEncrypt.Checked = true; else chkEncrypt.Checked = false; dbCon = null; // load language interface if ((strServer != null) && (!string.Empty.Equals(strServer))) { Control.ControlCollection ctrls = this.Controls; UIMessage.LoadLableName(ref ctrls); } }