Beispiel #1
0
        /// <summary>
        /// 获取所有雇员的信息
        /// </summary>
        /// <returns></returns>
        public static List <IEmployee> GetEmployeeInfo()
        {
            using (SqlConnection conn = sqlHelper.GetConnection())
            {
                conn.Open();
                List <IEmployee> list = new List <IEmployee>();
                string           sql  = "SELECT * FROM [dbo].[EmployeeInfo];";
                SqlCommand       cmd  = new SqlCommand(sql, conn);
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        System.Data.IDataRecord record = reader;
                        IEmployee emp = null;
                        if (record.GetString(4).Equals("Worker"))
                        {
                            emp = new WorkerFactory().Get();
                        }
                        else if (record.GetString(4).Equals("Manager"))
                        {
                            emp = new ManagerFactory().Get();
                        }
                        else
                        {
                            emp = new DriverFactory().Get();
                        }

                        emp.Id   = record.GetInt32(0);
                        emp.Name = record.GetString(1);
                        emp.Sex  = record.GetString(2);
                        emp.Age  = record.GetInt32(3);

                        list.Add(emp);
                    }
                }

                conn.Dispose();
                cmd.Dispose();
                return(list);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 根据ID查询雇员信息
        /// </summary>
        /// <param name="key">查询ID</param>
        /// <returns></returns>
        dynamic IModelService.Get(dynamic key)
        {
            string id = key;

            try
            {
                using (SqlConnection conn = sqlHelper.GetConnection())
                {
                    conn.Open();
                    string     sql = "SELECT * FROM [dbo].[EmployeeInfo] WHERE Id = @Id;";
                    SqlCommand cmd = new SqlCommand(sql, conn);
                    cmd.Parameters.Add("@Id", SqlDbType.NVarChar);
                    cmd.Parameters["@Id"].Value = id;
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            System.Data.IDataRecord record = reader;

                            IFactory  factory = FactoryService.GetFactory(record.GetString(4));
                            IEmployee emp     = factory.Get();
                            emp.Id   = int.Parse(record.GetString(0));
                            emp.Name = record.GetString(1);
                            emp.Age  = record.GetInt32(2);
                            emp.Sex  = record.GetString(6);

                            return(emp);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                }
            }
            catch (SqlException sqle)
            {
                throw sqle;
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Beispiel #3
0
            /// <summary>
            ///
            /// </summary>
            /// <param name="acDomain"></param>
            /// <param name="commandType"></param>
            /// <param name="record"></param>
            /// <returns></returns>
            internal static CommandRecord Create(IAcDomain acDomain, MessageTypeKind commandType, System.Data.IDataRecord record)
            {
                MessageType requestType;

                record.GetString(record.GetOrdinal("MessageType")).TryParse(out requestType);
                ClientType clientType;

                record.GetString(record.GetOrdinal("ClientType")).TryParse(out clientType);
                return(new CommandRecord(commandType,
                                         record.GetGuid(record.GetOrdinal("Id")),
                                         DataItemsTuple.Create(
                                             acDomain,
                                             record.GetNullableString("InfoId"),
                                             record.GetNullableString("InfoValue"),
                                             record.GetNullableString("QueryList"),
                                             record.GetString(record.GetOrdinal("InfoFormat"))))
                {
                    Verb = new Verb(record.GetString(record.GetOrdinal("Verb"))),
                    Ontology = record.GetString(record.GetOrdinal("Ontology")),
                    LocalEntityId = record.GetNullableString("LocalEntityId"),
                    CatalogCode = record.GetNullableString("CatalogCode"),
                    ClientId = record.GetString(record.GetOrdinal("ClientId")),
                    TimeStamp = record.GetDateTime(record.GetOrdinal("TimeStamp")),
                    ReceivedOn = record.GetDateTime(record.GetOrdinal("ReceivedOn")),
                    CreateOn = record.GetDateTime(record.GetOrdinal("CreateOn")),
                    ClientType = clientType,
                    MessageType = requestType,
                    MessageId = record.GetString(record.GetOrdinal("MessageId")),
                    Status = record.GetInt32(record.GetOrdinal("Status")),
                    ReasonPhrase = record.GetNullableString(record.GetOrdinal("ReasonPhrase")),
                    Description = record.GetNullableString(record.GetOrdinal("Description")),
                    EventSubjectCode = record.GetNullableString(record.GetOrdinal("EventSubjectCode")),
                    EventSourceType = record.GetNullableString(record.GetOrdinal("EventSourceType")),
                    UserName = record.GetNullableString("UserName"),
                    IsDumb = record.GetBoolean(record.GetOrdinal("IsDumb")),
                    Version = record.GetString(record.GetOrdinal("Version"))
                });
            }
 private static void WriteSingleRow(System.Data.IDataRecord rdr, string[] fieldNamesToUse, Type[] types, Utf8JsonWriter jsonWriter)
 {
     jsonWriter.WriteStartObject();
     for (int p = 0; p < fieldNamesToUse.Length; p++)
     {
         if (rdr.IsDBNull(p))
         {
             jsonWriter.WriteNull(fieldNamesToUse[p]);
         }
         else if (types[p] == typeof(string))
         {
             jsonWriter.WriteString(fieldNamesToUse[p], rdr.GetString(p));
         }
         else if (types[p] == typeof(DateTime))
         {
             jsonWriter.WriteString(fieldNamesToUse[p], rdr.GetDateTime(p));
         }
         else if (types[p] == typeof(DateTimeOffset))
         {
             jsonWriter.WriteString(fieldNamesToUse[p], (DateTimeOffset)rdr.GetValue(p));
         }
         else if (types[p] == typeof(bool))
         {
             jsonWriter.WriteBoolean(fieldNamesToUse[p], rdr.GetBoolean(p));
         }
         else if (types[p] == typeof(Guid))
         {
             jsonWriter.WriteString(fieldNamesToUse[p], rdr.GetGuid(p));
         }
         else if (types[p] == typeof(short))
         {
             jsonWriter.WriteNumber(fieldNamesToUse[p], rdr.GetInt16(p));
         }
         else if (types[p] == typeof(int))
         {
             jsonWriter.WriteNumber(fieldNamesToUse[p], rdr.GetInt32(p));
         }
         else if (types[p] == typeof(long))
         {
             jsonWriter.WriteNumber(fieldNamesToUse[p], rdr.GetInt64(p));
         }
         else if (types[p] == typeof(float))
         {
             jsonWriter.WriteNumber(fieldNamesToUse[p], rdr.GetFloat(p));
         }
         else if (types[p] == typeof(double))
         {
             jsonWriter.WriteNumber(fieldNamesToUse[p], rdr.GetDouble(p));
         }
         else if (types[p] == typeof(decimal))
         {
             jsonWriter.WriteNumber(fieldNamesToUse[p], rdr.GetDecimal(p));
         }
         else if (types[p] == typeof(byte[]))
         {
             jsonWriter.WriteBase64String(fieldNamesToUse[p], (byte[])rdr.GetValue(p));
         }
         else
         {
             string?vl = rdr.GetValue(p)?.ToString();
             jsonWriter.WriteString(fieldNamesToUse[p], vl);
         }
     }
     jsonWriter.WriteEndObject();
 }