Ejemplo n.º 1
0
        private void ReceiveMessage(object obj)
        {
            IPEndPoint remoteIpep = new IPEndPoint(IPAddress.Any, 7215);

            while (true)
            {
                try
                {
                    byte[] bytRecv = udpcRecv.Receive(ref remoteIpep);
                    string message = Encoding.UTF8.GetString(bytRecv, 0, bytRecv.Length);
                    //    MessageBox.Show("收到指令:" + code);
                    NELog.WriteLog("收到指令1:" + message);
                    message = message.Substring(0, message.LastIndexOf("*") + 1);
                    message = "$" + DesCode.DESDecode(message.Substring(1, message.Length - 2), "YN200916") + "*";
                    if (message == null || message.Equals("") || message.Length < 5 || !message.Substring(0, 5).Equals("$A712"))
                    {
                        continue;
                    }

                    currentStateCode = message;
                }
                catch (Exception ex)
                {
                    //    MessageBox.Show(ex.ToString());
                    continue;;
                }
            }
        }
Ejemplo n.º 2
0
        private void sendMessage(string code)
        {
            try
            {
                code = "$" + DesCode.DESEncode(code.Substring(1, code.Length - 2), "YN200916") + "*";
                byte[] sendbytes = Encoding.UTF8.GetBytes(code);

                IPEndPoint remoteIpep = new IPEndPoint(IPAddress.Parse(NEIni.ReadValue(".\\config.ini", "cfg", "equipmentip", "")), 7015); // 发送到的IP地址和端口号
                NELog.WriteLog("Q-----------");
                int i = udpcRecv.Send(sendbytes, sendbytes.Length, remoteIpep);
            }
            catch (System.Exception ex)
            {
                //
            }
        }
Ejemplo n.º 3
0
        private void ReceiveMessage(object obj)
        {
            IPEndPoint remoteIpep = new IPEndPoint(IPAddress.Any, 0);

            while (true)
            {
                try
                {
                    byte[] bytRecv = udpcRecv.Receive(ref remoteIpep);
                    printIPAddress = remoteIpep.Address;
                    string message = Encoding.UTF8.GetString(bytRecv, 0, bytRecv.Length);
                    if ("123456".Equals(message))
                    {
                        MessageBox.Show("收到指令:" + message);
                        return;
                    }
                    NELog.WriteLog("收到指令2:" + message + "-");

                    if (message == null || message.Equals("") || message.Length < 5)
                    {
                        continue;
                    }

                    message = message.Substring(0, message.LastIndexOf("*") + 1);
                    message = "$" + DesCode.DESDecode(message.Substring(1, message.Length - 2), "YN200916") + "*";

                    if (!message.Substring(0, 5).Equals("$Q703") && !message.Substring(0, 5).Equals("$Q701"))
                    {
                        continue;
                    }
                    mySyncdQ.Enqueue(message);
                }
                catch (Exception ex)
                {
                    //    MessageBox.Show(ex.ToString());
                    NELog.WriteLog(ex.ToString());
                    continue;
                }
            }
        }
Ejemplo n.º 4
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (haschecked && !pause)
            {
                if (iProcess >= sList.Count)
                {
                    label2.Text    = "盘点完毕!";
                    timer1.Enabled = false;
                    label5.Text    = sList.Count + "/" + sList.Count;
                    return;
                }
                else
                {
                    label5.Text = iProcess + "/" + sList.Count;
                }
                label2.Text = "正在盘点 " + sList[iProcess].RowNO + " 行 " + sList[iProcess].ColNO + " 列";

                // 发送盘点指令
                string side = "1";
                if (int.Parse(sList[iProcess].ColNO) < 61)
                {
                    side = "1";
                }
                else
                {
                    side = "2";
                }
                NELog.WriteLog("开始盘点:" + iProcess);

                //string code = "$Q3012F1" + side + sList[iProcess].StockHor.Length + sList[iProcess].StockHor + sList[iProcess].StockVer.Length + sList[iProcess].StockVer + string.Format("{0:D3}", int.Parse(sList[iProcess].StockWidth)) + string.Format("{0:D2}", int.Parse(sList[iProcess].RowNO)) + string.Format("{0:D3}", int.Parse(sList[iProcess].ColNO)) + string.Format("{0:D3}", int.Parse(sList[iProcess].PackageLength)) + Rand.Str(4) + "*";
                string code = "$Q3012F1" + side + sList[iProcess].StockHor.Length + sList[iProcess].StockHor + sList[iProcess].StockVer.Length + sList[iProcess].StockVer + string.Format("{0:D3}", int.Parse(sList[iProcess].StockWidth)) + string.Format("{0:D2}", int.Parse(sList[iProcess].RowNO)) + string.Format("{0:D3}", int.Parse(sList[iProcess].ColNO)) + string.Format("{0:D3}", int.Parse(sList[iProcess].PackageLength)) + Rand.Str(4) + "*";

                MachineFill.sendMsg(code);
                haschecked = false;
            }
        }
