Using system.collections; using system.componentmodel; using system.windows.form; using system.data; using system.thread;
Summary description of Namespace WinMsmq {///
/// summary> private System.ComponentModel.Container components = null; public Form1 () {// // // InitializeComponent Windows Form Designer supports required (); this.qryname = System.Configuration.ConfigurationSettings .AppSettings [ "pubMsmqQryName"]; if (MessageQueue.Exists (qryname)) {this.pubMsq = new MessageQueue (qryname, true);} else {this.pubMsq = System.Messaging.MessageQueue.Create (qryname, true); } This.richtextbox1.appendtext ("=================== / r / n"); this.RichtextBox1.AppendText (this.pubmsq .queueename ": Public queue creates Success! / R / n "); // // Todo: Add any constructor code //} ///
#REGION Windows Form Designer The code ///
/// summary> private void initializecomponent () {this.button1 = new system.windows.Forms.Button (); this.button2 = new system.windows.Forms.Button (); this.button3 = new system. Windows.Forms.Button (); this.richTextBox1 = new System.Windows.Forms.RichTextBox (); this.groupBox1 = new System.Windows.Forms.GroupBox (); this.groupBox2 = new System.Windows.Forms.GroupBox (); This.Button4 = new system.windows.Forms.Button (); this.button7 = new system.windows.Forms.Button (); this.creaet = new system.windows.forms.button (). Button6 = new system.windows.Forms.Button (); this.button5 = new system.windows.forms.button (); this.groupbox3 = new system.windows.forms.groupbox (); this.srpub = new system. Windows.Forms.Button (); this.delPubmsg = new System.Windows.Forms.Button (); this.readFromPub = new System.Windows.Forms.Button (); this.sendToPub = new System.Windows.Forms.Button (); This.sqlConnection1 = new system.data.sqlclient.sqlConnection (); this.groupbox1.sus Pendlayout (); this.groupbox2.suspendlayout (); this.groupbox3.suspendlayout (); this.suspendlayout (); // // button1 // this.button1.location = new system.drawing.point (8, 56) This.button1.name = "button1"; this.button1.tabindex = 0; this.button1.text = "sendmsg"; this.button1.click = new system.eventhandler (this.button1_click); //// Button2 // this.button2.location = new system.drawing.point (8, 16); this.button2.name = "button2"; this.button2.tabindex = 1; this.button2.text = "createmsmq"; "THITEMSMQ"; this .Button2.click =
New system.eventhandler (this.button2_click); // // Button3 // this.button3.location = new system.drawing.point (8, 104); this.button3.name = "button3"; this.button3.tabindex = 2; this.button3.text = "readmsg"; this.button3.click = new system.eventhandler (this.button3_click); // // richtextbox1 // this.richtextBox1.anchor = ((System.Windows.Forms) .AnchorStyles) ((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right)) ); This.richtextBox1.Location = new system.drawing.point (0, 152); this.richtextbox1.name = "richtextbox1"; this.richtextbox1.size = new system.drawing.size (640, 188); this. richTextBox1.TabIndex = 3; this.richTextBox1.Text = "richTextBox1"; // // groupBox1 // this.groupBox1.Controls.Add (this.button2); this.groupBox1.Controls.Add (this.button1); this .groupBox1.controls.add (this.button3); this.groupbox1.loc at = new system.drawing.point (16, 0); this.groupBox1.name = "groupbox1"; this.groupBox1.size = new system.drawing.size (144, 136); this.groupBox1.tabindex = 4; THIS.GroupBox1.Tabstop = false; this.groupbox1.text = "non-transaction"; // // Groupbox2 // this.groupBox2.controls.add (this.button4); this.groupbox2.controls.add (this.button7 ); This.groupBox2.controls.add (this.creaet); this.groupbox2.controls.add (this.button6); this.groupBox2.controls.add (this.button5); this.groupbox2.location = new system. Drawing.Point (184, 0); this.groupbox2.name = "groupbox2"; this.groupbox2.size =
New system.drawing.size (240, 136); this.groupbox2.tabindex = 5; this.groupbox2.tabstop = false; this.groupbox2.text = "transaction"; // // button4 // this.button4. Location = new system.drawing.point (168, 80); this.Button4.name = "button4"; this.button4.size = new system.drawing.size (56, 48); this.button4.tabindex = 5; This.button4.text = "createmsmqwithtran"; this.button4.click = new system.eventhandler (this.button4_click); // // button7 // this.button7.location = new system.drawing.point (16, 104 This.button7.name = "button7"; this.button7.size = new system.drawing.size (136, 23); this.button7.tabindex = 4; this.button7.text = "cleanmsgofrichtxt =" ClearmsgofrichtxtBox "; this. Button7.Click = new system.eventhandler (this.button7_click); // // creaet // this.creaet.location = new system.drawing.point (144, 32); this.creaet.name = "creAet"; this.creaet.size = new system.drawing.size (80, 40); this.creaet.tabindex = 3; this.creaet.text = "Asynchronous Read Message"; THIS .Creaet.click = new system.eventhandler (this.read); // // Button6 // this.button6.location = new system.drawing.point (16, 72); this.button6.name = "button6" This.button6.size = new system.drawing.size (104, 23); this.button6.tabindex = 2; this.button6.text = "readmsgtran"; this.button6.click = new System.EventHandler (this .button6_click; // // Button5 // this.button5.location = new system.drawing.point (16, 32); this.button5.name = "button5"; this.button5.size =
New system.drawing.size (104, 24); this.button5.tabindex = 1; this.button5.text = "sendmsgtran"; this.button5.click = new system.eventhandler (this.button5_click); // / / groupBox3 // this.groupBox3.Anchor = ((System.Windows.Forms.AnchorStyles) (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms. Anchorstyles.right))))))); this.groupBox3.controls.add (this.srpub); this.groupBox3.controls.add (this.delpubmsg); this.groupBox3.controls.add (this.readfrom); this.groupBox3. Controls.add (this.sendtopub); this.groupbox3.location = new system.drawing.point (432, 0); this.groupbox3.name = "groupbox3"; this.groupBox3.size = new system.drawing.size 208, 136); this.groupBox3.Tabindex = 6; this.groupBox3.tabstop = false; this.groupbox3.text = "Public queue"; // srpub // this.srpub.location = new system.drawing. Point (144, 72); this.srpub.name = "srpub"; this.srpub.size = new system.drawing.size (56, 48); TH Is.srpub.tabindex = 4; this.srpub.text = "Search public queue"; this.srpub.click = new system.eventhandler (this.srpub_click; // // Delpubmsg // this.delpubmsg.location = New system.drawing.point (8, 96); this.delpubmsg.name = "delpubmsg"; this.delpubmsg.size = new system.drawing.size (112, 24); this.delpubmsg.tabindex = 3; this. delPubmsg.Text = "DeletePubMsmg"; this.delPubmsg.Click = new System.EventHandler (this.delPubmsg_Click); // // readFromPub // this.readFromPub.Location = new System.Drawing.Point (8, 64); this.readfrompub.name = "readfrompub";
this.readFromPub.Size = new System.Drawing.Size (128, 24); this.readFromPub.TabIndex = 2; this.readFromPub.Text = "ReadMsgFromPubMsmg"; this.readFromPub.Click = new System.EventHandler (this. ReadFromPub_Click; // // sendtopub // this.sendtopub.location = new system.drawing.point (8, 32); this.sendtopub.name = "sendtopub"; this.sendtopub.size = new system.drawing.size (144, 24); this.sendToPub.TabIndex = 1; this.sendToPub.Text = "SendMsgToPubMsmq"; this.sendToPub.Click = new System.EventHandler (this.sendToPub_Click); // // sqlConnection1 // this. sqlConnection1.ConnectionString = "workstation id = DHZ; packet size = 4096; integrated security = SSPI; data source = /" DHZ // DHZ " " / "; persist security info = False; initial catalog = Northwind"; // / / Form1 // this.autoscalebasesize = new system.drawing.size (6, 14); this.clientsize = new system.drawing.size (648, 349); this.Controls.add (this.groupbox3); this.controls .Add (this.groupbox2); this.controls.ad D (this.groupBox1); this.controls.add (this.richtextbox1); this.name = "form1"; this.text = "form1"; this.Load = new system.EventHandler (this.form1_load); this .GroupBox1.ResumeLayout (false); this.groupBox2.ResumeLayout (false); this.groupBox3.ResumeLayout (false); this.ResumeLayout (false);} #ENDREGION
///
} Private void button3_Click (object sender, System.EventArgs e) {if (! This.mq = null) {System.Messaging.MessageEnumerator msg = this.mq.GetMessageEnumerator (); while (msg.MoveNext ()) {System. Messaging .Message Oc = msg.current; OD = OC.BODY AS OD; this.richtextbox1.appendtext (od.name ":" Od.city ":" Od.Time "; / R / N ");}}} Private void button4_click (object sender, system.eventargs e) {if (@" ./ private $ / dhztrans ")) {this.msq = new messagequeue (@" ./ private $ / DHZTRANS ");} else {this.msq = messagequeue.create (@" ./ private $ / dhztrans ", true);} this.richtextbox1.appendtext (" ============= ===== / r / n "); this.richtextbox1.appendtext (msq.queueename ": creation success! / r / n ");} private void button5_click (object sender, system.eventargs e) {this. Msq = new messagequeue (@ "./ private $ / dhztrans"); if (this.msq.transactional) {OD = New OD ("Wan Qing", "Jingde Town", datetime.now.tostring ("U") ); Messagequeuetransaction myTransaction = NEW MessageQueueTransAction (); myTransaction.begin (); msq.send (od, myTransaction); myTransaction.commit (); this.richtextbox1.appendtext ("OK! Successful:" Od.Time "/ r / n") }
} Private void button6_Click (object sender, System.EventArgs e) {this.msq = new MessageQueue (@ "./ private $ / dhzTrans"); if (this.msq .Transactional) {MessageQueueTransaction myTransaction = new MessageQueueTransaction (); this .msq.Formatter = new System.Messaging.XmlMessageFormatter (new Type [] {Type.GetType ( "WinMsmq.Od")}); myTransaction.Begin (); System.Messaging.Message ms = msq.Receive (myTransaction); OD = ms.body as od; this.richtextbox1.appendtext (od.name ":" od.city ":" Od.Time "; / r / n"); myTransaction.commit (); THIS.RICHTextBox1.AppendText ("OK! Send Success / R / N");}} }.com ; if (this.msq.Transactional) {MessageQueueTransaction myTransaction = new MessageQueueTransaction (); msq.ReceiveCompleted = new ReceiveCompletedEventHandler (MyReceiveCompleted); this.msq.Formatter = new System.Messaging.XmlMessageFormatter (new Type [] {Type.GetType "" WinMsmq. Od ")}); myTransaction.Begin (); msq.BeginReceive (); Form1.signal.WaitOne (); myTransaction.Commit ();}} private void MyReceiveCompleted (Object source, ReceiveCompletedEventArgs asyncResult) {try {MessageQueue mq = (MessageQueue) Source; System.Messaging .Message M = Mq.Endreceive (asyncResult.asyncRece); Form1.Signal.Set (); od = m.body as od; this.richtextbox1.appendtext ("Read:" OD .Name ":" OD.city ":" Od.Time "/ r / n" "Insert Database Complete / R / N"); MQ.BeginReceive ();
} Catch (MessageQueueException c) {this.richTextBox1.AppendText. ( "Error:" c.Message "/ r / n"); this.button5.Enabled = false;} // Handle other exceptions} private void button7_Click ( object sender, System.EventArgs e) {this.richTextBox1.Clear ();} private void delPubmsg_Click (object sender, System.EventArgs e) {// delete the created common queue System.Messaging.MessageQueue.Delete (qryname);} private void srPub_Click (object sender, System.EventArgs e) {MessageQueue [] mq = System.Messaging.MessageQueue.GetPublicQueuesByMachine ( "dhz"); for (int i = 0; i } Private void sendToPub_Click (object sender, System.EventArgs e) {if (this.pubMsq == null) this.pubMsq = new MessageQueue (this.qryname); if (this.pubMsq.Transactional) {Od od = new Od ( "Wan Qing", "Jingde Town", DateTime.Now.ToString ("U")); MessageQueueTransaction MyTransaction = New MessageQueueTransAction (); MyTransaction.Begin (); Pubmsq.send (OD, MyTransAction); MyTransAction.commit (); MyTransaction.commit () }} private void readFromPub_Click (object sender, System.EventArgs e) {this.pubMsq = new MessageQueue (this.qryname); if (this.pubMsq.Transactional) {MessageQueueTransaction myTransaction = new MessageQueueTransaction (); pubMsq.ReceiveCompleted = new ReceiveCompletedEventHandler (MyReceiveCompleted); this.pubMsq.Formatter = new System.Messaging.XmlMessageFormatter (new Type [] {Type.GetType ( "WinMsmq.Od")}); myTransaction.Begin (); pubMsq.BeginReceive (); Form1. Signal.waitone (); myTransaction.commit ();}}}} / ========================= p () {// // TODO: Add Constructor Logic //} Public OD (String Na, String Cty, String TimeStr) {this.Name = Na; this.city = cty; this.time = TIMESTR; Private string time = ""; private string name; public string name {get {return this.name;} set {twus name = value;}} public string city}} public string city}} Set {this.city = value;}} public string time {get {return this.time;} set {this.time = value;}}} ================= ====== app.config XML Version = "1.0" encoding = "UTF-8"?> public class DBUtility: System.EnterpriseServices.ServicedComponent, ISqlConn {public DBUtility () {// // TODO: Add constructor logic here //} protected override void Construct (string s) {// TODO: Add DBUtility.Construct Realize this.m_sqlcnn = new SqlConnection (s); } Private SqlConnection m_sqlcnn; protected override bool CanBePooled () {// TODO: Add DBUtility.CanBePooled achieved return true;} #region ISqlConn member /// A summary description of Namespace WinMsmqcomqc {/// Public Int AddRecord (Order OD) {// Todo: Add SRVCOMQC.AddRecord to implement Return 0;} Public Order GetRecord (int Ordid) {// Todo: Add SRVCOMQC.GETRECORD to implement Return Null;} Public void Delrecord (int Ordid) {// Todo: Add SRVCOMQC.DelRecord Implementation} Public Void Updrecord (int Ordid, Order OD) {// Todo: Add SRVCOMQC.UPDRecord implementation} Public Dateset getAllRecord () {// Todo: Add SRVCOMQC.GETALLRECORD to implement Return Null;} #ndregion #Region isplitPage Member Public system.data.dataable firstpage () {// Todo: Add SRVCOMQC.FirstPage to implement return null;} Public system.data.DataTable nextpage () {// Todo: Add SRVCOMQC.NEXTPAGE to implement Return null;} Public system.data.DataTable lastpage () {// Todo: Add SRVCOMQC.LastPage to implement return null;} Public System.Data.DataTable Page (INT i) {// Todo: Add SRVCOMQC.PAGE to implement Return null;} PUBLIC INT PageCount {Get {// Todo: Add SRVCOMQC.PAGECUNT GETTER Implement Return 0;}} PUBLIC INT PageIndex {Get {// Todo: Add SRVCOMQC.PAGEIDEX GetTer Realization Return 0;}} #ndregion}} =================== order.csusing system;