public cEMail() { EMailID = -1; SortedList sParams = new SortedList(); DataTable dtEmailTypes = cUtilities.LoadDataTable("uspGetEmailTypes", sParams, "LARPortal", "", "cEmail.Creator"); EmailTypes = new List <cEmailType>(); if (new DataView(dtEmailTypes, "EmailTypeID = 0", "", DataViewRowState.CurrentRows).Count == 0) { cEmailType NewEmailType = new cEmailType(); NewEmailType.EmailTypeID = 0; NewEmailType.EmailType = "Choose..."; EmailTypes.Add(NewEmailType); } foreach (DataRow dRow in dtEmailTypes.Rows) { cEmailType NewEmailType = new cEmailType(); NewEmailType.EmailTypeID = dRow["EmailTypeID"].ToString().ToInt32(); NewEmailType.EmailType = dRow["EmailType"].ToString(); EmailTypes.Add(NewEmailType); } EmailTypeID = 0; }
// Passing an ID of -1 should produce the devault values, and on update should generate a new record. public cEMail(Int32 intEMailID, string strUserName, Int32 intUserID) { MethodBase lmth = MethodBase.GetCurrentMethod(); // this is where we use refelection to store the name of the method and class to use it to report errors string lsRoutineName = lmth.DeclaringType + "." + lmth.Name; _UserName = strUserName; _UserID = intUserID; _EMailID = intEMailID; try { SortedList slParams = new SortedList(); slParams.Add("@intEMailID", intEMailID); // need to put the correct stored procedure in to the class DataSet lds = cUtilities.LoadDataSet("uspGetEmailData", slParams, "LARPortal", strUserName, lsRoutineName); if (lds.Tables[0].Rows.Count > 0) { DataRow dRow = lds.Tables[0].Rows[0]; _EMailID = dRow["EMailID"].ToString().ToInt32(); // Now checking for both DBNull and null. Added the bool.TryParse because I'm OCD. JBradshaw 9/14/2015 bool bTemp; if (dRow["PrimaryEmail"] != DBNull.Value) { if (dRow["PrimaryEmail"] != null) { if (bool.TryParse(dRow["PrimaryEmail"].ToString(), out bTemp)) { IsPrimary = bTemp; } } } // Now checking for both DBNull and null. Added the int.TryParse because I'm OCD. JBradshaw 9/14/2015 int iTemp; if (dRow["EmailTypeID"] != DBNull.Value) { if (dRow["EmailTypeID"] != null) { if (int.TryParse(dRow["EmailTypeID"].ToString(), out iTemp)) { EmailTypeID = iTemp; } } } _EMailAddress = dRow["EMailAddress"].ToString().Trim(); _Comments = dRow["Comments"].ToString().Trim(); _DateAdded = Convert.ToDateTime(dRow["DateAdded"].ToString()); _DateChanged = Convert.ToDateTime(dRow["DateChanged"].ToString()); if (dRow["DateDeleted"] == DBNull.Value) { _DateDeleted = null; } else { _DateDeleted = Convert.ToDateTime(dRow["DateDeleted"].ToString()); } } if (lds.Tables.Count > 1) { EmailTypes = new List <cEmailType>(); foreach (DataRow dRow in lds.Tables[1].Rows) { cEmailType NewEmailType = new cEmailType(); NewEmailType.EmailTypeID = dRow["EmailTypeID"].ToString().ToInt32(); NewEmailType.EmailType = dRow["EmailType"].ToString(); EmailTypes.Add(NewEmailType); } } } catch (Exception ex) { ErrorAtServer lobjError = new ErrorAtServer(); lobjError.ProcessError(ex, lsRoutineName, _UserName + lsRoutineName); } }