示例#1
0
        private void button12_Click(object sender, EventArgs e)
        {
            DataClasses1DataContext db = new DataClasses1DataContext();

            tbsanpham = db.GetTable <TBL_HOADONCT>();
            int i = 1;

            TBL_HOADONCT    a = new TBL_HOADONCT();
            TBL_LOAISANPHAM b = new TBL_LOAISANPHAM();

            a.PHANBIET   = i;
            a.MASAPHAM   = cbxtensanpham.SelectedValue.ToString();
            a.TENSANPHAM = cbxtensanpham.Text;
            a.SOLUONG    = (int)numericUpDownsoluong.Value;
            a.MAHDBAN    = tbxmahoadon.Text;
            b            = db.TBL_LOAISANPHAMs.Single(p => p.MASANPHAM.Equals(a.MASAPHAM));
            a.GIA        = b.DONGIA * (double)numericUpDownsoluong.Value;
            a.THANHTOAN  = false;
            a.SOBAN      = int.Parse(tbxtenban.Text.Substring(4, 1));
            db.TBL_HOADONCTs.InsertOnSubmit(a);
            db.SubmitChanges();
            tbhoadonct.ghi();
            datagridviewspdadat.AutoGenerateColumns = false;

            datagridviewspdadat.DataSource = tbsanpham.Where(p => p.MAHDBAN.Equals(tbxmahoadon.Text));
            loadtongtien();
            i++;
        }
示例#2
0
        private void datagridviewspdadat_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0 && e.ColumnIndex <= 5)
            {
                int INDEX = 0;
                foreach (DataGridViewRow r in datagridviewspdadat.Rows)
                {
                    if (r.Index == e.RowIndex)
                    {
                        INDEX = int.Parse(r.Cells[0].Value.ToString());
                    }
                }
                MessageBox.Show(e.ColumnIndex.ToString());
                if (e.ColumnIndex == 4)
                {
                    DataClasses1DataContext db = new DataClasses1DataContext();
                    tbsanpham = db.GetTable <TBL_HOADONCT>();

                    //TBL_HOADONCT a = new TBL_HOADONCT();
                    //a = (TBL_HOADONCT)hoadonct.Current;

                    TBL_HOADONCT b = db.TBL_HOADONCTs.Single(p => p.MAHDBAN.Equals(tbxmahoadon.Text) && p.PHANBIET.Equals(INDEX));
                    b.SOLUONG += 1;
                    db.SubmitChanges();
                    TBL_HOADONCT c = db.TBL_HOADONCTs.Single(p => p.MAHDBAN.Equals(tbxmahoadon.Text) && p.PHANBIET.Equals(INDEX));
                    c.GIA = c.SOLUONG * c.GIA;
                    db.SubmitChanges();
                    tbhoadonct.ghi();

                    //datagridviewspdadat.AutoGenerateColumns = false;
                    //tbhoadonct.DefaultView.RowFilter = "MAHDBAN='" + tbxmahoadon.Text + "'";
                    datagridviewspdadat.DataSource = tbsanpham.Where(p => p.MAHDBAN.Equals(tbxmahoadon.Text));
                    loadtongtien();
                }


                else
                if (e.ColumnIndex == 5)
                {
                    DataClasses1DataContext db = new DataClasses1DataContext();
                    tbsanpham = db.GetTable <TBL_HOADONCT>();
                    TBL_HOADONCT a = (TBL_HOADONCT)hoadonct.Current;
                    TBL_HOADONCT b = new TBL_HOADONCT();
                    b = db.TBL_HOADONCTs.Single(p => p.MAHDBAN.Equals(tbxmahoadon.Text) && p.PHANBIET.Equals(INDEX));
                    db.TBL_HOADONCTs.DeleteOnSubmit(b);
                    db.SubmitChanges();
                    //datagridviewspdadat.AutoGenerateColumns = false;
                    //tbhoadonct.DefaultView.RowFilter = "MAHDBAN='" + tbxmahoadon.Text + "'";
                    datagridviewspdadat.DataSource = tbsanpham.Where(p => p.MAHDBAN.Equals(tbxmahoadon.Text));
                    loadtongtien();
                }
            }
        }
 partial void DeleteTBL_HOADONCT(TBL_HOADONCT instance);
 partial void UpdateTBL_HOADONCT(TBL_HOADONCT instance);
 partial void InsertTBL_HOADONCT(TBL_HOADONCT instance);