protected void btnReset_Click(object sender, EventArgs e) { if (txtNewPass2.Text.Length >= 5) { Linq_1DataContext db = new Linq_1DataContext(); var usr = (from a in db.WebAccounts where a.id == Convert.ToInt32(txtId.Text) select a).FirstOrDefault(); if (usr != null) { usr.Password = txtNewPass2.Text; db.SubmitChanges(); lblStatus.Text = "User's password has been reset."; } } else { lblStatus.Text = "Password must be at least 5 characters long."; } }
protected void btnSave_Click(object sender, EventArgs e) { int iCstId = 0; if (Request.QueryString["IsNew"] == "true") { Linq_1DataContext db = new Linq_1DataContext(); Customer c = new Customer(); c.Company = txtCompany.Text; c.Address = txtAddress.Text; c.City = txtCity.Text; if (txtZip.Text != "") { c.Zip = Convert.ToInt32(txtZip.Text); } c.FName = txtContact.Text; c.Phone = txtPhone.Text; c.Phone2 = txtPhone2.Text; c.Email = txtEmail.Text; try { db.Customers.InsertOnSubmit(c); db.SubmitChanges(); iCstId = c.id; } catch (Exception et) { Shared.WriteError(et, HttpContext.Current, "btnSave_Click"); } finally { string redir = "~/ticketdetail.aspx?IsNew=true&cst=" + iCstId.ToString() ; //string redir = "~/ticketdetail.aspx?IsNew=true"; Response.Redirect(redir); } } else { int cid = Convert.ToInt32(txtId.Text); Linq_1DataContext db = new Linq_1DataContext(); var t = (from a in db.Customers where a.id == cid select a).FirstOrDefault(); if (t != null) { t.Company = txtCompany.Text; t.FName = txtContact.Text; t.Address = txtAddress.Text; t.City = txtCity.Text; if (txtZip.Text != "") { t.Zip = Convert.ToInt32(txtZip.Text); } t.Email = txtEmail.Text; t.Phone = txtPhone.Text; t.Phone2 = txtPhone2.Text; try { db.SubmitChanges(); lblStatus.Text = "Customer " + cid.ToString() + " has been updated."; } catch (Exception et) { Shared.WriteError(et, HttpContext.Current, "btnSave_Click" ); } } } }
protected void btnYes_Click(object sender, EventArgs e) { //delete customer and confirm message - if customer has tickets, cannot delete Linq_1DataContext db = new Linq_1DataContext(); var hastickets = (from b in db.Trans where b.CstId == Convert.ToInt32(txtId.Text) select b.id).Count(); if (hastickets == 0) { var cst = (from b in db.Customers where b.id == Convert.ToInt32(txtId.Text) select b).FirstOrDefault(); if (cst != null) { try { db.Customers.DeleteOnSubmit(cst); db.SubmitChanges(); lblStatus.Text = "Customer has been deleted."; confirm.Visible = false; txtAddress.Text = txtCity.Text = txtCompany.Text = txtContact.Text = txtEmail.Text = txtId.Text = txtPhone.Text = txtPhone2.Text = txtZip.Text = ""; } catch (Exception ex) { lblStatus.Text = "Unable to delete customer, contact your web master."; confirm.Visible = false; } } } else { lblStatus.Text = "Customer has service tickets, cannot delete."; confirm.Visible = false; } }
private static void ErrorOnError(Exception ex) { EmailError(ex); Linq_1DataContext db = new Linq_1DataContext(); Error t = new Error(); t.LongDescription = ex.ToString(); t.ErrorDate = DateTime.Today; db.Errors.InsertOnSubmit(t); db.SubmitChanges(); }
public static void WriteError(Exception ex, HttpContext con, string method = "") { Linq_1DataContext db = new Linq_1DataContext(); Error t = new Error(); t.BrowserName = con.Request.UserAgent.ToString(); t.LongDescription = method + " " + ex.Message.ToString(); t.ErrorUser = (int)con.Session["userid"]; t.ErrorDate = DateTime.Today; try { db.Errors.InsertOnSubmit(t); db.SubmitChanges(); } catch (Exception e) { ErrorOnError(e); } }
protected void btnSave_Click(object sender, EventArgs e) { if (btnNew.Visible == false) { if (txtNewPass1.Text == "" || txtNewPass2.Text == "") { lblStatus.Text = "Please enter a new password for this user"; return; } //if (ddAccountType.SelectedItem.Value != "B" || ddAccountType.SelectedItem.Value != "C") //{ // lblStatus.Text = "Please select a valid account type. Admin account is B and standard is C"; // return; //} Linq_1DataContext db = new Linq_1DataContext(); WebAccount t = new WebAccount(); t.AccountType = Convert.ToChar(ddAccountType.SelectedValue); if (chkActive.Checked) { t.Active = true; } t.DateOpen = DateTime.Today; t.Email = txtEmail.Text; t.FName = txtFirst.Text; t.LName = txtLast.Text; t.Password = txtNewPass1.Text; t.UserName = txtUserName.Text; db.WebAccounts.InsertOnSubmit(t); //insert new record //Show success message + refresh try { db.SubmitChanges(); lblStatus.Text = "New web user Successfully added."; chkActive.Checked = true; txtEmail.Text = txtNewPass2.Text = txtNewPass1.Text = txtId.Text = txtFirst.Text = txtLast.Text = txtLast.Text = txtUserName.Text = ""; } catch (Exception ex) { Shared.WriteError(ex, HttpContext.Current, "btnSave_Click"); } } else { try { Linq_1DataContext db = new Linq_1DataContext(); var usr = (from a in db.WebAccounts where a.id == Convert.ToInt32(txtId.Text) select a).FirstOrDefault(); if (usr != null) { usr.Active = chkActive.Checked; usr.FName = txtFirst.Text; usr.LName = txtLast.Text; usr.Email = txtEmail.Text; usr.AccountType = Convert.ToChar(ddAccountType.SelectedValue); usr.UserName = txtUserName.Text; db.SubmitChanges(); lblStatus.Text = "User's profile updated."; } } catch (Exception ex) { Shared.WriteError(ex, HttpContext.Current); lblStatus.Text = "Error updating user's profile."; } } }
protected void btnSave_Click(object sender, EventArgs e) { if (Request.QueryString["IsNew"] == "true" ) { txtClosed.Visible = false; if (linkCustomer.Text == "") { lblStatus.Text = "Please select a customer first."; return; } Linq_1DataContext db = new Linq_1DataContext(); Tran t = new Tran(); t.Phone = txtPhone.Text; t.CstId = Convert.ToInt32(hideId.Value); t.Customer = hideCustomer.Value; t.Contact = txtContact.Text; t.DateAdded = DateTime.Today; t.Amount = Convert.ToDecimal(txtCost.Text.Replace('$','0')); t.Address = txtServiceAddress.Text; t.AssignedTo = ddTech.SelectedItem.Text; t.City = txtCity.Text; if (txtZip.Text != "") { t.Zip = Convert.ToInt32(txtZip.Text); } t.TransactionType = 1; t.Status = ddStatus.SelectedItem.Text; t.Service = txtService.Text; if (txtScheduled.Text != "") { t.DateSch = Convert.ToDateTime(txtScheduled.Text); } if (txtClosed.Text != "") { t.DateComplete = Convert.ToDateTime(txtClosed.Text); } t.LastMod = DateTime.Today; t.Equip = txtEquipment.Text; db.Trans.InsertOnSubmit(t); //insert new record //Show success message + refresh try { db.SubmitChanges(); lblStatus.Text = "New Service Request Successfully added."; hideCustomer.Value = linkCustomer.Text = txtCity.Text = txtCost.Text = txtEquipment.Text = txtPhone.Text = txtScheduled.Text = txtService.Text = txtServiceAddress.Text = txtContact.Text = txtZip.Text = ""; CstName = ""; if (chkNotify.Checked == true) { Shared.EmailTicket(ddTech.SelectedItem.Text, "Customer: " + t.Customer, t.id); } } catch { } IsNew = false; } else { cid = Convert.ToInt32(Request.QueryString["id"]); //Update existing ticket Linq_1DataContext db = new Linq_1DataContext(); var t = (from a in db.Trans where a.id == cid select a).FirstOrDefault(); if (t != null) { t.CstId = Convert.ToInt32(hideId.Value); t.Customer = hideCustomer.Value; t.Amount = Convert.ToDecimal(txtCost.Text.Replace('$', '0')); t.Address = txtServiceAddress.Text; t.Contact = txtContact.Text; t.AssignedTo = ddTech.SelectedItem.Text; t.City = txtCity.Text; if (txtZip.Text != "") { t.Zip = Convert.ToInt32(txtZip.Text); } t.Phone = txtPhone.Text; t.TransactionType = 1; t.Status = ddStatus.SelectedItem.Text; t.Service = txtService.Text; if (txtScheduled.Text != "") { t.DateSch = Convert.ToDateTime(txtScheduled.Text); } t.LastMod = DateTime.Today; t.Equip = txtEquipment.Text; if (txtClosed.Text != "") { t.DateComplete = Convert.ToDateTime(txtClosed.Text); } try { db.SubmitChanges(); lblStatus.Text = "Ticket " + cid.ToString() + " has been updated."; } catch (FormatException et) { lblStatus.Text = "Incorrect date format. Please use the date picker to the right of the date textbox."; } catch (Exception ex) { } } } }
protected void btnSaveNote_Click(object sender, EventArgs e) { cid = Convert.ToInt32(Request.QueryString["id"]); if (cid == 0) { lblStatus.Text = "Please save the ticket before adding notes."; } else { Linq_1DataContext db = new Linq_1DataContext(); TransNote t = new TransNote(); t.Note = txtNote.Text; t.NoteDate = DateTime.Today; t.NoteUser = (string)Session["username"]; t.Trans = cid; db.TransNotes.InsertOnSubmit(t); var z = (from g in db.Trans where g.id == cid select g).FirstOrDefault(); if (z != null) { z.LastMod = DateTime.Today; } try { db.SubmitChanges(); LoadNotes(); } catch (Exception ex) { Shared.WriteError(ex, HttpContext.Current, "btnSaveNote_Click - Error Saving note or updating MODDATE on trans table"); } } txtNote.Text = ""; }