public HttpResponseMessage GetData_EQIW_RLD(Info_EQIW_RLD info)
        {
            string result = null;

            try
            {
                DateTime BeginDate = DateTime.Parse(info.fldBeginDate);

                DateTime EndDate = DateTime.Parse(info.fldEndDate);



                if (info.type == "STatType1")
                {
                    using (MiddleContext db = new MiddleContext())
                    {
                        List <tblHM_EQIW_RLD_STatType1_Midd>      query      = new List <tblHM_EQIW_RLD_STatType1_Midd>();
                        List <tblHM_EQIW_RLD_STatType1_Item_Midd> query_Item = new List <tblHM_EQIW_RLD_STatType1_Item_Midd>();

                        if (info.fldSTCode == "-1")
                        {
                            query = (from x in db.tblHM_EQIW_RLD_STatType1_Midd
                                     select x).ToList();
                        }
                        else
                        {
                            query = (from x in db.tblHM_EQIW_RLD_STatType1_Midd
                                     where info.fldSTCode.Contains(x.fldSTCode + "." + x.fldRCode + "." + x.fldRSCode)
                                     select x).ToList();
                        }



                        if (info.fldItemCode != null)
                        {
                            query_Item = (from x in query
                                          join y in db.tblHM_EQIW_RLD_STatType1_Item_Midd
                                          on x.fldAutoID equals y.fldFKID
                                          select y).ToList();

                            if (info.fldItemCode != "All")
                            {
                                string[] ItemCodeList = info.fldItemCode.Split(',');

                                query_Item = (from x in query_Item
                                              where ItemCodeList.Contains(x.fldItemCode)
                                              select x).ToList();
                            }
                        }


                        ReturnData rd = new ReturnData();
                        rd.dangqi      = query;
                        rd.dangqi_Item = query_Item;

                        if (info.IsYear == "1")
                        {
                            int year = int.Parse(info.fldYear) - 1;

                            List <tblHM_EQIW_RLD_STatType1_Midd>      query2      = new List <tblHM_EQIW_RLD_STatType1_Midd>();
                            List <tblHM_EQIW_RLD_STatType1_Item_Midd> query_Item2 = new List <tblHM_EQIW_RLD_STatType1_Item_Midd>();

                            if (info.fldSTCode == "-1")
                            {
                                query2 = (from x in db.tblHM_EQIW_RLD_STatType1_Midd
                                          select x).ToList();
                            }
                            else
                            {
                                query2 = (from x in db.tblHM_EQIW_RLD_STatType1_Midd
                                          where info.fldSTCode.Contains(x.fldSTCode + "." + x.fldRCode + "." + x.fldRSCode)
                                          select x).ToList();
                            }



                            if (info.fldItemCode != null)
                            {
                                query_Item2 = (from x in query2
                                               join y in db.tblHM_EQIW_RLD_STatType1_Item_Midd
                                               on x.fldAutoID equals y.fldFKID
                                               select y).ToList();

                                if (info.fldItemCode != "All")
                                {
                                    string[] ItemCodeList = info.fldItemCode.Split(',');

                                    query_Item2 = (from x in query_Item2
                                                   where ItemCodeList.Contains(x.fldItemCode)
                                                   select x).ToList();
                                }
                            }

                            rd.tongqi      = query2;
                            rd.tongqi_Item = query_Item2;
                        }

                        result = rule.JsonStr("ok", "", rd);
                    }
                }



                if (info.type == "STatType3")
                {
                    using (MiddleContext db = new MiddleContext())
                    {
                        List <tblHM_EQIW_RLD_STatType3_Midd>      query      = new List <tblHM_EQIW_RLD_STatType3_Midd>();
                        List <tblHM_EQIW_RLD_STatType3_Item_Midd> query_Item = new List <tblHM_EQIW_RLD_STatType3_Item_Midd>();

                        if (info.fldSTCode == "-1")
                        {
                            query = (from x in db.tblHM_EQIW_RLD_STatType3_Midd
                                     select x).ToList();
                        }
                        else
                        {
                            query = (from x in db.tblHM_EQIW_RLD_STatType3_Midd
                                     where info.fldSTCode.Contains(x.fldSTCode + "." + x.fldRCode + "." + x.fldRSCode)
                                     select x).ToList();
                        }



                        if (info.fldItemCode != null)
                        {
                            query_Item = (from x in query
                                          join y in db.tblHM_EQIW_RLD_STatType3_Item_Midd
                                          on x.fldAutoID equals y.fldFKID
                                          select y).ToList();

                            if (info.fldItemCode != "All")
                            {
                                string[] ItemCodeList = info.fldItemCode.Split(',');

                                query_Item = (from x in query_Item
                                              where ItemCodeList.Contains(x.fldItemCode)
                                              select x).ToList();
                            }
                        }


                        ReturnData1 rd = new ReturnData1();
                        rd.dangqi      = query;
                        rd.dangqi_Item = query_Item;

                        if (info.IsYear == "1")
                        {
                            int year = int.Parse(info.fldYear) - 1;

                            List <tblHM_EQIW_RLD_STatType3_Midd>      query2      = new List <tblHM_EQIW_RLD_STatType3_Midd>();
                            List <tblHM_EQIW_RLD_STatType3_Item_Midd> query_Item2 = new List <tblHM_EQIW_RLD_STatType3_Item_Midd>();

                            if (info.fldSTCode == "-1")
                            {
                                query2 = (from x in db.tblHM_EQIW_RLD_STatType3_Midd
                                          select x).ToList();
                            }
                            else
                            {
                                query2 = (from x in db.tblHM_EQIW_RLD_STatType3_Midd
                                          where info.fldSTCode.Contains(x.fldSTCode + "." + x.fldRCode + "." + x.fldRSCode)
                                          select x).ToList();
                            }



                            if (info.fldItemCode != null)
                            {
                                query_Item2 = (from x in query2
                                               join y in db.tblHM_EQIW_RLD_STatType3_Item_Midd
                                               on x.fldAutoID equals y.fldFKID
                                               select y).ToList();

                                if (info.fldItemCode != "All")
                                {
                                    string[] ItemCodeList = info.fldItemCode.Split(',');

                                    query_Item2 = (from x in query_Item2
                                                   where ItemCodeList.Contains(x.fldItemCode)
                                                   select x).ToList();
                                }
                            }

                            rd.tongqi      = query2;
                            rd.tongqi_Item = query_Item2;
                        }

                        result = rule.JsonStr("ok", "", rd);
                    }
                }
            }
            catch (Exception e)
            {
                result = rule.JsonStr("error", e.Message, "");
            }

            return(new HttpResponseMessage {
                Content = new StringContent(result, System.Text.Encoding.UTF8, "application/json")
            });
        }
