Ejemplo n.º 1
0
        private void LuuThongTinNCC()
        {
            //kiểm tra xem đã có ncc này trong db chưa? nếu chưa thì lưu mới
            string maNCC = txtMaNCC.Text.Trim();

            foreach (NhaCungCap ncc in new QuanLyBanHoaEntities().NhaCungCap)
            {
                if (ncc.MaNCC.ToString() == maNCC)
                {
                    return; // nếu có rồi thì thoát
                }
            }

            // ngược lại lưu mới
            string tenNCC = txtTenNCC.Text.Trim();
            string diaChi = txtDiaChi.Text.Trim();
            string sdt = txtDienThoai.Text.Trim();

            dbNCC.InsertNhaCC(maNCC, tenNCC, diaChi, sdt);
        }
        private void btnLuu_Click(object sender, EventArgs e)
        {
            string maNCC = txtMaNCC.Text.Trim();

            if (isInsert == true)
            {
                if (!dbNCC.InsertNhaCC(maNCC, txtTenNCC.Text.Trim(),
                                       txtDiaChi.Text.Trim(), txtSDT.Text.Trim()))
                {
                    MessageBox.Show("Không thêm được dữ liệu.n", "Lỗi");
                    txtMaNCC.Focus();
                    return;
                }
                else
                {
                    isInsert = false;
                }
            }
            else
            {
                if (!dbNCC.UpdateNhaCC(maNCC, txtTenNCC.Text.Trim(),
                                       txtDiaChi.Text.Trim(), txtSDT.Text.Trim()))
                {
                    MessageBox.Show("Không cập nhật được dữ liệu.", "Lỗi");
                    txtTenNCC.Focus();
                    return;
                }
            }
            DataLoad();
            SetSelectedRow(maNCC);

            btnThem.Enabled  = true;
            btnSua.Enabled   = true;
            btnHuy.Enabled   = false;
            btnLuu.Enabled   = false;
            txtMaNCC.Enabled = true;
        }