//Update info khách hàng public bool UpdateCustomer(customerDTO customerDTO) { try { this.openConnection(); SqlCommand cmd = new SqlCommand("update CUSTOMER set fname = @fname, lname = @lname, gender = @gender, address = @address, phone = @phone where id = @id", this.getConnection); cmd.Parameters.Add("@fname", SqlDbType.NChar).Value = customerDTO.fname; cmd.Parameters.Add("@lname", SqlDbType.NChar).Value = customerDTO.lname; cmd.Parameters.Add("@gender", SqlDbType.NChar).Value = customerDTO.gender; cmd.Parameters.Add("@address", SqlDbType.NVarChar).Value = customerDTO.address; cmd.Parameters.Add("@phone", SqlDbType.Int).Value = customerDTO.phone; cmd.Parameters.Add("@id", SqlDbType.NChar).Value = customerDTO.id; if (cmd.ExecuteNonQuery() == 1) { return(true); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { this.closeConnection(); } return(false); }
//insert customer vô bảng public bool insertCustomer(customerDTO customerDTO) { try { this.openConnection(); SqlCommand cmd = new SqlCommand("INSERT INTO CUSTOMER(id, fname, lname, gender, address, phone, status)" + "VALUES (@id, @fname, @lname, @gender, @address, @phone, @status)", this.getConnection); cmd.Parameters.Add("@id", SqlDbType.NChar).Value = customerDTO.id; cmd.Parameters.Add("@fname", SqlDbType.NChar).Value = customerDTO.fname; cmd.Parameters.Add("@lname", SqlDbType.NChar).Value = customerDTO.lname; cmd.Parameters.Add("@gender", SqlDbType.NChar).Value = customerDTO.gender; cmd.Parameters.Add("@address", SqlDbType.NVarChar).Value = customerDTO.address; cmd.Parameters.Add("@phone", SqlDbType.Int).Value = customerDTO.phone; cmd.Parameters.Add("@status", SqlDbType.Int).Value = customerDTO.status; if (cmd.ExecuteNonQuery() == 1) { return(true); } } catch (Exception ex) { MessageBox.Show("Error: ", ex.Message); } finally { this.closeConnection(); } return(false); }
public async Task <ActionResult <customerDTO> > Createcustomer(customerDTO cus2) { var cus1 = cus2.toCustomer(); _context.customers.Add(cus1); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(Getcustomer), new { id = cus1.id }, cus1)); }
public async Task <IActionResult> Updatecustomer(customerDTO cus2) { var cus1 = await _context.customers.FindAsync(cus2.id); if (cus1 == null) { return(NotFound()); } cus1.Mapto4(cus2); _context.customers.Update(cus1); try{ await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) when(!CusExist(cus1.id)) { return(NotFound()); } return(NoContent()); }
private void btnAdd_Click(object sender, EventArgs e) { if (!this.verify()) { try { string cccd = this.txtCCCD.Text; string fname = this.txtFname.Text; string lname = this.txtLname.Text; string gender = ""; if (this.rbMale.Checked == true) { gender = "Nam"; } else { gender = "Nữ"; } string address = this.rtxtAddress.Text; int phone = int.Parse(this.txtPhone.Text); customerDTO customerDTO = new customerDTO(cccd, fname, lname, gender, address, phone, this.status); if (this.customerBUS.insertCustomer(customerDTO)) { MessageBox.Show("Thêm thông tin khách hàng thành công", "Khách Thuê", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Thêm thông tin khách hàng không thành công", "Khách Thuê", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); } } else { MessageBox.Show("Empty Fields", "Khách Thuê", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
//insert customer public bool insertCustomer(customerDTO customerDTO) { return(this.customerDAL.insertCustomer(customerDTO)); }
//Update info khách hàng public bool UpdateCustomer(customerDTO customerDTO) { return(this.customerDAL.UpdateCustomer(customerDTO)); }