public void pathtohis(string blh, string bglx, string bgxh, string msg1, string debug1, string[] cslb)
        {
            if (bglx == "")
            {
                bglx = "cg";
            }
            if (bgxh == "")
            {
                bgxh = "0";
            }


            string CZY   = f.ReadString("yh", "yhmc", "").Replace("\0", "").Trim();
            string CZYGH = f.ReadString("yh", "yhbh", "").Replace("\0", "").Trim();

            debug = f.ReadString("savetohis", "debug", "").Replace("\0", "").Trim();
            string isbghj = f.ReadString("savetohis", "isbghj", "1").Replace("\0", "").Trim();

            string xtdm = f.ReadString("savetohis", "xtdm", "2060000");

            string certificate = f.ReadString("savetohis", "certificate", "ZmmJ9RMCKAUxFsiwl/08iiA3J17G0OpI");

            msg = msg1;

            string IP        = f.ReadString("savetohis", "IP", "223.220.200.7");
            string toPDFPath = f.ReadString("savetohis", "toPDFPath", "");
            string useName   = f.ReadString("savetohis", "useName", "");
            string pwd       = f.ReadString("savetohis", "pwd", "");
            string tjtxpath  = toPDFPath;

            string qxsh = "";
            string xdj  = "";

            bglx = bglx.ToLower();

            if (cslb.Length == 5)
            {
                if (cslb[4].ToLower() == "qxsh")
                {
                    qxsh = "1"; //取消审核动作
                }
                if (cslb[3].ToLower() == "new")
                {
                    xdj = "1";
                }
            }

            dbbase.odbcdb aa   = new odbcdb("DSN=pathnet;UID=pathnet;PWD=4s3c2a1p", "", "");
            DataTable     jcxx = new DataTable();

            try
            {
                jcxx = aa.GetDataTable("select * from T_jcxx where F_blh='" + blh + "'", "jcxx");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
                return;
            }
            if (jcxx == null)
            {
                MessageBox.Show("病理数据库设置有问题!");
                return;
            }
            if (jcxx.Rows.Count < 1)
            {
                MessageBox.Show("病理号有错误!");
                return;
            }
            if (jcxx.Rows[0]["F_SQXH"].ToString().Trim() == "")
            {
                log.WriteMyLog("无申请序号,不处理");
                ZGQClass.BGHJ(blh, CZY, "保存", "无申请序号,不处理", "ZGQJK", "");
                aa.ExecuteSQL("update T_JCXX_FS set F_bz='无申请序号,不处理',F_FSZT='已处理'  where F_blh='" + blh + "' and F_BGLX='" + bglx.ToLower() + "' and F_BGXH='" + bgxh + "'");

                return;
            }

            string bgzt = jcxx.Rows[0]["F_BGZT"].ToString().Trim();

            if (qxsh == "1")
            {
                bgzt = "取消审核";
            }



            string brbh = jcxx.Rows[0]["F_BRBH"].ToString().Trim();
            string brlb = jcxx.Rows[0]["F_brlb"].ToString().Trim();
            string sqxh = jcxx.Rows[0]["F_SQXH"].ToString().Trim();

            if (brlb == "住院")
            {
                brlb = "I";
            }
            else
            {
                brlb = "O";
            }

            string ZYH = jcxx.Rows[0]["F_MZH"].ToString().Trim();

            if (brlb == "I")
            {
                ZYH = jcxx.Rows[0]["F_ZYH"].ToString().Trim();
            }

            string SFZH = jcxx.Rows[0]["F_SFZH"].ToString().Trim();
            string XM   = jcxx.Rows[0]["F_XM"].ToString().Trim();
            string SJKS = jcxx.Rows[0]["F_BQ"].ToString().Trim();
            string CH   = jcxx.Rows[0]["F_CH"].ToString().Trim();
            string YZXM = jcxx.Rows[0]["F_YZXM"].ToString().Trim();

            //回写状态   客户端用
            int hczt = f.ReadInteger("savetohis", "hczt", 1);

            if (hczt == 1)
            {
                if (bglx != "bc" && bglx != "bd")
                {
                    if (debug == "1")
                    {
                        log.WriteMyLog("回传状态");
                    }

                    #region  回状态(不包括审核)
                    if (bgzt == "已登记" || bgzt == "已取材" || bgzt == "已写报告" || bgzt == "报告延期" || bgzt == "取消审核")
                    {
                        string bgzt_1 = "";
                        if (bgzt == "已登记" || bgzt == "已取材")
                        {
                            bgzt_1 = "S";
                        }

                        if (bgzt == "已写报告" || bgzt == "报告延期")
                        {
                            bgzt_1 = "R";
                        }

                        if (bgzt == "已审核")
                        {
                            bgzt_1 = "F";
                        }

                        if (bgzt == "已写报告" && jcxx.Rows[0]["F_HXBJ"].ToString().Trim() == "1")
                        {
                            bgzt_1 = "C";
                        }

                        if (bgzt == "取消审核")
                        {
                            bgzt_1 = "C";
                        }


                        if (bgzt_1 == "")
                        {
                            log.WriteMyLog("bgzt_1状态为空,不回写!");
                            return;
                        }

                        string ChangeGmsApplyStatus_Hl7 = "MSH|^~\\&|GMS||HIS||" + DateTime.Now.ToString("yyyyMMddHHmmss") + "||ORM^O01|" + DateTime.Now.ToString("yyyyMMddHHmmss") + "|P|2.4" + "\r"
                                                          + "PID|||" + jcxx.Rows[0]["F_YZID"].ToString().Trim() + "^^^^PI~" + ZYH + "^^^^||" + XM + "^||||||||||||\r"

                                                          + "PV1||" + brlb + "|||||||||||||||||" + ZYH + "\r"
                                                          + "ORC|SC|" + sqxh + "|||RC|||||" + CZYGH + "^" + CZY + "\r"
                                                          + "OBR||" + sqxh + "|" + blh + "|" + YZXM + "|||||||||||||||||||||" + bgzt_1;

                        if (debug == "1")
                        {
                            log.WriteMyLog(blh + "^" + bglx + "^" + bgxh + "-修改报告状态入参:" + ChangeGmsApplyStatus_Hl7);
                        }

                        string rtn_msg2 = rtn_CallInterface("HL7v2", "ChangeGmsApplyStatus", ChangeGmsApplyStatus_Hl7, "", certificate);


                        if (debug == "1")
                        {
                            log.WriteMyLog(blh + "^" + bglx + "^" + bgxh + "-修改报告状态平台返回:" + rtn_msg2);
                        }

                        if (rtn_msg2.Trim() == "-1")
                        {
                            log.WriteMyLog(blh + "^" + bglx + "^" + bgxh + "-回写报告状态失败:" + rtn_msg2);
                            if (isbghj == "1")
                            {
                                ZGQClass.BGHJ(blh, CZY, "保存", "回写报告状态失败:-1", "ZGQJK", "回写报告状态:" + bgzt);
                            }
                            return;
                        }
                        else
                        {
                            readhl7_fjfy r7 = new readhl7_fjfy();
                            int          xy = 0;
                            r7.Adt01(rtn_msg2, ref xy);
                            if (r7.MSA[1].Trim() == "AA")
                            {
                                if (debug == "1")
                                {
                                    log.WriteMyLog(r7.MSA[3].Trim());
                                }
                                if (isbghj == "1")
                                {
                                    ZGQClass.BGHJ(blh, CZY, "保存", "回写报告状态成功:" + r7.MSA[3].Trim(), "ZGQJK", "回写报告状态:" + bgzt);
                                }
                            }
                            else
                            {
                                log.WriteMyLog("回写报告状态失败:" + r7.MSA[3].Trim());
                                if (isbghj == "1")
                                {
                                    ZGQClass.BGHJ(blh, CZY, "保存", "回写报告状态失败:" + r7.MSA[3].Trim(), "ZGQJK", "回写报告状态:" + bgzt);
                                }
                            }
                        }
                    }
                    if (debug == "1")
                    {
                        log.WriteMyLog("回传状态结束");
                    }
                    #endregion
                }
                else
                {
                    if (debug == "1")
                    {
                        log.WriteMyLog("报告类型bc或bd,不回传状态");
                    }
                }
            }

            //回写报告   plsc用
            int plsc = f.ReadInteger("fsjk", "plsc", 1);

            if (plsc == 1)
            {
                string bz = "";
                if (bgzt == "已审核")
                {
                    if (debug == "1")
                    {
                        log.WriteMyLog("回传审核状态");
                    }
                    string txwebpath = ZGQClass.getSZ_String("savetohis", "txwebpath", @"http://223.220.200.11/pathimages").Replace("\0", "").Trim();

                    //上传结果
                    if (bglx != "bc" && bglx != "bd")
                    {
                        #region 回写审核状态
                        string ChangeGmsApplyStatus_Hl7 = "MSH|^~\\&|GMS||HIS||" + DateTime.Now.ToString("yyyyMMddHHmmss") + "||ORM^O01|" + DateTime.Now.ToString("yyyyMMddHHmmss") + "|P|2.4" + "\r"
                                                          + "PID|||" + jcxx.Rows[0]["F_YZID"].ToString().Trim() + "^^^^PI~" + ZYH + "^^^^||" + XM + "^||||||||||||\r"

                                                          + "PV1||" + brlb + "|||||||||||||||||" + ZYH + "\r"
                                                          + "ORC|SC|" + sqxh + "|||RC|||||" + CZYGH + "^" + CZY + "\r"
                                                          + "OBR||" + sqxh + "|" + blh + "|" + YZXM + "|||||||||||||||||||||F";

                        if (debug == "1")
                        {
                            log.WriteMyLog(blh + "^" + bglx + "^" + bgxh + "-修改报告审核状态入参:" + ChangeGmsApplyStatus_Hl7);
                        }

                        string rtn_msg_zt = rtn_CallInterface("HL7v2", "ChangeGmsApplyStatus", ChangeGmsApplyStatus_Hl7, "", certificate);

                        if (debug == "1")
                        {
                            log.WriteMyLog(blh + "^" + bglx + "^" + bgxh + "-修改报告审核状态平台返回:" + rtn_msg_zt);
                        }

                        if (rtn_msg_zt.Trim() == "-1")
                        {
                            if (isbghj == "1")
                            {
                                ZGQClass.BGHJ(blh, CZY, "保存", "回写报告审核状态失败:-1", "ZGQJK", "回写报告状态:已审核");
                            }
                            log.WriteMyLog(blh + "^" + bglx + "^" + bgxh + "-回写报告状态失败:" + rtn_msg_zt);
                            return;
                        }
                        else
                        {
                            readhl7_fjfy r7 = new readhl7_fjfy();
                            int          xy = 0;
                            r7.Adt01(rtn_msg_zt, ref xy);
                            if (r7.MSA[1].Trim() == "AA")
                            {
                                if (debug == "1")
                                {
                                    log.WriteMyLog(r7.MSA[3].Trim());
                                }
                                if (isbghj == "1")
                                {
                                    ZGQClass.BGHJ(blh, CZY, "保存", "回写报告状态成功:" + r7.MSA[3].Trim(), "ZGQJK", "回写报告状态:已审核");
                                }
                            }
                            else
                            {
                                if (isbghj == "1")
                                {
                                    ZGQClass.BGHJ(blh, CZY, "保存", "回写报告状态失败:" + r7.MSA[3].Trim(), "ZGQJK", "回写报告状态:已审核");
                                }
                                log.WriteMyLog("回写报告状态失败:" + r7.MSA[3].Trim());
                            }
                        }
                    }
                    if (debug == "1")
                    {
                        log.WriteMyLog("回传结果结束");
                    }
                    #endregion

                    string jpgname = "";
                    string jpgpath = "";
                    string ispdf   = f.ReadString("savetohis", "ispdf", "1").Replace("\0", "").Trim();
                    // string txwebpath = f.ReadString("savetohis", "txwebpath", "").Replace("\0", "").Trim();


                    if (ispdf == "1")
                    {
                        if (debug == "1")
                        {
                            log.WriteMyLog("生成pdf开始");
                        }

                        #region  生成pdf
                        string bgzt2 = "";
                        try
                        {
                            if (bglx.ToLower().Trim() == "bd")
                            {
                                DataTable dt_bd = aa.GetDataTable("select * from T_BDBG where F_BLH='" + blh + "' and  F_BD_BGXH='" + bgxh + "'", "bd");
                                bgzt2 = dt_bd.Rows[0]["F_BD_BGZT"].ToString();
                            }
                            if (bglx.ToLower().Trim() == "bc")
                            {
                                DataTable dt_bc = aa.GetDataTable("select * from T_BCBG where F_BLH='" + blh + "' and  F_BC_BGXH='" + bgxh + "'", "bc");
                                bgzt2 = dt_bc.Rows[0]["F_BC_BGZT"].ToString();
                            }
                            if (bglx.ToLower().Trim() == "cg")
                            {
                                // DataTable jcxx2 = aa.GetDataTable("select * from T_jcxx where F_blh='" + blh + "'", "jcxx");
                                bgzt2 = jcxx.Rows[0]["F_BGZT"].ToString();
                            }
                        }
                        catch
                        {
                        }

                        if (bgzt2.Trim() == "")
                        {
                            log.WriteMyLog("报告状态为空!不处理!" + blh + "^" + bglx + "^" + bgxh);
                        }

                        if (bgzt2.Trim() == "已审核" && bgzt != "取消审核")
                        {
                            string ML      = DateTime.Parse(jcxx.Rows[0]["F_SDRQ"].ToString()).ToString("yyyyMM");
                            string err_msg = "";


                            ZGQClass zgq = new ZGQClass();

                            if (jcxx.Rows[0]["F_BRLB"].ToString().Trim() == "体检")
                            {
                                //生成jpg
                                bool isrtn = MD_PDF_JPG(blh, bglx, bgxh, ML, ZGQClass.type.JPG, ref err_msg, ref jpgname, ref jpgpath, IP, useName, pwd);
                                if (isrtn)
                                {
                                    jpgname = jpgname.Substring(jpgname.LastIndexOf('\\') + 1);
                                    ZGQClass.BGHJ(blh, "his接口", "报告审核", "生成jpg成功:" + jpgpath + "\\" + jpgname, "ZGQJK", "pdf");
                                    aa.ExecuteSQL("delete T_BG_PDF  where F_BLH='" + blh + "' and  F_BGLX='" + bglx + "'  and F_BGXH='" + bgxh + "'");
                                    aa.ExecuteSQL("insert  into T_BG_PDF(F_BLH,F_BGLX,F_BGXH,F_ML,F_FILENAME) values('" + blh + "','" + bglx + "','" + bgxh + "','" + jpgpath + "','" + jpgname + "')");
                                }
                                else
                                {
                                    log.WriteMyLog(blh + "-" + err_msg);
                                    ZGQClass.BGHJ(blh, "his接口", "审核jpg", "生成jpg失败" + err_msg, "ZGQJK", "pdf");

                                    if (msg == "1")
                                    {
                                        MessageBox.Show("病理号:" + blh + "  生成jpg失败,请重新审核!\r\n" + err_msg);
                                    }
                                    return;
                                }
                            }
                            else
                            {
                                //生成pdf
                                bool isrtn = MD_PDF_JPG(blh, bglx, bgxh, ML, ZGQClass.type.PDF, ref err_msg, ref jpgname, ref jpgpath, IP, useName, pwd);
                                if (isrtn)
                                {
                                    jpgname = jpgname.Substring(jpgname.LastIndexOf('\\') + 1);
                                    ZGQClass.BGHJ(blh, "his接口", "报告审核", "生成pdf成功:" + jpgpath + "\\" + jpgname, "ZGQJK", "pdf");

                                    aa.ExecuteSQL("delete T_BG_PDF  where F_BLH='" + blh + "' and  F_BGLX='" + bglx + "'  and F_BGXH='" + bgxh + "'");
                                    aa.ExecuteSQL("insert  into T_BG_PDF(F_BLH,F_BGLX,F_BGXH,F_ML,F_FILENAME) values('" + blh + "','" + bglx + "','" + bgxh + "','" + jpgpath + "','" + jpgname + "')");
                                }
                                else
                                {
                                    log.WriteMyLog(blh + "-" + err_msg);
                                    ZGQClass.BGHJ(blh, "his接口", "审核PDF", "生成pdf失败" + err_msg, "ZGQJK", "pdf");

                                    if (msg == "1")
                                    {
                                        MessageBox.Show("病理号:" + blh + "  生成pdf失败,请重新审核!\r\n" + err_msg);
                                    }
                                    return;
                                }
                            }
                        }
                        if (debug == "1")
                        {
                            log.WriteMyLog("生成pdf或jpg结束");
                        }
                        # endregion
                    }


                    #region 回传报告

                    if (debug == "1")
                    {
                        log.WriteMyLog("回传结果开始");
                    }

                    string pdflj = tjtxpath + "\\" + jpgpath + "\\" + jpgname;

                    string bgys   = jcxx.Rows[0]["F_BGYS"].ToString().Trim();
                    string bgysgh = getyhgh(bgys);

                    string shys   = jcxx.Rows[0]["F_SHYS"].ToString().Trim();
                    string shysgh = getyhgh(shys);

                    string qcys   = jcxx.Rows[0]["F_QCYS"].ToString().Trim();
                    string qcysgh = getyhgh(qcys);

                    string qcrq = jcxx.Rows[0]["F_QCrq"].ToString().Trim();
                    try
                    {
                        qcrq = DateTime.Parse(qcrq).ToString("yyyyMMddHHmmss");
                    }
                    catch
                    {
                    }

                    string hxbj = jcxx.Rows[0]["F_HXBJ"].ToString().Trim();

                    string zt2 = "F";
                    if (hxbj == "1")
                    {
                        zt2 = "C";
                    }


                    string xb = jcxx.Rows[0]["F_XB"].ToString().Trim();
                    if (xb == "女")
                    {
                        xb = "M";
                    }
                    else if (xb.Trim() == "男")
                    {
                        xb = "F";
                    }
                    else
                    {
                        xb = "U";
                    }
                    ////就诊科室,检查方法,检查部位,异常标记,申请科室,登记时间,登记人,检查时间,检查人,性别


                    string bgrq = DateTime.Parse(jcxx.Rows[0]["F_BGRQ"].ToString().Trim()).ToString("yyyyMMddHHmmss");
                    string SendGmsReport_hl7 = "MSH|^~\\&|GMS||HIS||" + DateTime.Now.ToString("yyyyMMddHHmmss") + "||ORU^R01|" + DateTime.Now.ToString("yyyyMMddHHmmss") + "|P|2.4" + "\r"
                                               + "PID|||" + brbh + "^^^^PI||" + jcxx.Rows[0]["F_XM"].ToString().Trim() + "^||^" + jcxx.Rows[0]["F_nl"].ToString().Trim() + "|" + xb + "|||||||" + "\r"
                                               + "PV1||" + brlb + "|" + SJKS + "^^" + CH + "||||^" + jcxx.Rows[0]["F_SJYS"].ToString().Trim() + "||||||||||||" + ZYH + "|||||||||||||||||||||||||" + "\r"
                                               + "OBR||" + sqxh + "|" + blh + "|" + YZXM + "||" + DateTime.Parse(jcxx.Rows[0]["F_sdrq"].ToString().Trim()).ToString("yyyyMMddHHmmss") + "|" + qcrq + "|||" + qcysgh + "^" + qcys + "||||" + DateTime.Parse(jcxx.Rows[0]["F_sdrq"].ToString().Trim()).ToString("yyyyMMddHHmmss") + "|" + jcxx.Rows[0]["F_BBMC"].ToString().Trim() + "|^" + jcxx.Rows[0]["F_SJYS"].ToString().Trim() + "||||||" + bgrq + "||||||||||" + bgysgh + "&" + bgys + "^^" + "\r"
                                               + "NTE|1||" + pdflj + "|Z-RP" + "\r"
                                               + "OBX|1|FT|^肉眼所见||" + (jcxx.Rows[0]["F_RYSJ"].ToString().Trim() + "\r\n" + jcxx.Rows[0]["F_JXSJ"].ToString().Trim()).Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", "\\.br\\.") + "|||N|||" + zt2 + "|||" + bgrq + "||" + shysgh + "^" + shys + "|^" + jcxx.Rows[0]["F_BLK"].ToString().Trim() + "|" + "\r"
                                               + "OBX|2|FT| ^病理诊断||" + (jcxx.Rows[0]["F_BLZD"].ToString().Trim() + "\r\n" + jcxx.Rows[0]["F_TSJC"].ToString().Trim()).Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", "\\.br\\.") + "|||N|||" + zt2 + "|||" + bgrq + "||" + shysgh + "^" + shys + "|^" + jcxx.Rows[0]["F_BLK"].ToString().Trim() + "|" + "\r";

                    DataTable dt_tx = aa.GetDataTable("select * from V_DYTX where F_blh='" + blh + "'", "tx");
                    if (dt_tx.Rows.Count > 0)
                    {
                        for (int x = 0; x < dt_tx.Rows.Count; x++)
                        {
                            string txlj = txwebpath + "/" + jcxx.Rows[0]["F_TXML"].ToString().Trim() + "/" + dt_tx.Rows[x]["F_TXM"].ToString();
                            SendGmsReport_hl7 = SendGmsReport_hl7 + "ZIM|" + (x + 1).ToString() + "|" + dt_tx.Rows[x]["F_ID"].ToString() + "|" + blh + "|" + txlj + "||1" + "\r";
                        }
                    }
                    else
                    {
                        SendGmsReport_hl7 = SendGmsReport_hl7 + "ZIM|1|1|" + blh + "|||" + "\r";
                    }

                    if (debug == "1")
                    {
                        log.WriteMyLog("报告审核回写结果:" + SendGmsReport_hl7);
                    }



                    string rtn_msg2 = rtn_CallInterface("HL7v2", "SendGmsReport", SendGmsReport_hl7, "", certificate);

                    if (rtn_msg2.Contains("error"))
                    {
                        if (msg == "1")
                        {
                            MessageBox.Show("报告审核回写结果错误:" + rtn_msg2);
                        }
                        log.WriteMyLog("报告审核回写结果错误:" + rtn_msg2);
                        if (isbghj == "1")
                        {
                            ZGQClass.BGHJ(blh, "批量上传", "审核", "报告审核回写结果错误:" + rtn_msg2, "ZGQJK", "报告审核回写结果");
                        }
                        aa.ExecuteSQL("update T_JCXX_FS set F_errmsg='" + rtn_msg2 + "'  where F_blh='" + blh + "' and F_BGLX='" + bglx.ToLower() + "' and F_BGXH='" + bgxh + "'");
                        return;
                    }
                    else
                    {
                        readhl7_fjfy r7 = new readhl7_fjfy();
                        int          xy = 0;
                        r7.Adt01(rtn_msg2, ref xy);
                        if (r7.MSA[1].Trim() == "AA")
                        {
                            if (debug == "1")
                            {
                                log.WriteMyLog(r7.MSA[3].Trim());
                            }
                            if (isbghj == "1")
                            {
                                ZGQClass.BGHJ(blh, "批量上传", "审核", "报告审核回写结果成功:" + r7.MSA[3].Trim(), "ZGQJK", "报告审核回写结果");
                            }
                        }
                        else
                        {
                            if (msg == "1")
                            {
                                MessageBox.Show(r7.MSA[3].Trim());
                            }
                            log.WriteMyLog("报告审核回写结果失败:" + r7.MSA[3].Trim());
                            if (isbghj == "1")
                            {
                                ZGQClass.BGHJ(blh, "批量上传", "审核", "报告审核回写结果失败:" + r7.MSA[3].Trim(), "ZGQJK", "报告审核回写结果");
                            }
                            aa.ExecuteSQL("update T_JCXX_FS set F_errmsg='报告审核回写结果失败:" + r7.MSA[3].Trim() + "'  where F_blh='" + blh + "' and F_BGLX='" + bglx.ToLower() + "' and F_BGXH='" + bgxh + "'");

                            return;
                        }
                    }
                    if (debug == "1")
                    {
                        log.WriteMyLog("回传结果结束");
                    }

                    #endregion

                    aa.ExecuteSQL("update T_JCXX_FS set F_errmsg='',F_FSZT='已处理'  where F_blh='" + blh + "' and F_BGLX='" + bglx.ToLower() + "' and F_BGXH='" + bgxh + "'");
                    aa.ExecuteSQL("update T_JCXX set F_HXBJ='1' where F_blh='" + blh + "'");
                    return;
                }
                //取消审核,删除pdf
                #region
                if (bgzt == "取消审核")
                {
                    DataTable dt2 = aa.GetDataTable("select top 1 * from T_BG_PDF where F_blh='" + blh + "'  and F_BGXH='" + bgxh + "' and F_BGLX='" + bglx + "'", "dt2");
                    if (dt2.Rows.Count > 0)
                    {
                        //开共享

                        if (useName.Trim() != "")
                        {
                            Process pro = new Process();
                            try
                            {
                                pro.StartInfo.FileName               = "cmd.exe";
                                pro.StartInfo.UseShellExecute        = false;
                                pro.StartInfo.RedirectStandardInput  = true;
                                pro.StartInfo.RedirectStandardOutput = true;
                                pro.StartInfo.RedirectStandardError  = true;
                                pro.StartInfo.CreateNoWindow         = true;
                                pro.Start();
                                pro.StandardInput.WriteLine("net use  \\\\" + IP + "\\ipc$ " + pwd + " /user:"******"");
                                Thread.Sleep(1000);

                                if (File.Exists(tjtxpath + "\\" + dt2.Rows[0]["F_ML"] + "\\" + dt2.Rows[0]["F_FILENAME"]))
                                {
                                    //删除共享上的pdf文件
                                    File.Delete(tjtxpath + "\\" + dt2.Rows[0]["F_ML"] + "\\" + dt2.Rows[0]["F_FILENAME"]);
                                }
                            }
                            catch (Exception ee)
                            {
                            }
                            finally
                            {
                                pro.StandardInput.WriteLine("net use  \\\\" + IP + "\\ipc$ /del");
                            }
                        }
                        else
                        {
                            if (File.Exists(tjtxpath + "\\" + dt2.Rows[0]["F_ML"] + "\\" + dt2.Rows[0]["F_FILENAME"]))
                            {
                                //删除共享上的pdf文件
                                File.Delete(tjtxpath + "\\" + dt2.Rows[0]["F_ML"] + "\\" + dt2.Rows[0]["F_FILENAME"]);
                            }
                        }
                        //判断共享上是否存在该pdf文件

                        aa.ExecuteSQL("delete T_BG_PDF  where F_BLH='" + blh + "' and  F_BGLX='" + bglx + "'  and F_BGXH='" + bgxh + "'");
                    }
                }
                #endregion
            }

            return;
        }
