private void okbut_Click(object sender, EventArgs e) { MongoClient client = new MongoClient("mongodb://*****:*****@ds141902.mlab.com:41902/ox"); MongoServer server = client.GetServer(); MongoDatabase database = server.GetDatabase("ox"); MongoCollection symbolcollection = database.GetCollection <Usermain>("User"); Usermain user = new Usermain(); BindingList <Usermain> doclist = new BindingList <Usermain>(); var pd = database.GetCollection <Usermain>("User"); var pd1 = pd.AsQueryable().Where(pd01 => pd01.Username == boxusername.Text); foreach (var p in pd1) { doclist.Add(p); Application.DoEvents(); } dataGridView1.DataSource = doclist; if (dataGridView1.Rows.Count == 0) { user.Username = boxusername.Text; user.Password = boxpassword.Text; user.User = boxname.Text; /*user.picture = null; * user.win = "0"; * user.draw = "0"; * user.lose = "0";*/ symbolcollection.Insert(user); MessageBox.Show("เพิ่มข้อมูลเรียบร้อย"); } }
private void okbut_Click(object sender, EventArgs e) { try { MongoClient client = new MongoClient("mongodb://*****:*****@ds141902.mlab.com:41902/ox"); MongoServer server = client.GetServer(); MongoDatabase database = server.GetDatabase("ox"); MongoCollection symbolcollection = database.GetCollection <Usermain>("User"); Usermain user = new Usermain(); BindingList <Usermain> doclist = new BindingList <Usermain>(); var pd = database.GetCollection <Usermain>("User"); var pd1 = pd.AsQueryable().Where(pd01 => pd01.Username == boxusername.Text); foreach (var p in pd1) { doclist.Add(p); Application.DoEvents(); } dataGridView1.DataSource = doclist; if (dataGridView1.Rows.Count == 0) { if (!string.IsNullOrEmpty(boxusername.Text.Trim())) { user.Username = boxusername.Text; } else { MessageBox.Show("กรุณาใส่ข้อมูลUsername"); } if (!string.IsNullOrEmpty(boxpassword.Text.Trim())) { user.Password = boxpassword.Text; } else { MessageBox.Show("กรุณาใส่ข้อมูลPassword"); } if (!string.IsNullOrEmpty(boxname.Text.Trim())) { user.Name = boxname.Text; } else { MessageBox.Show("กรุณาใส่ข้อมูลName"); } user.Avatar = null; user.Win = 0; user.Draw = 0; user.Lose = 0; if (!string.IsNullOrEmpty(boxusername.Text.Trim()) && !string.IsNullOrEmpty(boxpassword.Text.Trim()) && !string.IsNullOrEmpty(boxname.Text.Trim())) { symbolcollection.Insert(user); MessageBox.Show("เพิ่มข้อมูลเรียบร้อย"); } else { } } } catch (Exception ex) { MessageBox.Show("กรุณาใส่ข้อมูลให้ถูกต้อง"); } }