Exemple #1
0
        public void TestMethod1()
        {
            EnergyDB db    = new EnergyDB();
            int      count = db.BuildInfo.ToList().Count();

            Assert.AreEqual(1, count);
        }
Exemple #2
0
        public void TestGetReport()
        {
            EnergyDB _db = new EnergyDB();

            DepartmentReportDbContext context = new DepartmentReportDbContext();

            string[] depts =
            {
                "D000001G001001",
                "D000001G001002"
            };

            string       sql   = string.Format(DepartmentReportResources.YearReportSQL, "'" + string.Join("','", depts) + "'");
            SqlParameter param = new SqlParameter();

            param.ParameterName = "@EndTime";
            param.SqlDbType     = SqlDbType.Date;
            param.Value         = "2018-07-01";
            SqlParameter[] sqlParameters =
            {
                param,
                new SqlParameter("@EnergyItemCode", "02000")
            };
            String             connStr = _db.Database.Connection.ConnectionString;
            List <ReportValue> list    = new List <ReportValue>();

            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
            using (SqlConnection conn = new SqlConnection(connStr))
            {
                conn.Open();
                Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));

                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.Add(new SqlParameter("@EndTime", "2018-07-01"));
                cmd.Parameters.Add(new SqlParameter("@EnergyItemCode", "02000"));

                SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                DataTable      table   = new DataTable();
                adapter.Fill(table);
                Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));


                foreach (DataRow row in table.Rows)
                {
                    ReportValue report = new ReportValue();
                    report.Id    = row["ID"].ToString();
                    report.Name  = row["Name"].ToString();
                    report.Time  = Convert.ToDateTime(row["Time"]);
                    report.Value = Convert.ToDecimal(row["Value"]);
                    list.Add(report);
                }
                Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
            }


            Console.WriteLine(list.Count);
            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
        }
Exemple #3
0
        public void TestRegionReportBySqlReader()
        {
            EnergyDB _db = new EnergyDB();

            string connString = "data source=192.168.105.227,1433;initial catalog=EMS;persist security info=True;user id=sa;password=Acrel001";

            List <ReportValue> list = new List <ReportValue>();

            using (SqlConnection conn = new SqlConnection(connString))
            {
                conn.Open();

                string sql = string.Format(RegionReportResources.YearReportSQL, @"'000001G0010002',
                                                                                    '000001G0010005',
                                                                                    '000001G0010006',
                                                                                    '000001G0010007',
                                                                                    '000001G0010008',
                                                                                    '000001G0010009',
                                                                                    '000001G0010010',
                                                                                    '000001G0010011',
                                                                                    '000001G0010012',
                                                                                    '000001G0010013',
                                                                                    '000001G0010014'");

                SqlCommand     cmd           = new SqlCommand(sql, conn);
                SqlParameter[] sqlParameters =
                {
                    new SqlParameter("@BuildID",        "000001G001"),
                    new SqlParameter("@EnergyItemCode", "01000"),
                    new SqlParameter("@EndTime",        "2018-01-01")
                };

                cmd.Parameters.AddRange(sqlParameters);

                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    ReportValue report = new ReportValue();
                    report.Id    = reader["ID"].ToString();
                    report.Name  = reader["Name"].ToString();
                    report.Time  = Convert.ToDateTime(reader["Time"]);
                    report.Value = Convert.ToDecimal(reader["Value"]);

                    list.Add(report);
                }
            }

            Console.WriteLine(list.Count);
        }