Esempio n. 1
0
 public PageDataTable GetPageData()
 {
     using (SqlConnection con = new SqlConnection(DataConfig.connectionString))
     {
         PageDataTable objT = new PageDataTable();
         con.Open();
         SqlCommand sc = new SqlCommand(CountRecord, con);
         sc.CommandType = CommandType.StoredProcedure;
         sc.Parameters.AddWithValue("@PSize", CurrentFilter.PageSize);
         sc.Parameters.AddWithValue("@PCurr", CurrentFilter.PageIndex);
         SqlDataReader dreader = sc.ExecuteReader();
         StringBuilder sb      = new StringBuilder();
         if (dreader.HasRows)
         {
             while (dreader.Read())
             {
                 object[] objData = new object[dreader.FieldCount];
                 dreader.GetValues(objData);
                 objT.FieldsMap = objData;
             }
         }
         dreader.Close();
         con.Close();
         return(objT);
     }
 }
Esempio n. 2
0
        public string SearchJSON()
        {
            StringBuilder sb = new StringBuilder();
            Dictionary <string, StringBuilder> DicData = new Dictionary <string, StringBuilder>();

            using (SqlConnection con = new SqlConnection(DataConfig.connectionString))
            {
                T objT = new T();
                objT.ActiveReference();
                con.Open();
                SqlCommand sc = new SqlCommand(SearchProcName, con);
                sc.CommandType = CommandType.StoredProcedure;
                sc.Parameters.AddWithValue("@strDataRef", objT.DataRef);
                sc.Parameters.AddWithValue("@strDataIRef", objT.DataIJRef);
                if (CurrentFilter != null)
                {
                    sc.Parameters.AddRange(CurrentFilter.GetSearchParams());
                    PageData = GetPageData();
                }
                SqlDataReader          dreader = sc.ExecuteReader();
                System.IO.StringWriter sw      = new System.IO.StringWriter(sb);

                using (JsonWriter jsonWriter = new JsonTextWriter(sw))
                {
                    jsonWriter.WriteStartArray();
                    while (dreader.Read())
                    {
                        jsonWriter.WriteStartObject();

                        int fields = dreader.FieldCount;

                        for (int i = 0; i < fields; i++)
                        {
                            jsonWriter.WritePropertyName(dreader.GetName(i));
                            jsonWriter.WriteValue(dreader[i]);
                        }
                        jsonWriter.WriteEndObject();
                    }
                    jsonWriter.WriteEndArray();
                }

                dreader.Close();
                con.Close();
            }
            return(sb.ToString());
        }
Esempio n. 3
0
        public List <T> Search()
        {
            List <T> LstModelRet = new List <T>();
            Dictionary <string, StringBuilder> DicData = new Dictionary <string, StringBuilder>();

            using (SqlConnection con = new SqlConnection(DataConfig.connectionString))
            {
                T objT = new T();
                objT.ActiveReference();
                con.Open();
                SqlCommand sc = new SqlCommand(SearchProcName, con);
                sc.CommandType = CommandType.StoredProcedure;
                sc.Parameters.AddWithValue("@strDataRef", objT.DataRef);
                sc.Parameters.AddWithValue("@strDataIRef", objT.DataIJRef);
                if (CurrentFilter != null)
                {
                    sc.Parameters.AddRange(CurrentFilter.GetSearchParams());
                    PageData = GetPageData();
                }
                SqlDataReader dreader = sc.ExecuteReader();
                StringBuilder sb      = new StringBuilder();
                if (dreader.HasRows)
                {
                    while (dreader.Read())
                    {
                        object[] objData = new object[dreader.FieldCount];
                        dreader.GetValues(objData);
                        objT.FieldsMap = objData;
                        LstModelRet.Add((T)objT.Clone());
                    }
                }
                dreader.Close();
                con.Close();
            }

            return(LstModelRet);
        }