Ejemplo n.º 5
0
        private void timer2_Tick(object sender, EventArgs e)
        {
            try
            {
                string code = (string)CoderQueue.fdSyncdQueue.Dequeue();
                if (code == null)
                {
                    return;
                }

                if (code.Substring(0, 5).Equals("$Q202")) //完成初始化
                {
                    //SpeechSynthesizer ss = new SpeechSynthesizer();
                    //ss.Rate = -1;
                    //if (side.Equals("1"))
                    //{
                    //    ss.Speak("请将药品放到左侧");
                    //}
                    //else
                    //{
                    //    ss.Speak("请将药品放到右侧");
                    //}
                    // 提示可放药了 $Q2022F1 00(正常) xxxx*
                    label7.Text      = side == 1 ? "将药品放到左侧" : "将药品放到右侧";
                    button5.Visible  = true;
                    button5.Enabled  = true;
                    textBox1.Visible = false;
                }
                else if (code.Substring(0, 5).Equals("$Q204"))
                {
                    // 盘点返回 $Q2042F1 01 001 05 xxxx*
                    int row = int.Parse(code.Substring(8, 2));
                    int col = int.Parse(code.Substring(10, 3));
                    int qty = int.Parse(code.Substring(13, 2));
                    new StockCheckDao().stockChecked(row, col, qty);
                    for (int i = 0; i < dataGridView2.RowCount; i++)
                    {
                        if (int.Parse(dataGridView2.Rows[i].Cells[1].Value.ToString()) == row && int.Parse(dataGridView2.Rows[i].Cells[2].Value.ToString()) == col)
                        {
                            dataGridView2.Rows[i].Cells[3].Value = qty + "";
                            dataGridView2.Rows[i].Cells[4].Value = (int.Parse(drugInfo.StockLimit) - qty) + "";
                            if (int.Parse(dataGridView2.Rows[i].Cells[4].Value.ToString()) < 1)
                            {
                                dataGridView2.Rows.RemoveAt(i);
                            }
                            break;
                        }
                    }
                }
                else if (code.Substring(0, 5).Equals("$Q206"))
                {
                    // 上药结果 $Q2062F1 01 001 05 xxxx*
                    int row = int.Parse(code.Substring(8, 2));
                    int col = int.Parse(code.Substring(10, 3));
                    int qty = int.Parse(code.Substring(13, 2));
                    new DrugFill().updateStock(row, col, qty, label8.Text, "");
                    for (int i = 0; i < dataGridView2.RowCount; i++)
                    {
                        if (int.Parse(dataGridView2.Rows[i].Cells[1].Value.ToString()) == row && int.Parse(dataGridView2.Rows[i].Cells[2].Value.ToString()) == col)
                        {
                            dataGridView2.Rows[i].Cells[3].Value = (int.Parse(dataGridView2.Rows[i].Cells[3].Value.ToString()) + qty) + "";
                            dataGridView2.Rows[i].Cells[4].Value = (int.Parse(dataGridView2.Rows[i].Cells[4].Value.ToString()) - qty) + "";
                            if (int.Parse(dataGridView2.Rows[i].Cells[4].Value.ToString()) < 1)
                            {
                                dataGridView2.Rows.RemoveAt(i);
                            }
                            updataBnot(row.ToString(), col.ToString());
                            break;
                        }
                        label2.Text = "  " + int.Parse(dataGridView2.Rows[i].Cells[4].Value.ToString());
                    }
                    int needQty = 0;
                    for (int i = 0; i < dataGridView2.RowCount; i++)
                    {
                        needQty += int.Parse(dataGridView2.Rows[i].Cells[4].Value.ToString());
                    }
                    //label2.Text = "    "+needQty.ToString();
                }
                else if (code.Substring(0, 5).Equals("$Q992"))
                {
                    // 上药结果 $Q2062F1 01 001 05 xxxx* 返回数量为0,提示盘点
                    int row = int.Parse(code.Substring(8, 2));
                    int col = int.Parse(code.Substring(10, 3));
                    int qty = int.Parse(code.Substring(13, 2));
                    new DrugFill().updateStock(row, col, qty, label8.Text, "");
                    for (int i = 0; i < dataGridView2.RowCount; i++)
                    {
                        if (int.Parse(dataGridView2.Rows[i].Cells[1].Value.ToString()) == row && int.Parse(dataGridView2.Rows[i].Cells[2].Value.ToString()) == col)
                        {
                            dataGridView2.Rows[i].Cells[3].Value = (int.Parse(dataGridView2.Rows[i].Cells[3].Value.ToString()) + qty) + "";
                            dataGridView2.Rows[i].Cells[4].Value = (int.Parse(dataGridView2.Rows[i].Cells[4].Value.ToString()) - qty) + "";
                            if (int.Parse(dataGridView2.Rows[i].Cells[4].Value.ToString()) < 1)
                            {
                                dataGridView2.Rows.RemoveAt(i);
                            }
                            updataBnot(row.ToString(), col.ToString());
                            break;
                        }
                    }

                    int needQty = 0;
                    for (int i = 0; i < dataGridView2.RowCount; i++)
                    {
                        needQty += int.Parse(dataGridView2.Rows[i].Cells[4].Value.ToString());
                    }
                    label2.Text        = needQty.ToString();
                    textBox1.Visible   = true;
                    textBox1.Text      = row + "行" + col + "完成加药数量为" + qty + "  药槽计数可能发生异常,建议盘点";
                    textBox1.ForeColor = Color.Red;
                }
                else if (code.Substring(0, 5).Equals("$Q208"))
                {
                    // 上药完成
                    if (dataGridView2.RowCount == 0)
                    {
                        //SpeechSynthesizer ss = new SpeechSynthesizer();
                        //ss.Rate = -1;
                        label7.Text = "上药完成!";
                        //ss.SpeakAsync(label7.Text);
                        timer1.Enabled = false;
                        timer2.Enabled = false;
                        this.Close();
                    }
                    else
                    {
                        // 还有药槽没完成,继续
                        timer1.Enabled = true;
                    }
                }
                //else if (code.Substring(0, 5).Equals("$Q991"))
                //{
                //    string code_d = code.Substring(8, 2);
                //    string num_back = code.Substring(10, 2);
                //    if (code_d.Equals("E3"))
                //    {
                //        //返回已加药数量,同步到界面
                //        label2.ForeColor = Color.Red;
                //        int number = Convert.ToInt32(label2.Text) - Convert.ToInt32(num_back);
                //        label15.Text = number.ToString()+"/"+label2.Text;
                //    }
                //}
                else if (code.Substring(0, 5).Equals("$Q210"))
                {
                    //SpeechSynthesizer ss = new SpeechSynthesizer();
                    //ss.Rate = -1;
                    errKey  = code.Substring(8, 2);
                    errCode = code.Substring(10, 2);

                    // 异常 $Q2102F1 E0 01(初始化时急停)/02(初始化门控)/03(有药) xxxx*
                    if (errKey.Equals("E0"))
                    {
                        if (errCode.Equals("01"))
                        {
                            label7.Text = "急停异常!旋开急停后点击『继续』按钮";
                            //ss.SpeakAsync(label7.Text);
                        }
                        else if (errCode.Equals("03"))
                        {
                            label7.Text = "机械手上有药品!取出药品后点击『继续』按钮";
                            //ss.SpeakAsync(label7.Text);
                        }
                        else if (errCode.Equals("04"))
                        {
                            label7.Text = "返回窗口错误,检查是否异常?点击『继续』按钮";
                        }
                        button2.Visible = true;
                    }
                    else if (errKey.Equals("E2"))
                    {
                        // E2加药过程异常
                        if (errCode.Equals("01"))
                        {
                            label7.Text = "药品未进入药槽!";
                            //ss.SpeakAsync(label7.Text);
                        }
                        else if (errCode.Equals("02"))
                        {
                            label7.Text = "拨药异常报警!";
                            //ss.SpeakAsync(label7.Text);
                        }
                        else if (errCode.Equals("03"))
                        {
                            label7.Text = "齐药异常报警!";
                            //ss.SpeakAsync(label7.Text);
                        }
                        else if (errCode.Equals("04"))
                        {
                            Thread.Sleep(3000);
                            label7.Text = "加药异常!";
                            //ss.SpeakAsync("加药出现异常,请处理");
                        }
                        else if (errCode.Equals("05"))
                        {
                            label7.Text = "加药超时";
                        }
                        else
                        {
                            label7.Text = "未知异常:" + errCode;
                            //ss.SpeakAsync(label7.Text);
                        }

                        button4.Visible = true;
                        //textBox1.Visible = true;
                        //textBox1.Text = "该药槽可能未计到数,建议盘点";
                        //textBox1.ForeColor = Color.Red;
                    }
                    else if (errKey.Equals("E1"))
                    {
                        // E1机械手运动异常
                        if (errCode.Equals("11"))
                        {
                            label7.Text = "机械手未初始化!";
                        }
                        else if (errCode.Equals("02"))
                        {
                            label7.Text = "急停异常!";
                        }
                        else if (errCode.Equals("03"))
                        {
                            label7.Text = "门控异常!";
                        }
                        else if (errCode.Equals("04"))
                        {
                            label7.Text = "对射异常!";
                        }
                        else if (errCode.Equals("21"))
                        {
                            label7.Text = "运动超时!";
                        }
                        else
                        {
                            label7.Text = "机械手运动异常:" + errCode;
                        }
                        button2.Visible = true;
                    }
                }
            }
            catch (System.Exception ex)
            {
                NELog.WriteLog(ex.ToString());
            }
        }
