コード例 #1
0
 public static void SetInstance(string ConnectionString)
 {
     if (Instance == null)
     {
         Instance = new AddressRepo(ConnectionString);
     }
 }
コード例 #2
0
ファイル: TraderRepo.cs プロジェクト: benlokos/Barter_Final
        private IEnumerable <TraderModel> TraderCondition(string condition)

        {
            if (!String.IsNullOrEmpty(condition) && !condition.Equals("*"))
            {
                condition = " where " + condition;
            }
            else
            {
                condition = "";
            }
            Console.WriteLine("Select * from dbo.Traders" + condition);
            List <TraderModel> MyList = new List <TraderModel>();
            TraderModel        curr;

            sqlConnection.Open();
            var arg = "Select * from dbo.Traders" + condition;

            using (var command = new SqlCommand(arg, sqlConnection))
            {
                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        curr           = new TraderModel();
                        curr.ID        = reader["Trader_ID"] as string;
                        curr.FirstName = reader["FirstName"] as string;
                        curr.LastName  = reader["LastName"] as string;
                        string address = reader["Addr"] as string;

                        curr.Address = AddressRepo.GetInstance().GetById(address);

                        string rating = reader["Rating"] + "";
                        curr.rating = Double.Parse(rating);
                        curr.Photo  = reader["Photo"] as byte[];
                        MyList.Add(curr);
                    }
                }
            }
            sqlConnection.Close();
            return(MyList);
        }