Exemplo n.º 1
0
 private void buttonX1_Click(object sender, EventArgs e)
 {
     if (dateTimeInput_ngaylap.IsEmpty)
     {
         MessageBox.Show("Nhập vào ngày tháng");
         trangthai1();
     }
     else
     {
         labelX_mncc.Text = "Mã NCC : " + textBoxX_mncc.Text;
         labelX_mnv.Text  = "Mã NV : " + textBoxX_mnv.Text;
         trangthai2();
         nh = new NhapHang(textBoxX_mncc.Text, textBoxX_mnv.Text);
     }
 }
Exemplo n.º 2
0
        public Boolean NhapHang(NhapHang nh)
        {
            connect();
            if (con.State == ConnectionState.Closed)
            {
                con.Open();
            }


            SqlTransaction nhaphang = con.BeginTransaction();

            try
            {
                SqlCommand insert_nh = new SqlCommand("INSERT_PNH", con, nhaphang);
                insert_nh.CommandType = CommandType.StoredProcedure;
                insert_nh.Parameters.Add("@MNCC", SqlDbType.Char).Value = nh.GetMNCC();
                insert_nh.Parameters.Add("@MNV", SqlDbType.Char).Value  = nh.GetMNV();
                nh.SetMPN((int)insert_nh.ExecuteScalar());
                foreach (SP sp in nh.GetListSP())
                {//ghi chi tiet hoa don
                    SqlCommand insert_ctnh = new SqlCommand("INSERT_CTPNH", con, nhaphang);
                    insert_ctnh.CommandType = CommandType.StoredProcedure;
                    insert_ctnh.Parameters.Add("@MPN", SqlDbType.Int).Value         = nh.GetMPN();
                    insert_ctnh.Parameters.Add("@MSP", SqlDbType.Char).Value        = sp.GetMSP();
                    insert_ctnh.Parameters.Add("@GIAMUA", SqlDbType.Money).Value    = sp.GetGiaMua();
                    insert_ctnh.Parameters.Add("@SLNHAP", SqlDbType.Int).Value      = sp.GetSoluong();
                    insert_ctnh.Parameters.Add("@THANHTIEN", SqlDbType.Money).Value = sp.GetThanhtien();
                    insert_ctnh.ExecuteNonQuery();
                }
                nhaphang.Commit();
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("loi " + ex.ToString());
                nhaphang.Rollback();
                return(false);
            }
            finally
            {
                con.Dispose();
            }
        }