예제 #1
0
        public List <SCAudit> GetAll()
        {
            var scAuditModel = new SCAuditModel();

            if (QueryBuilderObject != null)
            {
                base.DateRange        = QueryBuilderObject.DateRange;
                base.EndDate          = QueryBuilderObject.EndDate;
                base.EndDateInclusive = QueryBuilderObject.EndDateInclusive;
                base.EndDateString    = QueryBuilderObject.EndDateString;
                base.LastQueryString  = QueryBuilderObject.LastQueryString;
                base.OrderBy          = QueryBuilderObject.OrderBy;
                base.PageCount        = QueryBuilderObject.PageCount;
                base.SkipCount        = QueryBuilderObject.SkipCount;
                base.StartDate        = QueryBuilderObject.StartDate;
                base.StartDateString  = QueryBuilderObject.StartDateString;
                base.TimeRange        = QueryBuilderObject.TimeRange;
                base.WhereExpression  = QueryBuilderObject.WhereExpression;
            }

            using (var connection = _sqlDbConnection.CreateConnection(_connectionString))
            {
                var command = new SqlCommand(UseQueryBuilder ? QueryBuilder() : QueryString, connection);

                try
                {
                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        scAuditModel.SCAuditList.Add(new SCAudit()
                        {
                            Audit_Ser_Num         = string.IsNullOrEmpty(reader["SERIAL_NO"]?.ToString()) ? null : reader["SERIAL_NO"]?.ToString().Trim(),
                            Audit_Part_Num        = reader["PART_NO"]?.ToString(),
                            Audit_Prod_Desc       = reader["PART_DESC"]?.ToString(),
                            Audit_Prod_Desc_Alt   = reader["PART_DESC_ALT"]?.ToString(),
                            Audit_Source_Site_Num = reader["SOURCE_SITE_NO"]?.ToString(),
                            Audit_Dest_Site_Num   = reader["DESTINATION_SITE_NO"]?.ToString(),
                            Audit_Part_Type       = reader["PART_TYPE"]?.ToString(),
                            Audit_Rem             = reader["REMARK"]?.ToString(),
                            Audit_User            = reader["USER"]?.ToString(),
                            Audit_Move_Date       = DateTime.Parse(reader["MOVE_DATE"].ToString()),
                            Audit_Last_Update     = DateTime.Parse(reader["UPDATE_DATE"].ToString())
                        });
                    }
                    Reset();
                    reader.Close();
                }
                catch (Exception exp)
                {
                    JSON_FileExport.WriteFile("EntityModel" + "_ScheduleRepeater_Exception_04_" + DateTime.Now.ToString("yyMMddhhmm"), exp, 0, "Exception");
                    Console.WriteLine(exp.Message);
                }
            }

            return(scAuditModel.SCAuditList);
        }
        public void Basic_select_query_to_DB()
        {
            var connectionString = "Server=Tesseract;Database=LineTess;Uid=Hugh;Pwd=Pr0ct0r";

            var queryString = "select TOP 10 " +
                              "[Audit_Ser_Num], " +
                              "[Audit_Part_Num], " +
                              "[Audit_Source_Site_Num], " +
                              "[Audit_Rem], " +
                              "[Audit_User], " +
                              "[Audit_Move_Date], " +
                              "[Audit_Last_Update] " +
                              "FROM scaudit (nolock) " +
                              "WHERE audit_last_update >= '2017-06-01' AND audit_last_update <= '2017-06-30' " +
                              "ORDER BY Audit_Move_date desc";
            var scAuditModel = new SCAuditModel();

            scAuditModel.SCAuditList = scAuditModel.SCAuditList ?? new List <SCAudit>();

            using (var sqlConnection = new SqlConnection(connectionString))
            {
                var command = new SqlCommand(queryString, sqlConnection);

                try
                {
                    sqlConnection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        scAuditModel.SCAuditList.Add(new SCAudit()
                        {
                            Audit_Dest_Site_Num   = reader[0].ToString(),
                            Audit_Part_Num        = reader[1].ToString(),
                            Audit_Source_Site_Num = reader[2].ToString(),
                            Audit_Rem             = reader[3].ToString(),
                            Audit_User            = reader[4].ToString(),
                            Audit_Move_Date       = DateTime.Parse(reader[5].ToString()),
                            Audit_Last_Update     = DateTime.Parse(reader[6].ToString())
                        });
                    }
                    reader.Close();
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                }
            }
            Assert.IsNotNull(scAuditModel.SCAuditList);
            Assert.IsTrue(scAuditModel.SCAuditList.Any());
            Assert.IsTrue(scAuditModel.SCAuditList.Count == 10);
            Assert.IsTrue(!string.IsNullOrEmpty(scAuditModel.SCAuditList.First().Audit_Part_Num));
        }
        public List <SCAudit> GetAll()
        {
            var scAuditModel = new SCAuditModel();

            using (var connection = _sqlDbConnection.CreateConnection(_connectionString))
            {
                var command = new SqlCommand(UseQueryBuilder ? QueryBuilder() : QueryString, connection);

                try
                {
                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        scAuditModel.SCAuditList.Add(new SCAudit()
                        {
                            Audit_Ser_Num         = reader["SERIAL_NO"].ToString(),
                            Audit_Part_Num        = reader["PART_NO"].ToString(),
                            Audit_Source_Site_Num = reader["SOURCE_SITE_NO"].ToString(),
                            Audit_Dest_Site_Num   = reader["DESTINATION_SITE_NO"].ToString(),
                            Audit_Rem             = reader["REMARK"].ToString(),
                            Audit_User            = reader["USER"].ToString(),
                            Audit_Move_Date       = DateTime.Parse(reader["MOVE_DATE"].ToString()),
                            Audit_Last_Update     = DateTime.Parse(reader["UPDATE_DATE"].ToString())
                        });
                    }
                    Reset();
                    reader.Close();
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                }
            }

            return(scAuditModel.SCAuditList);
        }