Я пытаюсь сделать приложение, чтобы сделать заказ.У меня есть 4 таблицы в Mysql:
CREATE TABLE `containers` (
`id_containers` int(11) NOT NULL AUTO_INCREMENT,
`container_name` varchar(45) DEFAULT NULL,
PRIMARY KEY (`id_containers`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4
CREATE TABLE `order` (
`id_order` int(11) NOT NULL AUTO_INCREMENT,
`out_number` varchar(45) NOT NULL,
`out_date` datetime DEFAULT CURRENT_TIMESTAMP,
`order_date` datetime DEFAULT CURRENT_TIMESTAMP,
`client` varchar(45) NOT NULL,
`client_ref` varchar(45) DEFAULT NULL,
`billed` tinyint(1) DEFAULT NULL,
`notes` longtext,
PRIMARY KEY (`id_order`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4
CREATE TABLE `order_details` (
`id_order_item` int(11) NOT NULL AUTO_INCREMENT,
`id_order` int(11) NOT NULL,
`id_product` int(11) NOT NULL,
`id_container` int(11) NOT NULL,
`pallets` int(11) DEFAULT NULL,
`volumes` int(11) DEFAULT NULL,
`caliber` varchar(45) DEFAULT NULL,
PRIMARY KEY (`id_order_item`),
KEY `id_container` (`id_exportation`),
CONSTRAINT `id_container` FOREIGN KEY (`id_order`) REFERENCES `containers` (`id_containers`),
CONSTRAINT `id_order` FOREIGN KEY (`id_order`) REFERENCES `order` (`id_order`),
CONSTRAINT `id_product` FOREIGN KEY (`id_order`) REFERENCES `products` (`id_product`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
CREATE TABLE `products` (
`id_product` int(11) NOT NULL AUTO_INCREMENT,
`product_name` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id_product`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
В своем приложении на C # я создал DatagridView и показываю элементы в порядке, используя функцию INNER JOIN.
private BindingSource GetOrderList()
{
string connString = ConfigurationManager.ConnectionStrings["ManagementApp.Properties.Settings.ConnectionString"].ConnectionString;
MySqlConnection con = new MySqlConnection(connString);
con.Open();
mysqladapter1.SelectCommand = new MySqlCommand("SELECT products.product_name as 'Produto', containers.container_name as 'Vasilhame', order_details.pallets 'Pallets', order_details.volumes as 'Volumes', order_details.caliber as 'Calibre' " +
"FROM order" +
"INNER JOIN order_details ON order.id_exportation = order_details.id_order " +
"INNER JOIN products ON order_details.id_product = products.id_product " +
"INNER JOIN containers ON order_details.id_container = containers.id_containers " +
"WHERE order.id_order = 1;", con);
cmdbuilder = new MySqlCommandBuilder(mysqladapter1);
DataTable table = new DataTable();
mysqladapter1.Fill(table);
OrderBindingSource.DataSource = table;
return OrderBindingSource;
}
Для этого представления данных может бытьдобавил новую строку для вставки элементов товаров и удалил, но я не знаю, как отправить это в MYSQL, потому что у меня есть несколько таблиц с внешними ключами в каждой строке.Я хочу нажать «ВВОД» внутри ячейки продукта, открыть окно со всеми продуктами и выбрать, какой продукт я хочу вставить в строку и в контейнер.