예제 #1
0
        public object GetClassInfo()
        {
            HttpCookie cookie   = HttpContext.Current.Request.Cookies["UserInfoRemember"];
            String     username = cookie["username"].ToString();
            HttpCookie cookie1  = HttpContext.Current.Request.Cookies["CurrentCourse"];
            String     id       = cookie1["CourseId"];
            int        courseId = int.Parse(id);
            var        query    = new BmobQuery();

            query.WhereEqualTo("tId", username);
            var q1 = new BmobQuery();

            q1.WhereEqualTo("courseId", courseId);
            query.And(q1);
            var future = Bmob.FindTaskAsync <Class>("Class", query);

            try
            {
                classList = future.Result.results;
                return(ResultToJson.toJson(classList));
            }
            catch
            {
                return("获取失败");
            }
        }
예제 #2
0
        public HttpResponseMessage PostSpeechReturn(JObject JsonRequest)
        {
            //解析所需进行的操作
            //JObject Pipixia = JsonRequest;
            string functionName = JsonRequest["functionName"].ToString();

            try
            {
                switch (functionName)
                {
                //初始化
                //只需要执行一次即可生成
                case "init":
                    //初始化命令词
                    Choices conmmonds = new Choices();
                    //添加命令词
                    conmmonds.Add(new string[] { "李明登录", "史晓丹登录", "廉颖登录", "欧阳里盘登录" });
                    //初始化命令词管理
                    GrammarBuilder gBuilder = new GrammarBuilder();
                    //将命令词添加到管理中
                    gBuilder.Append(conmmonds);
                    //实例化命令词管理
                    Grammar grammar = new Grammar(gBuilder);
                    //创建并加载听写语法(添加命令词汇识别的比较精准)
                    recognizer.LoadGrammar(grammar);
                    break;

                case "start":
                    //为语音识别事件添加处理程序。
                    recognizer.SpeechRecognized += new EventHandler <SpeechRecognizedEventArgs>(recognizer_SpeechRRecongized);
                    //将输入配置到语音识别器。
                    recognizer.SetInputToDefaultAudioDevice();
                    //启动异步,连续语音识别。
                    recognizer.RecognizeAsync(RecognizeMode.Multiple);
                    break;

                case "stop":
                    break;

                case "return":
                    //移除多播委托 否则会出现再次start时叠加输入信息
                    recognizer.SpeechRecognized -= new EventHandler <SpeechRecognizedEventArgs>(recognizer_SpeechRRecongized);
                    //关闭异步语音识别
                    recognizer.RecognizeAsyncCancel();
                    //编辑回传字符串
                    returnValue = JsonConvert.SerializeObject(new { list = Common.recognize });
                    break;
                }
            }
            catch (Exception e)
            {
                returnValue = JsonConvert.SerializeObject(new { error = e.ToString() });
            }
            return(ResultToJson.toJson(returnValue));
            //是否需要清空LIST??
            //Common.recognize.Clear();
        }
        public HttpResponseMessage GetHeartBeat()
        {
            int    status      = 1;
            String returnValue = JsonConvert.SerializeObject(new
            {
                status = status.ToString()
            });

            return(ResultToJson.toJson(returnValue));
        }
예제 #4
0
        private static extern int ReadBaseInfos(StringBuilder Name, StringBuilder Gender, StringBuilder Folk, StringBuilder BirthDay, StringBuilder Code, StringBuilder Address, StringBuilder Agency, StringBuilder ExpireStart, StringBuilder ExpireEnd);//读取数据,推荐使用


        public HttpResponseMessage GetNationalCardReturn(string JsonRequest)
        {
            int    status      = 0;
            string returnValue = String.Empty;

            //解析方法名
            JObject Parameters   = JObject.Parse(JsonRequest);
            string  functionName = Parameters["functionName"].ToString();

            try
            {
                switch (functionName)
                {
                //这里也不需要先新建一个connection??
                case "InitComm":
                    int port = Int32.Parse(Parameters["port"].ToString());
                    status      = InitComm(port);
                    returnValue = JsonConvert.SerializeObject(new { status = status.ToString() });
                    break;

                case "Authenticate":
                    status      = Authenticate();
                    returnValue = JsonConvert.SerializeObject(new { status = status.ToString() });
                    break;

                case "CloseComm":
                    status      = CloseComm();
                    returnValue = JsonConvert.SerializeObject(new { status = status.ToString() });
                    break;

                case "ReadBaseInfos":
                    StringBuilder Name        = new StringBuilder(31);
                    StringBuilder Gender      = new StringBuilder(3);
                    StringBuilder Folk        = new StringBuilder(10);
                    StringBuilder BirthDay    = new StringBuilder(9);
                    StringBuilder Code        = new StringBuilder(19);
                    StringBuilder Address     = new StringBuilder(71);
                    StringBuilder Agency      = new StringBuilder(31);
                    StringBuilder ExpireStart = new StringBuilder(9);
                    StringBuilder ExpireEnd   = new StringBuilder(9);

                    status      = ReadBaseInfos(Name, Gender, Folk, BirthDay, Code, Address, Agency, ExpireStart, ExpireEnd);
                    returnValue = JsonConvert.SerializeObject(new { Name    = Name.ToString(), Gender = Gender.ToString(), Folk = Folk.ToString(), BirthDay = BirthDay.ToString(), Code = Code.ToString(),
                                                                    Address = Address.ToString(), Agency = Agency.ToString(), ExpireStart = ExpireStart.ToString(), ExpireEnd = ExpireEnd.ToString(), status = status.ToString() });
                    break;
                }
            }
            catch (Exception e)
            {
                returnValue = JsonConvert.SerializeObject(new { error = e.ToString() });
            }

            return(ResultToJson.toJson(returnValue));
        }
        public HttpResponseMessage PostImageVerficationReturn(JObject JsonRequest)
        {
            int    status  = 1;
            string picPath = JsonRequest["picPath"].ToString();

            InitEngines();
            status = ReadImage(picPath);
            String returnValue = JsonConvert.SerializeObject(new
            {
                status = status.ToString()
            });
            int retCode = ASIDCardFunctions.ArcSoft_FIC_UninitialEngine(pEngine);

            return(ResultToJson.toJson(returnValue));
        }
