Post by Goborijung at 2020-10-26 13:22:44 | ID: 832
// Create Class UserLogin :: UserLogin.cs public class UserLogin { private static int _UserOID; public void setUserOID(int userOID) { _UserOID = userOID; } public static int getUserOID() { return _UserOID; } } // Login.cs private void btnLogin_Click(object sender, EventArgs e) { string username = txtUserName.Text; string password = new objForm().md5(txtPassword.Text); Console.WriteLine("Username : " + username); Console.WriteLine("Password : " + txtPassword.Text); Console.WriteLine("Hash : " + password); if (username == "" || txtPassword.Text == "") { new objForm().showWarningMessage("กรุณาป้อน UserName หรือ Password ให้ถั่วต้ม!"); } else { SqlConnection conn = new dbConn().GSSv2_Prod(); try { conn.Open(); string sql = "SELECT OID,UserName,Password From [User] Where GCRecord is null and UserName = '" + username + "' and Password='" + password + "' "; Console.WriteLine("Sqlcmd : " + sql); SqlCommand cmd = new SqlCommand(sql, conn); SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read() == true) { //หรือจะใช้เป็น dr.HasRows //MessageBox.Show("OK : "+dr["OID"]); new objForm().showInfoMessage("ยินดีต้อนรับ " + username + " เข้าสู่ระบบจ้า :)"); UserLogin ulogin = new UserLogin(); ulogin.setUserOID(Convert.ToInt32(dr["OID"])); this.Hide(); frmGSS13 main = new frmGSS13(); main.Show(); } else { new objForm().showWarningMessage("UserName หรือ Password ไม่ถั่วต้ม!"); txtPassword.Clear(); txtUserName.Focus(); } conn.Close(); } catch {} } } // Main.cs int userOID = UserLogin.getUserOID(); // OutherForm.cs int userOID = UserLogin.getUserOID();
Post by Goborijung at 2022-03-26 19:20:52 | ID: 1429
for (int i = 0; i < 10; i++) { if (i == 4) { continue; } Console.WriteLine(i); }
Post by Goborijung at 2020-09-14 16:43:35 | ID: 801
dataAdapter.Fill(dataSet); DataTable dtView = dataSet.Tables[0]; if (dtView.Rows.Count > 0) { dgrdReciver.Rows.Clear(); dgrdReciver.Rows.Add(dtView.Rows.Count); int i = 0; foreach (DataRow drow in dtView.Rows) { dgrdReciver.Rows[i].Cells["Addressid"].Value = drow["ADRSID"]; dgrdReciver.Rows[i].Cells["ReciverName"].Value = drow["NAME"]; i++; } }
Post by Goborijung at 2020-09-23 08:41:33 | ID: 791
try { conn.Open(); cmd = new SqlCommand(strCond, conn); dr = cmd.ExecuteReader(); while (dr.Read()) { int n = dgS.Rows.Add(); dgS.Rows[n].Cells[0].Value = dr[0]; dgS.Rows[n].Cells[1].Value = dr[1]; dgS.Rows[n].Cells[2].Value = dr[2]; } conn.Close(); } catch (Exception ex) { MessageBox.Show("Can not Open Connection!"); }// แบบสร้าง Columns Header เอง
dataGridView2.ColumnCount = 3; dataGridView2.Columns[0].Name = "No"; dataGridView2.Columns[1].Name = "Product ID"; dataGridView2.Columns[2].Name = "Product Name"; int no = 1; dataGridView2.Rows.Add(no++,textBox1.Text, textBox2.Text);
Post by Goborijung at 2020-09-23 08:24:32 | ID: 760
Example : https://www.c-sharpcorner.com/UploadFile/mahesh/understanding-message-box-in-windows-forms-using-C-Sharp/ https://www.dotnetperls.com/messagebox-show DialogResult status = MessageBox.Show("Do you want to close?" , "This Title" , MessageBoxButtons.YesNo); if (status == DialogResult.Yes) { MessageBox.Show("ok close"); Application.Exit(); } else { MessageBox.Show("ok cancel"); }
Post by Goborijung at 2020-09-22 11:20:57 | ID: 814
MessageBox.Show("มึงก็ใส่ Capacitor Code ด้วยสิวะ ไอ้ห่าเอ้ย! โง่ชิปหาย","Programs Warning!",MessageBoxButtons.OK, MessageBoxIcon.Warning);
Post by Goborijung at 2020-09-10 08:21:49 | ID: 774
Point mousedownpoint = Point.Empty; private void test001_MouseUp(object sender, MouseEventArgs e) { mousedownpoint = Point.Empty; } private void test001_MouseDown(object sender, MouseEventArgs e) { mousedownpoint = new Point(e.X, e.Y); } private void test001_MouseMove(object sender, MouseEventArgs e) { if (mousedownpoint.IsEmpty) { return; } Form f = sender as Form; f.Location = new Point(f.Location.X + (e.X - mousedownpoint.X), f.Location.Y + (e.Y - mousedownpoint.Y)); }
Post by Goborijung at 2021-03-29 23:08:54 | ID: 946
Int32 total = 1000; MessageBox.Show(total.ToString("#,##0")); //Output : 1,000 double rs = 123.456; rs.ToString("F2"); //123.46
Post by Goborijung at 2020-09-23 23:41:58 | ID: 823
ตัวอย่างที่ 1
namespace SoloLearn { // Class Movie class Movie { // Global Variable Function public string title; public string rating; // Function Movie public Movie(string Title, string Rating) { title = Title; rating = Rating; } } // การใช้งาน class Program { static void Main(string[] args) { Movie m = new Movie("noTitle","7.9"); Console.WriteLine(m.title); } } }
ตัวอย่างที่ 2
namespace SoloLearn { // Class Movie class Movie { // Global Variable Function public string _title; public string _rating; // Function Movie public Movie(string Title, string Rating) { _title = Title; _rating = Rating; } public string Title { get; set; } public string Rating { get { return _rating; } set { if (value == "10") { _rating = value; } else { _rating = "This rating is < 10"; } } } } // การใช้งาน class Program { static void Main(string[] args) { Movie m = new Movie("noTitle", "7.9"); m.Title = "www"; m.Rating = "8.2"; Console.WriteLine(m.Title + " :: " + m._title + " :: " + m.Rating); } } }
Post by Goborijung at 2020-09-23 23:18:28 | ID: 110
Ref : https://code.sololearn.com/c1IMnuYG7MUF/#cs Menu: Project >Add Class... ตั้งชื่อคลาส เช่น Customers.cs จากนั้นก็เขียนเพิ่ม Field เข้าไปในคลาส ตัวอย่างเช่น : namespace SoloLearn { // Class Customers class Customers { // Global Variable Function private string _fullname; public int CustomerID { get; set; } public string FullName { get { return _fullname;} set { if(value == "Kanom") { _fullname = value; } else { _fullname = "Unknow Name"; } } } public string Address { get; set; } } // การใช้งาน class Program { static void Main(string[] args) { Customers c = new Customers(); c.CustomerID = 444; c.FullName = "Kanoms"; c.Address = "Bangkok Thailand"; Console.WriteLine(c.CustomerID); Console.WriteLine(c.FullName); Console.WriteLine(c.Address); } } }