private void button4_Click(object sender, EventArgs e) { string str = "Server=localhost;User ID=root;Password=979268;Database=project;CharSet=gbk"; MySqlConnection con = new MySqlConnection(str); con.Open(); string strcmd = ""; string id = textBox2.Text; string quantity = textBox3.Text; if (id != "" && quantity != "") { strcmd = "select Product_id from shelf where Product_id = " + id + ";"; MySqlCommand cmd = new MySqlCommand(strcmd, con); MySqlDataReader mysqldr = cmd.ExecuteReader(); if (mysqldr.HasRows) { mysqldr.Close(); strcmd = "select Product_id,product_name,sale_price,description from product where Product_id = " + id + ";"; cmd = new MySqlCommand(strcmd, con); MySqlDataAdapter ada = new MySqlDataAdapter(cmd); DataSet ds = new DataSet(); ada.Fill(ds);//查询结果填充数据集 double totalpriceofoneproduct = (Convert.ToDouble(ds.Tables[0].Rows[0]["sale_price"].ToString())) * (Convert.ToInt32(quantity)); orderItem newOrderItem = new orderItem(); newOrderItem.Location = new Point(10, itemHeight); newOrderItem.ID = id; newOrderItem.name = ds.Tables[0].Rows[0]["product_name"].ToString(); newOrderItem.money = totalpriceofoneproduct.ToString(); newOrderItem.description = ds.Tables[0].Rows[0]["description"].ToString(); newOrderItem.quantity = quantity; panel1.Controls.Add(newOrderItem); myArr.Add(newOrderItem); itemHeight += 40; con.Close(); } else { MessageBox.Show("There is no such product with this id in shelf now!"); textBox2.Text = ""; textBox3.Text = ""; } } else { MessageBox.Show("Both ID and quantity are required!"); } textBox2.Text = ""; textBox3.Text = ""; }
private void timer1_Tick(object sender, EventArgs e) { today_date = today.ToString("yyyy-MM-dd"); totalCost = 0; for (int i = 0; i < myArr.Count; i++) { orderItem o = myArr[i] as orderItem; totalCost += Convert.ToDouble(o.money); } totalCost0 = totalCost; this.label4.Text = totalCost.ToString() + "¥"; }
private void button3_Click(object sender, EventArgs e) { string str = "Server=localhost;User ID=root;Password=979268;Database=project;CharSet=gbk"; MySqlConnection con = new MySqlConnection(str); con.Open(); string strcmd = ""; string strcmd0 = ""; string VIPid = textBox1.Text; if (VIPid != "") { strcmd0 = "select user_id from user where user_type = 'member' and user_id = " + VIPid + ";"; MySqlCommand cmd0 = new MySqlCommand(strcmd0, con); MySqlDataReader mysqldr0 = cmd0.ExecuteReader(); if (mysqldr0.HasRows) { mysqldr0.Close(); VIPIfExist = true; } else { mysqldr0.Close(); VIPIfExist = false; } } else { VIPIfExist = true; } if (VIPIfExist) { MessageBox.Show("Order completed with cost : " + totalCost0); for (int i = 0; i < myArr.Count; i++) { orderItem o = myArr[i] as orderItem; strcmd += "UPDATE shelf SET quantity=quantity - " + o.quantity + " WHERE Product_id=" + o.ID + ";"; if (VIPid != "") { strcmd += "INSERT INTO `salerecord` (`product_id`, `quantity`, `Sale_date`, `user_id`) VALUES ('" + o.ID + "', '" + o.quantity + "', '" + today_date + "', '" + VIPid + "');"; } else { strcmd += "INSERT INTO `salerecord` (`product_id`, `quantity`, `Sale_date`) VALUES ('" + o.ID + "', '" + o.quantity + "', '" + today_date + "');"; } } strcmd += "INSERT INTO assets (`change_date`, `changeofmoney`) VALUES ('" + today_date + "', '" + totalCost0.ToString() + "');"; MySqlCommand cmd = new MySqlCommand(strcmd, con); cmd.ExecuteNonQuery(); con.Close(); myArr.Clear(); totalCost = 0; textBox1.Text = ""; this.label4.Text = "0¥"; this.panel1.Controls.Clear(); } else { DialogResult result = MessageBox.Show("VIP not exist! Do you want to create a new VIP with this id ?", "Sorry", MessageBoxButtons.OKCancel); if (result == DialogResult.OK) { string strcmd1 = "INSERT INTO `user` (`user_id`, `user_type`, `user_name`, `passward`) VALUES ('" + VIPid + "', 'member', 'admin', '" + VIPid + "');"; MySqlCommand cmd = new MySqlCommand(strcmd1, con); cmd.ExecuteNonQuery(); con.Close(); MessageBox.Show("VIP created! Please click OK again to complete the order!"); } else { textBox1.Text = ""; } } itemHeight = 10; }