DataManager.cs :  » Network-Clients » iReaper » IReaper » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Network Clients » iReaper 
iReaper » IReaper » DataManager.cs
namespace iReaper{
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Runtime.CompilerServices;
    using System.Web.Configuration;

    public class DataManager
    {
        private static volatile SqlConnection conn;

        public static void Init()
        {
            InitDataBaseConnection();
        }

        public static DataSet GetDailyReportOfDownload()
        {
            SqlCommand selectCommand = conn.CreateCommand();
            selectCommand.CommandType = CommandType.Text;
            selectCommand.CommandText = "select convert(nvarchar,dayofYear,107)  ,Amount Webcast , ActiveUser , Average  from dailyreportofdownload order by dayofYear";
            SqlDataAdapter adapter = new SqlDataAdapter(selectCommand);
            DataSet dataSet = new DataSet();
            adapter.Fill(dataSet);
            return dataSet;
        }

        public static int GetDistinctUserNumber()
        {
            SqlCommand command = conn.CreateCommand();
            command.CommandType = CommandType.Text;
            command.CommandText = "select count(distinct(userid)) from userbehavior";
            SqlDataReader reader = command.ExecuteReader();
            int num = 0;
            while (reader.Read())
            {
                num = reader.GetInt32(0);
                break;
            }
            reader.Close();
            return num;
        }

        public static DataSet GetDistinctUserNumberList()
        {
            SqlCommand selectCommand = conn.CreateCommand();
            selectCommand.CommandType = CommandType.Text;
            selectCommand.CommandText = "select Range  ,Amount  from RangStatics()";
            SqlDataAdapter adapter = new SqlDataAdapter(selectCommand);
            DataSet dataSet = new DataSet();
            adapter.Fill(dataSet);
            return dataSet;
        }


        [MethodImpl(MethodImplOptions.Synchronized)]
        private static void InitDataBaseConnection()
        {
            try
            {
                if (conn != null)
                {
                    conn.Close();
                }
                conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["ireaper"].ConnectionString);
                conn.Open();
            }
            catch
            {
                if (conn != null)
                {
                    conn.Close();
                }
                conn = null;
            }
        }

        public static void Log(LogRequest request)
        {
            SqlCommand command = conn.CreateCommand();
            command.CommandType = CommandType.Text;
            command.CommandText = "insert into downloadlog(UserID,CourseID,[Type],IP,[Version]) values (@UserID,@CourseID,@Type,@IP,@Version)";
            command.Parameters.Add("@CourseID", SqlDbType.Int).Value = request.CourseID;
            command.Parameters.Add("@UserID", SqlDbType.UniqueIdentifier).Value = request.UserID;
            command.Parameters.Add("@Type", SqlDbType.Int).Value = request.CourseType;
            command.Parameters.Add("@IP", SqlDbType.BigInt).Value = request.IP;
            command.Parameters.Add("@Version", SqlDbType.VarChar, 50).Value = request.UserAgent + "";

            command.ExecuteNonQuery();
        }

        public static void UpdateGeoInfo()
        {
            SqlCommand command = conn.CreateCommand();
            command.CommandType = CommandType.Text;
            command.CommandText = "select IP, City, Region, UserID from [user] where City is null";

            
            SqlDataAdapter sda = new SqlDataAdapter(command);
            SqlCommandBuilder scb = new SqlCommandBuilder(sda);
            DataSet ds = new DataSet();
            sda.Fill(ds);

            GeoInfoManager.UpdateTableSet(ds);

            sda.Update(ds);
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.