103 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			103 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			C#
		
	
	
	
| using System;
 | |
| using System.Linq;
 | |
| using System.Collections.Generic;
 | |
| using System.ComponentModel;
 | |
| using System.Data;
 | |
| using System.Drawing;
 | |
| using System.Text;
 | |
| using System.Windows.Forms;
 | |
| using System.Net;
 | |
|  
 | |
| 
 | |
| namespace dnSeeds
 | |
| {
 | |
|     public partial class NewSeeds : Form
 | |
|     {
 | |
|         public NewSeeds()
 | |
|         {
 | |
|             InitializeComponent();
 | |
|         }
 | |
|         int deskId;
 | |
|         string seedsNo;
 | |
|         string svrUrl = "http://192.168.1.101:9998/DNLight/startSeeds?deskId={0}&seedsNo={1}";
 | |
|         private void btnStart_Click(object sender, EventArgs e)
 | |
|         {
 | |
| 
 | |
|             if (validInput())
 | |
|             {
 | |
|                 startNewSeeds(deskId,seedsNo);
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         void startNewSeeds(int deskId,string seedsNo)
 | |
|         { 
 | |
|             svrUrl = string.Format(svrUrl, deskId, seedsNo);
 | |
|             HttpWebRequest webReq;
 | |
|             webReq = (HttpWebRequest)WebRequest.Create(new Uri(svrUrl));
 | |
| 
 | |
|             System.Net.HttpWebResponse response;
 | |
|             response = (System.Net.HttpWebResponse)webReq.GetResponse();
 | |
|             System.IO.StreamReader myreader = new System.IO.StreamReader(response.GetResponseStream(), Encoding.UTF8);
 | |
|             string responseText = myreader.ReadToEnd();
 | |
|             myreader.Close();
 | |
|            // MessageBox.Show(responseText);
 | |
|             logMsg(responseText);
 | |
|         }
 | |
|         bool validInput()
 | |
|         {
 | |
|             deskId = 1;
 | |
|             /*try
 | |
|             {
 | |
|                 deskId = Convert.ToInt16(textBoxDeskId.Text.Trim().ToString());
 | |
|             }
 | |
|             catch (Exception e)
 | |
|             {
 | |
|                 MessageBox.Show("请输入播种台ID");
 | |
|                 textBoxDeskId.SelectAll();
 | |
|                 textBoxDeskId.Focus();
 | |
|                 return false;
 | |
|             }
 | |
|             */
 | |
|                 seedsNo = txtboxSeedsNo.Text.Trim();
 | |
| 
 | |
|                 if (seedsNo.Length == 0)
 | |
|                 {
 | |
| 
 | |
|                    // MessageBox.Show("请输入播种台ID");
 | |
|                     logMsg("请扫描条码");
 | |
|                     txtboxSeedsNo.SelectAll();
 | |
|                     txtboxSeedsNo.Focus();
 | |
|                     return false;
 | |
|                 }
 | |
| 
 | |
| 
 | |
| 
 | |
|                 return true;
 | |
| 
 | |
| 
 | |
|         }
 | |
| 
 | |
|         private void txtboxSeedsNo_KeyPress(object sender, KeyPressEventArgs e)
 | |
|         {
 | |
|            // if (e.KeyCode == Keys.Enter)
 | |
|             {
 | |
| 
 | |
|                 if (validInput())
 | |
|                 {
 | |
|                     startNewSeeds(deskId, seedsNo);
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         private void logMsg(String mesg)
 | |
|         {
 | |
|              if (txtLog.Text.Length > 500)
 | |
|             {
 | |
|                 txtLog.Text = "";
 | |
|             }
 | |
|             mesg = String.Format("{0} {1}", DateTime.Now, mesg);
 | |
|             txtLog.Text = mesg + txtLog.Text;
 | |
| 
 | |
|         }
 | |
|     }
 | |
| } |