static void Main(string[] args) { MyCallback myCallbackObj = new MyCallback(); CppClass instance = MyDLL.CreateInstance(); string str = "テストHello World!"; instance.SetString(str); Debug.WriteLine($"str = {instance.GetString()}"); FloatVector v = new FloatVector(); v.Add((float)-0.1); v.Add((float)-1); v.Add((float)-10); int i = 0; instance.SetVector(v); FloatVector buf = instance.GetVector(); foreach (float value in buf) { Debug.WriteLine($"[{i}] :value = {value}"); i += 1; } instance.SetCallback(myCallbackObj); instance.ExeCallback(); }
private void button2_Click(object sender, EventArgs e) { if (dataGridView1.RowCount <= 0) { MessageBox.Show("没有要打印的内容"); return; } /////////////////////////////////////////////////////打印模块 System.Data.DataTable dt = new System.Data.DataTable(); DataRow dr; //设置列表头 foreach (DataGridViewColumn headerCell in dataGridView1.Columns) { dt.Columns.Add(headerCell.HeaderText); } foreach (DataGridViewRow item in dataGridView1.Rows) { dr = dt.NewRow(); for (int i = 0; i < dt.Columns.Count; i++) { dr[i] = item.Cells[i].Value; } dt.Rows.Add(dr); } DataSet dy = new DataSet(); dy.Tables.Add(dt); MyDLL.TakeOver(dy); ////////////////////////////////////////////////////// }
public static void Pgm(String stSeconds, Queue <int> iQueue, Int16 lenQueue2, Int16 lenQueue4, bool flagDebug) { MyDLL.setWhite(0); MyDLL.cleanScreen(); MyDLL.setAutoMaxMin(true, true); int ScaleValue = MyDLL.getScaleMove(); WriteDebug.Pgm("MOVE = " + ScaleValue.ToString(), flagDebug); if (stSeconds == "4S") { for (int x = 0; x <= lenQueue4; x++) { if (x % 4 == ScaleValue) { MyDLL.addData(iQueue.ElementAt(x)); } } } if (stSeconds == "2S") { for (int x = 0; x <= lenQueue2; x++) { if (x % 2 == ScaleValue) { MyDLL.addData(iQueue.ElementAt(x)); } } } }
private void btnPrint_Click(object sender, EventArgs e) { DataSet dy = new DataSet(); dy.Tables.Add(SSP.MainTable.Copy()); MyDLL.TakeOver(dy); }
public static String[] Pgm(bool flagDebug) { MyDLL.addCOMPort(""); String[] ports = SerialPort.GetPortNames(); // Add port list if (ports.Count() != 0) { String ListPort = ""; foreach (string port in ports) { if (!ListPort.Contains(port)) { ListPort = ListPort + port + ","; } WriteDebug.Equals("SERIALPORT = " + port, flagDebug); } if (ListPort != "") { MyDLL.addCOMPort(ListPort); } else { MyDLL.addCOMPort(""); } } return(ports); }
//**********************************************************************************// // //**********************************************************************************// private static bool initPORTCOM(String PortName) { if (PortName == "") { WriteDebug.Pgm("NO COM port", FlagDebug); MyDLL.setVisible("START", false); MyDLL.setVisible("STOP", false); MyDLL.setVisible("1S1", false); MyDLL.setVisible("1S2", false); MyDLL.setVisible("1S3", false); MyDLL.setVisible("1S4", false); MyDLL.setVisible("2S1", false); MyDLL.setVisible("2S2", false); MyDLL.setVisible("4S", false); } else { if (!ComPort.IsOpen) { try { WriteDebug.Pgm("Init COM port", FlagDebug); ComPort.PortName = PortName; ComPort.BaudRate = 115200; ComPort.DataBits = 8; ComPort.StopBits = StopBits.One; ComPort.RtsEnable = false; ComPort.Handshake = Handshake.None; ComPort.Parity = Parity.None; //ComPort.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived); ComPort.Open(); } catch (Exception ex) { WriteDebug.Pgm("ERROR : init COM port - " + ex.Message.ToString(), FlagDebug); return(false); } } else { WriteDebug.Pgm("COM port is still opened", FlagDebug); } int totalBytes = ComPort.BytesToRead; while (totalBytes > 0) { char[] buffer = new char[totalBytes]; ComPort.Read(buffer, 0, totalBytes); Thread.Sleep(100); totalBytes = ComPort.BytesToRead; } } return(true); }
public static void Pgm(Queue <int> iQueue) { String myDate = DateTime.Now.ToString("ddMMyyyy-HHmmss"); String NameFile = "MicroSupply_" + myDate + ".csv"; System.IO.StreamWriter file = new System.IO.StreamWriter(NameFile); foreach (int iQ in iQueue) { file.WriteLine(iQ.ToString()); } file.Close(); MyDLL.writeMessageYesNo("Save", "File " + NameFile + " created"); }
public static void Pgm(SerialPort comPort, int longueur, Int16 lenQueue1, Int16 lenQueue2, Int16 lenQueue3, Int16 lenQueue4, bool flagDebug) { try { int totalBytes = comPort.BytesToRead; while (totalBytes > 0) { WriteDebug.Pgm("Send data END (E)", flagDebug); comPort.Write("E"); char[] buffer = new char[totalBytes]; comPort.Read(buffer, 0, totalBytes); Thread.Sleep(100); totalBytes = comPort.BytesToRead; if (buffer[1] == 'j' && buffer[2] == 'o' && buffer[3] == '?') { totalBytes = 0; } } totalBytes = comPort.BytesToRead; char[] buffer2 = new char[totalBytes]; comPort.Read(buffer2, 0, totalBytes); } catch {} MyDLL.setVisible("START", true); MyDLL.setVisible("REFRESH", true); MyDLL.setVisible("STOP", false); MyDLL.setVisible("HELP", true); MyDLL.setAutoMaxMin(false, false); if (longueur > lenQueue4) { MyDLL.setVisible("1S", true); MyDLL.setVisible("2S", true); MyDLL.setVisible("4S", true); } else { if (longueur > lenQueue3) { MyDLL.setVisible("1S", true); MyDLL.setVisible("2S", true); } else { if (longueur > lenQueue1) { MyDLL.setVisible("1S", true); } } } }
public static bool Pgm(SerialPort comPort, bool flagDebug) { try { int totalBytes = comPort.BytesToRead; while (totalBytes > 0) { char[] buffer = new char[totalBytes]; comPort.Read(buffer, 0, totalBytes); Thread.Sleep(100); totalBytes = comPort.BytesToRead; } int retValue = 0; while (retValue != 65534) { WriteDebug.Pgm("Send data BEGIN (B)", flagDebug); comPort.Write("B"); retValue = readCOM.Pgm(comPort, true, flagDebug); } } catch (Exception ex) { WriteDebug.Pgm("ERROR : COM port - " + ex.Message.ToString(), flagDebug); MyDLL.writeMessage("ERROR", "START button", "Error Com port !"); return(false); } MyDLL.setVisible("START", false); MyDLL.setVisible("REFRESH", false); MyDLL.setVisible("SAVE", false); MyDLL.setVisible("INSIDE", false); MyDLL.setVisible("MOVE", false); MyDLL.setVisible("1S", false); MyDLL.setVisible("2S", false); MyDLL.setVisible("4S", false); MyDLL.setVisible("STOP", true); MyDLL.setVisible("HELP", false); MyDLL.setAutoMaxMin(true, true); MyDLL.cleanScreen(); MyDLL.setWhite(50); MyDLL.setVisible("MAX", true); return(true); }
private void button3_Click(object sender, EventArgs e) {//入库按钮事件处理 if (dataGridView1.RowCount > 0) { insert_inlib(); //添加入库记录 update_lib(); // 修改库存 if (MessageBox.Show("入库完成,是否需要打印?", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK) { /////////////////////////////////////////////////////打印模块 datato3(); System.Data.DataTable dt = new System.Data.DataTable(); DataRow dr; //设置列表头 foreach (DataGridViewColumn headerCell in dataGridView3.Columns) { dt.Columns.Add(headerCell.HeaderText); } foreach (DataGridViewRow item in dataGridView3.Rows) { dr = dt.NewRow(); for (int i = 0; i < dt.Columns.Count; i++) { dr[i] = item.Cells[i].Value; } dt.Rows.Add(dr); } DataSet dy = new DataSet(); dy.Tables.Add(dt); MyDLL.TakeOver(dy); } dataGridView3.Rows.Clear(); //打印完成后清空表格中数据 dataGridView1.Rows.Clear(); ////////////////////////////////////////////////////// } else { MessageBox.Show("待入库药品为空!"); } }
static void Main(string[] args) { //Testdllsharp(); WinAPI.Message(IntPtr.Zero, "Привіт", "Вікно", 0); int m = 10; double d = 9.99; WinAPI.printf("m=%d d=%f\n", m, d); WinAPI.printf("%d * %f =%f ", __arglist(m, d, m * d)); double a = 10; double b = 0; Console.WriteLine($"\n{a}+{b}={MyDLL.Add(a,b)}"); Console.WriteLine($"{a}-{b}={MyDLL.Sub(a,b)}"); Console.WriteLine($"{a}*{b}={MyDLL.Mult(a,b)}"); Console.WriteLine($"{a}/{b}={MyDLL.Div(a,b)}"); Console.ReadKey(); }
private void button1_Click(object sender, EventArgs e) { System.Data.DataTable dt = new System.Data.DataTable(); DataRow dr; //设置列表头 foreach (DataGridViewColumn headerCell in dataGridView1.Columns) { dt.Columns.Add(headerCell.HeaderText); } foreach (DataGridViewRow item in dataGridView1.Rows) { dr = dt.NewRow(); for (int i = 0; i < dt.Columns.Count; i++) { dr[i] = item.Cells[i].Value.ToString(); } dt.Rows.Add(dr); } DataSet dy = new DataSet(); dy.Tables.Add(dt); MyDLL.TakeOver(dy); }
//**********************************************************************************// // //**********************************************************************************// private static void ENDApplication() { while (!MyDLL.getStatusClose()) { Thread.Sleep(500); } try { WriteDebug.Pgm("Send data : E", FlagDebug); ComPort.Write("E"); } catch (Exception) { } try { if (ComPort.IsOpen) { Thread.Sleep(500); ComPort.Close(); } } catch (Exception) { } Thread.Sleep(500); Environment.Exit(0); }
public static int Pgm(String stSeconds, int longeur, Int16 lenQueue1, Int16 lenQueue2, Int16 lenQueue3, Int16 lenQueue4, bool flagDebug) { MyDLL.setWhite(0); MyDLL.cleanScreen(); MyDLL.setAutoMaxMin(true, true); int ScaleValue = MyDLL.getScaleInside(); WriteDebug.Pgm("INSIDE = " + ScaleValue.ToString(), flagDebug); int valDecale = 0; if (stSeconds == "1S") { valDecale = ScaleValue * 250; if ((lenQueue1 + valDecale) < longeur) { switch (ScaleValue) { case 0: MyDLL.setZero("0"); MyDLL.setValueX("0.25", "0.5", "0.75", "1s"); break; case 1: MyDLL.setZero("0.25"); MyDLL.setValueX("0.5", "0.75", "1", "1.25s"); break; case 2: MyDLL.setZero("0.5"); MyDLL.setValueX("0.75", "1", "1.25", "1.5s"); break; case 3: MyDLL.setZero("0.75"); MyDLL.setValueX("1", "1.25", "1.5", "1.75s"); break; case 4: MyDLL.setZero("1"); MyDLL.setValueX("1.25", "1.5", "1.75", "2s"); break; case 5: MyDLL.setZero("1.25"); MyDLL.setValueX("1.5", "1.75", "2", "2.25s"); break; case 6: MyDLL.setZero("1.5"); MyDLL.setValueX("1.75", "2", "2.25", "2.5s"); break; case 7: MyDLL.setZero("1.75"); MyDLL.setValueX("2", "2.25", "2.5", "2.75s"); break; case 8: MyDLL.setZero("2"); MyDLL.setValueX("2.25", "2.5", "2.75", "3s"); break; case 9: MyDLL.setZero("2.25"); MyDLL.setValueX("2.5", "2.75", "3", "3.25s"); break; case 10: MyDLL.setZero("2.5"); MyDLL.setValueX("2.75", "3", "3.25", "3.5s"); break; case 11: MyDLL.setZero("2.75"); MyDLL.setValueX("3", "3.25", "3.5", "3.75s"); break; case 12: MyDLL.setZero("3"); MyDLL.setValueX("3.25", "3.5", "3.75", "4s"); break; default: break; } } } if (stSeconds == "2S") { valDecale = ScaleValue * 500; if ((lenQueue1 + valDecale) < longeur) { switch (ScaleValue) { case 0: MyDLL.setZero("0"); MyDLL.setValueX("0.5", "1", "1.5", "2s"); break; case 1: MyDLL.setZero("0.5"); MyDLL.setValueX("1", "1.5", "2", "2.5s"); break; case 2: MyDLL.setZero("1"); MyDLL.setValueX("1.5", "2", "2.5", "3s"); break; case 3: MyDLL.setZero("1.5"); MyDLL.setValueX("2", "2.5", "3", "3.5s"); break; case 4: MyDLL.setZero("2"); MyDLL.setValueX("2.5", "3", "3.5", "4s"); break; default: break; } } } return(valDecale); }
public static void Pgm(String stSeconds, Queue <int> iQueue, Int16 lenQueue1, Int16 lenQueue2, Int16 lenQueue3, Int16 lenQueue4) { switch (stSeconds) { case "1S": MyDLL.setEnable("1S", false); MyDLL.setEnable("2S", true); MyDLL.setEnable("4S", true); MyDLL.setVisible("SAVE", true); MyDLL.setVisible("INSIDE", true); MyDLL.setInside(12); MyDLL.setVisible("MOVE", false); MyDLL.setWhite(0); MyDLL.cleanScreen(); MyDLL.setAutoMaxMin(true, true); MyDLL.setZero("0"); MyDLL.setValueX("0.25", "0.5", "0.75", "1s"); for (int x = 0; x <= lenQueue1; x++) { MyDLL.addData(iQueue.ElementAt(x)); } break; case "2S": MyDLL.setEnable("1S", true); MyDLL.setEnable("2S", false); MyDLL.setEnable("4S", true); MyDLL.setVisible("SAVE", true); MyDLL.setVisible("INSIDE", true); MyDLL.setVisible("MOVE", true); MyDLL.setInside(4); MyDLL.setMove(1); MyDLL.setWhite(0); MyDLL.cleanScreen(); MyDLL.setAutoMaxMin(true, true); MyDLL.setZero("0"); MyDLL.setValueX("0.5", "1", "1.5", "2s"); for (int x = 0; x <= lenQueue2; x++) { if (x % 1 == 0) { MyDLL.addData(iQueue.ElementAt(x)); } } break; case "4S": MyDLL.setEnable("1S", true); MyDLL.setEnable("2S", true); MyDLL.setEnable("4S", false); MyDLL.setVisible("SAVE", true); MyDLL.setVisible("INSIDE", false); MyDLL.setVisible("MOVE", true); MyDLL.setMove(3); MyDLL.setWhite(0); MyDLL.cleanScreen(); MyDLL.setAutoMaxMin(true, true); MyDLL.setZero("0"); MyDLL.setValueX("1", "2", "3", "4s"); for (int x = 0; x <= lenQueue4; x++) { if (x % 4 == 0) { MyDLL.addData(iQueue.ElementAt(x)); } } break; default: break; } }
//**********************************************************************************// // Main program (if arg is "DEBUG" than the Console mode not be hiden // and debug informations will be print //**********************************************************************************// static void Main(string[] args) { // test arg = DEBUG if (args.Length > 0) { if (args[0].ToUpper() == "DEBUG") { FlagDebug = true; } } // test Version Windows 10 WriteDebug.Pgm("<< Test Version Windows 10 >>", FlagDebug); String Version = GetOsVer().ToString().Replace(".", ""); Int64 xVersion = 0; if (Int64.TryParse(Version, out xVersion)) { WriteDebug.Pgm("Version Windows : " + xVersion.ToString(), FlagDebug); if (xVersion < 10014393) { String errorVer = "Version Windows 10 is not updated : " + Version; MessageBox((IntPtr)0, errorVer, "Error Windows 10", 0); Environment.Exit(0); } } else { if (Version != "") { MessageBox((IntPtr)0, "Version Windows 10 not found", "Error Windows 10", 0); Environment.Exit(0); } } // test JAVA files WriteDebug.Pgm("<< Test folder Java >>", FlagDebug); try { bool bJava = Directory.Exists("C:\\Program files\\Java"); if (!bJava) { bJava = Directory.Exists("C:\\Program Files (x86)\\Java"); if (!bJava) { MessageBox((IntPtr)0, "Folder Java doesn't found !", "Error Java", 0); Environment.Exit(0); } } } catch { MessageBox((IntPtr)0, "Folder Java doesn't found !", "Error Java", 0); Environment.Exit(0); } // test version Java WriteDebug.Pgm("<< Test Version Java >>", FlagDebug); int verJava = 0; try { String registryKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"; using (RegistryKey key = Registry.LocalMachine.OpenSubKey(registryKey)) { foreach (RegistryKey subkey in key.GetSubKeyNames().Select(keyName => key.OpenSubKey(keyName))) { string oneKey = subkey.GetValue("DisplayName") as string; if (oneKey != null && oneKey.Contains("Java") && !oneKey.Contains("Updater")) { string versionMEM = subkey.GetValue("DisplayVersion") as String; WriteDebug.Pgm("<< Version Java (1) >> " + versionMEM, FlagDebug); string[] tempo = versionMEM.Split('.'); verJava = int.Parse(tempo[0]); } } } if (verJava == 0) { registryKey = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"; using (RegistryKey key = Registry.LocalMachine.OpenSubKey(registryKey)) { foreach (RegistryKey subkey in key.GetSubKeyNames().Select(keyName => key.OpenSubKey(keyName))) { string oneKey = subkey.GetValue("DisplayName") as string; if (oneKey != null && oneKey.Contains("Java") && !oneKey.Contains("Updater")) { string versionMEM = subkey.GetValue("DisplayVersion") as String; WriteDebug.Pgm("<< Version Java (2) >> " + versionMEM, FlagDebug); string[] tempo = versionMEM.Split('.'); verJava = int.Parse(tempo[0]); } } } } if (verJava == 0) { registryKey = @"SOFTWARE\JavaSoft\Java Runtime Environment"; using (RegistryKey key = Registry.LocalMachine.OpenSubKey(registryKey)) { string versionMEM = key.GetValue("CurrentVersion") as string; WriteDebug.Pgm("<< Version Java (3) >> " + versionMEM, FlagDebug); string[] tempo = versionMEM.Split('.'); verJava = int.Parse(tempo[1]); } } if (verJava == 0) { registryKey = @"SOFTWARE\Wow6432Node\JavaSoft\Java Runtime Environment"; using (RegistryKey key = Registry.LocalMachine.OpenSubKey(registryKey)) { string versionMEM = key.GetValue("CurrentVersion") as string; WriteDebug.Pgm("<< Version Java (4) >> " + versionMEM, FlagDebug); string[] tempo = versionMEM.Split('.'); verJava = int.Parse(tempo[1]); } } if (verJava < 8) { MessageBox((IntPtr)0, "Java must have version 1.8 or over !", "Error version Java", 0); Environment.Exit(0); } } catch (Exception ex) { MessageBox((IntPtr)0, "ERROR : " + ex.Message.ToString(), "Error version Java", 0); Environment.Exit(0); } // test files IKVM WriteDebug.Pgm("<< Test IKVM DLL files >>", FlagDebug); if (!File.Exists("ikvm-native-win32-x64.dll")) { MessageBox((IntPtr)0, "file ikvm-native-win32-x64.dll is missing", "File missing", 0); Environment.Exit(0); } if (!File.Exists("IKVM.OpenJDK.Core.dll")) { MessageBox((IntPtr)0, "file IKVM.OpenJDK.Core.dll is missing", "File missing", 0); Environment.Exit(0); } // test files SWT WriteDebug.Pgm("<< Test files SWT >>", FlagDebug); String pathSWT = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); pathSWT += "\\.swt\\lib\\win32\\x86_64"; bool[] bools = new bool[6]; bools[0] = File.Exists(pathSWT + "\\swt-gdip-win32-4233.dll"); bools[1] = File.Exists(pathSWT + "\\swt-gdip-win32-4763.dll"); bools[2] = File.Exists(pathSWT + "\\swt-gdip-win32-4919.dll"); bools[3] = File.Exists(pathSWT + "\\swt-win32-4233.dll"); bools[4] = File.Exists(pathSWT + "\\swt-win32-4763.dll"); bools[5] = File.Exists(pathSWT + "\\swt-win32-4919.dll"); int[] arrs = Array.ConvertAll(bools, b => b ? 0 : 1); int arrCount = arrs[0] + arrs[1] + arrs[2] + arrs[3] + arrs[4] + arrs[5]; switch (arrCount) { case 0: break; case 1: String stFile = ""; if (bools[0]) { stFile = "swt-gdip-win32-4233.dll"; } if (bools[1]) { stFile = "swt-gdip-win32-4763.dll"; } if (bools[2]) { stFile = "swt-gdip-win32-4919.dll"; } if (bools[3]) { stFile = "swt-win32-4233.dll"; } if (bools[4]) { stFile = "swt-win32-4763.dll"; } if (bools[5]) { stFile = "swt-win32-4919.dll"; } MessageBox((IntPtr)0, "file " + stFile + " is missing in " + pathSWT, "File missing", 0); Environment.Exit(0); break; case 2: case 3: case 4: case 5: MessageBox((IntPtr)0, arrCount + " files missing in " + pathSWT, "Files missing", 0); Environment.Exit(0); break; case 6: MessageBox((IntPtr)0, "All files missing in " + pathSWT, "Files missing", 0); Environment.Exit(0); break; default: break; } // test if no COM port WriteDebug.Pgm("<< Test if COM port found >>", FlagDebug); string[] testPorts = SerialPort.GetPortNames(); if (testPorts.Count() == 0) { MessageBox((IntPtr)0, "No COM port found !", "Error port COM", 0); Environment.Exit(0); } // Application standard //Application.EnableVisualStyles(); //Application.SetCompatibleTextRenderingDefault(false); // Hide Console if not debug mode if (!FlagDebug) { var handle = GetConsoleWindow(); ShowWindow(handle, SW_HIDE); } else { WriteDebug.Pgm("<< BEGIN >>", true); } // test to acces to the MicroSupply_JA.dll WriteDebug.Pgm("<< Test DLL MicroSupply_JA >>", FlagDebug); try { //String dllVersion = MyDLL.getVersion(); //var thisApp = Assembly.GetExecutingAssembly(); //AssemblyName name = new AssemblyName(thisApp.FullName); //String pgmVersion = name.Version.ToString().Substring(0, name.Version.ToString().Length - 2); //if (String.Compare(dllVersion, pgmVersion) == 0) //{ // WriteDebug.Pgm("MicroSupply_JA.dll Version : " + dllVersion, FlagDebug); // WriteDebug.Pgm("MicroSupply.exe Version : " + pgmVersion, FlagDebug); //} //else //{ // WriteDebug.Pgm("Versions ERROR", true); // WriteDebug.Pgm("MicroSupply_JA.dll Version : " + dllVersion, true); // WriteDebug.Pgm("MicroSupply Version : " + pgmVersion, true); // Thread.Sleep(5000); // Environment.Exit(0); //} } catch (Exception e) { WriteDebug.Pgm(e.Message.ToString(), FlagDebug); Thread.Sleep(5000); Environment.Exit(0); } // INIT screen WriteDebug.Pgm("<< Launch the screen >>", FlagDebug); try { MyDLL.initScreenJA(); } catch (Exception e) { WriteDebug.Pgm(e.Message.ToString(), FlagDebug); Thread.Sleep(5000); Environment.Exit(0); } try { while (!MyDLL.testScreenReady()) { } MyDLL.setValueX("0.25", "0.5", "0.75", "1s"); MyDLL.setValueY("10", "20", "30", "40", "µA"); MyDLL.setVisible("COM", false); MyDLL.setVisible("REFRESH", false); MyDLL.setVisible("HELP", true); MyDLL.setVisible("EXIT", true); MyDLL.setVisible("START", false); // test arg = TEST if (args.Length > 0) { if (args[0].ToUpper() == "TEST") { MyDLL.setVisible("COM", true); MyDLL.setVisible("REFRESH", true); MyDLL.setVisible("START", true); MyDLL.setVisible("STOP", true); MyDLL.setVisible("1S", true); MyDLL.setVisible("2S", true); MyDLL.setVisible("4S", true); MyDLL.setVisible("SAVE", true); MyDLL.setVisible("INSIDE", true); MyDLL.setVisible("MOVE", true); MyDLL.setVisible("MAX", true); MyDLL.setVisible("MIN", true); while (true) { while (!MyDLL.getStatusKey()) { } String stKey = MyDLL.getKeyValue(); WriteDebug.Pgm("KEY : " + stKey, FlagDebug); if (stKey.Contains("EXIT")) { Thread.Sleep(500); Environment.Exit(0); } } } } } catch (Exception e) { WriteDebug.Pgm(e.Message.ToString(), FlagDebug); Thread.Sleep(5000); Environment.Exit(0); } // Launch Thread if the screen will be closed t = new Thread(ENDApplication); t.Start(); // Identify Serial port list string[] ports = null; String stPort = ""; ports = SerialPort.GetPortNames(); // Add port list MyDLL.setVisible("START", false); if (ports.Count() != 0) { String ListPort = ""; bool flagPort = true; foreach (string port in ports) { if (ListPort.Contains(port)) { flagPort = false; } else { ListPort = ListPort + port + ","; } WriteDebug.Pgm("COM PORT : " + port, FlagDebug); } if (!flagPort) { string[] lports = ListPort.Split(','); foreach (string port in lports) { try { if (port != "") { ComPort.PortName = port; try { ComPort.Open(); } finally { if (ComPort.IsOpen) { ComPort.Close();//<---this is the important bit!!! } } ComPort.Close(); } } catch (UnauthorizedAccessException ex) { //Process[] processlist = Process.GetProcesses(); //foreach (Process theprocess in processlist) //{ // Console.WriteLine("Process: {0} ID: {1}", theprocess.ProcessName, theprocess.Id); //} try { ComPort.Close(); } catch (UnauthorizedAccessException ex2) { WriteDebug.Log(FlagDebug); WriteDebug.Pgm(ex2.Message.ToString(), FlagDebug); WriteDebug.Log(FlagDebug); } WriteDebug.Log(FlagDebug); WriteDebug.Pgm("ERROR : " + port + " port doesn't work", FlagDebug); WriteDebug.Pgm(ex.Message.ToString(), FlagDebug); WriteDebug.Log(FlagDebug); MyDLL.writeMessage("ERROR", "MicroSupply ERROR", port + " port doesn't work !"); ListPort = ListPort.Replace(port + ",", ""); } catch (IOException ex) { WriteDebug.Log(FlagDebug); WriteDebug.Pgm("WARNING : " + port + " port can't be open", FlagDebug); WriteDebug.Pgm(ex.Message.ToString(), FlagDebug); WriteDebug.Log(FlagDebug); MyDLL.writeMessage("WARNING", "MicroSupply WARNING", port + " port can't be open !"); } } } //if (!flagPort) //{ // error port COM // wDebug("ERROR : A COM port doesn't work"); // MyDLL.writeMessage("ERROR", "MicroSupply ERROR", "A COM port doesn't work !"); // Thread.Sleep(500); // t.Abort(); // Environment.Exit(0); //} MyDLL.setVisible("COM", true); MyDLL.setVisible("REFRESH", true); MyDLL.addCOMPort(ListPort); if (ports.Length == 1) { initPORTCOM(ports[0]); stPort = ports[0]; // Launch Thread to receive datas but not now (FlagReceive is false) tw = new Thread(launchRECEIVE); FlagReceive = false; tw.Start(); } } // Wait a key to begin the program WriteDebug.Pgm("Wait Key Start", FlagDebug); String stTouchSeconds = ""; while (true) { while (!MyDLL.getStatusKey()) { } String stKey = MyDLL.getKeyValue(); WriteDebug.Pgm("KEY : " + stKey, FlagDebug); // Refresh the port COM if (stKey.Contains("REFRESH")) { ports = refresh.Pgm(FlagDebug); if (ports.Length == 1) { bool bRet = initPORTCOM(ports[0]); // Launch Thread to receive datas but not now if (bRet) { tw = new Thread(launchRECEIVE); FlagReceive = false; tw.Start(); } else { MyDLL.addCOMPort(""); } } } // COM port if (stKey.Contains("COM")) { stPort = stKey.Replace(",", ""); initPORTCOM(stPort); tw = new Thread(launchRECEIVE); FlagReceive = false; tw.Start(); MyDLL.setVisible("START", true); } // START button if (stKey.Contains("START")) { initPORTCOM(stPort); bool codeReturn = start.Pgm(ComPort, FlagDebug); FlagReceive = true; MyDLL.setEnable("COM", false); } // STOP button if (stKey.Contains("STOP")) { FlagReceive = false; int retValue = 0; while (retValue < 50000) { WriteDebug.Pgm("Send data END (E)", FlagDataDebug); try { ComPort.Write("E"); } catch { } retValue = readCOM.Pgm(ComPort, true, FlagDebug); } stop.Pgm(ComPort, intQueue.Count, LenQueue1, LenQueue2, LenQueue3, LenQueue4, FlagDebug); MyDLL.setEnable("COM", true); } // 1 secondes button if (stKey.Contains("1S")) { stTouchSeconds = "1S"; seconds.Pgm("1S", intQueue, LenQueue1, LenQueue2, LenQueue3, LenQueue4); } // 2 secondes button if (stKey.Contains("2S")) { stTouchSeconds = "2S"; seconds.Pgm("2S", intQueue, LenQueue1, LenQueue2, LenQueue3, LenQueue4); } // 4 secondes button if (stKey.Contains("4S")) { stTouchSeconds = "4S"; seconds.Pgm("4S", intQueue, LenQueue1, LenQueue2, LenQueue3, LenQueue4); } // INSIDE button if (stKey.Contains("INSIDE")) { int valDecale = inside.Pgm(stTouchSeconds, intQueue.Count, LenQueue1, LenQueue2, LenQueue3, LenQueue4, FlagDebug); for (int x = valDecale; x <= (LenQueue1 + valDecale); x++) { MyDLL.addData(intQueue.ElementAt(x)); } } // MOVE button if (stKey.Contains("MOVE")) { move.Pgm(stTouchSeconds, intQueue, LenQueue2, LenQueue4, FlagDebug); } // the SAVE button is choose if (stKey.Contains("SAVE")) { save.Pgm(intQueue); } // the EXIT button is choose if (stKey.Contains("EXIT")) { FlagReceive = false; int retValue = 0; while (retValue < 50000) { WriteDebug.Pgm("Send data END (E)", FlagDataDebug); try { ComPort.Write("E"); } catch { } retValue = readCOM.Pgm(ComPort, true, FlagDebug); } try { if (ComPort.IsOpen) { Thread.Sleep(500); ComPort.Close(); } } catch (Exception) { } Thread.Sleep(500); t.Abort(); Environment.Exit(0); } if (stKey.Contains("HELP")) { WebRequest request = WebRequest.Create("http://www.acrd.fr"); try { request.GetResponse(); } catch //If exception thrown then couldn't get response from address { WriteDebug.Pgm("The URL is incorrect", FlagDebug); } } } }
//**********************************************************************************// // //**********************************************************************************// private static void launchRECEIVE() { try { int ComptNoReceive = 0; while (true) { if (FlagReceive) { int iRead = 0; while ((byte)ComPort.ReadChar() != '\n') { ComptNoReceive++; iRead++; if (ComptNoReceive > 2000) { WriteDebug.Pgm("Compteur No Receive : " + ComptNoReceive.ToString(), FlagDebug); ComptNoReceive = 0; } } ComptNoReceive = 0; if (FlagDebug) { if (iRead > 0) { WriteDebug.Pgm("Error decalage : " + iRead, FlagDebug); } } while (FlagReceive) { int Value = readCOM.Pgm(ComPort, false, FlagDebug); //wDebug("=> " + Value.ToString()); if (Value > 40000) { WriteDebug.Pgm("=> " + Value.ToString(), FlagDebug); // 40184 WriteDebug.Nothing(); switch (Value) { case 65530: MyDLL.writeMessage("WARNING", "MicroSupply disconneted !", "Warning datas received !"); FlagReceive = false; stop.Pgm(ComPort, intQueue.Count, LenQueue1, LenQueue2, LenQueue3, LenQueue4, FlagDebug); break; // OK launch datas serial case 65520: MyDLL.writeMessage("ERROR", "MicroSupply disconneted !", "Low Power Output !"); FlagReceive = false; stop.Pgm(ComPort, intQueue.Count, LenQueue1, LenQueue2, LenQueue3, LenQueue4, FlagDebug); break; case 65100: FlagReceive = false; try { if (ComPort.IsOpen) { WriteDebug.Pgm("Send data : E", FlagDebug); ComPort.Write("E"); } } catch (Exception) { } try { if (ComPort.IsOpen) { Thread.Sleep(500); ComPort.Close(); } } catch (Exception) { } Thread.Sleep(500); MyDLL.writeMessage("ERROR", "MicroSupply Error Serial Port", "ERROR Serial Port ! \n\n EXIT"); t.Abort(); Environment.Exit(0); break; default: break; } } else { intQueue.Enqueue(Value); if (intQueue.Count > LenQueue) { int firstToLeave = intQueue.Dequeue(); } MyDLL.addData(Value); if (MyDLL.getStatusScale()) { int ValScale = MyDLL.getScale(); if (ValScale == 0) { MyDLL.setValueY("10", "20", "30", "40", "µA"); } else { if (ValScale == 1) { MyDLL.setValueY("100", "200", "300", "400", "µA"); } else { if (ValScale == 10) { MyDLL.setValueY("1", "2", "3", "4", "mA"); } else { if (ValScale == 100) { MyDLL.setValueY("10", "20", "30", "40", "mA"); } else { MyDLL.setValueY("-", "-", "-", "-", "?"); } } } WriteDebug.Nothing(); } } } } } else { Thread.Sleep(100); } } } catch (Exception) { FlagReceive = false; MyDLL.setVisible("START", false); MyDLL.setVisible("STOP", false); } }
private void button3_Click(object sender, EventArgs e) { int dadan = 0; bool flag = false; int count = dataGridView1.Rows.Count; double sum = 0;//每一行的总金 DialogResult MsgBoxResult; MsgBoxResult = MessageBox.Show("你确定出库吗?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2); if (MsgBoxResult == DialogResult.Yes) //确认出库; { string nowtime = dateTimePicker1.Value.ToString(); MsgBoxResult = MessageBox.Show("系统当前的时间是" + nowtime, "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2); if (MsgBoxResult == DialogResult.No) { nowtime = Interaction.InputBox("请输入时间格式为" + nowtime); } MsgBoxResult = MessageBox.Show("是否打印出库单", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2); if (MsgBoxResult == DialogResult.Yes) { dadan = 1; flag = true; } if (flag) { //需要打印出库单,开始打印出库单。 //出库单内容,药名,规格,数量,平均单价,金额合计 for (int i = 0; i < count - 1; ++i) { sum = Convert.ToDouble(dataGridView1.Rows[i].Cells["Column12"].Value); sumJ += sum; dataGridView3.Rows.Add(dataGridView1.Rows[i].Cells["Column2"].Value, dataGridView1.Rows[i].Cells["Column3"].Value, dataGridView1.Rows[i].Cells["Column5"].Value, dataGridView1.Rows[i].Cells["Column10"].Value, dataGridView1.Rows[i].Cells["Column12"].Value); } dataGridView3.Rows.Add(null, null, null, null, sumJ); //打印 System.Data.DataTable dt = new System.Data.DataTable(); DataRow dr; foreach (DataGridViewColumn headerCell in dataGridView3.Columns) { dt.Columns.Add(headerCell.HeaderText); } foreach (DataGridViewRow item in dataGridView3.Rows) { dr = dt.NewRow(); for (int i = 0; i < dt.Columns.Count; i++) { dr[i] = item.Cells[i].Value; } dt.Rows.Add(dr); } DataSet dy = new DataSet(); dy.Tables.Add(dt); MyDLL.TakeOver(dy); } // DB db = new DB(); db.close(); if (db.connect()) { shijian = nowtime; for (int i = 0; i < count - 1; ++i) { // MessageBox.Show((string)dataGridView1.Rows[i].Cells["Column5"].Value); string shu = (string)dataGridView1.Rows[i].Cells["Column5"].Value; shuliang = System.Convert.ToDouble(shu); keshi = (String)dataGridView1.Rows[i].Cells["Column8"].Value; yaohao = (String)dataGridView1.Rows[i].Cells["Column1"].Value; jinjia = (Double)dataGridView1.Rows[i].Cells["Column10"].Value; // yaokujingshou= (String)dataGridView1.Rows[i].Cells["Column4"].Value; keshijingshou = (String)dataGridView1.Rows[i].Cells["Column9"].Value; //yaofangjingshou = null; // string shou = (string)dataGridView1.Rows[i].Cells["Column11"].Value; shoujia = (Double)dataGridView1.Rows[i].Cells["Column11"].Value; yaofangshangzhang = 1; yaokujingshou = "zhang"; string str = "insert into 出库记录(科室,药号,数量,进价,日期,药库经手,科室经手,药房上账,售价,是否打单) values('" + keshi + "','" + yaohao + "'," + shuliang + "," + jinjia + ",'" + shijian + "','" + yaokujingshou + "','" + keshijingshou + "'," + yaofangshangzhang + "," + shoujia + "," + dadan + ")"; string sql = "update 药库库存 set 本期出库 =本期出库 +" + shuliang + " where 药号='" + yaohao + "'"; /* string sql2 = null; * if(keshi.Equals("门诊")) * { * sql2="update 药房库存 set 门诊领药 ="+shuliang; * } * if(keshi.Equals("病房")) * { * sql2 = "update 药房库存 set 药房领药 =" + shuliang; * } * if(keshi.Equals("门诊")) * { * sql2 = "update 药房库存 set 科室领药 =" + shuliang; * }*/ if (db.change(sql)) { MessageBox.Show("update success" + sql); } // MessageBox.Show(str); if (db.change(str) == false) { return; } } } dataGridView3.Rows.Clear(); dataGridView1.Rows.Clear(); sumJ = 0; db.close(); return; } }