예제 #6
0
        public HttpResponseMessage GetSpeaker(string JsonRequest)
        {
            JObject Parameters = JObject.Parse(JsonRequest);
            string  text       = Parameters["text"].ToString();

            if (!Common.texts.Contains(text))
            {
                Common.texts.Enqueue(text);
            }
            int    status      = 0;
            String returnValue = JsonConvert.SerializeObject(new
            {
                status = status.ToString()
            });

            return(ResultToJson.toJson(returnValue));
        }
예제 #7
0
        public HttpResponseMessage PostDossierReturn(JObject JsonRequest)
        {
            int status = 1;

            MySqlConnection sqlCnn = new MySqlConnection();

            sqlCnn.ConnectionString = "server = '127.0.0.1'; uid = 'root'; pwd = 'mysql'; database = 'dossierstransfer';Allow User Variables=True;";//连接字符串
            string malePatientName          = JsonRequest["malePatientName"].ToString();
            string malePatientIdCard        = JsonRequest["malePatientIdCard"].ToString();
            string malePatientFingerPrint   = JsonRequest["malePatientFingerPrint"].ToString();
            string femalePatientName        = JsonRequest["femalePatientName"].ToString();
            string femalePatientIdCard      = JsonRequest["femalePatientIdCard"].ToString();
            string femalePatientFingerPrint = JsonRequest["femalePatientFingerPrint"].ToString();
            string insertDate          = JsonRequest["insertDate"].ToString();
            string folderWithTimeStamp = JsonRequest["folderWithTimeStamp"].ToString();

            try
            {
                sqlCnn.Open();
                string       sql    = "INSERT INTO dossier VALUES(@malePatientName, @malePatientIdCard, @malePatientFingerPrint, @femalePatientName, @femalePatientIdCard, @femalePatientFingerPrint, @insertDate, @folderWithTimeStamp)";
                MySqlCommand sqlCmd = new MySqlCommand(sql, sqlCnn);
                sqlCmd.Parameters.AddWithValue("@malePatientName", malePatientName);
                sqlCmd.Parameters.AddWithValue("@malePatientIdCard", malePatientIdCard);
                sqlCmd.Parameters.AddWithValue("@malePatientFingerPrint", malePatientFingerPrint);
                sqlCmd.Parameters.AddWithValue("@femalePatientName", femalePatientName);
                sqlCmd.Parameters.AddWithValue("@femalePatientIdCard", femalePatientIdCard);
                sqlCmd.Parameters.AddWithValue("@femalePatientFingerPrint", femalePatientFingerPrint);
                sqlCmd.Parameters.AddWithValue("@insertDate", insertDate);
                sqlCmd.Parameters.AddWithValue("@folderWithTimeStamp", folderWithTimeStamp);
                MySqlDataReader rdr = sqlCmd.ExecuteReader();
                rdr.Close();
                sqlCnn.Close();
                status = 0;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }

            String returnValue = JsonConvert.SerializeObject(new
            {
                status = status.ToString()
            });

            return(ResultToJson.toJson(returnValue));
        }
        public HttpResponseMessage PostFaceCompareFormReturn(JObject JsonRequest)
        {
            int             status          = 1;
            string          imagePath       = JsonRequest["imagePath"].ToString();
            string          rootPath        = System.Environment.CurrentDirectory;
            string          localImagePath  = Path.Combine(rootPath, "photo.bmp");
            string          imageLoadPath   = imagePath.Equals("") ? localImagePath : imagePath;
            FaceCompareForm faceCompareForm = new FaceCompareForm(imageLoadPath);

            Application.Run(faceCompareForm);
            faceCompareForm.TopMost = true;
            status = faceCompareForm.formReturnValue;
            String returnValue = JsonConvert.SerializeObject(new
            {
                status = status.ToString()
            });

            return(ResultToJson.toJson(returnValue));
        }
