public List <Model.QueryRecoder> CheckQueryRecord(Model.QueryRecoder model) { BLL.QueryRecoder qr = new BLL.QueryRecoder(); QueryRecoder queryRecoder = new QueryRecoder(); //查询本地数据库有没有数据 StringBuilder strWhere = new StringBuilder(); if (!string.IsNullOrEmpty(model.Uname)) { strWhere.AppendFormat("Uname = {0} and ", "'" + model.Uname + "'"); } if (!string.IsNullOrEmpty(model.Code)) { strWhere.AppendFormat("Code = {0} and ", "'" + model.Code + "'"); } if (!string.IsNullOrEmpty(model.CodeType)) { strWhere.AppendFormat("CodeType = {0} and ", "'" + model.CodeType + "'"); } if (!string.IsNullOrEmpty(model.QueryType)) { strWhere.AppendFormat("QueryType = {0} and ", "'" + model.QueryType + "'"); } if (!model.IsDel) { strWhere.AppendFormat("IsDel = {0}", "'" + model.IsDel + "'"); } //查询条件是,当前用户添加的卡号为X的卡号类型为Y的没有标记删除的并且临床数据类型为Z的数据 return(qr.GetModelList(strWhere.ToString())); }
/// <summary> /// 查询完WebService之后更新记录表 /// </summary> /// <param name="cq">记录表对象</param> /// <param name="msg">查询之后的消息</param> private void ChangeQueryRecordStatu(BLL.Request.Request cq, string msg) { Model.QueryRecoder queryRecoder = cq.QueryRecoderModel; int queryDateInterval = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["QueryDateInterval"].Trim()); if (queryRecoder != null) { try { if ((DateTime.Now - queryRecoder.AddDate).Days > queryDateInterval) { //超时数据 queryRecoder.LastQueryDate = DateTime.Now; queryRecoder.IsDel = true; } else { //不超时数据 queryRecoder.LastQueryDate = DateTime.Now; } queryRecoder.QueryResult = (" " + DateTime.Now.ToLocalTime() + " " + msg + queryRecoder.QueryResult); QueryRecoder q = new QueryRecoder(); q.Update(queryRecoder); } catch (Exception ex) { Common.LogHelper.WriteError(ex); } } }
private void QueryData(HttpContext context, bool p) { if (p) { } else { //查询数据 //string Mzzybz = context.Request["Mzzybz"];//0 门诊 1住院 string code = context.Request.Params["code"];//住院号或门诊号 string codeType = context.Request.Params["codeType"]; string dateNow = context.Request.Params["dateNow"]; Model.QueryRecoder qqq = new Model.QueryRecoder(); qqq.Code = code; qqq.CodeType = codeType; qqq.QueryType = "NormalLisReport"; qqq.Uname = Common.CookieHelper.GetCookieValue("username"); qqq.AddDate = DateTime.Parse(dateNow); qqq.IsDel = false; BLL.Request.Request request = new BLL.Request.NormalLisReportRequest(qqq); BLL.NormalLisReport NData = new BLL.NormalLisReport(); string result = NData.GetData(qqq, true); context.Response.Write(result); } }
/// <summary> /// 字典转化为model /// </summary> /// <returns></returns> public Model.QueryRecoder DicToQueryRecoderModel(Dictionary <string, string> dic) { string str = JsonConvert.SerializeObject(dic); Model.QueryRecoder queryRecoder = JsonConvert.DeserializeObject <Model.QueryRecoder>(str); return(queryRecoder); }
//private Model.DTO.NormalLisItemsRequest request; public List <Model.NormalLisItems> GetData(Model.QueryRecoder model, bool queryBycode) { BLL.Request.NormalLisItemsRequest normalLisItemsRequest = new Request.NormalLisItemsRequest(model); normalLisItemsRequest.CreatRequest(queryBycode); Model.QueryRecoder queryRecoderModel = normalLisItemsRequest.QueryRecoderModel; this.RequestList = normalLisItemsRequest.RequestStr;//临时变量 List <Model.NormalLisItems> normalLisItems = new List <Model.NormalLisItems>(); // 保存记录(查询记录数据,更新或添加) string.IsNullOrEmpty(cq.RequestStr)存在值 修改修!string.IsNullOrEmpty(cq.RequestStr) kaka if (normalLisItemsRequest.RequestStr != null && normalLisItemsRequest.RequestStr.Count > 0) { // 调用接口获取数据 // 正常这里只会传入一个连接字符串 foreach (var item in normalLisItemsRequest.RequestStr) { string xmlStr = GetWebServiceData(item); string Msg = ""; List <Model.NormalLisItems> tem = new List <Model.NormalLisItems>(); // 将xml数据转换成list集合会查询本地数据库去除重复项 tem = this.GetList(xmlStr, out Msg); if (string.IsNullOrEmpty(Msg)) { normalLisItems.AddRange(tem); } } } return(normalLisItems); }
public override void CreatRequest(bool quertByCode) { //此方法this.RequestStr 赋值 //01.按照code查询数据 if (quertByCode) { //检查数据是否有记录 //根据code、username、type、isdel 查询数据记录 Model.QueryRecoder newModel = this.QueryRecoderModel; BLL.QueryRecoder queryRecoder = new QueryRecoder(); List <Model.QueryRecoder> list = queryRecoder.CheckQueryRecord(newModel); if (list != null && list.Count > 0) { //本地数据库有数据 Model.QueryRecoder oldModel = list.OrderByDescending(a => a.LastQueryDate).FirstOrDefault(); //对比数据库数据,并更新数据库数据 this.QueryRecoderModel = ContrastQueryRecoderModel(newModel, oldModel); } else { //本地数据库无数据 this.QueryRecoderModel = ContrastQueryRecoderModel(newModel, null); } } //02.datagrid 提交过来的数据 else { //数据肯定有记录 Model.QueryRecoder oldModel = this.QueryRecoderModel; this.QueryRecoderModel = ContrastQueryRecoderModel(null, oldModel); //更新数据库的记录--更新X内容 } }
private Model.QueryRecoder CreatQueryRecoderModel() { Model.QueryRecoder model = new Model.QueryRecoder(); model.Code = this.Code; model.CodeType = this.CodeType; model.QueryType = "NormalLisItems"; model.Uname = Common.CookieHelper.GetCookieValue("username"); model.IsDel = false; return(model); }
/// <summary> /// 上传数据 /// </summary> /// <param name="code">条码</param> /// <param name="codeType">条码的类型:0 卡号,1 住院号</param> /// <param name="dataStr">传入数据</param> /// <returns></returns> public string PostData(string dataStr, string username) { List <Dictionary <string, string> > dicList = GetClinicalInfoDgDicList(dataStr); string mes = ""; //读取code和codeType if (dicList != null && dicList.Count > 0) { for (int i = 0; i < dicList.Count; i++) { Model.QueryRecoder model = new Model.QueryRecoder(); model = DicToQueryRecoderModel(dicList[i]);//转化为MODEL //获取值 string code = dicList[i]["Code"]; string codeType = dicList[i]["CodeType"]; //string date = dicList[i]["LastQueryDate"]; //判断传入类型 if (model.QueryType == "NormalLisReport") { // BLL.Request.NormalLisReportRequest nrr = new Request.NormalLisReportRequest(model); BLL.NormalLisReport nr = new NormalLisReport(); //nrr.CreatRequest(false); string result = nr.GetData(model, false); Model.DTO.JsonModel jsonModel_N = JsonConvert.DeserializeObject <Model.DTO.JsonModel>(result); if (jsonModel_N.Statu == "ok") { string strdata = JsonConvert.SerializeObject(jsonModel_N.Data); mes = mes + nr.PostData(code, codeType, strdata, username, true);//导入到临床检验数据 } else { mes = mes + "," + jsonModel_N.Msg; } } else if (model.QueryType == "PatientDiagnose") { BLL.Request.PatientDiagnoseResuest nrr = new Request.PatientDiagnoseResuest(model); BLL.PatientDiagnose nr = new PatientDiagnose(); nrr.CreatRequest(false); string result = nr.GetData(model, false); Model.DTO.JsonModel jsonModel_N = JsonConvert.DeserializeObject <Model.DTO.JsonModel>(result); if (jsonModel_N.Statu == "ok") { string strdata = JsonConvert.SerializeObject(jsonModel_N.Data); mes = mes + nr.PostData(strdata, code, codeType, username, true);//导入到患者信息 } else { mes = mes + "," + jsonModel_N.Msg; } } } } return(mes); }
/// <summary> /// 检查数据是否存在,会检测添加日期 true存在 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool CheckRecord(Model.QueryRecoder model) { BLL.QueryRecoder qr = new BLL.QueryRecoder(); QueryRecoder queryRecoder = new QueryRecoder(); //查询本地数据库有没有数据 StringBuilder strWhere = new StringBuilder(); if (!string.IsNullOrEmpty(model.Uname)) { strWhere.AppendFormat("Uname = {0} and ", "'" + model.Uname + "'"); } if (!string.IsNullOrEmpty(model.Code)) { strWhere.AppendFormat("Code = {0} and ", "'" + model.Code + "'"); } if (!string.IsNullOrEmpty(model.CodeType)) { strWhere.AppendFormat("CodeType = {0} and ", "'" + model.CodeType + "'"); } if (!string.IsNullOrEmpty(model.QueryType)) { strWhere.AppendFormat("QueryType = {0} and ", "'" + model.QueryType + "'"); } if (!model.IsDel) { strWhere.AppendFormat("IsDel = {0} and ", "'" + model.IsDel + "'"); } DateTime date = new DateTime(); if (DateTime.TryParse(model.AddDate.ToString("yyyy-MM-dd"), out date)) { // select * from dbo.QueryRecoder where REPLACE(CONVERT(Char(10),AddDate,111),'/','-')='2015-08-06' strWhere.AppendFormat("REPLACE(CONVERT(Char(10),AddDate,111),'/','-')={0}", "'" + model.AddDate.ToString("yyyy-MM-dd") + "'"); //strWhere.AppendFormat("AddDate = {0}", "'" + model.AddDate + "'"); } //查询条件是,当前用户添加的卡号为X的卡号类型为Y的没有标记删除的并且临床数据类型为Z的数据 List <Model.QueryRecoder> list = new List <Model.QueryRecoder>(); list = qr.GetModelList(strWhere.ToString()); if (list != null && list.Count > 0) { return(true); } else { return(false); } }
//private bool SaveQueryRecord(ref Model.DTO.NormalLisItemsRequest resquet, string Msg, string codeType) //{ // bool result = false; // QueryRecoder queryRecoder = new QueryRecoder(); // //根据传入的查询字符串创建的当此查询的记录model // Model.QueryRecoder model = new Model.QueryRecoder(); // //model.AddDate = DateTime.Now; // model.Code = request.hospnum; // model.CodeType = codeType; // model.QueryType = "NormalLisItems"; // model.Uname = Common.CookieHelper.GetCookieValue("username"); // model.IsDel = false; // List<Model.QueryRecoder> list = CheckQueryRecord(model); // if (list != null && list.Count > 0) // { // //判断查询出来的数据是否满足要求(时间差距lastdate<dateNow-5) // Model.QueryRecoder oldModel = list.OrderByDescending(a => a.LastQueryDate).FirstOrDefault(); // model.AddDate = oldModel.AddDate; // model.Id = oldModel.Id; // DateTime dtAdd = Convert.ToDateTime(oldModel.AddDate); // DateTime dtLastQuery = Convert.ToDateTime(oldModel.LastQueryDate); // DateTime dt = DateTime.Now;//当前时间 // int days = (dt - dtAdd).Days;//获取当前日期与添加日期时间差 // int getDays = 0; // if (days > getDays) // { // model.IsDel = true; // model.LastQueryDate = dtAdd.AddDays(5); // } // else // { // int chaday = (dtLastQuery - dtAdd).Days;//获取最后查询日期与添加日期时间差 // int nowday = (dt - dtLastQuery).Days;//当前时间与最后查询时间差 // int addnowDay = (dt - dtAdd).Days;//当前时间与添加时间差 // if (nowday == 0) // { // //resquet.jsrq00 = ""; // //resquet.ksrq00 = ""; // result = true; // model.IsDel = false; // model.QueryResult += " " + DateTime.Now.ToLocalTime() + " " + Msg + oldModel.QueryResult; // } // if (nowday > 0)//当前时间与最后查询时间差大于0 // { // if (addnowDay == 0) // { // result = true; // model.IsDel = false; // model.QueryResult += " " + DateTime.Now.ToLocalTime() + " " + Msg + oldModel.QueryResult; // } // if (chaday >= getDays) // { // model.IsDel = true; // } // else // { // resquet.ksrq00 = dtLastQuery.ToString("yyyy-MM-dd"); // resquet.jsrq00 = dtLastQuery.AddDays(1).ToString("yyyy-MM-dd"); // result = true; // //添加日期是距离添加日期是5天内的 // model.IsDel = false; // model.QueryResult += " " + DateTime.Now.ToLocalTime() + " " + Msg + oldModel.QueryResult; // } // } // } // //本地数据库有数据 // result = queryRecoder.Update(model); // } // else // { // model.QueryResult += " " + DateTime.Now.ToLocalTime() + " " + Msg.Trim(); // model.AddDate = DateTime.Now; // model.LastQueryDate = DateTime.Now; // bool bo = queryRecoder.Add(model) > 0; // model.QueryType = "PatientDiagnose"; // bool boo = queryRecoder.Add(model) > 0; // if (bo && boo) // { // result = true; // } // else { result = false; } // } // return result; //} private List <Model.QueryRecoder> CheckQueryRecord(Model.QueryRecoder model) { QueryRecoder queryRecoder = new QueryRecoder(); //查询本地数据库有没有数据 StringBuilder strWhere = new StringBuilder(); strWhere.AppendFormat("Uname = {0} and ", "'" + model.Uname + "'"); strWhere.AppendFormat("Code = {0} and ", "'" + model.Code + "'"); strWhere.AppendFormat("CodeType = {0} and ", "'" + model.CodeType + "'"); strWhere.AppendFormat("IsDel = {0} and ", "'" + model.IsDel + "'"); strWhere.AppendFormat("QueryType = {0} and ", "'" + model.QueryType + "'"); strWhere.AppendFormat("IsDel = {0}", "'" + false + "'"); //查询条件是,当前用户添加的卡号为X的卡号类型为Y的没有标记删除的并且临床数据类型为Z的数据 return(queryRecoder.GetModelList(strWhere.ToString())); }
protected void Button1_Click(object sender, EventArgs e) { RuRo.Model.QueryRecoder model = new Model.QueryRecoder(); DateTime dt = new DateTime(); for (int i = 0; i < 100; i++) { model.Uname = "kaka" + i.ToString(); dt = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")); model.AddDate = dt.AddDays(i); model.LastQueryDate = dt.AddDays(i); model.Code = "code" + i.ToString(); model.CodeType = "CodeType" + i.ToString(); model.QueryType = "QueryType" + i.ToString(); model.QueryResult = "QueryResult" + i.ToString(); model.IsDel = true; RuRo.BLL.QueryRecoder bll = new BLL.QueryRecoder(); bll.Add(model); } }
private void QueryData(HttpContext context, bool p) { if (p) { } else { //查询数据 //string Mzzybz = context.Request["Mzzybz"];//0 门诊 1住院 string code = context.Request.Params["code"];//住院号或门诊号 string codeType = context.Request.Params["codeType"]; string dateNow = context.Request.Params["dateNow"]; Model.QueryRecoder qqq = new Model.QueryRecoder(); qqq.Code = code; qqq.CodeType = codeType; qqq.QueryType = "PatientDiagnose"; qqq.Uname = Common.CookieHelper.GetCookieValue("username"); qqq.AddDate = DateTime.Parse(dateNow); qqq.IsDel = false; BLL.Request.PatientDiagnoseResuest nnnnn = new BLL.Request.PatientDiagnoseResuest(qqq); BLL.PatientDiagnose NData = new BLL.PatientDiagnose(); string result = NData.GetData(qqq, true); context.Response.Write(result); //NData.GetData(BLL.Request.Request r); } }
public PatientDiagnoseResuest(Model.QueryRecoder queryRecoder) { this.QueryRecoderModel = queryRecoder; }
/// <summary> /// 上传数据 /// </summary> /// <param name="code">条码</param> /// <param name="codeType">条码的类型:0 卡号,1 住院号</param> /// <param name="dataStr">传入数据</param> /// <returns></returns> public string PostData(string dataStr, string username) { List<Dictionary<string, string>> dicList = GetClinicalInfoDgDicList(dataStr); string mes = ""; //读取code和codeType if (dicList != null && dicList.Count > 0) { for (int i = 0; i < dicList.Count; i++) { Model.QueryRecoder model = new Model.QueryRecoder(); model = DicToQueryRecoderModel(dicList[i]);//转化为MODEL //获取值 string code = dicList[i]["Code"]; string codeType = dicList[i]["CodeType"]; //string date = dicList[i]["LastQueryDate"]; //判断传入类型 if (model.QueryType == "NormalLisReport") { // BLL.Request.NormalLisReportRequest nrr = new Request.NormalLisReportRequest(model); BLL.NormalLisReport nr = new NormalLisReport(); //nrr.CreatRequest(false); string result = nr.GetData(model, false); Model.DTO.JsonModel jsonModel_N = JsonConvert.DeserializeObject<Model.DTO.JsonModel>(result); if (jsonModel_N.Statu == "ok") { string strdata = JsonConvert.SerializeObject(jsonModel_N.Data); mes = mes + nr.PostData(code, codeType, strdata, username, true);//导入到临床检验数据 } else { mes = mes + "," + jsonModel_N.Msg; } } else if (model.QueryType == "PatientDiagnose") { BLL.Request.PatientDiagnoseResuest nrr = new Request.PatientDiagnoseResuest(model); BLL.PatientDiagnose nr = new PatientDiagnose(); nrr.CreatRequest(false); string result = nr.GetData(model, false); Model.DTO.JsonModel jsonModel_N = JsonConvert.DeserializeObject<Model.DTO.JsonModel>(result); if (jsonModel_N.Statu == "ok") { string strdata = JsonConvert.SerializeObject(jsonModel_N.Data); mes = mes + nr.PostData(strdata, code, codeType, username, true);//导入到患者信息 } else { mes = mes + "," + jsonModel_N.Msg; } } } } return mes; }
private List<Model.NormalLisItems> GetNormalLisItemsList(Model.QueryRecoder queryRecoder, bool queryByCode) { BLL.Request.NormalLisItemsRequest normalLisItemsRequest = new Request.NormalLisItemsRequest(queryRecoder); BLL.NormalLisItems normalLisItems = new NormalLisItems(); //将前台页面传入的model和标识传入到NormalLisItems中产生request List<Model.NormalLisItems> list = normalLisItems.GetData(queryRecoder, queryByCode); //查询完毕之后的QueryRecoder 对象 this.queryRecoderModel = normalLisItemsRequest.QueryRecoderModel; this.requestStrList = normalLisItems.RequestList; return list; }
//private Model.DTO.PatientDiagnoseResuest request = new Model.DTO.PatientDiagnoseResuest(); //private Model.QueryRecoder queryRecoderModel = null; //private List<string> requestStrList = null; public string GetData(Model.QueryRecoder model, bool queryBycode) { BLL.Request.PatientDiagnoseResuest cq = new Request.PatientDiagnoseResuest(model); cq.CreatRequest(queryBycode); Model.QueryRecoder queryRecoderModel = cq.QueryRecoderModel; Model.DTO.JsonModel jsonmodel = new Model.DTO.JsonModel() { Statu = "err", Msg = "无数据", Data = "" }; //保存记录(查询记录数据,更新或添加) string.IsNullOrEmpty(cq.RequestStr)存在值 修改修!string.IsNullOrEmpty(cq.RequestStr) kaka if (cq.RequestStr != null && cq.RequestStr.Count > 0) { List <Model.PatientDiagnose> patientDiagnoseList = new List <Model.PatientDiagnose>(); StringBuilder msg = new StringBuilder(); //调用接口获取数据 foreach (var item in cq.RequestStr) { string xmlStr = GetWebServiceData(item); string _Msg = ""; //返回数据缺少结束标记 if (!xmlStr.Contains("</Response>")) { xmlStr += "</Response>"; } Model.DTO.PatientDiagnoseResuest request = XmlStrToPatientDiagnoseResuest(item); if (request != null) { Model.PatientDiagnose patientDiagnose = StrTObject(xmlStr, out _Msg, request); if (patientDiagnose != null) { if (!patientDiagnoseList.Contains(patientDiagnose)) { bool check = CheckData(patientDiagnose); if (!check) { patientDiagnoseList.Add(patientDiagnose); } } if (!string.IsNullOrEmpty(_Msg)) { msg.Replace(_Msg, ""); msg.Append("   " + _Msg); } } } //nnn.Add(model.Code); else { if (!string.IsNullOrEmpty(_Msg)) { msg.Replace(_Msg, ""); msg.Append("   " + _Msg); } } } if (patientDiagnoseList != null && patientDiagnoseList.Count > 0) { //有数据 jsonmodel = CreatJsonMode("ok", msg.ToString(), patientDiagnoseList); ChangeQueryRecordStatu(cq, msg.ToString()); } else { //无数据 jsonmodel = CreatJsonMode("err", msg.ToString(), patientDiagnoseList); ChangeQueryRecordStatu(cq, msg.ToString()); } } return(JsonConvert.SerializeObject(jsonmodel)); }
/// <summary> /// datagrid查询数据 /// </summary> public NormalLisItemsRequest(Model.QueryRecoder queryRecoder) { this.QueryRecoderModel = queryRecoder; }
private Model.QueryRecoder CreatQueryRecoderModel() { Model.QueryRecoder model = new Model.QueryRecoder(); model.Code = this.Code; model.CodeType = this.CodeType; model.QueryType = "PatientDiagnose"; model.Uname = Common.CookieHelper.GetCookieValue("username"); model.IsDel = false; return model; }
private Model.QueryRecoder ContrastQueryRecoderModel(Model.QueryRecoder newModel, Model.QueryRecoder oldModel) { this.RequestStr = new List <string>(); Model.QueryRecoder resultModel = new Model.QueryRecoder(); BLL.QueryRecoder queryRecoder = new QueryRecoder(); //对比创建的model和数据库中的model。 //对比方面:addDate、lastQueryDate、QueryResult int queryDateInterval = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["QueryDateInterval"].Trim()); if (newModel == null) { //datagrid里面的数据 #region datagrid里面的数据 if ((DateTime.Now - oldModel.AddDate).Days > queryDateInterval) { //最后一次查询时间 string lastQueryDateStr = Convert.ToDateTime(oldModel.LastQueryDate).ToString("yyyy-MM-dd"); //更新最后一次查询时间 oldModel.LastQueryDate = DateTime.Now; resultModel = oldModel; try { bool updateResult = queryRecoder.Update(resultModel); if (updateResult) { //更新数据成功 // this.RequestStr = 最后一次查询时间到adddate+5 this.RequestStr.Add(CreatRequestStr(lastQueryDateStr, oldModel.AddDate.AddDays(queryDateInterval).ToString("yyyy-MM-dd"))); } } catch (Exception ex) { Common.LogHelper.WriteError(ex); } } else { //5天范围内添加的数据 string lastQueryDateStr = Convert.ToDateTime(oldModel.LastQueryDate).ToString("yyyy-MM-dd"); if (oldModel.AddDate == oldModel.LastQueryDate && oldModel.AddDate == DateTime.Now) { //当天的数据 } else if (oldModel.AddDate == oldModel.LastQueryDate && oldModel.AddDate < DateTime.Now) { oldModel.LastQueryDate = DateTime.Now; resultModel = oldModel; try { bool updateResult = queryRecoder.Update(resultModel); if (updateResult) { //更新数据成功 // this.RequestStr = 最后一次查询时间到adddate+5 this.RequestStr.Add(CreatRequestStr(lastQueryDateStr, oldModel.AddDate.AddDays(queryDateInterval).ToString("yyyy-MM-dd"))); } } catch (Exception ex) { Common.LogHelper.WriteError(ex); } } } #endregion datagrid里面的数据 } else if (oldModel == null) { //本地数据库没数据,并且是用code添加信息 #region 本地数据库没数据,并且是用code添加信息 //超时的老数据第一次添加 if ((DateTime.Now - newModel.AddDate).Days > queryDateInterval) { newModel.LastQueryDate = DateTime.Now; try { int res = queryRecoder.Add(newModel); if (res > 0) { resultModel = queryRecoder.CheckQueryRecord(newModel).OrderByDescending(a => a.AddDate).FirstOrDefault(); string k = newModel.AddDate.AddDays(-queryDateInterval).ToString("yyyy-MM-dd"); string j = newModel.AddDate.AddDays(queryDateInterval).ToString("yyyy-MM-dd"); this.RequestStr.Add(CreatRequestStr(k, j)); } } catch (Exception ex) { Common.LogHelper.WriteError(ex); } } else { //新添加的数据并且是在范围内 newModel.LastQueryDate = DateTime.Now; try { int res = queryRecoder.Add(newModel); if (res > 0) { resultModel = queryRecoder.CheckQueryRecord(newModel).OrderByDescending(a => a.AddDate).FirstOrDefault(); string k = newModel.AddDate.AddDays(-queryDateInterval).ToString("yyyy-MM-dd"); string j = DateTime.Now.ToString("yyyy-MM-dd"); //查询字符串的范围是当前日期的前几天,到当前日期 this.RequestStr.Add(CreatRequestStr(k, j)); } } catch (Exception ex) { Common.LogHelper.WriteError(ex); } } #endregion 本地数据库没数据,并且是用code添加信息 } else if (newModel != null && oldModel != null) { //当前时间和最后的查询时间的查值 int dateDifWithOldLastDateAndDateNow = (DateTime.Now - Convert.ToDateTime(oldModel.LastQueryDate)).Days; int dateDifWithOldAddDateAndDateNow = (DateTime.Now - oldModel.AddDate).Days; int dateDifWithLastAndAddDate = (Convert.ToDateTime(oldModel.LastQueryDate) - oldModel.AddDate).Days; //本地数据库有数据,并且是用code添加信息 //01.判断lastquery 和当前日期 if (oldModel.LastQueryDate == newModel.LastQueryDate && oldModel.LastQueryDate == DateTime.Now) { //重复查询数据 } else if (dateDifWithOldAddDateAndDateNow >= 2 * queryDateInterval) { string lastQueryDateStr = Convert.ToDateTime(oldModel.LastQueryDate).ToString("yyyy-MM-dd"); //超时 并且是2倍时间间隔之前的数据——新建一条数据 Model.QueryRecoder newRecord = new Model.QueryRecoder() { AddDate = DateTime.Now.AddDays(-queryDateInterval), Code = newModel.Code, CodeType = newModel.CodeType, IsDel = false, LastQueryDate = DateTime.Now.AddDays(-queryDateInterval), QueryType = newModel.QueryType, Uname = newModel.Uname }; oldModel.LastQueryDate = oldModel.AddDate.AddDays(queryDateInterval); try { bool q = queryRecoder.CheckRecord(newRecord); if (!q) { //不存在 int add = queryRecoder.Add(newRecord); } } catch (Exception ex) { Common.LogHelper.WriteError(ex); } resultModel = oldModel; //最后查询时间到老model的添加时间加上时间间隔 if (dateDifWithLastAndAddDate >= queryDateInterval) { this.RequestStr.Add(CreatRequestStr(oldModel.AddDate.ToString("yyyy-MM-dd"), oldModel.AddDate.AddDays(queryDateInterval).ToString("yyyy-MM-dd"))); } else { this.RequestStr.Add(CreatRequestStr(lastQueryDateStr, oldModel.AddDate.AddDays(queryDateInterval).ToString("yyyy-MM-dd"))); } } else if (dateDifWithOldAddDateAndDateNow >= queryDateInterval && dateDifWithOldAddDateAndDateNow < 2 * queryDateInterval) { //查询时间有重合 string lastQueryDateStr = Convert.ToDateTime(oldModel.LastQueryDate).ToString("yyyy-MM-dd"); this.RequestStr.Add(CreatRequestStr(lastQueryDateStr, oldModel.AddDate.AddDays(queryDateInterval).ToString("yyyy-MM-dd"))); //超时 并且是2倍时间间隔之前的数据——新建一条数据 Model.QueryRecoder newRecord = new Model.QueryRecoder() { AddDate = oldModel.AddDate.AddDays(queryDateInterval), Code = newModel.Code, CodeType = newModel.CodeType, IsDel = false, LastQueryDate = oldModel.AddDate.AddDays(queryDateInterval), QueryType = newModel.QueryType, Uname = newModel.Uname }; try { bool q = queryRecoder.CheckRecord(newRecord); if (!q) { //不存在 int add = queryRecoder.Add(newRecord); } } catch (Exception ex) { Common.LogHelper.WriteError(ex); throw; } oldModel.LastQueryDate = oldModel.AddDate.AddDays(queryDateInterval); resultModel = oldModel; } else { string lastQueryDateStr = Convert.ToDateTime(oldModel.LastQueryDate).ToString("yyyy-MM-dd"); //没超时,还在时间范围内的 oldModel.LastQueryDate = DateTime.Now; this.RequestStr.Add(CreatRequestStr(lastQueryDateStr, DateTime.Now.ToString("yyyy-MM-dd"))); resultModel = oldModel; } } List <string> temResquestStrList = new List <string>(); if (this.RequestStr != null && this.RequestStr.Count > 0) { foreach (string item in this.RequestStr) { if (!temResquestStrList.Contains(item)) { temResquestStrList.Add(item); } } } this.RequestStr = temResquestStrList; return(resultModel); }
private Model.QueryRecoder ContrastQueryRecoderModel(Model.QueryRecoder newModel, Model.QueryRecoder oldModel) { this.RequestStr = new List<string>(); Model.QueryRecoder resultModel = new Model.QueryRecoder(); BLL.QueryRecoder queryRecoder = new QueryRecoder(); //对比创建的model和数据库中的model。 //对比方面:addDate、lastQueryDate、QueryResult int queryDateInterval = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["QueryDateInterval"].Trim()); if (newModel == null) { //datagrid里面的数据 #region datagrid里面的数据 int nowAndAddDate = (DateTime.Now - oldModel.AddDate).Days; if (nowAndAddDate > queryDateInterval) { //最后一次查询时间 string lastQueryDateStr = Convert.ToDateTime(oldModel.LastQueryDate).ToString("yyyy-MM-dd"); DateTime lastDate = new DateTime(); try { lastDate = Convert.ToDateTime(lastQueryDateStr); } catch (Exception ex) { Common.LogHelper.WriteError(ex); } int lastDateAndAddDate = (lastDate - oldModel.AddDate).Days; //更新最后一次查询时间 oldModel.LastQueryDate = DateTime.Now; try { bool updateResult = queryRecoder.Update(resultModel); if (updateResult && lastDate != null) { if (lastDateAndAddDate >= 0) { //正常情况 for (int i = 0; i < (queryDateInterval - lastDateAndAddDate); i++) { string temStr = this.CreatRequestStr(oldModel.Code, lastDate.AddDays(i)); this.RequestStr.Add(temStr); } } else { //没有最后查询时间 for (int i = 0; i < (queryDateInterval - 0); i++) { string temStr = this.CreatRequestStr(oldModel.Code, oldModel.AddDate.AddDays(i)); this.RequestStr.Add(temStr); } } } } catch (Exception ex) { Common.LogHelper.WriteError(ex); } resultModel = oldModel; } else { //5天范围内添加的数据 string lastQueryDateStr = Convert.ToDateTime(oldModel.LastQueryDate).ToString("yyyy-MM-dd"); DateTime lastDate = new DateTime(); try { lastDate = Convert.ToDateTime(lastQueryDateStr); } catch (Exception ex) { Common.LogHelper.WriteError(ex); } if ((oldModel.AddDate == oldModel.LastQueryDate && oldModel.AddDate == DateTime.Now) || (oldModel.LastQueryDate < oldModel.AddDate && oldModel.AddDate == DateTime.Now)) { //当天的数据 } else if ((oldModel.AddDate == oldModel.LastQueryDate && oldModel.AddDate < DateTime.Now) || (oldModel.LastQueryDate < oldModel.AddDate && oldModel.AddDate < DateTime.Now)) { oldModel.LastQueryDate = DateTime.Now; try { bool updateResult = queryRecoder.Update(resultModel); if (updateResult) { //更新数据成功 // this.RequestStr = 最后一次查询时间到adddate+5 for (int i = 0; i < nowAndAddDate; i++) { string temStr = CreatRequestStr(oldModel.Code, oldModel.AddDate.AddDays(i)); this.RequestStr.Add(temStr); } } } catch (Exception ex) { Common.LogHelper.WriteError(ex); } resultModel = oldModel; } } #endregion datagrid里面的数据 } else if (oldModel == null) { //本地数据库没数据,并且是用code添加信息 #region 本地数据库没数据,并且是用code添加信息 //超时的老数据第一次添加 if ((DateTime.Now - newModel.AddDate).Days > queryDateInterval) { newModel.LastQueryDate = DateTime.Now; try { int res = queryRecoder.Add(newModel); if (res > 0) { resultModel = queryRecoder.CheckQueryRecord(newModel).OrderByDescending(a => a.AddDate).FirstOrDefault(); for (int i = 0; i < queryDateInterval; i++) { string temStr1 = this.CreatRequestStr(newModel.Code, newModel.AddDate.AddDays(-i).AddDays(-1)); string temStr2 = this.CreatRequestStr(newModel.Code, newModel.AddDate.AddDays(i)); this.RequestStr.Add(temStr1); this.RequestStr.Add(temStr2); } } } catch (Exception ex) { Common.LogHelper.WriteError(ex); } } else { //新添加的数据并且是在范围内 newModel.LastQueryDate = DateTime.Now; try { int res = queryRecoder.Add(newModel); if (res > 0) { resultModel = queryRecoder.CheckQueryRecord(newModel).OrderByDescending(a => a.AddDate).FirstOrDefault(); string k = newModel.Code; string j = DateTime.Now.ToString("yyyy-MM-dd"); for (int i = 0; i < queryDateInterval; i++) { string temStr = this.CreatRequestStr(newModel.Code, newModel.AddDate.AddDays(-i).AddDays(-1)); this.RequestStr.Add(temStr); } for (int i = 0; i < (DateTime.Now - newModel.AddDate).Days; i++) { string temStr = this.CreatRequestStr(newModel.Code, newModel.AddDate.AddDays(i)); this.RequestStr.Add(temStr); } } } catch (Exception ex) { Common.LogHelper.WriteError(ex); } } #endregion 本地数据库没数据,并且是用code添加信息 } else if (newModel != null && oldModel != null) { //当前时间和最后的查询时间的查值 int dateDifWithOldLastDateAndDateNow = (DateTime.Now - Convert.ToDateTime(oldModel.LastQueryDate)).Days; int dateDifWithOldAddDateAndDateNow = (DateTime.Now - oldModel.AddDate).Days; //本地数据库有数据,并且是用code添加信息 //01.判断lastquery 和当前日期 if (oldModel.LastQueryDate == newModel.LastQueryDate && oldModel.LastQueryDate == DateTime.Now) { //重复查询数据 } else if (dateDifWithOldAddDateAndDateNow >= 2 * queryDateInterval) { string Code = oldModel.Code; //超时 并且是2倍时间间隔之前的数据——新建一条数据 Model.QueryRecoder newRecord = new Model.QueryRecoder() { AddDate = DateTime.Now.AddDays(-queryDateInterval), Code = newModel.Code, CodeType = newModel.CodeType, IsDel = false, LastQueryDate = DateTime.Now.AddDays(-queryDateInterval), QueryType = newModel.QueryType, Uname = newModel.Uname }; DateTime lastDate = new DateTime(); try { lastDate = Convert.ToDateTime(oldModel.LastQueryDate); } catch (Exception ex) { Common.LogHelper.WriteError(ex); } int lastDateAndAddDate = (lastDate - oldModel.AddDate).Days; oldModel.LastQueryDate = oldModel.AddDate.AddDays(queryDateInterval); try { bool q = queryRecoder.CheckRecord(newRecord); if (!q) { //不存在 int add = queryRecoder.Add(newRecord); } } catch (Exception ex) { Common.LogHelper.WriteError(ex); } resultModel = oldModel; //最后查询时间到老model的添加时间加上时间间隔 if (lastDateAndAddDate >= 0) { //正常情况 for (int i = 0; i < (queryDateInterval - lastDateAndAddDate); i++) { string temStr = this.CreatRequestStr(oldModel.Code, lastDate.AddDays(i)); this.RequestStr.Add(temStr); } } else { //没有最后查询时间 for (int i = 0; i < (queryDateInterval - 0); i++) { string temStr = this.CreatRequestStr(oldModel.Code, oldModel.AddDate.AddDays(i)); this.RequestStr.Add(temStr); } } } else if (dateDifWithOldAddDateAndDateNow >= queryDateInterval && dateDifWithOldAddDateAndDateNow < 2 * queryDateInterval) { //查询时间有重合 // string lastQueryDateStr = Convert.ToDateTime(oldModel.LastQueryDate).ToString("yyyy-MM-dd"); DateTime lastDate = new DateTime(); try { lastDate = Convert.ToDateTime(oldModel.LastQueryDate); } catch (Exception ex) { Common.LogHelper.WriteError(ex); } int lastDateAndAddDate = (lastDate - oldModel.AddDate).Days; //最后查询时间到老model的添加时间加上时间间隔 if (lastDateAndAddDate >= 0) { //正常情况 for (int i = 0; i < (queryDateInterval - lastDateAndAddDate); i++) { string temStr = this.CreatRequestStr(oldModel.Code, lastDate.AddDays(i)); this.RequestStr.Add(temStr); } } else { //没有最后查询时间 for (int i = 0; i < (queryDateInterval - 0); i++) { string temStr = this.CreatRequestStr(oldModel.Code, oldModel.AddDate.AddDays(i)); this.RequestStr.Add(temStr); } } // this.RequestStr.Add(CreatRequestStr(lastQueryDateStr, oldModel.AddDate.AddDays(queryDateInterval).ToString("yyyy-MM-dd"))); //超时 并且是时间间隔之前的数据——新建一条数据 Model.QueryRecoder newRecord = new Model.QueryRecoder() { AddDate = oldModel.AddDate.AddDays(queryDateInterval), Code = newModel.Code, CodeType = newModel.CodeType, IsDel = false, LastQueryDate = oldModel.AddDate.AddDays(queryDateInterval), QueryType = newModel.QueryType, Uname = newModel.Uname }; try { bool q = queryRecoder.CheckRecord(newRecord); if (!q) { //不存在 int add = queryRecoder.Add(newRecord); } } catch (Exception ex) { Common.LogHelper.WriteError(ex); throw; } oldModel.LastQueryDate = oldModel.AddDate.AddDays(queryDateInterval); resultModel = oldModel; } else { string strCode = oldModel.Code; //没超时,还在时间范围内的 DateTime lastDate = new DateTime(); try { lastDate = Convert.ToDateTime(oldModel.LastQueryDate); } catch (Exception ex) { Common.LogHelper.WriteError(ex); } //最后查询时间和当天时间对比 int nowAndLastDate = (DateTime.Now - lastDate).Days; //最后查询时间到老model的添加时间加上时间间隔 if (nowAndLastDate <= queryDateInterval) { //正常情况 for (int i = 0; i < (nowAndLastDate); i++) { string temStr = this.CreatRequestStr(oldModel.Code, lastDate.AddDays(i)); this.RequestStr.Add(temStr); } } // this.RequestStr.Add(CreatRequestStr(strCode, DateTime.Now.ToString("yyyy-MM-dd"))); oldModel.LastQueryDate = DateTime.Now; resultModel = oldModel; } } List<string> temResquestStrList = new List<string>(); if (this.RequestStr != null && this.RequestStr.Count > 0) { foreach (string item in this.RequestStr) { if (!temResquestStrList.Contains(item)) { temResquestStrList.Add(item); } } } this.RequestStr = temResquestStrList; return resultModel; }