/* * private void btn_Refresh_Click(object sender, EventArgs e) * { * SaveLog("Refresh, start scan printers"); * * startWait("Scan devices"); * * int handle1 = CreatePrinter(); * Application.DoEvents(); * SetClient(handle1, System.Text.Encoding.ASCII.GetBytes( m_pIPClient), m_iClientCount); * * int count = ScanPrinter(handle1); * * Application.DoEvents(); * StringBuilder pin = new StringBuilder(255 * 20); * GetPrinterInfos(handle1, count ,pin); * String strClient = pin.ToString(); * String[] strClients = null; * Application.DoEvents(); * strClients = strClient.Split(new Char[] { ',' }); * //} * * lstBox_Printers.Items.Clear(); * //lstBox_Printers.DataSource = strClients; * for(int i=0;i<strClients.Length;i++) * lstBox_Printers.Items.Add(strClients[i]); * * DelPrinter(handle1); * StopWait(); * SaveLog("scan end, find [" + count.ToString() + "] printers."); * } */ public LinePageForm newLinePage(string sLineName) { MainTables.TabPages.Add(sLineName); MainTables.SelectTab(MainTables.TabPages.Count - 1); LinePageForm lineform = new LinePageForm(); lineform.FormBorderStyle = FormBorderStyle.None; lineform.Dock = DockStyle.Fill; lineform.TopLevel = false; lineform.Parent = MainTables.SelectedTab; lineform.LineName = sLineName; lineform.mainForm = this; lineform.bNeedAutoConnect = m_bAutoConnect; lineform.bNeedAutoPrint = m_bAutoPrint; lineform.Show(); LineForms.Add(lineform); currLinePage = lineform; createAllLineName(); CLog.SaveLog("Create Line[" + sLineName + "]"); return(lineform); }
public void ReadLineInfo() { string str = System.Windows.Forms.Application.StartupPath; str += "\\DeviceServer.ini"; string sval = cIniFile.ReadIniKeys("ProductLines", "Count", str); int iCount = int.Parse(sval); LinePageForm lpf = null; LineForms.Clear(); for (int i = 0; i < iCount; i++) { string strtemp = "ProductLine" + i.ToString(); sval = cIniFile.ReadIniKeys(strtemp, "Name", str); lpf = newLinePage(sval); //LineForms.Add(lpf); sval = cIniFile.ReadIniKeys(strtemp, "IP", str); lpf.setIP(sval);// (IP2Str(uint.Parse(sval))); sval = cIniFile.ReadIniKeys(strtemp, "SN", str); lpf.setSN(sval); sval = cIniFile.ReadIniKeys(strtemp, "MsgName", str); lpf.setLastPrintedMsgName(sval); lpf.DoAuto(); } }
private void btn_RenameLine_Click(object sender, EventArgs e) { if (MainTables.SelectedIndex < 0) { return; } string sLineName = MainTables.TabPages[MainTables.SelectedIndex].Text; string sName = Input("Please input the new Product-Line Name:", sLineName); if (sName.Length < 1) { return; } MainTables.TabPages[MainTables.SelectedIndex].Text = sName; LinePageForm lpf = getPage(sLineName); lpf.LineName = sName; createAllLineName(); CLog.SaveLog("Rename line [" + sLineName + "] to [" + sName + "]"); }
private void MainTables_SelectedIndexChanged(object sender, EventArgs e) { //当当前活动页变化,当前活动Form也要改 if (MainTables.SelectedIndex < 0) { return; } currLinePage = getPage(MainTables.TabPages[MainTables.SelectedIndex].Text); }
private LinePageForm GetLineFormbyName(string sLineName) { for (int i = 0; i < LineForms.Count; i++) { LinePageForm lpf = LineForms[i]; if (lpf.LineName == sLineName) { return(lpf); } } return(null); }
private bool checkLineName(string sLineName) {//true = can use for (int i = 0; i < LineForms.Count; i++) { LinePageForm lpf = LineForms[i]; if (lpf.LineName == sLineName) { return(false); } } return(true); }
private void btn_Assign_Click(object sender, EventArgs e) { if (MainTables.TabCount < 1) { MessageBox.Show("Please create product-line first."); return; } if (lstBox_Printers.Items.Count < 1) { MessageBox.Show("Please refresh devices."); return; } if (lstBox_Printers.SelectedIndex < 0) { lstBox_Printers.SelectedIndex = 0; } String str; str = "Are your sure add "; str += lstBox_Printers.Items[lstBox_Printers.SelectedIndex].ToString(); str += " to ["; str += MainTables.TabPages[MainTables.SelectedIndex].Text; str += "]?"; DialogResult dr; dr = MessageBox.Show(str, "", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); if (dr == DialogResult.No) { return; } LinePageForm lPage = getPage(MainTables.TabPages[MainTables.SelectedIndex].Text); lPage.setIPstr(lstBox_Printers.Items[lstBox_Printers.SelectedIndex].ToString()); CLog.SaveLog("Add [" + lstBox_Printers.Items[lstBox_Printers.SelectedIndex].ToString() + "] to [" + MainTables.TabPages[MainTables.TabIndex].Text + "]"); //MainTables.TabPages[MainTables.TabIndex]. }
public void SaveLineInfo() { string str = System.Windows.Forms.Application.StartupPath; str += "\\DeviceServer.ini"; cIniFile.WriteIniKeys("ProductLines", "Count", LineForms.Count.ToString(), str); for (int i = 0; i < LineForms.Count; i++) { LinePageForm lpf = LineForms[i]; string strtemp = "ProductLine" + i.ToString(); cIniFile.WriteIniKeys(strtemp, "Name", lpf.LineName, str); cIniFile.WriteIniKeys(strtemp, "IP", lpf.getIP(), str); cIniFile.WriteIniKeys(strtemp, "SN", lpf.getSN(), str); cIniFile.WriteIniKeys(strtemp, "MsgName", lpf.getLastPrintedMsgName(), str); } }
private void btn_DelLine_Click(object sender, EventArgs e) { if (MainTables.SelectedIndex < 0) { return; } string sLineName = MainTables.TabPages[MainTables.SelectedIndex].Text; DialogResult rlt = MessageBox.Show("Are you sure delete this product-line[" + sLineName + "]?" , "", MessageBoxButtons.YesNo); if (rlt == DialogResult.No) { return; } MainTables.TabPages.Remove(MainTables.TabPages[MainTables.SelectedIndex]); LinePageForm lpf = getPage(sLineName); LineForms.Remove(lpf); if (MainTables.TabPages.Count == 0) { btn_DelLine.Enabled = false; btn_RenameLine.Enabled = false; } else { btn_DelLine.Enabled = true; btn_RenameLine.Enabled = true; } createAllLineName(); CLog.SaveLog("Delete line [" + sLineName + "]"); }
public void DealCMD(string StrIN, Socket currSocket) { //如果客户端的命令以LIST开头, string request = StrIN.Replace("\n", "").Replace("\r", ""); SaveRecStrings(StrIN); if (request.StartsWith("List:")) { byte[] responseBuffer = System.Text.Encoding.ASCII.GetBytes("List:" + m_sAllLineNames); currSocket.Send(responseBuffer); //clientStream.Write(responseBuffer, 0, responseBuffer.Length); } else if (request.StartsWith("Connect:")) { string[] requestMessage = request.Split(':'); string reqLineName = requestMessage[1]; string[] LineNames = m_sAllLineNames.Split(','); bool bFound = false; for (int i = 0; i < LineNames.Length; i++) { if (reqLineName == LineNames[i]) { bFound = true; break; } } byte[] data; if (bFound) { string strReturn = "Connect:OK"; data = System.Text.Encoding.ASCII.GetBytes(strReturn); } else { string strReturn = "Connect:ERROR [" + reqLineName + "] no found."; data = System.Text.Encoding.ASCII.GetBytes(strReturn); } currSocket.Send(data); if (dictLine.ContainsKey(currSocket)) { dictLine[currSocket] = reqLineName; } else { dictLine.Add(currSocket, reqLineName); } //clientStream.Write(data, 0, data.Length); } else if (request.StartsWith("Send:")) { string[] requestMessage = request.Split(':'); string strStrings = requestMessage[1]; byte[] data; string slinename = ""; try { slinename = dictLine[currSocket]; } catch (KeyNotFoundException knfe) { string strReturn = "Send:ERROR [ Please connect Line first ]! "; data = System.Text.Encoding.ASCII.GetBytes(strReturn); } //find line page LinePageForm lpf = GetLineFormbyName(slinename); int irlt = 0; if (lpf != null) { irlt = lpf.SendStrings(strStrings); } else { //找不到对应的,不显示 } //int irlt = SendDynStrings(iprin) if (irlt == Constant.ERR_OK) { string strReturn = "Send:OK"; data = System.Text.Encoding.ASCII.GetBytes(strReturn); } else { string strError = irlt.ToString(); if (irlt == Constant.ERR_SEND_STRINGS) { strError = "Probably Message not correct."; } else if (irlt == Constant.ERR_ERROR) { strError = "Probably Cache buffer is full or no dynamic text object."; } string strReturn = "Send:ERROR [" + strError + "] "; data = System.Text.Encoding.ASCII.GetBytes(strReturn); } currSocket.Send(data); //clientStream.Write(data, 0, data.Length); } }