예제 #9
0
        public object GetResourceInfo(int unitId, int knowledgeId)
        {
            HttpCookie cookie1  = HttpContext.Current.Request.Cookies["CurrentCourse"];
            String     id       = cookie1["CourseId"];
            int        courseId = int.Parse(id);
            var        query    = new BmobQuery();

            query.WhereEqualTo("courseId", courseId);
            if (unitId != 0)
            {
                var q1 = new BmobQuery();
                q1.WhereEqualTo("unitId", unitId);
                query.And(q1);
            }
            if (knowledgeId != 0)
            {
                var q1 = new BmobQuery();
                q1.WhereEqualTo("knowledgeId", knowledgeId);
                query.And(q1);
            }
            var future = Bmob.FindTaskAsync <Resource>("Resource", query);

            try
            {
                resourceList = future.Result.results;
                List <Resource_View> resourceView = new List <Resource_View>();
                foreach (var resource in resourceList)
                {
                    Resource_View resources = new Resource_View();
                    resources.id       = resource.id.Get();
                    resources.fileUrl  = resource.file.url;
                    resources.fileName = resource.file.filename;
                    resources.type     = resource.type;
                    resourceView.Add(resources);
                }
                return(ResultToJson.toJson(resourceView));
            }
            catch
            {
                return("fail");
            }
        }
        public HttpResponseMessage PostFaceRecordFormReturn(JObject JsonRequest)
        {
            int            status         = 1;
            FaceRecordForm faceRecordForm = new FaceRecordForm(Int32.Parse(JsonRequest["gender"].ToString()), JsonRequest["hostAddr"].ToString());

            Application.Run(faceRecordForm);
            faceRecordForm.TopMost = true;
            status = faceRecordForm.formReturnValue;
            var patientInfo = new
            {
                avatar    = faceRecordForm.picResizedHttpPath,
                originPic = faceRecordForm.picHttpPath,
            };
            String returnValue = JsonConvert.SerializeObject(new
            {
                status = status.ToString(),
                patientInfo,
            });

            return(ResultToJson.toJson(returnValue));
        }
예제 #11
0
        public HttpResponseMessage PostRFPrinterExecute(JObject Jsonrequest)
        {
            JObject             Parameters     = Jsonrequest;
            string              printType      = Parameters["printtype"].ToString();
            int                 printTimes     = Int32.Parse(Parameters["printtimes"].ToString()); // 打印次数
            JArray              usersInfo      = JArray.Parse(Parameters["usersInfo"].ToString());
            int                 RFStatus       = 0;
            int                 tagID          = 8;
            List <RFReturnPair> returnPairList = new List <RFReturnPair>();
            StringBuilder       sbRFID         = new StringBuilder(256);

            // 读取函数只能在Open函数之前 或者close函数之后运行 否则会报错
            // 读取RFID数值之后转换为PC端同一格式
            // 翻转整体数组然后奇偶位互换


            try
            {
                for (int count = 1; count <= printTimes; count++)
                {
                    for (int i = 0; i < usersInfo.Count; i++)
                    {
                        RFStatus = PTK_ReadHFTagUIDUSB(255, 1, sbRFID);
                        if (RFStatus != 0)
                        {
                            OpenPort(255);//打开打印机端口
                            //MessageBox.Show("错误码:" + RFStatus.ToString() + "当前标签不可用");
                            PTK_DrawTextTrueTypeW(180, 180, 40, 0, "宋体", 2, 900, false, false, false, "B1", "当前标签不可用");
                            int state = PTK_PrintLabel(1, 1);
                            ClosePort(); // 打印完成之后关闭打印端口
                            continue;
                        }
                        string temp   = sbRFID.ToString();
                        char[] RFInfo = temp.ToCharArray();
                        Array.Reverse(RFInfo);
                        for (int num = 0; num < RFInfo.Length; num += 2)
                        {
                            Array.Reverse(RFInfo, num, 2);
                        }
                        string RFID = string.Join("", RFInfo);
                        OpenPort(255);                          //打开打印机端口
                        PTK_ClearBuffer();                      //清空缓冲区
                        PTK_SetPrintSpeed(1);                   //设置打印速度
                        PTK_SetDarkness(20);                    //设置打印黑度
                        PTK_SetLabelHeight(436, 271, 0, false); //设置标签的高度和定位间隙\黑线\穿孔的高度
                        PTK_SetLabelWidth(200);                 //设置标签的宽度
                        //string femalename =string.Empty;
                        //string malename = string.Empty;
                        //string birthfemale =string.Empty;
                        //string birthmale = string.Empty;
                        //string cycleID = string.Empty;
                        //string cycletype = string.Empty;
                        //foreach (var test in usersInfo[i])
                        //{
                        //    femalename = test.Values(femalename).ToString();
                        //    malename = test.Values(malename).ToString();
                        //    birthfemale = test.Values(birthfemale).ToString();
                        //    birthmale = test.Values(birthmale).ToString();
                        //    cycleID = test.Values(cycleID).ToString();
                        //    cycletype = test.Values(cycletype).ToString();
                        //}
                        string femalename  = usersInfo[i]["femalename"].ToString();
                        string malename    = usersInfo[i]["malename"].ToString();
                        string birthfemale = usersInfo[i]["birthfemale"].ToString();
                        string birthmale   = usersInfo[i]["birthmale"].ToString();
                        string cycleID     = usersInfo[i]["cycleID"].ToString();
                        string cycletype   = usersInfo[i]["cycletype"].ToString();
                        PTK_DrawTextTrueTypeW(185, 180, 40, 0, "宋体", 2, 900, false, false, false, tagID.ToString(), femalename);
                        PTK_DrawTextTrueTypeW(80, 180, 40, 0, "宋体", 2, 900, false, false, false, (tagID + 1).ToString(), malename);
                        tagID += 2;
                        //PrintLab.PTK_DrawTextTrueTypeW(200, 100, 40, 0, "宋体", 2, 900, false, false, false, "A2", femaleName);
                        //PrintLab.PTK_DrawTextTrueTypeW(200, 100, 40, 0, "宋体", 2, 900, false, false, false, "A2", maleName);
                        //PTK_DrawText(200, 100, 0, 6, 3, 1, 'N', femalename);
                        //PTK_DrawText(50, 100, 0, 6, 3, 1, 'N', malename);
                        int status = PTK_PrintLabel(1, 1);
                        returnPairList.Add(new RFReturnPair(cycleID, RFID));
                        //ClosePort(); // 打印完成之后关闭打印端口
                    }
                }
                tempPairList = JsonConvert.SerializeObject(returnPairList);
                //ReturnList test = new ReturnList(RFStatus, returnPairList);
                returnValue = JsonConvert.SerializeObject(new { returnPairList = tempPairList, RFStatus });
                //returnValue = JsonConvert.SerializeObject(test);
            }

            catch (Exception e)
            {
                // 捕获错误之后返回所有已经打印的周期号以及相关报错信息
                string error = e.ToString();
                tempPairList = JsonConvert.SerializeObject(returnPairList);
                //ReturnList test = new ReturnList(RFStatus, error, returnPairList);
                returnValue = JsonConvert.SerializeObject(new { returnPairList = tempPairList, RFStatus, error });
                //returnValue = JsonConvert.SerializeObject(test);
            }
            ClosePort(); // 打印完成之后关闭打印端口
            return(ResultToJson.toJson(returnValue));
        }
        public HttpResponseMessage PostReport(JObject JsonRequest)
        {
            int    status = 0;
            string error  = "";

            try
            {
                String className  = "FastReport." + JsonRequest["ClassName"].ToString();
                string rootPath   = System.Environment.CurrentDirectory;
                string outputPath = Path.Combine(rootPath, "output.pdf");
                //FastReport.Report report = new FastReport.Report();
                //string filename = @"C:\Users\lipan\Desktop\report3.frx";
                //report.Load(filename);
                FastReport.Report report = (FastReport.Report)Activator.CreateInstance(System.Type.GetType(className));
                DataSet           data   = new DataSet();
                DataTable         table  = new DataTable();
                int num = 0;
                foreach (var item in JsonRequest)
                {
                    if (item.Key.StartsWith("ClassName"))
                    {
                        continue;
                    }
                    if (item.Key.StartsWith("Signature"))
                    {
                        DataTable dt = new DataTable();
                        dt.TableName = item.Key;
                        dt.Columns.Add(item.Key, typeof(byte[]));
                        WebClient wc = new WebClient();
                        byte[]    bytes;
                        if (item.Value.ToString() == "")
                        {
                            //此处留空时处理;
                            bytes = wc.DownloadData(Path.Combine(rootPath, "EmptySignature.PNG"));
                        }
                        else
                        {
                            bytes = wc.DownloadData(item.Value.ToString());
                        }
                        MemoryStream msIMG = new MemoryStream(bytes);
                        Image        img   = System.Drawing.Image.FromStream(msIMG);
                        //Image img = Image.FromFile(folderPath + item.Key + ".PNG");
                        DataRow      row = dt.NewRow();
                        MemoryStream ms  = new MemoryStream();
                        img.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
                        row[item.Key] = ms.ToArray();
                        dt.Rows.Add(row);
                        data.Tables.Add(dt);
                        continue;
                    }
                    table           = CSVHelper.ConvertJsonToDatatable(JsonRequest.ToString(), num);
                    table.TableName = item.Key;
                    data.Tables.Add(table);
                    num++;
                }
                report.RegisterData(data);
                int tableNum = data.Tables.Count;
                for (int i = 0; i < tableNum; i++)
                {
                    report.GetDataSource(data.Tables[i].TableName).Enabled = true;
                }
                report.Prepare();
                FastReport.Export.Pdf.PDFExport export = new FastReport.Export.Pdf.PDFExport();
                report.Export(export, outputPath);
                System.Diagnostics.Process.Start(outputPath);
            }
            catch (Exception e)
            {
                status = -1;
                error  = e.ToString();
            }

            String returnValue = JsonConvert.SerializeObject(new
            {
                status = status.ToString(), error = error
            });

            return(ResultToJson.toJson(returnValue));
        }