Beispiel #2
0
        public string ca(string yhxx)
        {
            dbbase.odbcdb aa = new odbcdb("DSN=pathnet;UID=pathnet;PWD=4s3c2a1p", "", "");

            ////-------获取sz中设置的参数---------------------
            string debug = f.ReadString("CA", "debug", "").Replace("\0", "").Trim();
            string msg   = f.ReadString("CA", "message", "1").Replace("\0", "").Trim();

            string getblh = "";
            string type   = "";
            string type2  = "";
            string yhm    = "";

            string yhmc = "";
            string yhbh = "";
            string yhmm = "";
            string bglx = "";
            string bgxh = "";

            #region CA登陆

            if (ZGQClass.GetSZ("CA", "ca", "").Replace("\0", "").Trim() == "1")
            {
                if (yhxx == "")
                {
                    return(Login());
                }
            }

            #endregion

            string[] getyhxx = yhxx.Split('^');
            if (getyhxx.Length == 5)
            {
                type = getyhxx[0];
                yhm  = getyhxx[1];
                yhmc = getyhxx[3];
                yhbh = getyhxx[2];
                yhmm = getyhxx[4];
            }
            else
            {
                type2  = getyhxx[0];
                getblh = getyhxx[1];
                bgxh   = getyhxx[2];
                bglx   = getyhxx[3].ToLower();
                type   = getyhxx[4];
                yhm    = getyhxx[5];
                yhmc   = getyhxx[6];
                yhbh   = getyhxx[7];
                yhmm   = getyhxx[8];
            }

            #region 审核前验证KEY

            if (type == "SH")
            {
                return(YZKEY(msg, yhmc, yhbh));
            }

            #endregion

            string blbh = getblh + bglx + bgxh;

            #region 审核后执行,数字签名

            if (type == "QZ")
            {
                if (debug == "1")
                {
                    MessageBox.Show("审核签字");
                }

                string yw = "";

                string isb64yw = f.ReadString("CA", "b64yw", "0").Replace("\0", "").Trim();

                bool WithTSA = false; //带时间戳签名
                if ((f.ReadString("ca", "WithTSA", "0").Trim().Replace("\0", "").Trim()) == "1")
                {
                    WithTSA = true; //签名值包含原文
                }
                bool havcount = false;
                bool isVerify = false; //网关验证
                if ((f.ReadString("ca", "isVerify", "0").Trim().Replace("\0", "").Trim()) == "1")
                {
                    isVerify = true;
                }
                string usapurl    = f.ReadString("ca", "usapurl", "").Trim().Replace("\0", "").Trim();     //网关地址
                string svrcertb64 = f.ReadString("ca", "svrcertb64", "1").Trim().Replace("\0", "").Trim(); //网关证书
                string b64SignVal = "";
                SecuInter.X509Certificate oCert = null;
                DataTable dt_jcxx = new DataTable();
                DataTable dt_bc   = new DataTable();
                DataTable dt_bd   = new DataTable();
                try
                {
                    #region 原文

                    dt_jcxx = aa.GetDataTable("select * from T_JCXX where  F_BLH='" + getblh + "'", "cgbg");

                    if (dt_jcxx == null)
                    {
                        if (msg == "1")
                        {
                            MessageBox.Show("连接数据库异常");
                        }
                        return("0");
                    }
                    if (dt_jcxx.Rows.Count <= 0)
                    {
                        if (msg == "1")
                        {
                            MessageBox.Show("T_JCXX查询数据异常");
                        }
                        return("0");
                    }
                    if (bglx == "cg")
                    {
                        if (dt_jcxx.Rows[0]["F_BGZT"].ToString() != "已审核")
                        {
                            if (msg == "1")
                            {
                                MessageBox.Show("报告未审核");
                            }
                            return("0");
                        }
                        yw = "病理号:" + dt_jcxx.Rows[0]["f_blh"].ToString() + "&常规报告&&性别:" +
                             dt_jcxx.Rows[0]["F_XB"].ToString() + "&年龄:" + dt_jcxx.Rows[0]["F_nl"].ToString()
                             + "&住院号:" + dt_jcxx.Rows[0]["F_zyh"].ToString() + "&门诊号:" +
                             dt_jcxx.Rows[0]["F_mzh"].ToString() + "&身份证号:" + dt_jcxx.Rows[0]["F_SFZH"].ToString() +
                             "&科室:" + dt_jcxx.Rows[0]["F_sjks"].ToString()
                             + "&病理诊断:" + dt_jcxx.Rows[0]["F_blzd"].ToString() + "&报告医生:" +
                             dt_jcxx.Rows[0]["F_bgys"].ToString() + "&复诊医生:" + dt_jcxx.Rows[0]["F_FZYS"].ToString()
                             + "&审核医生:" + dt_jcxx.Rows[0]["F_SHYS"].ToString() + "&报告日期:" +
                             dt_jcxx.Rows[0]["F_bgrq"].ToString() + "&审核日期:" + dt_jcxx.Rows[0]["F_spare5"].ToString();
                    }
                    //// 补充审核
                    if (bglx == "bc")
                    {
                        dt_bc =
                            aa.GetDataTable(
                                "select * from T_BCBG where  F_BLH='" + getblh + "' and F_BC_BGZT='已审核'and F_BC_BGXH='" +
                                bgxh + "'", "bcbg");
                        if (dt_bc == null)
                        {
                            if (msg == "1")
                            {
                                MessageBox.Show("连接数据库异常");
                            }
                            return("0");
                        }
                        if (dt_bc.Rows.Count <= 0)
                        {
                            if (msg == "1")
                            {
                                MessageBox.Show("T_BCBG查询数据异常");
                            }
                            return("0");
                        }
                        yw = "病理号:" + dt_jcxx.Rows[0]["f_blh"].ToString() + "&补充报告:" + bgxh + "&性别:" +
                             dt_jcxx.Rows[0]["F_XB"].ToString() + "&年龄:" + dt_jcxx.Rows[0]["F_nl"].ToString()
                             + "&住院号:" + dt_jcxx.Rows[0]["F_zyh"].ToString() + "&门诊号:" +
                             dt_jcxx.Rows[0]["F_mzh"].ToString() + "&身份证号:" + dt_jcxx.Rows[0]["F_SFZH"].ToString() +
                             "&科室:" + dt_jcxx.Rows[0]["F_sjks"].ToString()
                             + "&病理诊断:" + dt_bc.Rows[0]["F_BCZD"].ToString() + "&报告医生:" +
                             dt_bc.Rows[0]["F_bc_bgys"].ToString() + "&复诊医生:" + dt_bc.Rows[0]["F_bc_FZYS"].ToString()
                             + "&审核医生:" + dt_bc.Rows[0]["F_bc_SHYS"].ToString() + "&报告日期:" +
                             dt_bc.Rows[0]["F_bc_bgrq"].ToString() + "&审核日期:" + dt_bc.Rows[0]["F_bc_spare5"].ToString();
                    }
                    ///// 小冰冻审核
                    if (bglx == "bd")
                    {
                        dt_bd =
                            aa.GetDataTable(
                                "select * from T_BDBG  where  F_BLH='" + getblh +
                                "' and  F_BD_BGZT='已审核' and F_BD_BGXH='" + bgxh + "'", "bcbg");
                        if (dt_bd == null)
                        {
                            if (msg == "1")
                            {
                                MessageBox.Show("连接数据库异常");
                            }
                            return("0");
                        }
                        if (dt_bd.Rows.Count <= 0)
                        {
                            if (msg == "1")
                            {
                                MessageBox.Show("T_BDBG查询数据异常");
                            }
                            return("0");
                        }
                        yw = "病理号:" + dt_jcxx.Rows[0]["f_blh"].ToString() + "&冰冻报告:" + bgxh + "&性别:" +
                             dt_jcxx.Rows[0]["F_XB"].ToString() + "&年龄:" + dt_jcxx.Rows[0]["F_nl"].ToString()
                             + "&住院号:" + dt_jcxx.Rows[0]["F_zyh"].ToString() + "&门诊号:" +
                             dt_jcxx.Rows[0]["F_mzh"].ToString() + "&身份证号:" + dt_jcxx.Rows[0]["F_SFZH"].ToString() +
                             "&科室:" + dt_jcxx.Rows[0]["F_sjks"].ToString()
                             + "&病理诊断:" + dt_bd.Rows[0]["F_BdZD"].ToString() + "&报告医生:" +
                             dt_bd.Rows[0]["F_bd_bgys"].ToString() + "&复诊医生:" + dt_bd.Rows[0]["F_bd_FZYS"].ToString()
                             + "&审核医生:" + dt_bd.Rows[0]["F_bd_SHYS"].ToString() + "&报告日期:" +
                             dt_bd.Rows[0]["F_bd_bgrq"].ToString();
                    }

                    if (yw.Trim() == "")
                    {
                        if (msg == "1")
                        {
                            MessageBox.Show("数字签名内容为空");
                        }
                        return("0");
                    }

                    #endregion

                    if (isb64yw == "1")
                    {
                        yw = changebase64(yw);
                    }

                    #region 签名

                    try
                    {
                        ////签名
                        if (WithTSA)
                        {
                            b64SignVal = NETCAPKIv4.signPKCS7WithTSA(yw, usapurl, havcount); //时间戳签名
                        }
                        else
                        {
                            b64SignVal = NETCAPKIv4.signNETCA(yw, havcount, userPwd); //不带时间戳签名
                        }
                    }
                    catch (Exception ee1)
                    {
                        if (msg == "1")
                        {
                            MessageBox.Show("签名失败:" + ee1.Message);
                        }
                        return("0");
                    }
                    if (b64SignVal == "")
                    {
                        if (msg == "1")
                        {
                            MessageBox.Show("签名失败");
                        }
                        return("0");
                    }

                    #endregion

                    #region 验签

                    try
                    {
                        string signTime = "";
                        oCert = NETCAPKIv4.verifyPKCS7(yw, b64SignVal, true, ref signTime);
                    }
                    catch (Exception ee2)
                    {
                        if (msg == "1")
                        {
                            MessageBox.Show("验签失败:" + ee2.Message);
                        }
                        return("0");
                    }
                    if (oCert == null)
                    {
                        if (msg == "1")
                        {
                            MessageBox.Show("验签失败");
                        }
                        return("0");
                    }

                    #endregion

//                    #region   验证证书
//
//                    if (isVerify)
//                    {
//                        try
//                        {
//                            bool bFlag = NETCAPKIv4.VerifyCert(usapurl, svrcertb64, 1, oCert); //再验证证书
//                            if (!bFlag)
//                            {
//                                MessageBox.Show("签名证书验证失败");
//                                return "0";
//                            }
//                        }
//                        catch (Exception ee3)
//                        {
//                            if (msg == "1")
//                                MessageBox.Show("签名证书验证失败:" + ee3.Message);
//                            return "0";
//                        }
//                    }
//
//                    #endregion

                    // 签字
                }
                catch (Exception ex)
                {
                    MessageBox.Show("签名异常:" + ex.Message);
                    return("0");
                }

                #region 签名完成,写数据库

                string errmsg = "";
                int    x      =
                    aa.ExecuteSQL(
                        "insert into T_SZQM(F_BLBH,F_BLH,F_BGLX,F_BGXH,F_CZY,F_YW,F_SignCert,F_SignData,F_QZRQ) values('" +
                        blbh + "','"
                        + getblh + "','" + bglx + "','" + bgxh + "','" + yhmc + "','" + yw + "','"
                        + oCert.ToString() + "','" + b64SignVal.ToString() + "','" +
                        DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "')");

                if (debug == "1")
                {
                    if (x >= 1)
                    {
                        MessageBox.Show("写入T_CAXX完成");
                    }
                    else
                    {
                        MessageBox.Show("写入T_CAXX失败:" + errmsg);
                    }
                }

                #endregion

                if (f.ReadString("ca", "hqkeytp", "0").Trim().Replace("\0", "").Trim() == "1")
                {
                    #region 获取签字图片

                    string szqmlj = ZGQClass.GetSZ("view", "szqmlj", @"\\127.0.0.1\pathqc\rpt-szqm\YSBMP\");


                    try
                    {
                        IPDFSign iPDFSign = new PDFSign();
                        //选择证书
                        iPDFSign.SelectCert("netca", 0);
                        IUtilTool iUtilTool = new UtilTool();
                        //传入选中的签名证书的base64编码
                        string CertBase64 = iPDFSign.SignCertBase64Encode;
                        if (CertBase64.Trim() == "")
                        {
                            if (msg == "1")
                            {
                                MessageBox.Show("获取签名证书的base64编码失败");
                            }
                            return("0");
                        }
                        try
                        {
                            //log.WriteMyLog("CertBase64:"+CertBase64);
                            byte[] image = iUtilTool.GetImageFromDevicByCert(CertBase64);
                            try
                            {
                                MemoryStream memoryStream = new MemoryStream(image, 0, image.Length);
                                memoryStream.Write(image, 0, image.Length);
                                //转成图片
                                Image ii = Image.FromStream(memoryStream);
                                log.WriteMyLog("szqmlj:" + szqmlj);
                                ii.Save(szqmlj + yhmc + ".bmp", System.Drawing.Imaging.ImageFormat.Bmp);
                            }
                            catch (Exception ee4)
                            {
                                if (msg == "1")
                                {
                                    MessageBox.Show("保存签名图片失败:" + ee4.Message);
                                }
                                return("0");
                            }


                            string pdfszqz = ZGQClass.GetSZ("CA", "pdfszqz", "1");
                            if (pdfszqz == "1")
                            {
                                #region  生成pdf

                                string blh = getblh;
                                try
                                {
                                    if (bglx == "")
                                    {
                                        bglx = "cg";
                                    }
                                    if (bgxh == "")
                                    {
                                        bgxh = "1";
                                    }

                                    string bgzt     = "";
                                    string filename = dt_jcxx.Rows[0]["F_SPARE5"].ToString();
                                    if (bglx.ToLower() == "bd")
                                    {
                                        bgzt     = dt_bd.Rows[0]["F_BD_BGZT"].ToString();
                                        filename = dt_bd.Rows[0]["F_BD_bgrq"].ToString();
                                    }
                                    if (bglx.ToLower() == "bc")
                                    {
                                        bgzt     = dt_bc.Rows[0]["F_BC_BGZT"].ToString();
                                        filename = dt_bc.Rows[0]["F_Bc_SPARE5"].ToString();
                                    }
                                    if (bglx.ToLower() == "cg")
                                    {
                                        bgzt     = dt_jcxx.Rows[0]["F_BGZT"].ToString();
                                        filename = dt_jcxx.Rows[0]["F_SPARE5"].ToString();
                                    }

                                    if (bgzt == "已审核")
                                    {
                                        try
                                        {
                                            filename = blh.Trim() + "_" + bglx.ToLower() + "_" + bgxh + "_" +
                                                       DateTime.Parse(filename.Trim()).ToString("yyyyMMddHHmmss") +
                                                       ".pdf";
                                        }
                                        catch
                                        {
                                            filename = blh.Trim() + "_" + bglx.ToLower() + "_" + bgxh + ".pdf";
                                        }
                                        string ml =
                                            DateTime.Parse(dt_jcxx.Rows[0]["F_SDRQ"].ToString()).ToString("yyyyMM");
                                        string pdfpath = "";
                                        string rptpath = ZGQClass.GetSZ("ca", "rptpath", "rpt").Replace("\0", "").Trim();

                                        string     scpdffs  = f.ReadString("ca", "scpdffs", "1").Replace("\0", "").Trim();
                                        ZGQ_PDFJPG zgq      = new ZGQ_PDFJPG();
                                        string     message  = "";
                                        string     filePath = "";

                                        //生成PDF
                                        string ErrMsg = "";
                                        // log.WriteMyLog("filename="+filename);
                                        bool pdf1 = zgq.CreatePDFJPG(blh, bglx, bgxh, ref filename, rptpath,
                                                                     ZGQ_PDFJPG.type.PDF, ref ErrMsg);
                                        log.WriteMyLog("filename=" + filename);
                                        if (!pdf1)
                                        {
                                            MessageBox.Show("生成PDF失败,请重新审核\r\n" + ErrMsg);
                                            DeleteTempFile(blh);
                                            return("0");
                                        }

                                        if (!File.Exists(filename))
                                        {
                                            MessageBox.Show("生成PDF失败,请重新审核");
                                            DeleteTempFile(blh);
                                            return("0");
                                        }

                                        filePath = filename;
                                        if (zgq.UpPDF(blh, filename, ml, 0, ref errmsg, ref pdfpath))
                                        {
                                            if (debug == "1")
                                            {
                                                log.WriteMyLog("上传PDF成功");
                                            }
                                            filename = filePath.Substring(filePath.LastIndexOf('\\') + 1);
                                            ZGQClass.BGHJ(blh, "上传PDF", "审核", "上传PDF成功:" + ml + "\\" + filename, "ZGQJK",
                                                          "上传PDF");
                                            aa.ExecuteSQL("delete T_BG_PDF  where F_BLBH='" + blbh + "'");
                                            aa.ExecuteSQL(
                                                "insert  into T_BG_PDF(F_BLBH,F_BLH,F_BGLX,F_BGXH,F_ML,F_FILENAME,F_FilePath,F_PDFLX) values('" +
                                                blbh + "','" + blh + "','" + bglx + "','" + bgxh + "','" + ml + "\\" +
                                                blh + "','" + filename + "','" + pdfpath + "','')");
                                        }
                                        else
                                        {
                                            MessageBox.Show("上传签字PDF失败,请重新审核\r\n" + errmsg);
                                            ZGQClass.BGHJ(blh, "上传PDF", "审核", "上传PDF失败:" + errmsg, "ZGQJK", "上传PDF");
                                        }
                                        //上传pdf

                                        iPDFSign.SetImage(image);
                                        iPDFSign.RenderMode  = 3;
                                        iPDFSign.SrcFileName = filePath;
                                        string szqm_filename = filePath.Replace(".pdf", "_szqm.pdf");
                                        iPDFSign.DestFileName = szqm_filename;
                                        int xPos =
                                            int.Parse(ZGQClass.GetSZ("ca", "xPos", "350").Replace("\0", "").Trim());
                                        int yPos =
                                            int.Parse(ZGQClass.GetSZ("ca", "yPos", "100").Replace("\0", "").Trim());
                                        int width =
                                            int.Parse(ZGQClass.GetSZ("ca", "width", "80").Replace("\0", "").Trim());
                                        int height =
                                            int.Parse(ZGQClass.GetSZ("ca", "height", "40").Replace("\0", "").Trim());
                                        iPDFSign.SignPosition(1, xPos, yPos, width, height);

                                        if (File.Exists(szqm_filename))
                                        {
                                            //上传签字的pdf

                                            if (zgq.UpPDF(blh, szqm_filename, ml, 0, ref errmsg, ref pdfpath))
                                            {
                                                if (debug == "1")
                                                {
                                                    log.WriteMyLog("上传签字PDF成功");
                                                }
                                                szqm_filename =
                                                    szqm_filename.Substring(szqm_filename.LastIndexOf('\\') + 1);
                                                ZGQClass.BGHJ(blh, "上传PDF", "审核",
                                                              "上传签字PDF成功:" + ml + "\\" + szqm_filename, "ZGQJK", "上传PDF");
                                                aa.ExecuteSQL("delete T_BG_PDF_CA  where F_BLBH='" + blbh + "'");
                                                log.WriteMyLog("insert  into T_BG_PDF_CA(F_BLBH,F_BLH,F_BGLX,F_BGXH,F_ML,F_FILENAME,F_FilePath,F_PDFLX) values('" +
                                                               blbh + "','" + blh + "','" + bglx + "','" + bgxh + "','" + ml + "\\" +
                                                               blh + "','" + szqm_filename + "','" + pdfpath + "','szqm')");
                                                aa.ExecuteSQL(
                                                    "insert  into T_BG_PDF_CA(F_BLBH,F_BLH,F_BGLX,F_BGXH,F_ML,F_FILENAME,F_FilePath,F_PDFLX) values('" +
                                                    blbh + "','" + blh + "','" + bglx + "','" + bgxh + "','" + ml + "\\" +
                                                    blh + "','" + szqm_filename + "','" + pdfpath + "','szqm')");
                                            }
                                            else
                                            {
                                                MessageBox.Show("上传签字PDF失败,请重新审核\r\n" + errmsg);
                                                ZGQClass.BGHJ(blh, "上传签字PDF", "审核", "上传PDF失败:" + errmsg, "ZGQJK",
                                                              "上传PDF");
                                            }
                                        }
                                        else
                                        {
                                            MessageBox.Show("PDF签字失败,请重新审核");
                                        }
                                        DeleteTempFile(blh);
                                        return("1");
                                    }
                                    else
                                    {
                                        MessageBox.Show("报告未审核");
                                        return("0");
                                    }
                                }
                                catch (Exception ee10)
                                {
                                    MessageBox.Show("生成PDF异常,请重新审核\r\n" + ee10.Message);
                                    DeleteTempFile(blh);
                                    return("0");
                                }

                                #endregion
                            }
                        }
                        catch (Exception ee5)
                        {
                            MessageBox.Show("获取签名图像异常,请重新审核\r\n" + ee5.Message);
                            return("0");
                        }
                    }
                    catch (Exception ee6)
                    {
                        MessageBox.Show("获取签名证书失败,请重新审核\r\n" + ee6.Message);
                        return("0");
                    }

                    #endregion
                }
                if (debug == "1")
                {
                    MessageBox.Show("签字完成");
                }

                return("1");
            }

            #endregion

            #region 取消审核

            if (type == "QXSH")
            {
                if (f.ReadString("ca", "qxshyz", "0").Trim().Replace("\0", "").Trim() == "1")
                {
                    return(YZKEY(msg, yhmc, yhbh));
                }
                return("1");
            }

            #endregion

            #region 取消签字

            if (type == "QXQZ") //&& (bglx == "BC" || bglx == "BD")
            {
                aa.ExecuteSQL("delete from  T_SZQM  where  F_BLBH='" + blbh + "' ");
                aa.ExecuteSQL("delete from  T_BG_PDF  where  F_BLBH='" + blbh + "' ");
                return("1");
            }

            #endregion

            return("1");
        }
Beispiel #3
0
        public void pathtohis(string blh, string bglx, string bgxh, string msg1, string debug1, string[] cslb)
        {
            if (bglx == "")
            {
                bglx = "cg";
            }
            if (bgxh == "")
            {
                bgxh = "0";
            }


            string CZY   = f.ReadString("yh", "yhmc", "").Replace("\0", "").Trim();
            string CZYGH = f.ReadString("yh", "yhbh", "").Replace("\0", "").Trim();

            debug = f.ReadString("savetohis", "debug", "").Replace("\0", "").Trim();
            string isbghj = f.ReadString("savetohis", "isbghj", "1").Replace("\0", "").Trim();



            string IP        = f.ReadString("savetohis", "IP", "223.220.200.7");
            string toPDFPath = f.ReadString("savetohis", "toPDFPath", "");
            string useName   = f.ReadString("savetohis", "useName", "");
            string pwd       = f.ReadString("savetohis", "pwd", "");
            string tjtxpath  = toPDFPath;

            string qxsh = "";
            string xdj  = "";

            bglx = bglx.ToLower();

            if (cslb.Length == 5)
            {
                if (cslb[4].ToLower() == "qxsh")
                {
                    qxsh = "1"; //取消审核动作
                }
                if (cslb[3].ToLower() == "new")
                {
                    xdj = "1";
                }
            }

            dbbase.odbcdb aa   = new odbcdb("DSN=pathnet;UID=pathnet;PWD=4s3c2a1p", "", "");
            DataTable     jcxx = new DataTable();

            try
            {
                jcxx = aa.GetDataTable("select * from T_jcxx where F_blh='" + blh + "'", "jcxx");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
                return;
            }
            if (jcxx == null)
            {
                MessageBox.Show("病理数据库设置有问题!");
                return;
            }
            if (jcxx.Rows.Count < 1)
            {
                MessageBox.Show("病理号有错误!");
                return;
            }


            string bgzt = jcxx.Rows[0]["F_BGZT"].ToString().Trim();

            if (qxsh == "1")
            {
                bgzt = "取消审核";
            }



            string brbh = jcxx.Rows[0]["F_BRBH"].ToString().Trim();
            string brlb = jcxx.Rows[0]["F_brlb"].ToString().Trim();
            string sqxh = jcxx.Rows[0]["F_SQXH"].ToString().Trim();

            if (brlb == "住院")
            {
                brlb = "I";
            }
            else
            {
                brlb = "O";
            }

            string ZYH = jcxx.Rows[0]["F_MZH"].ToString().Trim();

            if (brlb == "I")
            {
                ZYH = jcxx.Rows[0]["F_ZYH"].ToString().Trim();
            }

            string SFZH    = jcxx.Rows[0]["F_SFZH"].ToString().Trim();
            string XM      = jcxx.Rows[0]["F_XM"].ToString().Trim();
            string SJKS    = jcxx.Rows[0]["F_BQ"].ToString().Trim();
            string CH      = jcxx.Rows[0]["F_CH"].ToString().Trim();
            string YZXM    = jcxx.Rows[0]["F_YZXM"].ToString().Trim();
            string jpgname = "";
            string jpgpath = "";

            string bz = "";

            if (bgzt == "已审核")
            {
                if (debug == "1")
                {
                    log.WriteMyLog("生成pdf开始");
                }


                string bgzt2 = "";
                try
                {
                    if (bglx.ToLower().Trim() == "bd")
                    {
                        DataTable dt_bd = aa.GetDataTable("select * from T_BDBG where F_BLH='" + blh + "' and  F_BD_BGXH='" + bgxh + "'", "bd");
                        bgzt2 = dt_bd.Rows[0]["F_BD_BGZT"].ToString();
                    }
                    if (bglx.ToLower().Trim() == "bc")
                    {
                        DataTable dt_bc = aa.GetDataTable("select * from T_BCBG where F_BLH='" + blh + "' and  F_BC_BGXH='" + bgxh + "'", "bc");
                        bgzt2 = dt_bc.Rows[0]["F_BC_BGZT"].ToString();
                    }
                    if (bglx.ToLower().Trim() == "cg")
                    {
                        // DataTable jcxx2 = aa.GetDataTable("select * from T_jcxx where F_blh='" + blh + "'", "jcxx");
                        bgzt2 = jcxx.Rows[0]["F_BGZT"].ToString();
                    }
                }
                catch
                {
                }

                if (bgzt2.Trim() == "")
                {
                    log.WriteMyLog("报告状态为空!不处理!" + blh + "^" + bglx + "^" + bgxh);
                }

                if (bgzt2.Trim() == "已审核" && bgzt != "取消审核")
                {
                    string ML      = DateTime.Parse(jcxx.Rows[0]["F_SDRQ"].ToString()).ToString("yyyyMM");
                    string err_msg = "";


                    ZGQClass zgq = new ZGQClass();

                    if (jcxx.Rows[0]["F_BRLB"].ToString().Trim() == "体检")
                    {
                        //生成jpg
                        bool isrtn = MD_PDF_JPG(blh, bglx, bgxh, ML, ZGQClass.type.JPG, ref err_msg, ref jpgname, ref jpgpath, IP, useName, pwd);
                        if (isrtn)
                        {
                            jpgname = jpgname.Substring(jpgname.LastIndexOf('\\') + 1);
                            ZGQClass.BGHJ(blh, "his接口", "报告审核", "生成jpg成功:" + jpgpath + "\\" + jpgname, "ZGQJK", "pdf");
                            aa.ExecuteSQL("delete T_BG_PDF  where F_BLH='" + blh + "' and  F_BGLX='" + bglx + "'  and F_BGXH='" + bgxh + "'");
                            aa.ExecuteSQL("insert  into T_BG_PDF(F_BLH,F_BGLX,F_BGXH,F_ML,F_FILENAME) values('" + blh + "','" + bglx + "','" + bgxh + "','" + jpgpath + "','" + jpgname + "')");
                        }
                        else
                        {
                            log.WriteMyLog(blh + "-" + err_msg);
                            ZGQClass.BGHJ(blh, "his接口", "审核jpg", "生成jpg失败" + err_msg, "ZGQJK", "pdf");

                            if (msg == "1")
                            {
                                MessageBox.Show("病理号:" + blh + "  生成jpg失败,请重新审核!\r\n" + err_msg);
                            }
                            return;
                        }
                    }
                    else
                    {
                        //生成pdf
                        bool isrtn = MD_PDF_JPG(blh, bglx, bgxh, ML, ZGQClass.type.PDF, ref err_msg, ref jpgname, ref jpgpath, IP, useName, pwd);
                        if (isrtn)
                        {
                            jpgname = jpgname.Substring(jpgname.LastIndexOf('\\') + 1);
                            ZGQClass.BGHJ(blh, "his接口", "报告审核", "生成pdf成功:" + jpgpath + "\\" + jpgname, "ZGQJK", "pdf");

                            aa.ExecuteSQL("delete T_BG_PDF  where F_BLH='" + blh + "' and  F_BGLX='" + bglx + "'  and F_BGXH='" + bgxh + "'");
                            aa.ExecuteSQL("insert  into T_BG_PDF(F_BLH,F_BGLX,F_BGXH,F_ML,F_FILENAME) values('" + blh + "','" + bglx + "','" + bgxh + "','" + jpgpath + "','" + jpgname + "')");
                        }
                        else
                        {
                            log.WriteMyLog(blh + "-" + err_msg);
                            ZGQClass.BGHJ(blh, "his接口", "审核PDF", "生成pdf失败" + err_msg, "ZGQJK", "pdf");

                            if (msg == "1")
                            {
                                MessageBox.Show("病理号:" + blh + "  生成pdf失败,请重新审核!\r\n" + err_msg);
                            }
                            return;
                        }
                    }
                }
                if (debug == "1")
                {
                    log.WriteMyLog("生成pdf或jpg结束");
                }
            }
            //取消审核,删除pdf

            if (bgzt == "取消审核")
            {
                DataTable dt2 = aa.GetDataTable("select top 1 * from T_BG_PDF where F_blh='" + blh + "'  and F_BGXH='" + bgxh + "' and F_BGLX='" + bglx + "'", "dt2");
                if (dt2.Rows.Count > 0)
                {
                    //开共享

                    if (useName.Trim() != "")
                    {
                        Process pro = new Process();
                        try
                        {
                            pro.StartInfo.FileName               = "cmd.exe";
                            pro.StartInfo.UseShellExecute        = false;
                            pro.StartInfo.RedirectStandardInput  = true;
                            pro.StartInfo.RedirectStandardOutput = true;
                            pro.StartInfo.RedirectStandardError  = true;
                            pro.StartInfo.CreateNoWindow         = true;
                            pro.Start();
                            pro.StandardInput.WriteLine("net use  \\\\" + IP + "\\ipc$ " + pwd + " /user:"******"");
                            Thread.Sleep(1000);

                            if (File.Exists(tjtxpath + "\\" + dt2.Rows[0]["F_ML"] + "\\" + dt2.Rows[0]["F_FILENAME"]))
                            {
                                //删除共享上的pdf文件
                                File.Delete(tjtxpath + "\\" + dt2.Rows[0]["F_ML"] + "\\" + dt2.Rows[0]["F_FILENAME"]);
                            }
                        }
                        catch (Exception ee)
                        {
                        }
                        finally
                        {
                            pro.StandardInput.WriteLine("net use  \\\\" + IP + "\\ipc$ /del");
                        }
                    }
                    else
                    {
                        if (File.Exists(tjtxpath + "\\" + dt2.Rows[0]["F_ML"] + "\\" + dt2.Rows[0]["F_FILENAME"]))
                        {
                            //删除共享上的pdf文件
                            File.Delete(tjtxpath + "\\" + dt2.Rows[0]["F_ML"] + "\\" + dt2.Rows[0]["F_FILENAME"]);
                        }
                    }
                    //判断共享上是否存在该pdf文件

                    aa.ExecuteSQL("delete T_BG_PDF  where F_BLH='" + blh + "' and  F_BGLX='" + bglx + "'  and F_BGXH='" + bgxh + "'");
                }
            }



            return;
        }