private void btnLuu_Click(object sender, EventArgs e) { string email = this.txtEmail.Text; string hoTen = this.txtTen.Text; string sdt = this.txtPhone.Text; string diaChi = this.txtAddress.Text; int id = 1; double congNo = 0; bool isMan = this.rdNam.Checked; DateTime dob = this.dtDoB.Value; if (email == "" || hoTen == "" || sdt == "") { MessageBox.Show("Vui lòng điền đầy đủ thông tin!", "Thông Báo!", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (this.txtCongNo.Text == "") { this.txtCongNo.Text = "0"; } try { id = Int32.Parse(this.txtID.Text); congNo = Double.Parse(this.txtCongNo.Text); } catch { id = 1; congNo = 0; } Entity_KhachHang _kh = new Entity_KhachHang(id, hoTen, sdt, email, diaChi, dob, isMan, congNo); if (kh.insertKhachHang(_kh) == true) { MessageBox.Show("Thêm thành công khách hàng!", "Thông Báo!", MessageBoxButtons.OK, MessageBoxIcon.Information); this.gwKhachHang.DataSource = kh.getData(); } else { MessageBox.Show("Có lỗi xảy ra, không thể thêm!", "Thông Báo!", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public bool insertKhachHang(Entity_KhachHang _kh) { try { const string strSQL = "SP_INSERT_KHACHHANG"; string[] pNames = { "@id", "@ten", "@sdt", "@email", "@diaChi", "@ngaySinh", "@gender", "@congNo" }; object[] pValues = { _kh.KhId, _kh.Ten, _kh.Sdt, _kh.Email, _kh.DiaChi, _kh.NgaySinh, _kh.GioiTinh, _kh.CongNo }; int count = con.ExecuteStoredProcedure(strSQL, pNames, pValues); if (count >= 0) { return(true); } else { return(false); } } catch { return(false); } }
public bool insertKhachHang(Entity_KhachHang _kh) { return(kh.insertKhachHang(_kh)); }