示例#1
0
        //Print button clicked
        private void Print_Button_Click(object sender, EventArgs e)
        {
            var confirmResult1 = MessageBox.Show("Do you want to print this sales?", "Confirmation", MessageBoxButtons.YesNo);

            if (confirmResult1 == DialogResult.Yes)
            {
                int          Order_ID = Convert.ToInt32(Data_Sales_History_View.SelectedCells[0].Value.ToString());
                Sales_Report report   = new Sales_Report();
                report.Get_Order_ID(Convert.ToInt32(Order_ID.ToString()));
                report.Show();
            }
        }
示例#2
0
        //Save order to database
        private void Save_Order_Button_Click(object sender, EventArgs e)
        {
            if (this.Controls.OfType <TextBox>().Any(t => string.IsNullOrEmpty(t.Text))) //Apabila ada yang tidak diisi, lakukan ini
            {
                MessageBox.Show("All input must be filled!");
            }
            else
            {
                var confirmResult = MessageBox.Show("Confirm Order?", "Confirmation", MessageBoxButtons.YesNo);
                if (confirmResult == DialogResult.Yes)
                {
                    //input to Orders
                    SqlCommand input = con.CreateCommand();
                    input.CommandType = CommandType.Text;
                    input.CommandText = "INSERT INTO Orders VALUES('" + Customer_Box.Text + "','"
                                        + Total_Payment_Box.Text + "', '"
                                        + Sale_Date_Box.Text + "', '"
                                        + Username_Box.Text + "', '"
                                        + Bill_Type_Box.Text + "')";
                    input.ExecuteNonQuery();

                    //Input to Sell by taking Order_ID from Orders
                    int Order_ID = 0;

                    SqlCommand input2 = con.CreateCommand();
                    input2.CommandType = CommandType.Text;
                    input2.CommandText = "SELECT TOP 1 * FROM Orders ORDER BY Order_ID DESC";
                    input2.ExecuteNonQuery();

                    DataTable      dataTable2   = new DataTable();
                    SqlDataAdapter dataAdapter2 = new SqlDataAdapter(input2);
                    dataAdapter2.Fill(dataTable2);

                    foreach (DataRow dataRow2 in dataTable2.Rows)
                    {
                        Order_ID = Convert.ToInt32(dataRow2["Order_ID"].ToString());
                    }

                    foreach (DataRow temp_dataRow in temp_dataTable.Rows)
                    {
                        SqlCommand temp = con.CreateCommand();
                        temp.CommandType = CommandType.Text;
                        temp.CommandText = "INSERT INTO Sell VALUES('" + Order_ID + "','"
                                           + temp_dataRow["Product_ID"] + "', '"
                                           + temp_dataRow["Quantity"] + "', '"
                                           + temp_dataRow["Total_Price"] + "')";
                        temp.ExecuteNonQuery();

                        //Minus quantity
                        int    Quantity   = Convert.ToInt32(temp_dataRow["Quantity"].ToString());
                        string Product_ID = temp_dataRow["Product_ID"].ToString();

                        SqlCommand temp1 = con.CreateCommand();
                        temp1.CommandType = CommandType.Text;
                        temp1.CommandText = "UPDATE Products SET Product_Quantity = Product_Quantity - "
                                            + Quantity + " WHERE Product_ID = '" + Product_ID.ToString() + "'";
                        temp1.ExecuteNonQuery();
                    }

                    //Reset Textbox
                    Customer_Box.Text     = ""; Username_Box.Text = ""; Bill_Type_Box.Text = "";
                    Product_Name_Box.Text = ""; Product_ID_Box.Text = ""; Quantity_Box.Text = "0";
                    Sell_Price_Box.Text   = "0"; Total_Box.Text = ""; Total_Payment_Box.Text = "";

                    //Reset datagrid
                    temp_dataTable.Clear();
                    dataGridView1.DataSource = temp_dataTable;

                    MessageBox.Show("Sales Added!");

                    //Check if users want to print order
                    var confirmResult1 = MessageBox.Show("Do you want to print this sales?", "Confirmation", MessageBoxButtons.YesNo);
                    if (confirmResult1 == DialogResult.Yes)
                    {
                        Sales_Report report = new Sales_Report();
                        report.Get_Order_ID(Convert.ToInt32(Order_ID.ToString()));
                        report.Show();
                    }
                }
            }
        }