Exemple #1
0
        private void BtnXacNhan_Click(object sender, EventArgs e)
        {
            CT_HDBAN ct_hdb = new CT_HDBAN();

            ct_hdb.MaHDB      = int.Parse(txtMaHDB.Text);
            ct_hdb.MaSP       = int.Parse(txtMaSP.Text);
            ct_hdb.SoLuongBan = int.Parse(txtSoLuong.Text);
            ct_hdb.DonGiaBan  = float.Parse(txtGiaBan.Text);
            ct_hdb.TongTien   = (int.Parse(txtSoLuong.Text)) * (float.Parse(txtGiaBan.Text));
            if (banhangdal.ThemCT_HDB(ct_hdb))
            {
                drvCTHD.DataSource = ct_hdb;
                MessageBox.Show("Thanh cong");

                CapNhatThanhTien();
            }
            else
            {
                MessageBox.Show("That bai");
            }

            drvCTHD.DataSource = banhangdal.loadCT_HDB(int.Parse(txtMaHDB.Text));



            //int n = drvCTHD.Rows.Add();
            //drvCTHD.Rows[n].Cells[0].Value = int.Parse(txtMaHDB.Text);
            //drvCTHD.Rows[n].Cells[1].Value = int.Parse(cboNV.SelectedValue.ToString());
            //drvCTHD.Rows[n].Cells[2].Value = int.Parse(txtSoLuong.Text);
            ////dataGridView1.Rows[n].Cells[3].Value = cbHangHoa.SelectedValue.ToString();
            //dataGridView1.Rows[n].Cells[3].Value = Convert.ToInt32(cbHangHoa.SelectedValue.ToString());
            //txtSoLuong.Text = "";
        }
 public Boolean ThemCT_HDB(CT_HDBAN ct_hdb)
 {
     try
     {
         db.CT_HDBANs.InsertOnSubmit(ct_hdb);
         db.SubmitChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
        public Boolean XoaCT_HDB(int pMaSP)
        {
            try
            {
                //CT_HDBAN ct_hdb = db.CT_HDBANs.Where(t => Convert.ToString(t.MaSP) == pMaSP).FirstOrDefault();
                CT_HDBAN ct_hdb = db.CT_HDBANs.Where(t => t.MaSP == pMaSP).FirstOrDefault();

                db.CT_HDBANs.DeleteOnSubmit(ct_hdb);
                db.SubmitChanges();

                return(true);
            }
            catch
            {
                return(false);
            }
        }