Esempio n. 1
0
        public void LoadOrder()
        {
            int ID = EnterData.IDOrder();

            order = DBWork.LoadOrder(ID);

            Show.ShowOrder(order);
        }
Esempio n. 2
0
        public void CreateOrder()
        {
            int who = EnterData.ChoiceCustomer();

            order = ReturnTypeOrder(who == 1);

            GoMethod();

            EnterData.EnterDataOrder(order);
            //Изменяем общую сумму заказа
            order.Process();

            DBWork.InsertOrderInDB(order);
            Show.ShowOrder(order);
        }
Esempio n. 3
0
        public void UpdateOrder()
        {
            int ID = EnterData.IDOrder();

            order = DBWork.LoadOrder(ID);
            if (order != null)
            {
                Console.WriteLine("Новые данные заказа\n");
                order = ReturnTypeOrder(!order.IDSupplier.IsNull);

                GoMethod();
                EnterData.EnterDataOrder(order);
                //Изменяем общую сумму заказа
                order.Process();
                order.IDOrder = ID;
                DBWork.UpdateOrder(order);
            }
            Show.ShowOrder(order);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        public static Order CreateOrderToTheSupplier(OrderToTheSupplier order)
        {
            using (SqlConnection sqlConnection = new SqlConnection(connectionString))
            {
                sqlConnection.Open();
                SqlCommand    sqlCommand    = null;
                SqlDataReader sqlDataReader = null;

                Console.WriteLine("ID Поставщика");
                order.IDSupplier = (SqlInt32)(int.Parse(Console.ReadLine()));

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

                    EnterData.EnterDataSupplier(order);

                    sqlDataReader.Close();
                    sqlCommand             = new SqlCommand();
                    sqlCommand.Connection  = sqlConnection;
                    sqlCommand.CommandText = @"INSERT INTO Supplier (INN, PhysicalAddress, LegalAddress) VALUES (" +
                                             order.INN + ",'" + order.PhysicalAdress + "','" + order.LegalAdress + "');";
                    sqlCommand.ExecuteNonQuery();

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

            return(order);
        }