Esempio n. 2
0
        public HttpResponseMessage ExeCacheData_EQIW_RLD(Info_EQIW_RLD info)
        {
            string    result = null;
            DataTable dt     = new DataTable();

            try
            {
                //第一步
                #region 初始化变量

                tblHM_EQIW_RLD_Info_Midd info_Midd = new tblHM_EQIW_RLD_Info_Midd();

                DateTime BeginDate = DateTime.Parse(info.BeginDate);

                DateTime EndDate = DateTime.Parse(info.EndDate);



                DateTime?EBeginDate = null;

                DateTime?EEndDate = null;


                DateTime EBeginDate2 = new DateTime();

                DateTime EEndDate2 = new DateTime();

                if (!(info.EBeginDate == "" || info.EEndDate == ""))
                {
                    DateTime.TryParse(info.EBeginDate, out EBeginDate2);

                    DateTime.TryParse(info.EEndDate, out EEndDate2);

                    EBeginDate = EBeginDate2;

                    EEndDate = EEndDate2;
                }



                #endregion



                //第二步
                #region 处理参数表,检查此条件下是否已经进行过缓存

                using (MiddleContext db = new MiddleContext())
                {
                    var query = (from x in db.tblHM_EQIW_RLD_Info_Midd
                                 where x.TimeType == info.TimeType &&
                                 x.BeginDate == BeginDate &&
                                 x.EndDate == EndDate &&
                                 x.EBeginDate == EBeginDate &&
                                 x.EEndDate == EEndDate &&
                                 x.fldRSC == info.fldRSC &&
                                 x.fldRSCode == info.fldRSCode &&
                                 x.fldStandardName == info.fldStandardName &&
                                 x.fldLevel == info.fldLevel &&
                                 x.fldStandardNameG == info.fldStandardNameG &&
                                 x.fldLevelG == info.fldLevelG &&
                                 x.fldItemCode == info.fldItemCode &&
                                 x.DecCarry == info.DecCarry &&
                                 x.IsPre == info.IsPre &&
                                 x.IsYear == info.IsYear &&
                                 x.IsTotal == info.IsTotal &&
                                 x.IsDetail == info.IsDetail &&
                                 x.AppriseID == info.AppriseID &&
                                 x.SpaceID == info.SpaceID &&
                                 x.STatType == info.STatType &&
                                 x.Para1ID == info.Para1ID &&
                                 x.Para2ID == info.Para2ID &&
                                 x.Source == info.Source
                                 select x).Count();

                    if (query > 0)
                    {
                        result = rule.JsonStr("ok", "此条件下已经进行过数据缓存。", "");
                        return(new HttpResponseMessage {
                            Content = new StringContent(result, System.Text.Encoding.UTF8, "application/json")
                        });
                    }
                }

                #endregion



                //第三步
                #region 执行通用存储过程,返回数据

                SqlParameter[] paras = new SqlParameter[]
                {
                    new SqlParameter("@TimeType", info.TimeType),
                    new SqlParameter("@BeginDate", info.BeginDate),
                    new SqlParameter("@EndDate", info.EndDate),
                    new SqlParameter("@EBeginDate", info.EBeginDate),
                    new SqlParameter("@EEndDate", info.EEndDate),
                    new SqlParameter("@fldRSC", info.fldRSC),
                    new SqlParameter("@fldRSCode", info.fldRSCode),
                    new SqlParameter("@fldStandardName", info.fldStandardName),
                    new SqlParameter("@fldLevel", info.fldLevel),
                    new SqlParameter("@fldStandardNameG", info.fldStandardNameG),
                    new SqlParameter("@fldLevelG", info.fldLevelG),
                    new SqlParameter("@fldItemCode", info.fldItemCode),
                    new SqlParameter("@DecCarry", info.DecCarry),
                    new SqlParameter("@IsPre", info.IsPre),
                    new SqlParameter("@IsYear", info.IsYear),
                    new SqlParameter("@IsTotal", info.IsTotal),
                    new SqlParameter("@IsDetail", info.IsDetail),
                    new SqlParameter("@AppriseID", info.AppriseID),
                    new SqlParameter("@SpaceID", info.SpaceID),
                    new SqlParameter("@STatType", info.STatType),
                    new SqlParameter("@Para1ID", info.Para1ID),
                    new SqlParameter("@Para2ID", info.Para2ID),
                    new SqlParameter("@Source", info.Source)
                };

                dt = rule.RunProcedure_V2("usp_tblEQIW_RLD_Report_HMApprirse", paras.ToList(), null, "HMEntityContext");

                if (dt == null || dt.Rows.Count == 0)
                {
                    result = rule.JsonStr("ok", "此条件集合下并未返回数据", "");
                    return(new HttpResponseMessage {
                        Content = new StringContent(result, System.Text.Encoding.UTF8, "application/json")
                    });
                }

                #endregion



                //第四步
                #region 如果存储过程返回数据,那么将条件写入参数表

                using (MiddleContext db = new MiddleContext())
                {
                    info_Midd.TimeType         = info.TimeType;
                    info_Midd.BeginDate        = BeginDate;
                    info_Midd.EndDate          = EndDate;
                    info_Midd.EBeginDate       = EBeginDate;
                    info_Midd.EEndDate         = EEndDate;
                    info_Midd.fldRSC           = info.fldRSC;
                    info_Midd.fldRSCode        = info.fldRSCode;
                    info_Midd.fldStandardName  = info.fldStandardName;
                    info_Midd.fldLevel         = info.fldLevel;
                    info_Midd.fldStandardNameG = info.fldStandardNameG;
                    info_Midd.fldLevelG        = info.fldLevelG;
                    info_Midd.fldItemCode      = info.fldItemCode;
                    info_Midd.DecCarry         = info.DecCarry;
                    info_Midd.IsPre            = info.IsPre;
                    info_Midd.IsYear           = info.IsYear;
                    info_Midd.IsTotal          = info.IsTotal;
                    info_Midd.IsDetail         = info.IsDetail;
                    info_Midd.AppriseID        = info.AppriseID;
                    info_Midd.SpaceID          = info.SpaceID;
                    info_Midd.STatType         = info.STatType;
                    info_Midd.Para1ID          = info.Para1ID;
                    info_Midd.Para2ID          = info.Para2ID;
                    info_Midd.Source           = info.Source;

                    db.tblHM_EQIW_RLD_Info_Midd.Add(info_Midd);
                    db.SaveChanges();
                }

                #endregion



                //第五步
                #region 相关数据处理



                //年鉴格式
                if (info.STatType == 1)
                {
                    using (MiddleContext db = new MiddleContext())
                    {
                        List <tblHM_EQIW_RLD_STatType1_Midd> list = new List <tblHM_EQIW_RLD_STatType1_Midd>();

                        foreach (DataRow item in dt.Rows)
                        {
                            tblHM_EQIW_RLD_STatType1_Midd data = new tblHM_EQIW_RLD_STatType1_Midd();

                            //将参数实体的主键值,设置给数据表的FKID,从而确定数据是从哪个参数下生成的
                            data.fldFKID = info_Midd.fldAutoID;

                            data.fldWaterArea = item["fldWaterArea"].ToString();
                            data.fldLevel     = item["fldLevel"].ToString();
                            data.fldAtt       = item["fldAtt"].ToString();
                            data.fldSTCode    = item["fldSTCode"].ToString();
                            data.fldSTName    = item["fldSTName"].ToString();
                            data.fldRCode     = item["fldRCode"].ToString();
                            data.fldRName     = item["fldRName"].ToString();
                            data.fldRSCode    = item["fldRSCode"].ToString();
                            data.fldRSName    = item["fldRSName"].ToString();
                            data.fldDate      = item["fldDate"].ToString();
                            data.fldFun       = item["fldFun"].ToString();
                            data.fldStage     = item["fldStage"].ToString();

                            db.tblHM_EQIW_RLD_STatType1_Midd.Add(data);
                            db.SaveChanges();


                            List <tblHM_EQIW_RLD_STatType1_Item_Midd> data_item_list = new List <tblHM_EQIW_RLD_STatType1_Item_Midd>();

                            foreach (var item2 in info.fldItemCode.Split(','))
                            {
                                if (item.Table.Columns.Contains("fld" + item2))
                                {
                                    tblHM_EQIW_RLD_STatType1_Item_Midd data_item = new tblHM_EQIW_RLD_STatType1_Item_Midd();

                                    data_item.fldFKID = data.fldAutoID;

                                    data_item.fldItemCode  = item2;
                                    data_item.fldItemValue = item["fld" + item2].ToString();
                                    data_item_list.Add(data_item);
                                }
                            }

                            db.tblHM_EQIW_RLD_STatType1_Item_Midd.AddRange(data_item_list);
                            db.SaveChanges();
                        }
                    }
                }



                //断面或者河流综合评价
                if (info.STatType == 3)
                {
                    using (MiddleContext db = new MiddleContext())
                    {
                        List <tblHM_EQIW_RLD_STatType3_Midd> list = new List <tblHM_EQIW_RLD_STatType3_Midd>();

                        foreach (DataRow item in dt.Rows)
                        {
                            tblHM_EQIW_RLD_STatType3_Midd data = new tblHM_EQIW_RLD_STatType3_Midd();

                            //将参数实体的主键值,设置给数据表的FKID,从而确定数据是从哪个参数下生成的
                            data.fldFKID = info_Midd.fldAutoID;

                            //data.AppriseID = info.AppriseID.ToString();
                            //data.STatType = info.STatType.ToString();

                            data.fldWaterArea  = item["fldWaterArea"].ToString();
                            data.fldSTCode     = item["fldSTCode"].ToString();
                            data.fldSTName     = item["fldSTName"].ToString();
                            data.fldRCode      = item["fldRCode"].ToString();
                            data.fldRName      = item["fldRName"].ToString();
                            data.fldRSCode     = item["fldRSCode"].ToString();
                            data.fldRSName     = item["fldRSName"].ToString();
                            data.fldLevel      = item["fldLevel"].ToString();
                            data.fldAtt        = item["fldAtt"].ToString();
                            data.fldRSC        = item["fldRSC"].ToString();
                            data.fldAppDate    = item["fldAppDate"].ToString();
                            data.fldType       = item["fldType"].ToString();
                            data.fldFun        = item["fldFun"].ToString();
                            data.fldStage      = item["fldStage"].ToString();
                            data.fldSectionApp = item["fldSectionApp"].ToString();
                            data.fldStand      = item["fldStand"].ToString();

                            db.tblHM_EQIW_RLD_STatType3_Midd.Add(data);
                            db.SaveChanges();


                            List <tblHM_EQIW_RLD_STatType3_Item_Midd> data_item_list = new List <tblHM_EQIW_RLD_STatType3_Item_Midd>();

                            foreach (var item2 in info.fldItemCode.Split(','))
                            {
                                if (item.Table.Columns.Contains(item2 + "_Value"))
                                {
                                    tblHM_EQIW_RLD_STatType3_Item_Midd data_item = new tblHM_EQIW_RLD_STatType3_Item_Midd();

                                    data_item.fldFKID = data.fldAutoID;

                                    data_item.fldItemCode = item2;
                                    data_item.fld_Value   = item[item2 + "_Value"].ToString();


                                    if (item.Table.Columns.Contains(item2 + "_Stage"))
                                    {
                                        data_item.fld_Stage = item[item2 + "_Stage"].ToString();
                                    }


                                    if (item.Table.Columns.Contains(item2 + "_STG"))
                                    {
                                        data_item.fld_STG = item[item2 + "_STG"].ToString();
                                    }


                                    if (item.Table.Columns.Contains(item2 + "_Over"))
                                    {
                                        data_item.fld_Over = item[item2 + "_Over"].ToString();
                                    }


                                    if (item.Table.Columns.Contains(item2 + "_OutScale"))
                                    {
                                        data_item.fld_OutScale = item[item2 + "_OutScale"].ToString();
                                    }


                                    if (item.Table.Columns.Contains(item2 + "_Min"))
                                    {
                                        data_item.fld_Min = item[item2 + "_Min"].ToString();
                                    }


                                    if (item.Table.Columns.Contains(item2 + "_Max"))
                                    {
                                        data_item.fld_Max = item[item2 + "_Max"].ToString();
                                    }

                                    if (item.Table.Columns.Contains(item2 + "_MaxOut"))
                                    {
                                        data_item.fld_MaxOut = item[item2 + "_MaxOut"].ToString();
                                    }


                                    if (item.Table.Columns.Contains(item2 + "_MaxDate"))
                                    {
                                        data_item.fld_MaxDate = item[item2 + "_MaxDate"].ToString();
                                    }


                                    data_item_list.Add(data_item);
                                }
                            }

                            db.tblHM_EQIW_RLD_STatType3_Item_Midd.AddRange(data_item_list);
                            db.SaveChanges();
                        }
                    }
                }



                #endregion



                result = rule.JsonStr("ok", "执行成功!", info_Midd.fldAutoID);
            }
            catch (Exception e)
            {
                result = rule.JsonStr("error", e.Message, "");
            }

            return(new HttpResponseMessage {
                Content = new StringContent(result, System.Text.Encoding.UTF8, "application/json")
            });
        }