//添加商品 private void addButton_Click(object sender, EventArgs e) { try { //调用数据库操作,添加商品 DBOperation.AddProduct( Int32.Parse(this.productIdTextBox.Text), Double.Parse(this.productPriceTextBox.Text), Int32.Parse(this.productAmountTextBox.Text), this.productNameTextBox.Text, DBOperation.OrderCount - 1 ); } catch (FormatException exception) { MessageBox.Show(exception.Message, "ERROR", MessageBoxButtons.OK); } }
private void orderDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e) { try { //获取选中的订单的订单号 int row = this.orderDataGridView.CurrentRow.Index; int orderId = Int32.Parse( this.orderDataGridView.Rows[row].Cells[0].Value.ToString() ); //调用数据库操作 this.productDataGridView.DataSource = DBOperation.GetProductData(orderId); this.productDataGridView.DataMember = "products"; } catch (FormatException exception) { MessageBox.Show(exception.Message, "ERROR", MessageBoxButtons.OK); } }
public alterForm(int orderId, string recPerson, string recAddress) { InitializeComponent(); this.orderId = orderId; this.RecPersonTextBox.Text = this.recPerson = recPerson; this.RecAddressTextBox.Text = this.recAddress = recAddress; //设置表格属性 this.productBindingSource_1.DataSource = DBOperation.GetProductData(orderId); this.productDataGridView.DataSource = this.productBindingSource_1; this.productDataGridView.DataMember = "products"; //除了商品数量列外均设置为只读 this.productDataGridView.Columns[0].ReadOnly = true; this.productDataGridView.Columns[1].ReadOnly = true; this.productDataGridView.Columns[3].ReadOnly = true; this.productDataGridView.Columns[4].ReadOnly = true; this.productDataGridView.Columns[5].ReadOnly = true; }
//删除选中的商品 private void deleteProductButton_Click(object sender, EventArgs e) { try { //获取选中的商品的信息 int row = this.productDataGridView.CurrentRow.Index; int productId = Int32.Parse( this.productDataGridView.Rows[row].Cells[0].Value.ToString() ); //调用数据库操作删除商品 DBOperation.DeleteProduct(orderId, productId); //刷新表格 this.productDataGridView.DataSource = DBOperation.GetProductData(this.orderId); } catch (FormatException exception) { MessageBox.Show(exception.Message, "ERROR", MessageBoxButtons.OK); } }
//添加商品 private void Button_Click(object sender, EventArgs e) { try { //根据输入的信息添加商品 string name = this.productNameTextBox.Text; double price = Double.Parse( this.priceTextBox.Text); int amount = Int32.Parse( this.amountTextBox.Text); int productId = Int32.Parse( this.productIdtextBox.Text); //调用数据库操作 DBOperation.AddProduct(productId, price, amount, name, this.orderId); //刷新表格 data.DataSource = DBOperation.GetProductData(this.orderId); }catch (FormatException exception) { MessageBox.Show(exception.Message, "ERROR", MessageBoxButtons.OK); } }
//根据选择的条件查询订单信息 private void inquireButton_Click(object sender, EventArgs e) { try { //根据条件选择框的信息选择查询方式 switch (conditionComboBox.SelectedIndex) { //根据收货人查询 case 0: this.orderDataGridView.DataSource = DBOperation.QueryOrderByRecPerson(conditionTextBox.Text); break; //根据货物名查询 case 1: this.orderDataGridView.DataSource = DBOperation.QueryOrderByProductName(conditionTextBox.Text); break; //根据订单号查询 case 2: this.orderDataGridView.DataSource = DBOperation.QueryOrderByOrderId( Int32.Parse(conditionTextBox.Text )); break; default: break; } } catch (FormatException exception) { MessageBox.Show(exception.Message, "ERROR", MessageBoxButtons.OK); } }
//返回主界面 private void backButton_Click(object sender, EventArgs e) { data.DataSource = DBOperation.GetOrderData(); this.Close(); }
//查询结果后返回或者刷新表格 private void backButton_Click(object sender, EventArgs e) { this.orderDataGridView.DataSource = DBOperation.GetOrderData(); }
//还原数据库 private void importButton_Click(object sender, EventArgs e) { //调用数据库操作并更新表格 DBOperation.ImportFromSql(); this.orderDataGridView.DataSource = DBOperation.GetOrderData(); }
//备份数据库 private void exportButton_Click(object sender, EventArgs e) { //调用数据库操作 DBOperation.ExportToSql(); }