예제 #13
0
        public HttpResponseMessage PostFingerPrintReturn(JObject JsonRequest)
        {
            JObject Parameters   = JsonRequest;
            string  functionName = Parameters["functionName"].ToString();
            //string patientID = Parameters["PatientID"].ToString();
            string returnValue = String.Empty;
            IntPtr mDevHandle  = Common.mDevHandle;
            IntPtr mDBHandle   = Common.mDBHandle;
            int    size        = 4;

            byte[] paramValue = new byte[size];
            byte[] FPBuffer;
            int    cbCapTmp = 2048;

            byte[] CapTmp       = new byte[2048];
            string CapTmpOut    = String.Empty;
            string acquireCount = String.Empty;
            int    status       = 0;
            int    score        = 0;
            string rootPath     = System.Environment.CurrentDirectory;

            try
            {
                zkfp2.GetParameters(mDevHandle, 1, paramValue, ref size);
                zkfp2.ByteArray2Int(paramValue, ref mfpWidth);
                zkfp2.GetParameters(mDevHandle, 2, paramValue, ref size);
                zkfp2.ByteArray2Int(paramValue, ref mfpHeight);
                FPBuffer = new byte[mfpWidth * mfpHeight];
                switch (functionName)
                {
                case "FPInit":
                    // init device
                    status = zkfp2.Init();
                    if (status == 0)
                    {
                        int count = zkfp2.GetDeviceCount();
                        if (count != 1)
                        {
                            status      = ERR_MULTIPLE_DEVICES;
                            returnValue = JsonConvert.SerializeObject(new { status = status.ToString() });
                            break;
                        }
                    }
                    else
                    {
                        returnValue = JsonConvert.SerializeObject(new { status = status.ToString() });
                        break;
                    }

                    // open device
                    if (IntPtr.Zero == (mDevHandle = zkfp2.OpenDevice(DEVICE_NUMBER)))
                    {
                        status      = DEVICE_OPEN_FAILED;
                        returnValue = JsonConvert.SerializeObject(new { status = status.ToString() });
                        break;
                    }
                    if (IntPtr.Zero == (mDBHandle = zkfp2.DBInit()))
                    {
                        status = DB_INIT_FAILED;
                        zkfp2.CloseDevice(mDevHandle);
                        mDevHandle  = IntPtr.Zero;
                        returnValue = JsonConvert.SerializeObject(new { status = status.ToString() });
                        break;
                    }
                    Common.mDBHandle  = mDBHandle;
                    Common.mDevHandle = mDevHandle;
                    returnValue       = JsonConvert.SerializeObject(new { status = status.ToString() });
                    break;

                case "FPRegister":
                    // register fingerprint

                    acquireCount = Parameters["acquireCount"].ToString();
                    status       = zkfp2.AcquireFingerprint(mDevHandle, FPBuffer, CapTmp, ref cbCapTmp);
                    if (status == zkfp.ZKFP_ERR_OK)
                    {
                        if ((Int32.Parse(acquireCount) == 1) || ((Int32.Parse(acquireCount) > 1) && ((score = zkfp2.DBMatch(mDBHandle, zkfp2.Base64ToBlob(Parameters["regTmp"].ToString()), CapTmp)) > 0)))
                        {
                            CapTmpOut = zkfp2.BlobToBase64(CapTmp, cbCapTmp);
                            //Array.Copy(zkfp2.Base64ToBlob(strBase64), CapTmpOut, cbCapTmp);
                            MemoryStream ms = new MemoryStream();
                            BitmapFormat.GetBitmap(FPBuffer, mfpWidth, mfpHeight, ref ms);
                            Bitmap bmp = new Bitmap(ms);
                            bmp.Save(Path.Combine(rootPath, "regTmp.jpeg"));
                            returnValue = JsonConvert.SerializeObject(new { status = status.ToString(), FPTmp = CapTmpOut, score = score });
                        }
                        else
                        {
                            status      = FP_REGISTER_MISMATCH;
                            returnValue = JsonConvert.SerializeObject(new { status = status.ToString() });
                        }
                    }
                    else
                    {
                        returnValue = JsonConvert.SerializeObject(new { status = status.ToString() });
                    }
                    break;

                case "FPTerminate":
                    status      = zkfp2.Terminate();
                    returnValue = JsonConvert.SerializeObject(new { status = status.ToString() });
                    break;

                case "FPMatch":
                    // compare fingerprint
                    status = zkfp2.AcquireFingerprint(mDevHandle, FPBuffer, CapTmp, ref cbCapTmp);
                    if (status == zkfp.ZKFP_ERR_OK)
                    {
                        byte[] compTmp = zkfp2.Base64ToBlob(Parameters["compTmp"].ToString());
                        score     = zkfp2.DBMatch(mDBHandle, CapTmp, compTmp);
                        CapTmpOut = zkfp2.BlobToBase64(CapTmp, cbCapTmp);
                        MemoryStream ms = new MemoryStream();
                        BitmapFormat.GetBitmap(FPBuffer, mfpWidth, mfpHeight, ref ms);
                        Bitmap bmp = new Bitmap(ms);
                        bmp.Save(Path.Combine(rootPath, "compTmp.jpeg"));
                        returnValue = JsonConvert.SerializeObject(new { status = status.ToString(), FPTmp = CapTmpOut, score = score });
                    }
                    else
                    {
                        returnValue = JsonConvert.SerializeObject(new { status = status.ToString() });
                    }
                    break;

                case "FPMatchBatch":
                    // compare fingerprint

                    status = zkfp2.AcquireFingerprint(mDevHandle, FPBuffer, CapTmp, ref cbCapTmp);
                    int    hScore     = 0;
                    string matchedTmp = "";
                    if (status == zkfp.ZKFP_ERR_OK)     //== zkfp.ZKFP_ERR_OK
                    {
                        JArray compTmpArray = JArray.Parse(Parameters["compTmp"].ToString());
                        for (int i = 0; i < compTmpArray.Count; i++)
                        {
                            byte[] compTmp = zkfp2.Base64ToBlob(compTmpArray[i].ToString());
                            score = zkfp2.DBMatch(mDBHandle, CapTmp, compTmp);
                            if (score > 60 && score > hScore)
                            {
                                hScore     = score;
                                matchedTmp = compTmpArray[i].ToString();
                            }
                        }
                        if (hScore < 60)
                        {
                            status = ERR_NO_MATCHED_TMP;
                        }
                        returnValue = JsonConvert.SerializeObject(new { status = status.ToString(), matchedTmp = matchedTmp });
                    }
                    else
                    {
                        returnValue = JsonConvert.SerializeObject(new { status = status.ToString() });
                    }
                    break;

                case "FPMerge":
                    // merge fingerprint
                    byte[] mergeTmp01  = zkfp2.Base64ToBlob(Parameters["mergeTmp01"].ToString());
                    byte[] mergeTmp02  = zkfp2.Base64ToBlob(Parameters["mergeTmp02"].ToString());
                    byte[] mergeTmp03  = zkfp2.Base64ToBlob(Parameters["mergeTmp03"].ToString());
                    byte[] mergedTmp   = new byte[2048];
                    int    cbMergedTmp = 0;
                    if (zkfp.ZKFP_ERR_OK == (status = zkfp2.DBMerge(mDBHandle, mergeTmp01, mergeTmp02, mergeTmp02, mergedTmp, ref cbMergedTmp)))
                    {
                        string mergedTmpOut = zkfp2.BlobToBase64(mergedTmp, cbMergedTmp);
                        returnValue = JsonConvert.SerializeObject(new { status = status.ToString(), FPTmp = mergedTmpOut });
                        break;
                    }
                    returnValue = JsonConvert.SerializeObject(new { status = status.ToString() });
                    break;
                }
            }
            catch (Exception e)
            {
                returnValue = JsonConvert.SerializeObject(new { error = e.ToString() });
            }
            return(ResultToJson.toJson(returnValue));
        }
