Exemple #1
0
        public static void InsertOrder(OrderCL or)
        {
            try
            {
                SqlCommand cmd = new SqlCommand("SET IDENTITY_INSERT [dbo].[Orders] ON insert into Orders(OrderID,CustomerID,EmployeeID,OrderDate,Discount) "
                    + "values (@OrderID,@CustomerID,@EmployeeID,getDate(),@Discount)" +
                    "SET IDENTITY_INSERT [dbo].[Orders] OFF", con);
                cmd.Parameters.AddWithValue("@OrderID", or.OrderID);
                cmd.Parameters.AddWithValue("@CustomerID", or.CustomerID);
                cmd.Parameters.AddWithValue("@EmployeeID", or.EmployeeID);
                cmd.Parameters.AddWithValue("@Discount", or.Discount);

                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemple #2
0
        private void btComplete_Click(object sender, EventArgs e)
        {
            if (dataGridView1.Rows.Count > 0)
            {
                int tradingCode = int.Parse(txtTradingCode.Text);
                int empId = SelectDA.getEmpID(txtSeller.Text);
                int cusID = int.Parse(txtCustomer.Text);
                int dis = int.Parse(txtDiscount.Text);
                OrderCL or = new OrderCL(tradingCode, cusID, empId, dis);
                InsertDA.InsertOrder(or);

                int proID = 0, quan = 0, pri = 0;
                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    proID = int.Parse(dataGridView1.Rows[i].Cells[0].Value.ToString());
                    quan = int.Parse(dataGridView1.Rows[i].Cells[4].Value.ToString());
                    pri = int.Parse(dataGridView1.Rows[i].Cells[3].Value.ToString());
                    OrderDetailCL orDe = new OrderDetailCL(tradingCode, proID, quan, pri);
                    InsertDA.InsertOrderDetail(orDe);
                }
                tradingCode++;
                txtTradingCode.Text = tradingCode + "";
                setToDefault();
            }
            else
            {
                MessageBox.Show("Input product to sell !");
            }
        }