Example #1
0
 private void buttonX_hd_Click(object sender, EventArgs e)
 {
     if (hd == null || hd.GetListSP().Count == 0)
     {
         MessageBox.Show("Ban phai dien thong tin san pham");
     }
     else
     {
         Boolean f;
         f = c2.MuaHang(hd);
         if (f == true)
         {
             MessageBox.Show("thanh toan hoa don thanh cong");
         }
     }
 }
Example #2
0
        public Boolean MuaHang(HoaDon hd) //mua hang truc tiep va lap hoa don tu phieu dat hang
        {
            connect();
            if (con.State == ConnectionState.Closed)
            {
                con.Open();
            }

            SqlTransaction muahang = con.BeginTransaction();

            try
            {
                SqlCommand insert_hoadon = new SqlCommand("INSERT_HOADON", con, muahang);
                insert_hoadon.CommandType = CommandType.StoredProcedure;
                insert_hoadon.Parameters.Add("@MKH", SqlDbType.Char).Value = hd.GetMKH();
                insert_hoadon.Parameters.Add("@MNV", SqlDbType.Char).Value = hd.GetMNV();
                hd.SetMHD((int)insert_hoadon.ExecuteScalar());
                foreach (SP sp in hd.GetListSP())
                {//ghi chi tiet hoa don
                    SqlCommand insert_cthd = new SqlCommand("INSERT_CTHD", con, muahang);
                    insert_cthd.CommandType = CommandType.StoredProcedure;
                    insert_cthd.Parameters.Add("@MHD", SqlDbType.Int).Value         = hd.GetMHD();
                    insert_cthd.Parameters.Add("@MSP", SqlDbType.Char).Value        = sp.GetMSP();
                    insert_cthd.Parameters.Add("@GIABAN", SqlDbType.Money).Value    = sp.GetGiaban();
                    insert_cthd.Parameters.Add("@SOLUONG", SqlDbType.Int).Value     = sp.GetSoluong();
                    insert_cthd.Parameters.Add("@THANHTIEN", SqlDbType.Money).Value = sp.GetThanhtien();
                    insert_cthd.ExecuteNonQuery();
                }
                muahang.Commit();
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("loi " + ex.ToString());
                muahang.Rollback();
                return(false);
            }
            finally
            {
                con.Dispose();
            }
        }
 private void buttonX_Hd_Click(object sender, EventArgs e)
 {
     if (!hd.GetMKH().Equals("") || hd.GetListSP().Count != 0)
     {
         Boolean f;
         if (!mdh.Equals(""))
         {
             c2.SetDH(mdh);
         }
         f = c2.MuaHang(hd);
         if (f == true)
         {
             MessageBox.Show("ghi hoa don thanh cong");
         }
         else
         {
             MessageBox.Show("Bi loi ! thu lai");
         }
     }
     else
     {
         MessageBox.Show(" Ban phai chon don dat hang truoc");
     }
 }