Ejemplo n.º 6
0
 private void timer3_Tick(object sender, EventArgs e)
 {
     NELog.WriteLog("==============" + iProcess);
 }
Ejemplo n.º 7
0
        private void timer2_Tick(object sender, EventArgs e)
        {
            try
            {
                if (CoderQueue.ckSyncdQueue.Count < 1)
                {
                    return;
                }
                string code = (string)CoderQueue.ckSyncdQueue.Dequeue();

                if (code == null)
                {
                    return;
                }

                /*
                 * 判断是否门控异常
                 */

                if (code.Substring(0, 5).Equals("$Q302"))
                {
                    NELog.WriteLog("盘点完毕:" + iProcess);
                    // 解析盘点返回,$Q302/4 2 F1 01 002 000 0000 XXXX*
                    int         h     = int.Parse(code.Substring(8, 2));
                    int         l     = int.Parse(code.Substring(10, 3));
                    int         c     = int.Parse(code.Substring(13, 3));
                    int         cd    = int.Parse(code.Substring(16, 4));
                    VOStockList stock = new StockCheckDao().stockChecked(h, l, c, cd);
                    if (stock != null && iProcess < sList.Count)
                    {
                        int index = this.dataGridViewCK.Rows.Add();
                        this.dataGridViewCK.Rows[index].Cells[0].Value = sList[iProcess].StockID;
                        this.dataGridViewCK.Rows[index].Cells[1].Value = sList[iProcess].EqpID;
                        this.dataGridViewCK.Rows[index].Cells[2].Value = sList[iProcess].RowNO;
                        this.dataGridViewCK.Rows[index].Cells[3].Value = sList[iProcess].ColNO;
                        this.dataGridViewCK.Rows[index].Cells[4].Value = sList[iProcess].DrugName;
                        this.dataGridViewCK.Rows[index].Cells[5].Value = sList[iProcess].DrugSpec;
                        this.dataGridViewCK.Rows[index].Cells[6].Value = stock.Quantity;
                        this.dataGridViewCK.Rows[index].Cells[7].Value = stock.CheckQuantity;
                    }
                    label2.Text = "盘点完毕 " + sList[iProcess].RowNO + " 行 " + sList[iProcess].ColNO + " 列";
                    NELog.WriteLog("-------" + iProcess);
                    iProcess   = iProcess + 1;
                    haschecked = true;
                }
                else if (code.Substring(0, 5).Equals("$Q306"))
                {
                    NELog.WriteLog("----------------");
                    haschecked = true;
                    iProcess   = iProcess + 1;
                }
                else if (code.Substring(0, 5).Equals("$Q990"))
                {
                    // E1机械手运动异常
                    string errCode = code.Substring(10, 2);

                    if (errCode.Equals("11"))
                    {
                        label1.Text = "机械手未初始化!";
                    }
                    else if (errCode.Equals("02"))
                    {
                        label1.Text = "急停异常!";
                    }
                    else if (errCode.Equals("03"))
                    {
                        label1.Text = "门控异常!";
                    }
                    else if (errCode.Equals("04"))
                    {
                        label1.Text = "对射异常!";
                    }
                    else if (errCode.Equals("21"))
                    {
                        label1.Text = "运动超时!";
                    }
                    else
                    {
                        label1.Text = "机械手运动异常:" + errCode;
                    }
                    button6.Visible = true;
                }
            }
            catch (System.Exception ex)
            {
                NELog.WriteLog(ex.ToString());
            }
        }
