//insert in db public void AddWorkorder(WorkOrder.Workorder wo) { try { using (conn) { string sqlInsertString = "INSERT INTO Workorders (wo_ID, wo_Number, wo_Date, wo_Debtor, wo_Address, wo_StartTime)" + "VALUES ( @wo_ID, @wo_Number, @wo_Date, @wo_Debtor, @wo_Address, @wo_StartTime)"; conn = new SqlConnection(connString); command = new SqlCommand(); command.Connection = conn; command.Connection.Open(); command.CommandText = sqlInsertString; SqlParameter wo_IDParam = new SqlParameter("@wo_ID", wo.wo_ID); SqlParameter wo_NumberParam = new SqlParameter("@wo_Number", wo.wo_Number); SqlParameter wo_DateParam = new SqlParameter("@wo_Date", wo.wo_Date); SqlParameter wo_DebtorParam = new SqlParameter("@wo_Debtor", wo.wo_Debtor); SqlParameter wo_AddressParam = new SqlParameter("@wo_Address", wo.wo_Address); SqlParameter wo_StartTimeParam = new SqlParameter("@wo_StartTime", wo.wo_StartTime); command.Parameters.AddRange(new SqlParameter[] { wo_IDParam, wo_NumberParam, wo_DateParam, wo_DebtorParam, wo_AddressParam, wo_StartTimeParam }); command.ExecuteNonQuery(); command.Connection.Close(); } } catch (Exception ex) { err.ErrorMessage = ex.Message.ToString(); throw; } }
// delete from db public void DeleteWorkorder(WorkOrder.Workorder wo) { try { using (conn) { string sqlDeleteStr = "DELETE Workorders WHERE wo_ID = @wo_ID"; conn = new SqlConnection(connString); SqlCommand command = new SqlCommand(); command.Connection = conn; command.Connection.Open(); command.CommandText = sqlDeleteStr; SqlParameter wo_IDParam = new SqlParameter("@wo_ID", wo.wo_ID); command.Parameters.AddRange(new SqlParameter[] { wo_IDParam }); command.ExecuteNonQuery(); command.Connection.Close(); } } catch (Exception ex) { err.ErrorMessage = ex.Message.ToString(); throw; } }
//db update public void UpdateWorkorder(WorkOrder.Workorder wo) { try { using (conn) { string sqlUpdateStr = "UPDATE Employee SET wo_id = @wo_ID, wo_Number = @wo_Number, wo_Date = @wo_Date, wo_Debtor = @wo_Debtor, " + " wo_Address = @wo_Address, wo_StartTime = @wo_StartTime" + " WHERE wo_ID = @wo_id"; conn = new SqlConnection(connString); SqlCommand command = new SqlCommand(); command.Connection = conn; command.Connection.Open(); command.CommandText = sqlUpdateStr; SqlParameter wo_IDParam = new SqlParameter("@wo_ID", wo.wo_ID); SqlParameter wo_NumberParam = new SqlParameter("@wo_Number", wo.wo_Number); SqlParameter wo_DateParam = new SqlParameter("@wo_Date", wo.wo_Date); SqlParameter wo_DebtorParam = new SqlParameter("@wo_Debtor", wo.wo_Debtor); SqlParameter wo_AddressParam = new SqlParameter("@wo_Address", wo.wo_Address); SqlParameter wo_StartTimeParam = new SqlParameter("@wo_StartTime", wo.wo_StartTime); command.Parameters.AddRange(new SqlParameter[] { wo_IDParam, wo_NumberParam, wo_DateParam, wo_DebtorParam, wo_AddressParam, wo_StartTimeParam }); command.ExecuteNonQuery(); command.Connection.Close(); } } catch (Exception ex) { err.ErrorMessage = ex.Message.ToString(); throw; } }