private void btnCamKet_Click(object sender, EventArgs e) { try { string idContract = this.txtIDContract.Text.Trim(); string idCustomer = this.dgv_CusThue.CurrentRow.Cells[0].Value.ToString().Trim(); string idVehicle = this.lbBienSo.Text.Trim(); DateTime dateSign = this.dtPicker1.Value; float totalCost = float.Parse(this.txtCost.Text.Trim()); string idEmployee = Global.GlobalEmployeeId; contract_ThueDTO contract_ThueDTO = new contract_ThueDTO(idContract, idCustomer, idVehicle, dateSign, totalCost, idEmployee); if (this.contract_ThueBUS.insertContract_Thue(contract_ThueDTO)) { MessageBox.Show("Thêm hợp đồng thành công", "Contract Thuê", MessageBoxButtons.OK, MessageBoxIcon.Information); this.LoadVehicleChoThue_DGV(); } else { MessageBox.Show("Thêm hợp đồng không thành công", "Contract Thuê", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); } }
//insert public bool insertContract_Thue(contract_ThueDTO contract_ThueDTO) { try { this.openConnection(); SqlCommand cmd = new SqlCommand("INSERT INTO CONTRACT_THUE(id, idCustomer, idVehicle, dateSign, TotalCost, idEmployee)" + "VALUES (@id1, @id2, @id3, @ds, @TotalCost, @idEmployee)", this.getConnection); cmd.Parameters.Add("@id1", SqlDbType.NChar).Value = contract_ThueDTO.id; cmd.Parameters.Add("@id2", SqlDbType.NChar).Value = contract_ThueDTO.idCustomer; cmd.Parameters.Add("@id3", SqlDbType.NChar).Value = contract_ThueDTO.idVehicle; cmd.Parameters.Add("@ds", SqlDbType.Date).Value = contract_ThueDTO.dateSign; cmd.Parameters.Add("@TotalCost", SqlDbType.Float).Value = contract_ThueDTO.TotalCost; cmd.Parameters.Add("@idEmployee", SqlDbType.NChar).Value = contract_ThueDTO.idEmployee; if (cmd.ExecuteNonQuery() == 1) { return(true); } } catch (Exception ex) { MessageBox.Show("Error:1 ", ex.Message); } finally { this.closeConnection(); } return(false); }
//insert public bool insertContract_Thue(contract_ThueDTO contract_ThueDTO) { return(this.contract_ThueDAL.insertContract_Thue(contract_ThueDTO)); }