/// <summary> /// 上传订单处理 /// </summary> private void SendOrdersHandle() { try { DAOutSpecimenBLL bll = new DAOutSpecimenBLL(); //获取需要获取结果的条码号 List <DAOutspecimen> BarCodeList = bll.SelectRequestCodeBySendOrders(); if (BarCodeList.Count == 0) { SetTB("没有订单需要上传"); return; } //获取对照表 List <DATestmap> datestmap = new DATestmapBLL().GetDATestmapList(null); for (int i = 0; i < BarCodeList.Count; i++) { DAOutspecimen outspec = BarCodeList[i]; string barcode = outspec.Requestcode; try { Hashtable ht = new Hashtable(); ht.Add("Requestcode", barcode); DataTable dt = outspecimenbll.GetOutspecimenTable(ht); //基本信息 dt.TableName = "data_row"; /* 发送模式:1 组合发送, 0 单项发送(默认) * 组合发送: 发送订单表OutSpecimen的数据 * (DATESTCODES AS NaturalItem,CUSTOMERTESTNAMES AS NaturalItemDesc,CUSTOMERTESTCODES AS HospItemCode) * * 单项发送: 发送结果表da_result中的明细数据,获取Customertestcode,customertestname, * 并根据Customertestcode获取对照表的datestcode */ #region >>>> zhouy 发送项目拼装 string cuscode = "", cusname = "", daancode = ""; DataTable dtTest; if (config.Model == "1") { dtTest = new DAOutSpecimentestBLL().SelectSendGruopCodeByRequestCode(outspec.Requestcode); //组合 } else { dtTest = new DAResultBLL().SelectSendTestCodeByRequestCode(outspec.Requestcode); //明细 } foreach (DataRow dr in dtTest.Rows) { //没有达安代码,则对照表没有对应 if (dr["datestcode"] == null || dr["datestcode"].ToString() == "") { //没对项目跳出进行下一个条码 throw new Exception(string.Format("中的医院项目[{0}({1})]未对应好数据,请到项目对照表中对应好" , dr["customertestname"], dr["Customertestcode"])); } cuscode += dr["Customertestcode"] + ","; cusname += dr["customertestname"] + ","; daancode += dr["datestcode"] + ","; } dt.Rows[0]["HospItemCode"] = cuscode.TrimEnd(','); //医院项目代码 dt.Rows[0]["NaturalItemDesc"] = cusname.TrimEnd(','); //医院项目名称 dt.Rows[0]["NaturalItem"] = daancode.TrimEnd(','); //达安代码 #endregion string[] obj = new string[2] { SID, StringToXML(DataToXml.ConvertDataTableToXML(dt)) }; string strQueryResult = WebServiceUtils.ExecuteMethod("SendRequestInfo", obj); //调用webService if (strQueryResult.Contains("无法连接")) { throw new Exception("操作连接超时!" + strQueryResult); } else if (strQueryResult.Contains("MSG0006")) { string[] strlogin = commonbll.UserLogin(config); if (strlogin[0] == "0") { SetTB("登录失败:" + strlogin[1]); continue; } else { SID = strlogin[1]; i--; } } else { #region >>>> zhouy 发送成功记录成功日志,发送失败记录错误日志 string msg = strQueryResult; //strQueryResult.TrimEnd(',').Split('|'); 2019.1.29该接口康源系统返回的格式和其他接口不同做特殊处理 //0 为正常发送了 if (msg.Contains("|0")) { DAOperationlog daoperationlog = new DAOperationlog(); daoperationlog.Dictuserid = user.Dictuserid; daoperationlog.Usercode = user.Usercode; daoperationlog.Username = user.Username; daoperationlog.Usertype = "1";//系统自动上传 写成医院客户 daoperationlog.Optype = "订单已发送"; daoperationlog.Createdate = DateTime.Now; daoperationlog.Opcontent = "发送订单,订单号:" + outspec.Requestcode; daoperationlog.Requestcode = outspec.Requestcode; //达安条码 daoperationlog.Hospsampleid = outspec.Hospsampleid; //医院条码 daoperationlog.Hospsamplenumber = outspec.Hospsamplenumber; //医院样本号 if (new DAOperationlogBLL().SaveDAOperationlog(daoperationlog) == true) { Hashtable htstatus = new Hashtable(); htstatus.Add("Outspecimenid", outspec.Outspecimenid.ToString()); htstatus.Add("status", "2");//已发送 修改状态 new DAOutSpecimenBLL().UpdateStatus(htstatus); } //记录成功的达安条码号 SetTB(string.Format("达安条码[{0}]:发送成功", outspec.Requestcode)); } else { SetTB(string.Format("达安条码[{0}]:{1}", outspec.Requestcode, msg)); //记录失败的异常信息到日志表中 DAErrorlog error = new DAErrorlog(); error.Dictuserid = user.Dictuserid; error.Createdate = DateTime.Now; error.LastUpdateDate = DateTime.Now; error.Opcontent = "订单发送异常信息: " + msg; error.Usercode = user.Usercode; error.Usertype = "1"; error.Username = user.Username; error.Ipaddress = commonbll.GetHostIP(); //获取本机IP地址 error.Machinename = commonbll.GetHostName(); //获取本机机器名 new DAErrorLogBLL().SaveErrorLog(error); } #endregion } } catch (Exception e) { SetTB(string.Format("达安条码[{0}]:{1}", barcode, e.Message)); } } } catch (Exception e) { SetTB("发送订单出现异常:" + e.Message); } }
/// <summary> /// 发送订单信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSend_Click(object sender, EventArgs e) { try { #region >>>> zhouy 数据检查 //当前GridView是否存在数据 if (dgvReport.Rows.Count == 0) { ShowMessageHelper.ShowBoxMsg("没有选择要发送的订单!"); return; } //选择要发送的订单条数 List <DAOutspecimen> SelectList = (bgSource.DataSource as BindingCollection <DAOutspecimen>).ToList <DAOutspecimen>().FindAll(c => c.IsSelect); if (SelectList.Count == 0) { ShowMessageHelper.ShowBoxMsg("没有选择要发送的订单!"); return; } if (SystemConfig.Config == null) { ShowMessageHelper.ShowBoxMsg("获取系统配置失败,请重新登陆!"); return; } #endregion string strM = ""; //成功条码号 string errorMessage = ""; //错误信息 int num = 0; //记录符合发送状态的条码条数 string bacode = ""; //登录失败需要倒回上次一循环,不使用foreach for (int m = 0; m < SelectList.Count; m++) { DAOutspecimen _outs = SelectList[m]; //记录发送失败或不能发送的条码信息 if (_outs.Status != "0" && _outs.Status != "2") { bacode += _outs.Requestcode + ","; continue; } #region >>>> zhouy 发送订单 num++; Hashtable ht = new Hashtable(); ht.Add("Requestcode", _outs.Requestcode); DataTable dt = new DAOutSpecimenBLL().GetOutspecimenTable(ht); //基本信息 dt.TableName = "data_row"; /* 发送模式:1 组合发送, 0 单项发送 * 组合发送: 发送订单表OutSpecimen的数据 * (DATESTCODES AS NaturalItem,CUSTOMERTESTNAMES AS NaturalItemDesc,CUSTOMERTESTCODES AS HospItemCode) * * 单项发送: 发送结果表da_result中的明细数据,获取Customertestcode,customertestname, * 并根据Customertestcode获取对照表的datestcode */ #region >>>> zhouy 发送项目拼装 string cuscode = "", cusname = "", daancode = ""; DataTable dtTest; if (SystemConfig.Config.Model == "1") { dtTest = new DAOutSpecimentestBLL().SelectSendGruopCodeByRequestCode(_outs.Requestcode); //组合 } else { dtTest = new DAResultBLL().SelectSendTestCodeByRequestCode(_outs.Requestcode); //明细 } foreach (DataRow dr in dtTest.Rows) { //没有达安代码,则对照表没有对应 if (dr["datestcode"] == null || dr["datestcode"].ToString() == "") { errorMessage += string.Format("达安条码[{0}]中的医院项目[{1}({2})]未对应好数据,请到项目对照表中对应好\n" , _outs.Requestcode, dr["customertestname"], dr["Customertestcode"]); } cuscode += dr["Customertestcode"] + ","; cusname += dr["customertestname"] + ","; daancode += dr["datestcode"] + ","; } dt.Rows[0]["HospItemCode"] = cuscode.TrimEnd(','); //医院项目代码 dt.Rows[0]["NaturalItemDesc"] = cusname.TrimEnd(','); //医院项目名称 if (daancode.TrimEnd(',') == "") //判断达安项目是否为空,也就是是否有对照 { ShowMessageHelper.ShowBoxMsg("医院项目代码:" + cuscode.TrimEnd(',') + "没有和达安项目对照!"); return; } dt.Rows[0]["NaturalItem"] = daancode.TrimEnd(',');//达安代码 #endregion // string str = StringToXML("<NewDataSet><data_row><Outspecimenid>31</Outspecimenid><RequestCode>440590096900</RequestCode><HospSampleid>1307261704</HospSampleid><HospSamplenumber>1307262509</HospSamplenumber><PatientNumber>01158055</PatientNumber><BedNumber /><SamplingDate>2013-07-26T16:33:07+08:00</SamplingDate><PatientName>王钊</PatientName><Sex>M</Sex><Age>7岁</Age><PatientTel /><SectionOffice>儿童保健科</SectionOffice><Doctor>程双喜</Doctor><DoctorTel /><Diagnostication /><Lmp /><Lmpdate /><BabyCount /><UnineVolumn /><Bodystyle /><Weight /><Height /><Bultrasonic /><Pregnant /><Programid>5</Programid><NaturalItem /><NaturalItemDesc>类胰岛素样生长因子测定</NaturalItemDesc><HospItemCode>09589</HospItemCode><Remark /><operateby>100191</operateby><userName>44170340</userName></data_row></NewDataSet>"); string[] obj = new string[2] { SystemConfig.UserInfo.SID, StringToXML(DataToXml.ConvertDataTableToXML(dt)) }; // StringToXML(DataToXml.ConvertDataTableToXML(dt)) string strQueryResult = WebServiceUtils.ExecuteMethod("SendRequestInfo", obj); //调用webService //ShowMessageHelper.ShowBoxMsg("接口调试:" + strQueryResult); #region >>>> zhouy 处理发送结果 if (strQueryResult.Contains("MSG0006")) //登陆超时 { #region >>>> zhouy 登录超时,重新的登录 string strSideCode = SystemConfig.Config.Sitecode; string strUrl = SystemConfig.Config.Address; //调用webservice地址 string username = SystemConfig.Config.Username == string.Empty ? "无" : SystemConfig.Config.Username; //登录用户名 string password = SystemConfig.Config.Password; //登录用户密码 //设置调用webservice登录方法的参数 string[] par = new string[] { strSideCode, username, password, SystemConfig.UserInfo.UserName }; //返回登录验证信息:1|SID,0|errorMsg string[] loginMsg = WebServiceUtils.ExecuteMethod("Login", par).Split('|'); if (loginMsg[0] == "0") //登录失败 { ShowMessageHelper.ShowBoxMsg("登陆失败!" + loginMsg[1].ToString()); return; } else if (loginMsg[0] == "1") { SystemConfig.UserInfo.SID = loginMsg[1].ToString(); m--;//返回继续发送,不弹出消息 zhouy // ShowMessageHelper.ShowBoxMsg("发送条码[" + _outs.Requestcode + "]超时,请重新发送该条订单!"); } #endregion } else if (strQueryResult.Contains("无法连接")) { ShowMessageHelper.ShowBoxMsg("操作连接超时!" + strQueryResult.ToString()); return; } //else if (strQueryResult.Contains("未上传任何达安代码!")) //{ // ShowMessageHelper.ShowBoxMsg("项目匹配有误:" + _outs.Requestcode +"条码"+ strQueryResult.ToString()); // return; //} else { #region >>>> zhouy 发送成功记录成功日志,发送失败记录错误日志 string[] _messg = strQueryResult.TrimEnd(',').Split('|'); //0 为正常发送了 if (_messg[3] == "0") { DAOperationlog daoperationlog = new DAOperationlog(); daoperationlog.Dictuserid = SystemConfig.UserInfo.UserId == "" ? 0 : Convert.ToDecimal(SystemConfig.UserInfo.UserId); daoperationlog.Usercode = SystemConfig.UserInfo.UserCode; daoperationlog.Username = SystemConfig.UserInfo.UserName; daoperationlog.Usertype = SystemConfig.UserInfo.UserType.ToString(); daoperationlog.Optype = "订单已发送"; daoperationlog.Createdate = DateTime.Now; daoperationlog.Opcontent = "发送订单,订单号:" + _messg[0]; daoperationlog.Requestcode = _messg[0]; //达安条码 daoperationlog.Hospsampleid = _messg[1]; //医院条码 daoperationlog.Hospsamplenumber = _messg[2]; //医院样本号 if (new DAOperationlogBLL().SaveDAOperationlog(daoperationlog) == true) { Hashtable htstatus = new Hashtable(); htstatus.Add("Outspecimenid", _outs.Outspecimenid.ToString()); htstatus.Add("status", "2");//已发送 修改状态 new DAOutSpecimenBLL().UpdateStatus(htstatus); } strM += _messg[0] + ","; //记录成功的达安条码号 } else { errorMessage += string.Format("达安条码[{0}]:{1}\n", _messg[0], _messg[3]); //记录失败的异常信息到日志表中 DAErrorlog error = new DAErrorlog(); error.Dictuserid = Convert.ToDecimal(SystemConfig.UserInfo.UserId); error.Createdate = DateTime.Now; error.LastUpdateDate = DateTime.Now; error.Opcontent = "订单发送异常信息: " + _messg[0]; error.Usercode = SystemConfig.UserInfo.UserCode; error.Usertype = SystemConfig.UserInfo.UserType.ToString(); error.Username = SystemConfig.UserInfo.UserName; error.Ipaddress = common.GetHostIP(); //获取本机IP地址 error.Machinename = common.GetHostName(); //获取本机机器名 new DAErrorLogBLL().SaveErrorLog(error); } #endregion } #endregion #endregion } if (num == 0) //记录符合发送状态的条码条数 { ShowMessageHelper.ShowBoxMsg(string.Format("达安条码[{0}]状态为报告已出或部分结果的条码不能发送!", bacode.TrimEnd(','))); return; } if (bacode.ToString() != "") //记录不能发送的条码号 { ShowMessageHelper.ShowBoxMsg(string.Format("达安条码[{0}]状态为报告已出或部分结果的条码不能发送!", bacode.TrimEnd(','))); } if (errorMessage != "") //错误信息反馈 { ShowMessageHelper.ShowBoxMsg(errorMessage); } if (strM != "") { ShowMessageHelper.ShowBoxMsg(string.Format("达安条码[{0}] 发送成功!", strM.TrimEnd(','))); HeaderCheckBox.Checked = false; DataBind(); } } catch (Exception ex) { ShowMessageHelper.ShowBoxMsg(ex.Message); } }