Advertisement
Advertisement
| 01.03.2008 at 12:48AM PST, ID: 23055059 |
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: |
using System.Collections.Generic;
public class chapter
{
public string tpr_uid;
public float price;
}
[WebMethod]
public string AddSampleResources(int UserID, int SiteID, int RelativeExpiration, string TransactionID, List<chapter> lst, out string sErrorMessage)
{
string b_uid = "";
string status = "Success";
string FirstName = "";
string LastName = "";
string UserEmail = "";
string sSelectStmt ="";
int affectedrows = 0;
DataView dtvUserInfo = new DataView();
sErrorMessage = "";
try
{
if (UserID.Equals(0) || SiteID.Equals(0) || lst.Equals(""))
{
sErrorMessage = "Incomplete Data.";
status = "Failed";
}
if (RelativeExpiration.Equals(0))
{
RelativeExpiration = 365;
}
DateTime today = DateTime.Now;
//Calculating ExpirationDate
DateTime ExpirationDate = today.AddDays(RelativeExpiration);
string connstr = System.Configuration.ConfigurationSettings.AppSettings.Get("ConnString");
SqlConnection conn = new SqlConnection(connstr);
int i = 0;
int j = 0;
sSelectStmt = "select UserEmail,FirstName,LastName from tblUserProfile(nolock) where UserID= '" + UserID + "'";
dtvUserInfo = DML.GetRecords(sSelectStmt, connstr);
if (dtvUserInfo.Count == 0)
{
sErrorMessage = "User not found";
status = "Failed";
}
UserEmail = dtvUserInfo[0]["UserEmail"].ToString();
FirstName = dtvUserInfo[0]["FirstName"].ToString();
LastName = dtvUserInfo[0]["LastName"].ToString();
while (j < lst.Count)
{
if (lst.Count - j == 1)
{
b_uid = b_uid + lst[j].tpr_uid;
}
else
{
b_uid = b_uid + lst[j].tpr_uid + ",";
}
j++;
}
while (i < lst.Count)
{
SqlCommand cmd = new SqlCommand("Insert into tblContentAssignments values('" + SiteID + "' ,'" + UserID + "' ,'" + lst[i].tpr_uid + "','" + TransactionID + "','" + DateTime.Now + "','" + RelativeExpiration + "','" + ExpirationDate + "',convert(money,'" + lst[i].price + "')) ", conn);//Insert into tblContentAssignment
conn.Open();
affectedrows = affectedrows+ cmd.ExecuteNonQuery();
conn.Close();
i++;
}
if (affectedrows < lst.Count)
{
status = "Failed";
}
}
catch (SqlException ex)
{
WriteEvent(ex, UserID, SiteID, b_uid, UserEmail, FirstName, LastName);
status = "Failed";
}
return status;
}
void WriteEvent(SqlException ex, int UserID, int SiteID, string b_uid, string UserEmail, string FirstName, string LastName)
{
EventLog ev = new EventLog("Application");
// Event's Source name
ev.Source = ex.Source;
if (!EventLog.SourceExists(ev.Source))
//EventLog.CreateEventSource(ev.Source, sLog);
EventLog.CreateEventSource(ev.Source, "Application");
ev.WriteEntry("UserName:'" + FirstName + "' '" + LastName + "' UserID:'" + UserID + "' SiteID:'" + SiteID + "' tpr_uid:'" + b_uid + "' Exception:'" + ex.Message + "' ErrorCode:'" + ex.ErrorCode + "' ");
ev = null;
MailMessage objMail = new MailMessage();
objMail.From = "admin@tprpub.com";
objMail.To = "transaction@tprpub.com";
objMail.Subject = "Subject: Error Information";
objMail.Body = "Here is your requested info: " + "\n" +
"FirstName " + FirstName + "\n" +
"LastName " + LastName + "\n" +
"UserID " + UserID + "\n" +
"SiteID " + SiteID + "\n" +
"Email " + UserEmail + "\n" +
"tpr_uid '" + b_uid + "' ErrorCode: '" + ex.ErrorCode + "'";
objMail.Priority = MailPriority.High;
SmtpMail.SmtpServer = "...";
SmtpMail.Send(objMail);
}
|