Using mongodb;using docksample.db;using mongodb.driver;using system;using system.collections.generic;using System.componentmodel;using system.data;using system.drawing;using system.io;using System.Linq;using System.Text; Using system.windows.forms;using weifenluo.winformsui.docking;using mongodb.bson;namespace DockSample{Public Partial class Form2:dockcontent {public Form2 () {InitializeComponent (); }//////////////////////workaround of RichTextbox control ' s bug://////////////////////If load file before The control showed, all the text format is lost//////////////////////re-load the file after it get showed. private bool M_resettext = true; protected override void OnPaint (PaintEventArgs e)////////////////////{//////////////// Base. OnPaint (e); if (M_resettext)////////////////////{//////////M_resettext = false; }////////////////////}////////////////////////protected override string Getpersist String ()////////////////////////{//////////////////////////ADD extra information into the persist str ing for the document/////////////////////////So, it's available when deserialized. Return GetType (). ToString () + ", 1123," + Text; }////////////////////private void Menuitem2_click (object sender, System.EventArgs e) {////////////////////MessageBox.Show ("This was to demostrate the menu item has been SUCCESSFU Lly merged into the main form. Form text= "+ Text"); }////////////////////private void Menuitemchecktest_click (object sender, System.EventArgs e) {////////////////////}////////////////////protected override void OnTextChanged (EventArgs e)////////////////////{////////////////////base. OnTextChanged (e); private void Button1_Click (object sender, EventArgs e) {UserA u = new UserA (); U.cid = 10; U.name = "test to see"; Writeconcernresult s = mongodbhelper.insertone ("User", u); Label1. Text = s.documentsaffected.tostring () + "------" + s.haslasterrormessage.tostring ();//s.haslasterrormessage= False both indicates that the operation was successful! private void Button2_Click (object sender, EventArgs e) {imongoquery query = MongoDB.Driver.Bui Lders. Query.eq ("CID", 9); UserA u = mongodbhelper.getone<usera> ("user", query); ienumerable<usera> u = mongodbhelper.getall<usera> ("user"). Distinct<usera> (New Modelcomparer ()); UserA u = mongodbhelper.getone<usera> ("User", "555993c18825b905c8879edc"); Label1. Text =U.cid.tostring () + "---" + u.name; foreach (UserA ua in U) {richtextbox1.appendtext (ua.cid.ToString () + "--" + Ua.name + "\ r \ n"); }} private void Button3_Click (object sender, EventArgs e) {Mongodbhelper.delet Eall ("user"); }} public class UserA {public ObjectId ID {get; set;} public int CID {get; set;} public string name {get; set;} } public class Modelcomparer:iequalitycomparer<usera> {public bool Equals (UserA x, UserA y) { return X.name.toupper () = = Y.name.toupper (); } public int GetHashCode (UserA obj) {return obj.name.ToUpper (). GetHashCode (); } }}
Go to Heavy MongoDB LIST