public bool Remove(VendorQuote data, ref string msgError) { SqlConnection oConn = null; try { oConn = ConnManager.OpenConn(); } catch (Exception ex) { LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message); msgError = ex.Message; return(false); }; bool result; try { result = Remove(data, oConn); } catch (Exception ex) { ConnManager.CloseConn(oConn); LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message); return(false); } ConnManager.CloseConn(oConn); return(result); }
public VendorQuote Add(VendorQuote data, ref string msgError) { SqlConnection oConn = null; try { oConn = ConnManager.OpenConn(); } catch (Exception ex) { LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message); throw; }; string sql = "INSERT INTO VendorQuotes ({0}) VALUES ({1}) " + "SELECT SCOPE_IDENTITY()"; EnumExtension.setListValues(data, "VendorQuoteId", ref sql); SqlTransaction oTX = oConn.BeginTransaction(); SqlCommand cmd = new SqlCommand(sql, oConn, oTX); int keyGenerated = 0; try { keyGenerated = Convert.ToInt32(cmd.ExecuteScalar()); } catch (Exception ex) { cmd.Dispose(); oTX.Rollback(); ConnManager.CloseConn(oConn); LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message); msgError = ex.Message; return(null); } oTX.Commit(); cmd.Dispose(); VendorQuote returnData = Get(keyGenerated, oConn); ConnManager.CloseConn(oConn); return(returnData); }
private bool Remove(VendorQuote data, SqlConnection oConn) { string sql = "DELETE FROM VendorQuotes WHERE VendorQuoteId = @id"; SqlCommand cmd = new SqlCommand(sql, oConn); cmd.Parameters.Add("@id", SqlDbType.Int).Value = data.VendorQuoteId; int number = Convert.ToInt32(cmd.ExecuteNonQuery()); if (number > 0) { return(true); } return(false); }
public VendorQuote Get(int id, ref string msgError) { SqlConnection oConn = null; try { oConn = ConnManager.OpenConn(); } catch (Exception ex) { LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message); msgError = ex.Message; return(null); }; VendorQuote data = Get(id, oConn); ConnManager.CloseConn(oConn); return(data); }
public VendorQuote Update(VendorQuote data, ref string msgError) { SqlConnection oConn = null; try { oConn = ConnManager.OpenConn(); } catch (Exception ex) { LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message); throw; }; string sql = "UPDATE VendorQuotes SET {0} WHERE VendorQuoteId = @id"; EnumExtension.setUpdateValues(data, "VendorQuoteId", ref sql); SqlCommand cmd = new SqlCommand(sql, oConn); cmd.Parameters.Add("@id", SqlDbType.Int).Value = data.VendorQuoteId; try { cmd.ExecuteNonQuery(); } catch (Exception ex) { ConnManager.CloseConn(oConn); LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message); msgError = ex.Message; return(null); } VendorQuote returnData = Get(data.VendorQuoteId, oConn); ConnManager.CloseConn(oConn); return(returnData); }