Esempio n. 1
0
        /// <summary>
        /// 解析Json
        /// </summary>
        /// <param name="json"></param>
        private string readJsonString(JArray json, ref List <Hashtable> list, ref List <Hashtable> listapp)
        {
            string errstr = string.Empty;

            foreach (var item in json)
            {
                string barcode = item["BARCODE"].ToString();
                if (string.IsNullOrEmpty(barcode))
                {
                    errstr += "条码号为空;";
                }
                string testcode = item["TESTCODE"].ToString();
                if (string.IsNullOrEmpty(testcode))
                {
                    errstr += "全国统一码为空;";
                }
                string exctype = item["EXCEPTIONTYPE"].ToString();
                if (string.IsNullOrEmpty(exctype))
                {
                    errstr += "异常报告类型为空;";
                }
                else
                {
                    if (exctype != "2" && exctype != "1")
                    {
                        errstr += "异常报告类型错误;";
                    }
                }
                string reason = item["EXCEPTIONREASON"].ToString();
                if (string.IsNullOrEmpty(reason))
                {
                    errstr += "原因为空;";
                }
                string expdate = item["EXPREPORTDATE"].ToString();
                if (!string.IsNullOrEmpty(expdate))
                {
                    DateTime expreportdate;
                    bool     f = DateTime.TryParse(expdate, out expreportdate);
                    if (!f)
                    {
                        errstr += "预计发单日期格式错误;";
                    }
                    else
                    {
                        expdate = expreportdate.ToString("yyyy-mm-dd");
                    }
                }
                DateTime createdate;
                bool     dateb = DateTime.TryParse(item["CREATEDATE"].ToString(), out createdate);
                if (!dateb)
                {
                    errstr += "生成异常信息时间格式错误;";
                }
                if (string.IsNullOrEmpty(errstr))
                {
                    try
                    {
                        Hashtable ht = new Hashtable();
                        ht.Add("BARCODE", barcode);
                        ht.Add("TESTCODE", testcode);
                        ht.Add("EXCEPTIONTYPE", exctype);
                        ht.Add("EXCEPTIONREASON", reason);
                        ht.Add("EXPREPORTDATE", expdate);
                        ht.Add("STATUS", item["STATUS"].ToString() == "" ? "0" : item["STATUS"].ToString());
                        ht.Add("CREATEDATE", createdate);
                        list.Add(ht);
                        if (!string.IsNullOrEmpty(barcode))
                        {
                            //判断条码是否来自大众健康系统
                            DataTable dtBarcode = barcodeservice.CheckBarCode2(barcode);
                            if (dtBarcode != null && dtBarcode.Rows.Count > 0)
                            {
                                if (dtBarcode.Rows[0]["enterby"].ToString().Contains("大众平台"))
                                {
                                    Hashtable htapp = new Hashtable();
                                    htapp.Add("BARCODE", barcode);
                                    htapp.Add("CREATEDATE", createdate);
                                    htapp.Add("EXPREPORTDATE", expdate);
                                    htapp.Add("EXCEPTIONREASON", reason);
                                    string status = item["STATUS"].ToString() == "" ? "0" : item["STATUS"].ToString();
                                    string text   = string.Empty;
                                    if (expdate == "1")
                                    {
                                        if (status == "0")
                                        {
                                            text = "正常迟发";
                                        }
                                        else
                                        {
                                            text = "取消迟发";
                                        }
                                    }
                                    else if (expdate == "2")
                                    {
                                        text = "退单";
                                    }
                                    htapp.Add("STATUS", text);
                                    listapp.Add(htapp);
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        errstr = e.Message;
                    }
                }
            }
            return(errstr);
        }
Esempio n. 2
0
        /// <summary>上传体检订单
        ///
        /// </summary>
        /// <param name="xmlStr"></param>
        /// <returns></returns>
        public static string UploadOrderInfo(string xmlStr)
        {
            xmlStr = xmlStr.TrimStart('');
            string    str        = "<?xml version='1.0' encoding='utf-8'?>" + StringToXML(xmlStr);
            string    strMessage = string.Empty;
            DataTable dt         = new DataTable();

            try
            {
                dt = GetDataTable(str);
            }
            catch (Exception ex)
            {
                return(String.Format("{0} {1}", ErrorCode.Up_0001, ex.Message));
            }
            if (dt == null || dt.Rows.Count == 0 || dt.Columns.Count != 20)
            {
                return(ErrorCode.Up_0002);
            }
            List <Dicttestitem>      TestItemList  = loginservice.GetLoginDicttestitemList();  //项目字典表
            List <Dictproductdetail> ProductDetail = loginservice.GetLoginDictproductdetail(); //套餐组合字典
            string _productname = string.Empty;

            foreach (DataRow dr in dt.Rows)
            {
                #region 必填项
                //套餐代码
                string productTestCode = dr["uniquecode"].ToString().Replace('_', ' ').Trim();
                //客户代码
                string dictcustomerid = dr["dictcustomerid"].ToString().Trim();
                //姓名
                string realname = dr["realname"].ToString().Trim();
                //性别
                string sex = dr["sex"].ToString().Replace('_', ' ').Trim() == "女" ? "F" : (dr["sex"].ToString().Replace('_', ' ').Trim() == "男" ? "M" : "U");
                //婚否
                string ismarried = dr["ismarried"].ToString().Trim();
                //手机
                string mobile = dr["mobile"].ToString().Trim();
                //住址
                string address = dr["address"].ToString().Trim();
                //省
                string province = dr["province"].ToString().Trim();
                //市
                string city = dr["city"].ToString().Trim();
                //分点实验室
                string dictlabid = dr["dictlabid"].ToString().Trim();
                //条码号
                string barcode = dr["barcode"].ToString().Trim();
                if (string.IsNullOrEmpty(productTestCode) || string.IsNullOrEmpty(dictcustomerid) || string.IsNullOrEmpty(dictlabid) || string.IsNullOrEmpty(barcode) ||
                    string.IsNullOrEmpty(realname) || string.IsNullOrEmpty(sex) || string.IsNullOrEmpty(ismarried) ||
                    string.IsNullOrEmpty(mobile) || string.IsNullOrEmpty(address) || string.IsNullOrEmpty(province) || string.IsNullOrEmpty(city))
                {
                    strMessage = ErrorCode.Up_0003;
                    break;
                }
                #endregion
                #region 二者不可都为空
                //出生日期
                string birthday = dr["birthday"].ToString().Trim();
                //年龄
                string age = dr["age"].ToString().Trim();
                if (string.IsNullOrEmpty(birthday) && string.IsNullOrEmpty(age))
                {
                    strMessage = ErrorCode.Up_0004;
                    break;
                }
                #endregion
                #region 可空字段
                //身份证
                string idnumber = dr["idnumber"].ToString().Trim();
                //部门
                string section = dr["section"].ToString().Trim();
                //备注
                string remark = dr["remark"].ToString().Trim();
                //电话
                string phone = dr["phone"].ToString().Trim();
                //邮箱
                string email = dr["email"].ToString().Trim();
                //采样日期
                string samplingdate = dr["samplingdate"].ToString().Trim();
                //区
                string county = dr["county"].ToString().Trim();
                #endregion
                DateTime datebirthday;
                bool     datebirthdayb = DateTime.TryParse(birthday, out datebirthday);
                DateTime datesamplingdate;
                bool     datesamplingdateb = DateTime.TryParse(samplingdate, out datesamplingdate);
                if ((birthday != string.Empty && !datebirthdayb) || (samplingdate != string.Empty && !datesamplingdateb))
                {
                    strMessage = ErrorCode.Up_0010;
                    break;
                }
                //检查单位是否在体检系统中有维护
                try
                {
                    using (DataTable d = customerservice.CheckHasCustomer(dictcustomerid))
                    {
                        if (d == null || d.Rows.Count == 0 || d.Rows.Count > 1)
                        {
                            strMessage = ErrorCode.Up_0011;
                            break;
                        }
                    }
                }
                catch (Exception ee)
                {
                    strMessage = ErrorCode.Up_0015 + " " + ee.Message;
                    break;
                }
                #region 添加套餐
                //查询分点+公用套餐
                List <Dicttestitem> productlistTemp = new DicttestitemService().GetProduct(TypeParse.StrToDouble(dictcustomerid, 0));
                List <Dicttestitem> productList     = productlistTemp.Where <Dicttestitem>(c => c.Testcode == productTestCode && (c.Forsex == sex || c.Forsex == "B")).ToList <Dicttestitem>();
                List <Dicttestitem> grouptestList   = new List <Dicttestitem>();
                Dicttestitem        productinfo     = null;
                if (productList.Count == 0)
                {
                    strMessage = ErrorCode.Up_0005;
                    break;
                }
                else if (productList.Count > 1)
                {
                    strMessage = ErrorCode.Up_0006;
                    break;
                }
                else
                {
                    productinfo = productList.First <Dicttestitem>();
                    List <OrderRegister> _gridtestList = null;
                    #region 添加套餐
                    string msg = registerservice.AddProduct(ref _gridtestList, sex, productinfo.Dicttestitemid, false, null, ref _productname, null);
                    if (msg != string.Empty)
                    {
                        strMessage = ErrorCode.Up_0014;
                        break;
                    }
                    #endregion
                    if (barcode != string.Empty && barcode.Length != 12)//条码号必须为12位数字
                    {
                        strMessage = ErrorCode.Up_0007;
                        break;
                    }
                    if (barcode != string.Empty && barcode.Substring(barcode.Length - 2) != "00")//条码号必须以00结尾
                    {
                        strMessage = ErrorCode.Up_0008;
                        break;
                    }
                    //检验条码号是否合格且存在于体检系统
                    DataTable dtBarcode = barcodeservice.CheckBarCode2(barcode);
                    if (dtBarcode != null && dtBarcode.Rows.Count > 0)
                    {
                        //判断已存在的条码是否来自大众平台
                        if (!dtBarcode.Rows[0]["enterby"].ToString().Contains("大众平台"))
                        {
                            //条码已存在且不是通过大众平台上传
                            strMessage = ErrorCode.Up_0009;
                            break;
                        }
                        else
                        {
                            //判断该条码是否已经上传到康源系统,否则不允许修改;
                            if (dtBarcode.Rows[0]["transed"].ToString() == "1")
                            {
                                strMessage = ErrorCode.Update_0005;
                                break;
                            }
                            //删除该体检系统中订单
                            string    ordernum = dtBarcode.Rows[0]["ordernum"].ToString();
                            Hashtable ht       = new Hashtable();
                            ht["ordernum"] = ordernum;
                            new ProCentralizedManagementService().DeleteOrders(ht);
                        }
                    }

                    //套餐下组合项目
                    IEnumerable <Dictproductdetail> IEgroup = ProductDetail.Where <Dictproductdetail>(c => c.Productid == productinfo.Dicttestitemid);
                    bool iscontinue = true;
                    int  count      = IEgroup.Count <Dictproductdetail>();
                    int  k          = 0;
                    foreach (Dictproductdetail item in IEgroup)
                    {
                        IEnumerable <Dicttestitem> IEgruptest = TestItemList.Where <Dicttestitem>(c => c.Dicttestitemid == item.Testgroupid);
                        if (IEgruptest.Count() <= 0)
                        {
                            //没有找到套餐下组合
                            k++;
                            continue;
                        }
                        Dicttestitem groupinfo = IEgruptest.First <Dicttestitem>();
                        //校验性别是否符合
                        string res = registerservice.checkSex(groupinfo.Dicttestitemid, sex);
                        if (res != string.Empty)
                        {
                            //性别项目不合
                            strMessage = ErrorCode.Up_0012;
                            iscontinue = false;
                            break;
                        }

                        groupinfo.Productid   = productinfo.Dicttestitemid;
                        groupinfo.Productname = productinfo.Testname; ///套餐名
                        groupinfo.IsActive    = "1";                  //是否停止测试
                        groupinfo.Isadd       = "0";                  ///是否追加
                        groupinfo.Billed      = "0";
                        groupinfo.Sendbilled  = "0";
                        groupinfo.Adduserid   = null;//追加人ID

                        if (barcode == string.Empty)
                        {
                            IEnumerable <Dicttestitem> IEtempbarcodeList = grouptestList.Where <Dicttestitem>(c => c.Tubegroup == groupinfo.Tubegroup);
                            if (IEtempbarcodeList.Count() > 0)
                            {
                                groupinfo.Barcode = IEtempbarcodeList.First <Dicttestitem>().Barcode;
                            }
                            else
                            {
                                groupinfo.Barcode = registerservice.GetBarCode();
                            }
                        }
                        else
                        {
                            groupinfo.Barcode = barcode;
                        }

                        //获取外包客户
                        Dictproductdetail detail = ProductDetail.Where <Dictproductdetail>(c => c.Productid == productinfo.Dicttestitemid && c.Testgroupid == groupinfo.Dicttestitemid).First <Dictproductdetail>();
                        groupinfo.Sendoutcustomerid = detail.Sendoutcustomerid;

                        grouptestList.Add(groupinfo);
                    }
                    if (!iscontinue)
                    {
                        continue;
                    }
                    else
                    {
                        if (k >= count)
                        {
                            strMessage = ErrorCode.Up_0013;
                            break;
                        }
                    }
                }
                #endregion

                #region 添加会员信息
                Dictmember member = new Dictmember()
                {
                    Realname = realname, Idnumber = idnumber
                };

                registerservice.checkmember(null, ref member);
                if (datebirthdayb)
                {
                    member.Birthday = datebirthday;
                }
                member.Nickname = member.Realname;
                member.Sex      = sex;
                member.Addres   = address;
                member.Phone    = phone;
                member.Mobile   = mobile;
                member.Email    = email;
                #endregion

                #region 添加订单
                double year = 0, month = 0, day = 0;
                double hours  = 0;
                double aged   = 0;
                string agestr = age;
                bool   ageb   = double.TryParse(agestr, out aged);

                if (member.Birthday == null)
                {
                    if (agestr != string.Empty && ageb)
                    {
                        year            = aged;
                        day             = aged * 365;
                        member.Birthday = datebirthday = DateTime.Now.AddDays((0 - day));
                    }
                    else
                    {
                        strMessage = ErrorCode.Up_0004;
                        break;
                    }
                }
                TimeSpan ts = DateTime.Now - Convert.ToDateTime(member.Birthday);//时间差
                year  = Math.Truncate((double)(ts.Days / 365));
                month = (ts.Days % 365) / 30;
                day   = (ts.Days % 365) % 30;
                hours = ts.TotalHours;

                Orders _orders = new Orders()
                {
                    Ordernum       = new ProRegisterService().GetOrderNum(),
                    Dictmemberid   = member.Dictmemberid,
                    Dictcustomerid = Convert.ToDouble(dictcustomerid),
                    Realname       = realname,
                    Sex            = sex,
                    Caculatedage   = hours,
                    Remarks        = remark,
                    Age            = string.Format("{0}岁{1}月{2}日{3}时", year, month, day, 0),
                    Enterby        = enterby,
                    Ordertestlst   = _productname + ",",
                    Dictlabid      = Convert.ToDouble(dictlabid),
                    Ordersource    = "1",
                    Ismarried      = ismarried == "未婚" ? "0" : (ismarried == "已婚" ? "1" : "2"),
                    Section        = section,
                    Status         = ((int)daan.service.common.ParamStatus.OrdersStatus.BarCodePrint).ToString(),
                    Province       = province,
                    City           = city,
                    County         = county
                };
                if (datesamplingdateb)
                {
                    _orders.SamplingDate = datesamplingdate;
                }
                string errstr = string.Empty;
                System.Collections.Hashtable htScan = new System.Collections.Hashtable();
                htScan.Add("isScan", true);
                htScan.Add("EnterByID", enterbyID);
                htScan.Add("EnterBy", enterby);
                bool b = registerservice.insertUpdateOrders("大众健康平台对接订单", "", true, productList, grouptestList, member, _orders, "", ref errstr, htScan);
                if (!b)
                {
                    strMessage = String.Format("{0} {1}", ErrorCode.Up_0015, errstr);
                    break;
                }
                #endregion
            }

            return(strMessage);
        }