Last active
December 29, 2015 07:19
-
-
Save ngnguyen1/7635592 to your computer and use it in GitHub Desktop.
Cấu phần kết nối các loại CSDL.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| namespace COP { | |
| class CheckNumber { | |
| public bool isNguyenTo(int a) { | |
| if (a == 0 || a == 1) | |
| return false; | |
| for(int i = 2; i <= Math.Sqrt(a); i++) { | |
| if (a % i == 0) | |
| return false; | |
| } | |
| return true; | |
| } | |
| public bool isChinhPhuong(int a) { | |
| return (a == (int)(Math.Sqrt(a)) * (int)(Math.Sqrt(a))); | |
| } | |
| public bool isHoanHao(int a) { | |
| int tong = 1; | |
| for (int i = 2; i <= a/2; i++) { | |
| if (a % i == 0) | |
| tong += i; | |
| } | |
| if (tong == a) | |
| return true; | |
| else | |
| return false; | |
| } | |
| } | |
| } | |
| // How to use: Plese implement following code into your application. | |
| // if(CheckNumber.isNguyenTo(int number_to_check)) { // Todo Something } | |
| // Similar to isChinhPhuong(), isHoanHao() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Data.SqlClient; | |
| namespace COP { | |
| class ConnectDB { | |
| public static SQLServer = 1; | |
| public static MySql = 2; | |
| public static Access = 3; | |
| private static SqlConnection connect; | |
| public static void Connect(int ServerName, string Server, string db, string userId = "", string Pwd = "") { | |
| string strCon = ""; | |
| switch (ServerName) { | |
| case 1: | |
| strCon = "Server = " + Server + ";Database = " + db + ";User Id = " + userId + ";Password = " + Pwd + ";"; | |
| break; | |
| case 2: | |
| strCon = "Server = " + Server + ";Database = " + db + ";Uid = " + userId + ";Pwd = " + Pwd + ";"; | |
| break; | |
| case 3: | |
| strCon = "Driver = {Microsoft Access Driver (*.mdb, *.accdb)}; Dbd = " + db + "; Uid = " + userId + ";Pwd = " + Pwd + ";"; | |
| break; | |
| } | |
| connect = new SqlConnection(strCon); | |
| connect.Open(); | |
| } | |
| } | |
| } | |
| // How to use: Implement following code into your application | |
| // ConnectDB.Connect(ConnectDB.SQLServer, "localhost", "database_name", "user_name", "password"); | |
| // ConnectDB.Connect(ConnectDB.MySql, "localhost", "database_name", "user_name", "password"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment