Example #1
0
        /// <summary>
        /// Update the record.
        /// </summary>
        public static int Update(Payment payment, int payment_id)
        {
            Database db = new Database();

            db.Connect();

            SqlCommand command = db.CreateCommand(SQL_UPDATE);

            command.Parameters.AddWithValue("@payment_id", payment_id);
            command.Parameters.AddWithValue("@client_id", payment.client_id);
            command.Parameters.AddWithValue("@price", payment.price);
            command.Parameters.AddWithValue("@payment_status", payment.payment_status);
            command.Parameters.AddWithValue("@order_id", payment.order_id);



            int ret = db.ExecuteNonQuery(command);


            db.Close();

            Console.WriteLine("Executed");
            return(ret);
        }
        public static int new_order(Orders order)
        {
            Database db = new Database();

            db.Connect();

            SqlCommand command = db.CreateCommand("new_order");

            command.CommandType = CommandType.StoredProcedure;

            SqlParameter client = new SqlParameter();

            client.ParameterName = "@client_id";
            client.DbType        = DbType.Int32;
            client.Value         = order.client_id;
            client.Direction     = ParameterDirection.Input;
            command.Parameters.Add(client);

            /*
             * The analisys contains a mistake - there should not be a date of performing an action but
             * start date of the order
             * SELECT * FROM orders
             * WHERE truck_plate=$available_truck.plate
             * AND start_date-$current_date < 3
             * AND start_date-$current_date >(-3)
             */


            SqlParameter start_date = new SqlParameter();

            start_date.ParameterName = "@start_date";
            start_date.DbType        = DbType.Date;
            start_date.Value         = order.start_date;
            start_date.Direction     = ParameterDirection.Input;
            command.Parameters.Add(start_date);

            SqlParameter route_id = new SqlParameter();

            route_id.ParameterName = "@route_id";
            route_id.DbType        = DbType.Int32;
            route_id.Value         = order.route_id;
            route_id.Direction     = ParameterDirection.Input;
            command.Parameters.Add(route_id);

            SqlParameter width = new SqlParameter();

            width.ParameterName = "@width";
            width.DbType        = DbType.Int32;
            width.Value         = order.width;
            width.Direction     = ParameterDirection.Input;
            command.Parameters.Add(width);

            SqlParameter height = new SqlParameter();

            height.ParameterName = "@height";
            height.DbType        = DbType.Int32;
            height.Value         = order.height;
            height.Direction     = ParameterDirection.Input;
            command.Parameters.Add(height);

            SqlParameter description = new SqlParameter();

            description.ParameterName = "@description";
            description.DbType        = DbType.String;
            description.Value         = order.load_description;
            description.Direction     = ParameterDirection.Input;
            command.Parameters.Add(description);



            // 4. execute procedure

            int ret = db.ExecuteNonQuery(command);

            //db.ExecuteNonQuery(command);
            Console.WriteLine("Executed");
            // 5. get values of the output parameters
            //string result = command.Parameters["@result"].Value.ToString();


            db.Close();
            //Console.WriteLine("Executed");

            return(ret);
        }