Guest User

Untitled

a guest
Jan 23rd, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.39 KB | None | 0 0
  1. public WebDbConnection(string extraParameters, string configConnectionName, string databaseName,
  2. bool showDbName, string dialogName, bool isEncrypted,ref Page page)
  3. {
  4. _currentPage = page;
  5. _extraParameters = extraParameters;
  6. _dialogName = dialogName;
  7. IsEncrypted = isEncrypted;
  8. _showDbName = showDbName;
  9.  
  10. _configConnectionName = configConnectionName;
  11. LoadDefaultConnectionString(IsEncrypted);
  12.  
  13. _databaseName = databaseName;
  14.  
  15.  
  16. }
  17. protected void BtnConnect_Click(object sender, EventArgs e)
  18. {
  19. try
  20. {
  21. EnsureChildControls();
  22. _server = Dbconnection_txtServer.Text;
  23. _userName = Dbconnection_txtUser.Text;
  24. _password = Dbconnection_txtPass.Text;
  25. _databaseName = Dbconnection_txtdbname.Text;
  26.  
  27. if (Connection.State == ConnectionState.Connecting)
  28. return;
  29.  
  30. Connect();
  31. if (Connection.State == ConnectionState.Open)
  32. this.Controls.Clear();
  33. else
  34. {
  35. ScriptManager.RegisterStartupScript(this, this.GetType(), "alertbox",
  36. "alert('Can not connect to server.')", true);
  37.  
  38. Dbconnection_txtServer.Text = _server;
  39. Dbconnection_txtUser.Text = _userName;
  40. Dbconnection_txtPass.Text = _password;
  41. Dbconnection_txtdbname.Text = _databaseName;
  42. }
  43.  
  44. }
  45.  
  46. catch (Exception ex)
  47. {
  48. LastError = ex.Message;
  49. LoadDefaultConnectionString(IsEncrypted);
  50. Dbconnection_txtServer.Text = _server;
  51. Dbconnection_txtPass.Text = _password;
  52. Dbconnection_txtUser.Text = _userName;
  53. }
  54. }
  55. protected override void CreateChildControls()
  56. {
  57. Controls.Clear();
  58.  
  59. lbl_HeaderName = new Label();
  60. lbl_HeaderName.ID = "lbl_HeaderName";
  61. lbl_HeaderName.Text = "Server Credential";
  62.  
  63. lbl_servername = new Label();
  64. lbl_servername.ID = "lbl_servername";
  65. lbl_servername.Text = "Server Name";
  66.  
  67. Dbconnection_txtServer = new TextBox();
  68. Dbconnection_txtServer.ID = "Dbconnection_txtServer";
  69.  
  70. lbl_username = new Label();
  71. lbl_username.ID = "lbl_username";
  72. lbl_username.Text = "User Name:";
  73.  
  74. Dbconnection_txtUser = new TextBox();
  75. Dbconnection_txtUser.ID = "Dbconnection_txtUser";
  76.  
  77. lbl_password = new Label();
  78. lbl_password.ID = "lbl_password";
  79. lbl_password.Text = "Password:";
  80.  
  81. Dbconnection_txtPass = new TextBox();
  82. Dbconnection_txtPass.ID = "Dbconnection_txtPass";
  83.  
  84. lbl_databasename = new Label();
  85. lbl_databasename.ID = "lbl_databasename";
  86. lbl_databasename.Text = "Database Name:";
  87.  
  88. Dbconnection_txtdbname = new TextBox();
  89. Dbconnection_txtdbname.ID = "Dbconnection_txtdbname";
  90.  
  91. btnConnect = new Button();
  92. btnConnect.ID = "btnConnect";
  93. btnConnect.Text = "Connect";
  94. btnConnect.Click += BtnConnect_Click;
  95.  
  96. btnCancel = new Button();
  97. btnCancel.ID = "btnCancel";
  98. btnCancel.Text = "Cancel";
  99. btnCancel.Click += BtnCancel_Click;
  100.  
  101.  
  102. //add controls
  103. Controls.Add(lbl_password);
  104. Controls.Add(lbl_databasename);
  105. Controls.Add(lbl_servername);
  106. Controls.Add(lbl_username);
  107. Controls.Add(lbl_HeaderName);
  108. Controls.Add(Dbconnection_txtdbname);
  109. Controls.Add(Dbconnection_txtPass);
  110. Controls.Add(Dbconnection_txtServer);
  111. Controls.Add(Dbconnection_txtUser);
  112. Controls.Add(btnConnect);
  113. Controls.Add(btnCancel);
  114. }
  115. void ShowPage()
  116. {
  117. EnsureChildControls();
  118. if (!_currentPage.Form.Controls.Contains(this))
  119. _currentPage.Form.Controls.Add(this);
  120. else
  121. {
  122. _currentPage.Form.Controls.Remove(this);
  123. _currentPage.Form.Controls.Add(this);
  124. }
  125.  
  126. Dbconnection_txtdbname.Text = _databaseName;
  127. if (!_showDbName)
  128. {
  129. lbl_databasename.Visible = false;
  130. Dbconnection_txtdbname.Visible = false;
  131. }
  132.  
  133. //----------------------
  134. if (_dialogName.IsEmptyOrNull()) return;
  135. lbl_HeaderName.Text = "Fill " + _dialogName + " Information";
  136. }
  137.  
  138. protected void Page_Load(object sender, EventArgs e)
  139. {
  140. Page.Form.Controls.Add(WebDbConnection_instance);
  141. }
Add Comment
Please, Sign In to add comment