public static PayAgentLogger Instance() { if (_instance == null) { _instance = new PayAgentLogger(); } return(_instance); }
public void InsertNew(Operation card) { Operation existingCard = getOperation(card.SessionID); if (existingCard != null) { //throw new NotImplementedException(); PayAgentLogger.Instance().logError("+++++ Operation " + card.SessionID + " exist. Error. "); return; } StringBuilder columns = new StringBuilder(); StringBuilder parameters = new StringBuilder(); conn.Open(); try { SqlCommand cmd = new SqlCommand();//cmdStrPermCard, conn); cmd.Parameters.Add("@SessionID", System.Data.SqlDbType.NVarChar, 50 /*BigInt*/).Value = card.SessionID; columns.Append("[SessionID]"); parameters.Append("@SessionID"); if (card.ClientAccountID.HasValue) { columns.Append(",[ClientAccountID]"); parameters.Append("," + "@ClientAccountID"); cmd.Parameters.Add("@ClientAccountID", System.Data.SqlDbType.Int).Value = card.ClientAccountID; } if (card.ContractBindID.HasValue) { columns.Append(",[ContractBindID]"); parameters.Append("," + "@ContractBindID"); cmd.Parameters.Add("@ContractBindID", System.Data.SqlDbType.Int).Value = card.ContractBindID; } if (card.ContrAgentAccountID.HasValue) { columns.Append(",[ContrAgentAccountID]"); parameters.Append("," + "@ContrAgentAccountID"); cmd.Parameters.Add("@ContrAgentAccountID", System.Data.SqlDbType.Int).Value = card.ContrAgentAccountID; } if (card.ContrAgentClientAccountID.HasValue) { columns.Append(",[ContrAgentClientAccountID]"); parameters.Append("," + "@ContrAgentClientAccountID"); cmd.Parameters.Add("@ContrAgentClientAccountID", System.Data.SqlDbType.Int).Value = card.ContrAgentClientAccountID; } if (card.CurrentDate.HasValue) { columns.Append(",[CurrentDate]"); parameters.Append("," + "@CurrentDate"); cmd.Parameters.Add("@CurrentDate", System.Data.SqlDbType.DateTime).Value = card.CurrentDate; } if (card.DuetOperCode.HasValue) { columns.Append("," + "[DuetOperCode]"); parameters.Append("," + "@DuetOperCode"); cmd.Parameters.Add("@DuetOperCode", System.Data.SqlDbType.Int).Value = card.DuetOperCode; } if (!string.IsNullOrEmpty(card.DuetOperNote)) { columns.Append("," + "[DuetOperNote]"); parameters.Append("," + "@DuetOperNote"); cmd.Parameters.Add("@DuetOperNote", System.Data.SqlDbType.NVarChar, 250).Value = card.DuetOperNote; } if (card.ExternalDocDate.HasValue) { columns.Append(",[ExternalDocDate]"); parameters.Append("," + "@ExternalDocDate"); cmd.Parameters.Add("@ExternalDocDate", System.Data.SqlDbType.DateTime).Value = card.ExternalDocDate; } if (!string.IsNullOrEmpty(card.ExternalDocNumber)) { columns.Append(",[ExternalDocNumber]"); parameters.Append("," + "@ExternalDocNumber"); cmd.Parameters.Add("@ExternalDocNumber", System.Data.SqlDbType.NVarChar, 50).Value = card.ExternalDocNumber; } if (card.feeAmount.HasValue) { columns.Append(",[feeAmount]"); parameters.Append("," + "@feeAmount"); cmd.Parameters.Add("@feeAmount", System.Data.SqlDbType.Decimal).Value = card.feeAmount; } //if (card.Email != null) //{ columns.Append(",[FunctionType]"); parameters.Append("," + "@FunctionType"); cmd.Parameters.Add("@FunctionType", System.Data.SqlDbType.NVarChar, 40).Value = card.FunctionType; //} if (!string.IsNullOrEmpty(card.PaymentDetails)) { columns.Append(",[PaymentDetails]"); parameters.Append("," + "@PaymentDetails"); cmd.Parameters.Add("@PaymentDetails", System.Data.SqlDbType.NVarChar, 250).Value = card.PaymentDetails; } if (card.Result.HasValue) { columns.Append(",[Result]"); parameters.Append("," + "@Result"); cmd.Parameters.Add("@Result", System.Data.SqlDbType.Int).Value = card.Result; } if (!string.IsNullOrEmpty(card.ResultLog)) { columns.Append(",[ResultLog]"); parameters.Append("," + "@ResultLog"); cmd.Parameters.Add("@ResultLog", System.Data.SqlDbType.NVarChar, 250).Value = card.ResultLog; } if (!string.IsNullOrEmpty(card.ResultNote)) { columns.Append(",[ResultNote]"); parameters.Append("," + "@ResultNote"); cmd.Parameters.Add("@ResultNote", System.Data.SqlDbType.NVarChar, 250).Value = card.ResultNote; } //if (card.State != null) //{ columns.Append(",[TransactAmount]"); parameters.Append("," + "@TransactAmount"); cmd.Parameters.Add("@TransactAmount", System.Data.SqlDbType.Decimal).Value = card.TransactAmount; //} cmd.Connection = conn; cmd.CommandText = insertOperationBeginning + columns.ToString() + insertOperationMiddle + parameters.ToString() + insertOperationEnd; int rows = cmd.ExecuteNonQuery(); } catch (Exception ex) { PayAgentLogger.Instance().logError("Operation was not inserted: " + card.ToString() + " Reason: " + ex.Message); } finally { conn.Close(); } }
/// <summary> /// Update can occur only on 5 fields - Result, ResultLog, ResultNote, DuetoperCode, DuetOperNode /// </summary> /// <param name="card"></param> public void UpdateExisting(Operation card) { Operation existingCard = getOperation(card.SessionID); int rows = 0; StringBuilder parameters = new StringBuilder(); conn.Open(); try { SqlCommand cmd = new SqlCommand(); cmd.Parameters.Add("@SessionID", System.Data.SqlDbType.NVarChar, 50 /*BigInt*/).Value = card.SessionID; if (card.Result.HasValue) { parameters.Append("[Result]=@Result"); cmd.Parameters.Add("@Result", System.Data.SqlDbType.Int).Value = card.Result; } if (!string.IsNullOrEmpty(card.ResultLog)) { parameters.Append("," + "[ResultLog]=@ResultLog"); cmd.Parameters.Add("@ResultLog", System.Data.SqlDbType.NVarChar, 250).Value = card.ResultLog; } if (!string.IsNullOrEmpty(card.ResultNote)) { parameters.Append("," + "[ResultNote]=@ResultNote"); cmd.Parameters.Add("@ResultNote", System.Data.SqlDbType.NVarChar, 250).Value = card.ResultNote; } if (!string.IsNullOrEmpty(card.DuetOperNote)) { parameters.Append("," + "[DuetOperNote]=@DuetOperNote"); cmd.Parameters.Add("@DuetOperNote", System.Data.SqlDbType.NVarChar, 250).Value = card.DuetOperNote; } if (card.DuetOperCode.HasValue) { parameters.Append("," + "[DuetOperCode]=@DuetOperCode"); cmd.Parameters.Add("@DuetOperCode", System.Data.SqlDbType.Int).Value = card.DuetOperCode; } if (card.CurrentDate.HasValue) { parameters.Append("," + "[CurrentDate]=@CurrentDate"); cmd.Parameters.Add("@CurrentDate", System.Data.SqlDbType.DateTime).Value = card.CurrentDate; } cmd.Connection = conn; cmd.CommandText = updateOperationBeginning + parameters.ToString() + updateOperationEnd; rows = cmd.ExecuteNonQuery(); } catch (Exception ex) { //trans.Rollback(); PayAgentLogger.Instance().logError("error updating the rows in DB (PermCard). The info for PermCard " + card.ToString() + " was not updated. Reason: " + ex.Message); } finally { conn.Close(); } }