Example #1
0
        static public Order EnterDataClient(OrderFromBuyer order)
        {
            Console.WriteLine("Имя Клиента");
            order.NameClient = Console.ReadLine();

            Console.WriteLine("Адрес Клиента");
            order.AdressClient = Console.ReadLine();

            return(order);
        }
Example #2
0
        private Order ReturnTypeOrder(bool b)
        {
            Order ord = null;

            if (b)
            {
                ord = new OrderFromBuyer();
            }
            else
            {
                ord = new OrderToTheSupplier();
            }
            return(ord);
        }
Example #3
0
        public static Order CreateOrderFromBuyer(OrderFromBuyer order)
        {
            using (SqlConnection sqlConnection = new SqlConnection(connectionString))
            {
                sqlConnection.Open();
                SqlCommand    sqlCommand    = null;
                SqlDataReader sqlDataReader = null;

                Console.WriteLine("Выберите ID Клиента, на которого следует оформить заказ");
                order.IDClient = (SqlInt32)(int.Parse(Console.ReadLine()));

                string sqlQuery = String.Format("Select * From dbo.Client Where IDClient =" + order.IDClient);
                sqlCommand    = new SqlCommand(sqlQuery, sqlConnection);
                sqlDataReader = sqlCommand.ExecuteReader();
                if (!sqlDataReader.HasRows)
                {
                    Console.WriteLine("Такого клиента нет в базе данных. Добавим.\n");

                    EnterData.EnterDataClient(order);

                    sqlDataReader.Close();
                    sqlCommand             = new SqlCommand();
                    sqlCommand.Connection  = sqlConnection;
                    sqlCommand.CommandText = @"INSERT INTO Client (Name, Adress) VALUES ('" +
                                             order.NameClient + "','" + order.AdressClient + "');";
                    sqlCommand.ExecuteNonQuery();

                    sqlQuery      = String.Format("SELECT Top 1 * FROM OrderDB.dbo.Client ORDER BY IDClient DESC;");
                    sqlCommand    = new SqlCommand(sqlQuery, sqlConnection);
                    sqlDataReader = sqlCommand.ExecuteReader();
                    while (sqlDataReader.Read())
                    {
                        order.IDClient = sqlDataReader.GetInt32(0);
                    }
                }
                sqlDataReader.Close();
            }

            return(order);
        }
Example #4
0
        /// <summary>
        /// Выгружает из БД заказ с номером заказа, если такой есть
        /// </summary>
        public static Order LoadOrder(int ID)
        {
            Order order = null;

            using (SqlConnection sqlConnection = new SqlConnection(connectionString))
            {
                sqlConnection.Open();
                SqlParameter sqlParameter = new SqlParameter("@idOrder", System.Data.SqlDbType.Int);
                sqlParameter.Value = ID;
                string     sqlQuery   = String.Format("Select IDOrder,DocNumber,TotalAmountOrder,IDClient,Status,IDSupplier From dbo.OrderTable Where IDOrder = @idOrder");
                SqlCommand sqlCommand = new SqlCommand(sqlQuery, sqlConnection);
                sqlCommand.Parameters.Add(sqlParameter);
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();

                while (sqlDataReader.Read())
                {
                    if (sqlDataReader.IsDBNull(5) && sqlDataReader.IsDBNull(3))
                    {
                        throw new Exception("Столбцы IDSupplier и IDClient одновременно не могут быть null");
                    }
                    else if (sqlDataReader.IsDBNull(5))
                    {
                        order = new OrderFromBuyer();
                    }
                    else if (sqlDataReader.IsDBNull(3))
                    {
                        order = new OrderToTheSupplier();
                    }
                    order.IDOrder          = sqlDataReader.GetInt32(0);
                    order.DocNumber        = sqlDataReader.GetInt32(1);
                    order.TotalAmountOrder = sqlDataReader.GetSqlMoney(2);
                    order.IDClient         = sqlDataReader.GetInt32(3);
                    order.Status           = sqlDataReader.GetString(4);
                    order.IDSupplier       = sqlDataReader.GetSqlInt32(5);
                }
            }
            return(order);
        }