Exemplo n.º 1
0
        private void savedatabase()
        {
            int dem = -1;
            DataClasses1DataContext db     = new DataClasses1DataContext();
            Table <TBL_SANPHAM>     tbsanp = db.GetTable <TBL_SANPHAM>();

            foreach (TBL_SANPHAM r in tbsanp)
            {
                if (r.MASANPHAM != null)
                {
                    dem += 1;
                }
            }
            TBL_SANPHAM a = new TBL_SANPHAM();


            for (int j = dem + 1; j < dataGridViewnhapkho.Rows.Count - 1; j++)
            {
                ModuleDB.cnn = new SqlConnection(ModuleDB.cnnstr);
                SqlCommand cm = new SqlCommand("SELECT dbo.fu_createMANK()", ModuleDB.cnn);
                ModuleDB.cnn.Open();
                a.MASANPHAM = cm.ExecuteScalar().ToString();
                nhapkho.EndCurrentEdit();
                a.TENSANPHAM  = dataGridViewnhapkho.Rows[j].Cells[1].Value.ToString();
                a.LOAISANPHAM = dataGridViewnhapkho.Rows[j].Cells[2].Value.ToString();
                a.SOLUONG     = (int)dataGridViewnhapkho.Rows[j].Cells[3].Value;
                a.GIA         = (double)dataGridViewnhapkho.Rows[j].Cells[4].Value;
                a.THOIGIAN    = dateTimePicker1.Value;
                db.TBL_SANPHAMs.InsertOnSubmit(a);
                db.SubmitChanges();
                ModuleDB.cnn.Close();
            }
            MessageBox.Show("Thêm vào kho thành công");
        }
Exemplo n.º 2
0
 private void dataGridViewnhapkho_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.ColumnIndex <= 6 && e.RowIndex >= 0)
     {
         if (e.ColumnIndex == 5)
         {
             nhapkho.Position = e.RowIndex;
             DataClasses1DataContext db = new DataClasses1DataContext();
             TBL_SANPHAM             a  = new TBL_SANPHAM();
             a = (TBL_SANPHAM)nhapkho.Current;
             TBL_SANPHAM b = new TBL_SANPHAM();
             b = db.TBL_SANPHAMs.Single(p => p.MASANPHAM.Equals(a.MASANPHAM));
             db.TBL_SANPHAMs.DeleteOnSubmit(b);
             db.SubmitChanges();
             MessageBox.Show("Xóa thành công");
             loaddatagrid();
         }
     }
     nhapkho.Position = 0;
 }
 partial void DeleteTBL_SANPHAM(TBL_SANPHAM instance);
 partial void UpdateTBL_SANPHAM(TBL_SANPHAM instance);
 partial void InsertTBL_SANPHAM(TBL_SANPHAM instance);