Ejemplo n.º 8
0
        private Patient getPrescription(string procCode)
        {
            Patient patient = new Patient();
            List <PrescriptionInfo> pInfoList = new List <PrescriptionInfo>();

            if (true)
            {
                MySQLPool       pool = MySQLPool.getInstance();
                MySqlConnection conn = null;
                try
                {
                    conn = pool.getConnection();
                    string          sql = @"select PrescriptionNo,PatientName,Sex,Age,DeptName,DoctorName,Diagnosis,FetchWindow from prescriptionlist where procCode='" + procCode + "'";
                    MySqlCommand    cmd = new MySqlCommand(sql, conn);
                    MySqlDataReader dr  = cmd.ExecuteReader();
                    while (dr.Read())
                    {
                        if (patient.PName == null || "".Equals(patient.PName))
                        {
                            patient.PName       = dr.IsDBNull(1) ? "" : dr.GetString(1);
                            patient.Sex         = dr.IsDBNull(2) ? "" : dr.GetString(2);
                            patient.Age         = dr.IsDBNull(3) ? "" : dr.GetString(3);
                            patient.FetchWindow = dr.IsDBNull(7) ? "" : dr.GetString(7);
                        }

                        PrescriptionInfo prescriptionInfo = new PrescriptionInfo();
                        prescriptionInfo.PrescriptionNO = dr.IsDBNull(0) ? "" : dr.GetString(0);

                        pInfoList.Add(prescriptionInfo);
                    }
                    dr.Close();

                    foreach (PrescriptionInfo prescInfo in pInfoList)
                    {
                        List <PrescriptionDetl> pDetlList = new List <PrescriptionDetl>();

                        string          sql2 = "select b.Quantity,b.PrescriptionUnit,b.Price,b.UseFrequency,b.UseDosage,b.UseRoute,c.Drug_Name,c.Drug_Spec,c.Manufactory,c.StorageLoc,Notes from prescriptiondetail b left join drug_list c on b.DrugCode=c.Drug_Code where b.PrescriptionNo='" + prescInfo.PrescriptionNO + "'";
                        MySqlCommand    cmd2 = new MySqlCommand(sql2, conn);
                        MySqlDataReader dr2  = cmd2.ExecuteReader();
                        while (dr2.Read())
                        {
                            PrescriptionDetl prescriptionDetl = new PrescriptionDetl();
                            prescriptionDetl.DrugName         = dr2.IsDBNull(6) ? "" : dr2.GetString(6);
                            prescriptionDetl.DrugSpec         = dr2.IsDBNull(7) ? "" : dr2.GetString(7);
                            prescriptionDetl.Manufactory      = dr2.IsDBNull(8) ? "" : dr2.GetString(8);
                            prescriptionDetl.PrescriptionQty  = dr2.IsDBNull(0) ? "" : dr2.GetString(0);
                            prescriptionDetl.PrescriptionUnit = dr2.IsDBNull(1) ? "" : dr2.GetString(1);
                            prescriptionDetl.StorageLoc       = dr2.IsDBNull(9) ? "" : dr2.GetString(9);
                            prescriptionDetl.UseFrequency     = dr2.IsDBNull(3) ? "" : dr2.GetString(3);
                            prescriptionDetl.UseDosage        = dr2.IsDBNull(4) ? "" : dr2.GetString(4);
                            prescriptionDetl.UseRoute         = dr2.IsDBNull(5) ? "" : dr2.GetString(5);
                            prescriptionDetl.Notes            = dr2.IsDBNull(10) ? "" : dr2.GetString(10);
                            //prescriptionDetl.Num_1 = dr2.IsDBNull(11) ? "" : dr2.GetString(11);
                            prescriptionDetl.Price = dr2.IsDBNull(2) ? "" : dr2.GetString(2);
                            pDetlList.Add(prescriptionDetl);
                        }
                        dr2.Close();

                        prescInfo.DetlList = pDetlList;
                    }

                    patient.PrescInfo = pInfoList;

                    sql = "update prescriptionlist set ProcFlg=5 where ProcCode='" + procCode + "'";
                    MySqlCommand cmd3 = new MySqlCommand(sql, conn);
                    cmd3.ExecuteNonQuery();
                }
                catch (System.Exception ex)
                {
                    NELog.WriteLog(ex.ToString());
                }
                finally
                {
                    pool.releaseConnection(conn);
                }
            }
            else
            {
                patient.PName       = "张珊珊";
                patient.Sex         = "女";
                patient.Age         = "2岁半";
                patient.FetchWindow = "④";

                {
                    PrescriptionInfo prescriptionInfo = new PrescriptionInfo();
                    prescriptionInfo.PrescriptionNO = "200000102103";

                    List <PrescriptionDetl> pDetlList = new List <PrescriptionDetl>();

                    {
                        PrescriptionDetl prescriptionDetl = new PrescriptionDetl();
                        prescriptionDetl.DrugName         = "复方磺胺甲噁唑片";
                        prescriptionDetl.DrugSpec         = "150mgx10粒/盒";
                        prescriptionDetl.Manufactory      = "天津金耀氨基酸有限公司";
                        prescriptionDetl.PrescriptionQty  = "2";
                        prescriptionDetl.PrescriptionUnit = "盒";
                        prescriptionDetl.StorageLoc       = "22-2-2";
                        pDetlList.Add(prescriptionDetl);
                    }

                    {
                        PrescriptionDetl prescriptionDetl = new PrescriptionDetl();
                        prescriptionDetl.DrugName         = "复方磺胺甲噁唑片";
                        prescriptionDetl.DrugSpec         = "150mgx10粒/盒";
                        prescriptionDetl.Manufactory      = "天津金耀氨基酸有限公司";
                        prescriptionDetl.PrescriptionQty  = "2";
                        prescriptionDetl.PrescriptionUnit = "盒";
                        prescriptionDetl.StorageLoc       = "22-2-2";
                        pDetlList.Add(prescriptionDetl);
                    }
                    prescriptionInfo.DetlList = pDetlList;

                    pInfoList.Add(prescriptionInfo);
                }
                {
                    PrescriptionInfo prescriptionInfo = new PrescriptionInfo();
                    prescriptionInfo.PrescriptionNO = "200000102102";

                    List <PrescriptionDetl> pDetlList = new List <PrescriptionDetl>();

                    {
                        PrescriptionDetl prescriptionDetl = new PrescriptionDetl();
                        prescriptionDetl.DrugName         = "2复方磺胺甲噁唑片";
                        prescriptionDetl.DrugSpec         = "150mgx10粒/盒";
                        prescriptionDetl.Manufactory      = "天津金耀氨基酸有限公司";
                        prescriptionDetl.PrescriptionQty  = "2";
                        prescriptionDetl.PrescriptionUnit = "盒";
                        prescriptionDetl.StorageLoc       = "22-2-2";
                        pDetlList.Add(prescriptionDetl);
                    }

                    prescriptionInfo.DetlList = pDetlList;

                    pInfoList.Add(prescriptionInfo);
                }

                patient.PrescInfo = pInfoList;
            }

            return(patient);
        }