Ejemplo n.º 1
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            if (txtTenNCC.Text.Length <= 0 || txtDiaChi.Text.Length <= 0)
            {
                MessageBox.Show("Yêu cầu nhập đầy đủ thông tin!", "Thông báo", MessageBoxButtons.OK);
                return;
            }
            try
            {
                double phone_number = double.Parse(txtDienThoai.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("Số điện thoại phải là số!", "Thông báo", MessageBoxButtons.OK);
                return;
            }
            nha_cung_cap entity = new nha_cung_cap();

            entity.ten_nha_cung_cap = txtTenNCC.Text;
            entity.dia_chi          = txtDiaChi.Text;
            entity.so_dien_thoai    = txtDienThoai.Text;
            db.nha_cung_cap.Add(entity);
            db.SaveChanges();
            MessageBox.Show("Thêm dữ liệu thành công!", "Thông báo", MessageBoxButtons.OK);
            this.Hide();
        }
Ejemplo n.º 2
0
 private void dgvHoaDonMua_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
 {
     if (this.dgvHoaDonMua.Columns[e.ColumnIndex].Name == "nha_cung_cap_mua")
     {
         if (e.Value != null)
         {
             nha_cung_cap supplier = db.nha_cung_cap.Find(e.Value);
             e.Value = supplier.ten_nha_cung_cap;
         }
     }
     if (this.dgvHoaDonMua.Columns[e.ColumnIndex].Name == "tong_tien_mua")
     {
         if (e.Value != null)
         {
             e.Value = String.Format("{0:0,0}", e.Value);
         }
     }
 }
Ejemplo n.º 3
0
 private void btnXoaNCC_Click(object sender, EventArgs e)
 {
     try
     {
         if (db.hoa_don_mua.Where(x => x.ma_nha_cung_cap == nha_cung_cap_id).ToList().Count > 0)
         {
             MessageBox.Show("Nhà cung cấp này liên quan đến nhiều dữ liệu khác, không thể xóa!", "Chúc mừng", MessageBoxButtons.OK);
             return;
         }
         if (MessageBox.Show(null, "Bạn có chắc chắn muốn xóa không?", "Xác nhận", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
         {
             nha_cung_cap entity = new nha_cung_cap();
             entity = db.nha_cung_cap.SingleOrDefault(x => x.ma_nha_cung_cap == nha_cung_cap_id);
             db.nha_cung_cap.Remove(entity);
             db.SaveChanges();
             refresh();
             MessageBox.Show("Xóa dữ liệu thành công!", "Chúc mừng", MessageBoxButtons.OK);
         }
     }
     catch (Exception)
     {
         MessageBox.Show("Xóa thất bại", "Lỗi", MessageBoxButtons.OK);
     }
 }