예제 #14
0
        public HttpResponseMessage GetRFIDAPIReturn(string JsonRequest)
        {
            string returnValue             = String.Empty;
            IDictionary <int, string> dict = new Dictionary <int, string>();

            //解析方法名
            JObject Parameters   = JObject.Parse(JsonRequest);
            string  functionName = Parameters["functionName"].ToString();

            try
            {
                string RFID = "";

                switch (functionName)
                {
                case "reader_load":
                    status      = RDR_LoadReaderDrivers("");
                    returnValue = JsonConvert.SerializeObject(new { status = status.ToString(), error = errorMsg });
                    break;

                //这里也不需要先新建一个connection??
                case "rf_init_com":
                    //status = ReaderA.StaticClassReaderA.CloseComPort();
                    status = ReaderA.RWDev.CloseComPort();
                    //int port = Int32.Parse(Parameters["port"].ToString());
                    int           port       = 0;
                    StringBuilder portString = new StringBuilder(2);
                    int           baud       = Int32.Parse(Parameters["baud"].ToString());
                    //string configFilePath = System.Environment.CurrentDirectory + @"\resources\app.asar.unpacked\dist\electron\static\IVFMatchAPIs\config.ini";
                    //string configFilePath = Path.Combine(System.Environment.CurrentDirectory, "config.ini");
                    string configFilePath = @"C:\LabTrustConfig\config.ini";
                    GetPrivateProfileString("读卡器", "port", "", portString, 500, configFilePath);
                    port = Int32.Parse(portString.ToString());

                    if (port == 0)
                    {
                        fbaud = Convert.ToByte(baud / 19200 - 1);
                        for (port = 0; port < 18; port++)
                        {
                            //status = ReaderA.StaticClassReaderA.OpenComPort(port, ref readerAddr, fbaud, ref portIndex);
                            status = OpenComPort(port, ref readerAddr, fbaud, ref portIndex);
                            if (status == 0)
                            {
                                dict.Add(portIndex, "rongrui");
                                WritePrivateProfileString("读卡器", "port", port.ToString(), configFilePath);
                                break;
                            }

                            //添加安的读卡器的初始化
                            //
                        }
                    }
                    else if (port != -1)
                    {
                        status = OpenComPort(port, ref readerAddr, fbaud, ref portIndex);
                        if (status == 0)
                        {
                            dict.Add(portIndex, "rongrui");     //成功打开端口
                        }
                        else
                        {
                            WritePrivateProfileString("读卡器", "port", "0", configFilePath);     //打开失败则在配置文件中重置端口号为0,下次读取时,从0开始遍历端口号
                        }
                    }

                    status = RDR_LoadReaderDrivers("");
                    UInt32 nCount = HID_Enum("RL8000");
                    connStr = "RDType=RL8000;CommType=USB;AddrMode=1;SerNum=";
                    for (int i = 0; i < nCount; i++)
                    {
                        StringBuilder sernum = new StringBuilder();
                        sernum.Append('\0', 64);
                        UInt32 nSize;
                        nSize = (UInt32)sernum.Capacity;
                        int iret = HID_GetEnumItem((UInt32)i, 1, sernum, ref nSize);
                        if (iret == 0)
                        {
                            connStr = connStr + sernum.ToString();
                            status  = RDR_Open(connStr, ref hreader);
                            if (status == 0)
                            {
                                dict.Add((int)hreader, "andi");
                            }
                        }
                    }
                    UInt32 nnCount = HID_Enum("RD242");
                    connStr = "RDType=RD242;CommType=USB;AddrMode=1;SerNum=";
                    for (int i = 0; i < nnCount; i++)
                    {
                        StringBuilder sernum = new StringBuilder();
                        sernum.Append('\0', 64);
                        UInt32 nSize;
                        nSize = (UInt32)sernum.Capacity;
                        int iret = HID_GetEnumItem((UInt32)i, 1, sernum, ref nSize);
                        if (iret == 0)
                        {
                            connStr = connStr + sernum.ToString();
                            status  = RDR_Open(connStr, ref hreader);
                            if (status == 0)
                            {
                                dict.Add((int)hreader, "andi");
                            }
                        }
                    }
                    byte power = Convert.ToByte(7);
                    //status = ReaderA.RWDev.GetPwr(ref readerAddr, ref _Pwr, ref _PwrVal, portIndex);
                    status      = ReaderA.RWDev.SetPwr(ref readerAddr, ref power, portIndex);
                    Common.dict = dict;

                    if (dict.Count() == 0)
                    {
                        status      = -1;
                        errorMsg    = "设备未连接";
                        Common.dict = null;
                    }
                    else
                    {
                        status = 0;
                    }
                    returnValue = JsonConvert.SerializeObject(new { status = status.ToString(), error = errorMsg });
                    break;

                case "rf_light":
                    byte color = Convert.ToByte(Parameters["color"].ToString());
                    returnValue = JsonConvert.SerializeObject(new { status = status.ToString() });
                    break;

                case "rf_beep":
                    byte msec = Byte.Parse(Parameters["msec"].ToString());
                    returnValue = JsonConvert.SerializeObject(new { status = status.ToString() });
                    break;

                case "RF_Refresh_Cache":
                    Common.rfidDT.Clear();
                    break;

                case "ISO15693_Inventories":
                    var  rows         = Common.rfidDT.Select("TimeStamp < " + (MillisecNowCompute() - 2500).ToString());
                    bool foundNewRFID = false;
                    foreach (var row in rows)
                    {
                        row.Delete();
                    }
                    List <String> list             = new List <String>();
                    List <String> newFoundRFIDList = new List <String>();
                    dict = Common.dict;
                    try
                    {
                        foreach (KeyValuePair <int, string> item in dict)
                        {
                            if (item.Value == "rongrui")
                            {
                                portIndex = item.Key;
                                status    = Inventory(ref readerAddr, ref state, ref AFI, DSFIDAndUID, ref cardNumber, portIndex);
                                Array.Resize(ref DSFIDAndUID, cardNumber * 9);
                                strDSFIDAndUID = ByteArrayToHexString(DSFIDAndUID).Replace(" ", "");
                                for (int i = 0; i < cardNumber; i++)
                                {
                                    s    = strDSFIDAndUID.Substring(18 * i, 18);
                                    RFID = s.Substring(2, 16);
                                    list.Add(RFID);
                                }
                                status = (status == 14) ? 0 : status;
                                if (status != 0)
                                {
                                    status_rongrui = status;
                                    break;
                                }
                            }

                            else if (item.Value == "andi")
                            {
                                portIndex = item.Key;
                                UIntPtr hreader            = (UIntPtr)portIndex;
                                UIntPtr InvenParamSpecList = UIntPtr.Zero;
                                ISO15693_CreateInvenParam(InvenParamSpecList, 0, 0, 0, 0);
                                Byte[] antenna = new Byte[] { 1, 2, 3, 4 };
                                status = RDR_TagInventory(hreader, 1, 4, antenna, InvenParamSpecList);
                                UIntPtr TagDataReport;
                                TagDataReport = (UIntPtr)0;
                                TagDataReport = RDR_GetTagDataReport(hreader, 1);
                                while (TagDataReport.ToUInt64() > 0)
                                {
                                    UInt32 aip_id = 0;
                                    UInt32 tag_id = 0;
                                    UInt32 ant_id = 0;
                                    Byte   dsfid  = 0;
                                    Byte   uidlen = 0;
                                    Byte[] uid    = new Byte[16];

                                    int iret = ISO15693_ParseTagDataReport(TagDataReport, ref aip_id, ref tag_id, ref ant_id, ref dsfid, uid);
                                    uid = uid.Take(8).ToArray();
                                    Array.Reverse(uid);
                                    RFID = ByteArrayToHexString(uid).Replace(" ", "");
                                    list.Add(RFID);
                                    TagDataReport = RDR_GetTagDataReport(hreader, 2);
                                }
                                if (status != 0)
                                {
                                    status_andi = status;
                                    break;
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        status_andi    = -1;
                        status_rongrui = -1;
                    }

                    status = (status_rongrui != 0) ? status_rongrui : status_andi;
                    if (status == 17)
                    {
                        errorMsg = "天线位置异常或未被感应";
                    }
                    if (status != 0 && status != 17)
                    {
                        var data = new
                        {
                            functionName = "rf_init_com",
                            baud         = "19200",
                        };
                        var dataString = JsonConvert.SerializeObject(data);
                        GetRFIDAPIReturn(dataString).Content.ToString();
                    }
                    Console.WriteLine(Common.rfidDT.Rows.Count);
                    foreach (var rfid in list)
                    {
                        if (Common.rfidDT.Select("RFID = '" + rfid + "'").Count() == 0)
                        {
                            foundNewRFID = true;
                        }
                        DataRow row = Common.rfidDT.NewRow();
                        row["RFID"]      = rfid;
                        row["TimeStamp"] = MillisecNowCompute();
                        Common.rfidDT.Rows.Add(row);
                    }
                    if (foundNewRFID)
                    {
                        newFoundRFIDList = Common.rfidDT.AsEnumerable().Select(r => r.Field <string>("RFID")).Distinct().ToList();    //当发现新的标签时,跳出循环,将2500ms内所有扫描到的值赋给newFoundRFIDList
                    }
                    returnValue = JsonConvert.SerializeObject(new { list = newFoundRFIDList, existRFIDList = list, status = status.ToString(), error = errorMsg });
                    break;

                case "rf_closeport":
                    try
                    {
                        status = StaticClassReaderA.CloseComPort();
                        dict   = Common.dict;
                        foreach (KeyValuePair <int, string> item in dict)
                        {
                            if (item.Value == "andi")
                            {
                                portIndex = item.Key;
                                UIntPtr chreader = (UIntPtr)portIndex;
                                status = RDR_Close(chreader);
                            }
                        }
                        Common.dict = null;
                    }
                    catch (Exception e)
                    {
                    }
                    returnValue = JsonConvert.SerializeObject(new { status = status.ToString() });
                    break;
                }
            }
            catch (Exception e)
            {
                status      = INTERNALERROR;
                errorMsg    = e.ToString();
                returnValue = JsonConvert.SerializeObject(new { status = INTERNALERROR.ToString(), error = e.ToString() });
            }

            return(ResultToJson.toJson(returnValue));
        }
예제 #15
0
        public HttpResponseMessage GetPrinterExecute(string JsonRequest)
        {
            string returnValue = String.Empty;

            try
            {            //解析方法名
                JObject Parameters   = JObject.Parse(JsonRequest);
                string  printTimes   = Parameters["printtimes"].ToString();
                string  femaleName   = Parameters["femalename"].ToString();
                string  maleName     = Parameters["malename"].ToString();
                string  birthFemale  = Parameters["birthfemale"].ToString();
                string  barcodeInfo  = Parameters["barcode"].ToString();
                string  locationInfo = Parameters["location"].ToString();
                birthFemale = birthFemale.Substring(2).Replace("-", "");
                string birthMale = Parameters["birthmale"].ToString();
                birthMale = birthMale.Substring(2).Replace("-", "");
                string cycleType   = Parameters["cycletype"].ToString();
                string femaleInfo  = femaleName + " " + birthFemale;
                string maleInfo    = maleName + " " + birthMale;
                string cycleInfo   = "周期类型: " + cycleType;
                string printType   = Parameters["printtype"].ToString();
                string patientInfo = femaleName;
                string smallTagfemaleName;
                string smallTagmaleName;
                //string patientInfo = femaleName +" " + maleName + " " + birthFemale.Substring(4,2);
                int printLength = 9;
                if (femaleName.Length > 3)
                {
                    smallTagfemaleName = femaleName.Substring(0, 3);
                }
                else
                {
                    smallTagfemaleName = femaleName;
                }
                if (maleName.Length > 3)
                {
                    smallTagmaleName = maleName.Substring(0, 3);
                }
                else
                {
                    smallTagmaleName = maleName;
                }
                if (printLength >= smallTagfemaleName.Length + smallTagmaleName.Length)
                {
                    int offsetLength = printLength - smallTagfemaleName.Length - smallTagmaleName.Length;
                    patientInfo = smallTagfemaleName.PadRight(smallTagfemaleName.Length + offsetLength, ' ') + smallTagmaleName;
                }
                else if (printLength >= smallTagfemaleName.Length)
                {
                    patientInfo = (smallTagfemaleName + smallTagmaleName).Substring(0, 9);
                }


                openport("TSC TTP-244 Pro");                                           //Open specified printer driver
                clearbuffer();                                                         //Clear image buffer                                                                                                   //TSCLIB_DLL.barcode("100", "100", "128", "100", "1", "0", "2", "2", "Barcode Test"); //Drawing barcode
                //sendcommand("DIRECTION 0");
                switch (printType)
                {
                case "11":
                    //22*7.6mm tag
                    sendcommand("DIRECTION 0");
                    windowsfont(32, 8, 18, 0, 2, 0, "楷体", femaleInfo);
                    windowsfont(32, 24, 18, 0, 2, 0, "楷体", maleInfo);
                    //nobackfeed();
                    break;

                case "1":
                    //20*5 mm tag
                    sendcommand("DIRECTION 0");
                    windowsfont(20, 8, 18, 0, 2, 0, "楷体", patientInfo);
                    //windowsfont(32, 24, 18, 0, 2, 0, "楷体", maleInfo);
                    //nobackfeed();
                    break;

                case "2":
                    //大标签
                    //setup("25", "56", "4", "8", "1", "20", "0");
                    //sendcommand("DIRECTION 0");
                    //windowsfont(80, 174, 25, 270, 2, 0, "楷体", femaleInfo);
                    windowsfont(80, 152, 25, 270, 2, 0, "楷体", maleInfo);
                    windowsfont(140, 152, 25, 270, 2, 0, "楷体", femaleInfo);
                    break;

                case "3":
                    //条码
                    sendcommand("DIRECTION 0");
                    windowsfont(110, 88, 18, 0, 2, 0, "楷体", femaleInfo);
                    windowsfont(110, 108, 18, 0, 2, 0, "楷体", maleInfo);
                    barcode("110", "128", "128", "8", "0", "0", "1", "2", barcodeInfo);
                    windowsfont(110, 148, 18, 0, 2, 0, "楷体", locationInfo);
                    break;

                case "5":
                    windowsfont(32, 16, 18, 0, 2, 0, "楷体", "进位标签--无效");
                    break;
                }
                printlabel("1", printTimes);                                             //Print labels
                closeport();                                                             //Close specified printer driver
                returnValue = JsonConvert.SerializeObject(new
                {
                    status = 0
                });
            }
            catch (Exception e)
            {
                returnValue = JsonConvert.SerializeObject(new { status = -1, error = e.ToString() });
            }



            return(ResultToJson.toJson(returnValue));
        }