Advertisement
Guest User

CreateWorkOrder.aspx.cs

a guest
Nov 11th, 2015
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 26.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Net.Mail;
  8. using System.Net;
  9. using System.Data.SqlClient;
  10. using System.Configuration;
  11. using System.Data;
  12. using System.Security.Principal;
  13. using System.Web.Security;
  14. using System.DirectoryServices;
  15. using System.DirectoryServices.ActiveDirectory;
  16.  
  17.  
  18.  
  19. namespace WorkOrderManagement
  20. {
  21.     public partial class CreateWorkOrder : System.Web.UI.Page
  22.     {
  23.         bool successfull;
  24.         protected void Page_Load(object sender, EventArgs e)
  25.         {
  26.            // captureuseremail();
  27.             TextBox9.Visible = false;
  28.             Label11.Visible = false;
  29.             TextBox TextBoxStatus = (TextBox)(DetailsView1.FindControl("TextBox12"));
  30.             TextBoxStatus.Text = "Open";
  31.             TextBox13.Visible = false;
  32.             Label12.Visible = false;
  33.             TextBox14.Visible = false;
  34.             TextBox15.Visible = false;
  35.             //Label11.Text = "Hello";
  36.             //TextBox lab = (TextBox)DetailsView1.FindControl("TextBox12");
  37.             //lab.Visible = false;
  38.             //TextBox10.Visible = true;
  39.             //TextBox11.Visible = false;
  40.             //TextBox12.Visible = false;
  41.             //TextBox13.Visible = false;
  42.             //TextBox14.Visible = false;
  43.  
  44.             //DropDownList list = (DropDownList)(DetailsView1.FindControl("DropDownList1"));
  45.             //TextBox9.Text = list.SelectedValue;
  46.  
  47.         }
  48.  
  49.  
  50.         protected void TextBox7_TextChanged(object sender, EventArgs e)
  51.         {
  52.  
  53.         }
  54.  
  55.         protected void DetailsView1_PageIndexChanging(object sender, DetailsViewPageEventArgs e)
  56.         {
  57.  
  58.         }
  59.  
  60.         protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
  61.         {
  62.             if (successfull == true && Page.IsValid && e.AffectedRows ==1)
  63.             {
  64.  
  65.                 //TextBox TextBoxWorkOrderNumber = (TextBox)(DetailsView1.FindControl("TextBox11"));
  66.                 TextBox TextBoxRequestor = (TextBox)(DetailsView1.FindControl("TextBox3"));
  67.                 TextBox TextBoxDate = (TextBox)(DetailsView1.FindControl("TextBox1"));
  68.                 //TextBoxDate.Text = DateTime.Now.ToShortDateString();
  69.                 TextBox TextBoxDepartment = (TextBox)(DetailsView1.FindControl("TextBox4"));
  70.                 TextBox TextBoxCompletionDate = (TextBox)(DetailsView1.FindControl("TextBox16"));
  71.                 TextBox TextBoxMachineDescription = (TextBox)(DetailsView1.FindControl("TextBox5"));
  72.                 TextBox TextBoxMachineLocation = (TextBox)(DetailsView1.FindControl("TextBox6"));
  73.                 TextBox TextBoxWorkRequired = (TextBox)(DetailsView1.FindControl("TextBox7"));
  74.                 // DropDownList status = (DropDownList)(DetailsView1.FindControl("DropDownList2"));
  75.                 TextBox TextBoxStatus = (TextBox)(DetailsView1.FindControl("TextBox12"));
  76.                 TextBoxStatus.Text = "Open";
  77.  
  78.                 DropDownList list = (DropDownList)(DetailsView1.FindControl("DropDownList1"));
  79.                 TextBox9.Text = list.SelectedValue;
  80.                 DropDownList lists = (DropDownList)(DetailsView1.FindControl("DropDownList2"));
  81.                 TextBox14.Text = lists.SelectedValue;
  82.  
  83.  
  84.                 if (TextBoxRequestor.Text.Length <= 0)
  85.                 {
  86.                     TextBoxRequestor.Text = "Not Applicable";
  87.                 }
  88.                 if (TextBox14.Text.Length <= 0)
  89.                 {
  90.                     TextBoxDepartment.Text = "Not Provided";
  91.                 }
  92.                 if (TextBoxCompletionDate.Text.Length <= 0)
  93.                 {
  94.                     TextBoxCompletionDate.Text = "Not Provided";
  95.                 }
  96.                 if (TextBoxMachineDescription.Text.Length <= 0)
  97.                 {
  98.                     TextBoxMachineDescription.Text = "Not Provided";
  99.                 }
  100.  
  101.                 if (TextBoxMachineLocation.Text.Length <= 0)
  102.                 {
  103.                     TextBoxMachineLocation.Text = "Not Provided";
  104.                 }
  105.  
  106.                 if (TextBoxWorkRequired.Text.Length <= 0)
  107.                 {
  108.                     TextBoxWorkRequired.Text = "Not Provided";
  109.                 }
  110.  
  111.  
  112.                 if (TextBox9.Text == "Safety" && e.AffectedRows ==1)
  113.                 {
  114.                     {
  115.                         bool isLocal = HttpContext.Current.Request.IsLocal;
  116.                         if (isLocal == true)
  117.                         {
  118.                             string id = TextBox13.Text.ToString();
  119.                             System.Net.Mail.MailMessage mm = new System.Net.Mail.MailMessage();
  120.                             mm.From = new System.Net.Mail.MailAddress("abc@abc.com");//who send
  121.                             mm.To.Add(new System.Net.Mail.MailAddress("abc@abc.com"));
  122.  
  123.                             //abc@abc.com
  124.  
  125.                             mm.Subject = "WorkOrders Type Safety";
  126.                             mm.Body = "DO NOT REPLY TO THIS EMAIL" + "<br><br/>" + "WorkOrderNumber" + ": &nbsp;" + "<a href=\"http://localhost:49695/SafetyReport.aspx?WorkOrderNum=" + TextBox13.Text + "\">" + TextBox13.Text + "</a>" + "<-Click on the Work Order Number For Report" + "<br><br/>" + "WorkOrderNumber" + ": &nbsp;" + "<a href=\"http://localhost:49695/Safety.aspx?WorkOrderNum=" + TextBox13.Text + "\">" + TextBox13.Text + "</a>" + "<-Click on this Work Order Number To Enter Data" + "<br><br/>" + "Requestor" + ":&nbsp;" + TextBoxRequestor.Text + "<br><br/>" + "Date" + ":&nbsp;" + TextBoxDate.Text + "<br><br/>" + "Department" + ":&nbsp;" + TextBox14.Text + "<br><br/>" + "Machine Description" + ":&nbsp;" + TextBoxMachineDescription.Text + "<br><br/>" + "Machine Location" + ":&nbsp;" + TextBoxMachineLocation.Text + "<br><br/>" + "Work Required" + ":&nbsp;" + TextBoxWorkRequired.Text + "<br><br/>" + "Status" + ":&nbsp;" + TextBoxStatus.Text;
  127.                             //mm.Body = "WorkOrderNumber" + ": &nbsp;" + "<a href=\"http://localhost:49695/Safety.aspx?=WorkOrderNum=\">" + TextBox13.Text + "</a>" + "<-Click on the Work Order Number" + "<br><br/>" + "Requestor" + ":&nbsp;" + TextBoxRequestor.Text + "<br><br/>" + "Date" + ":&nbsp;" + TextBoxDate.Text + "<br><br/>" + "Department" + ":&nbsp;" + TextBoxDepartment.Text + "<br><br/>" + "Completion Date" + ":&nbsp;" + TextBoxCompletionDate.Text + "<br><br/>" + "Machine Description" + ":&nbsp;" + TextBoxMachineDescription.Text + "<br><br/>" + "Machine Location" + ":&nbsp;" + TextBoxMachineLocation.Text + "<br><br/>" + "Work Required" + ":&nbsp;" + TextBoxWorkRequired.Text + "<br><br/>" + "Status" + ":&nbsp;" + TextBoxStatus.Text;
  128.                             mm.IsBodyHtml = true;
  129.                             System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
  130.                             client.Host = ConfigurationManager.AppSettings["smtpServer"];
  131.                             client.Send(mm);
  132.                             captureuseremail();
  133.                         }
  134.                
  135.                         else
  136.                         {
  137.                             string id = TextBox13.Text.ToString();
  138.                             System.Net.Mail.MailMessage mm = new System.Net.Mail.MailMessage();
  139.                             mm.From = new System.Net.Mail.MailAddress("abc@abc.com");//who send
  140.                             mm.To.Add(new System.Net.Mail.MailAddress("abc@abc.com"));
  141.  
  142.                             //abc@rstover.com
  143.  
  144.                             mm.Subject = "WorkOrders Type Safety";
  145.                             mm.Body = "DO NOT REPLY TO THIS EMAIL" + "<br><br/>" + "WorkOrderNumber" + ": &nbsp;" + "<a href=\"http://ioksv004/WorkOrder/SafetyReport.aspx?WorkOrderNum=" + TextBox13.Text + "\">" + TextBox13.Text + "</a>" + "<-Click on the Work Order Number For Report" + "<br><br/>" + "WorkOrderNumber" + ": &nbsp;" + "<a href=\"http://ioksv004/WorkOrder/Safety.aspx?WorkOrderNum=" + TextBox13.Text + "\">" + TextBox13.Text + "</a>" + "<-Click on the Work Order Number To Enter Data" + "<br><br/>" + "Requestor" + ":&nbsp;" + TextBoxRequestor.Text + "<br><br/>" + "Date" + ":&nbsp;" + TextBoxDate.Text + "<br><br/>" + "Department" + ":&nbsp;" + TextBox14.Text + "<br><br/>" + "Completion Date" + ":&nbsp;" + TextBoxCompletionDate.Text + "<br><br/>" + "Machine Description" + ":&nbsp;" + TextBoxMachineDescription.Text + "<br><br/>" + "Machine Location" + ":&nbsp;" + TextBoxMachineLocation.Text + "<br><br/>" + "Work Required" + ":&nbsp;" + TextBoxWorkRequired.Text + "<br><br/>" + "Status" + ":&nbsp;" + TextBoxStatus.Text;
  146.                             //mm.Body = "WorkOrderNumber" + ": &nbsp;" + "<a href=\"http://localhost:49695/Safety.aspx?=WorkOrderNum=\">" + TextBox13.Text + "</a>" + "<-Click on the Work Order Number" + "<br><br/>" + "Requestor" + ":&nbsp;" + TextBoxRequestor.Text + "<br><br/>" + "Date" + ":&nbsp;" + TextBoxDate.Text + "<br><br/>" + "Department" + ":&nbsp;" + TextBoxDepartment.Text + "<br><br/>" + "Completion Date" + ":&nbsp;" + TextBoxCompletionDate.Text + "<br><br/>" + "Machine Description" + ":&nbsp;" + TextBoxMachineDescription.Text + "<br><br/>" + "Machine Location" + ":&nbsp;" + TextBoxMachineLocation.Text + "<br><br/>" + "Work Required" + ":&nbsp;" + TextBoxWorkRequired.Text + "<br><br/>" + "Status" + ":&nbsp;" + TextBoxStatus.Text;
  147.                             mm.IsBodyHtml = true;
  148.                             System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
  149.                             client.Host = ConfigurationManager.AppSettings["smtpServer"];
  150.                             client.Send(mm);
  151.                             captureuseremail();
  152.                         }
  153.                    
  154.                     }
  155.                    
  156.                 }
  157.                 if (TextBox9.Text == "Quality" && e.AffectedRows ==1)
  158.                 {
  159.                     bool isLocal = HttpContext.Current.Request.IsLocal;
  160.                     if (isLocal == true)
  161.                     {
  162.                         System.Net.Mail.MailMessage nn = new System.Net.Mail.MailMessage();
  163.                         nn.From = new System.Net.Mail.MailAddress("abc@abc.com");//who send
  164.                         nn.To.Add(new System.Net.Mail.MailAddress("abc@abc.com"));
  165.  
  166.  
  167.  
  168.                         nn.Subject = "WorkOrders Type Quality";
  169.                         nn.Body = "DO NOT REPLY TO THIS EMAIL" + "<br><br/>" + "WorkOrderNumber" + ": &nbsp;" + "<a href=\"http://localhost:49695/QualityReport.aspx?WorkOrderNum=" + TextBox13.Text + "\">" + TextBox13.Text + "</a>" + "<-Click on the Work Order Number For Report" + "<br><br/>" + "WorkOrderNumber" + ": &nbsp;" + "<a href=\"http://localhost:49695/Quality.aspx?WorkOrderNum=" + TextBox13.Text + "\">" + TextBox13.Text + "</a>" + "<-Click on the Work Order Number To Enter Data" + "<br><br/>" + "Requestor" + ":&nbsp;" + TextBoxRequestor.Text + "<br><br/>" + "Date" + ":&nbsp;" + TextBoxDate.Text + "<br><br/>" + "Department" + ":&nbsp;" + TextBox14.Text + "<br><br/>" + "Completion Date" + ":&nbsp;" + TextBoxCompletionDate.Text + "<br><br/>" + "Machine Description" + ":&nbsp;" + TextBoxMachineDescription.Text + "<br><br/>" + "Machine Location" + ":&nbsp;" + TextBoxMachineLocation.Text + "<br><br/>" + "Work Required" + ":&nbsp;" + TextBoxWorkRequired.Text + "<br><br/>" + "Status" + ":&nbsp;" + TextBoxStatus.Text;
  170.                         //mm.Body = "WorkOrderNumber" + ": &nbsp;" + "<a href=\"http://localhost:49695/Safety.aspx?=WorkOrderNum=\">" + TextBox13.Text + "</a>" + "<-Click on the Work Order Number" + "<br><br/>" + "Requestor" + ":&nbsp;" + TextBoxRequestor.Text + "<br><br/>" + "Date" + ":&nbsp;" + TextBoxDate.Text + "<br><br/>" + "Department" + ":&nbsp;" + TextBoxDepartment.Text + "<br><br/>" + "Completion Date" + ":&nbsp;" + TextBoxCompletionDate.Text + "<br><br/>" + "Machine Description" + ":&nbsp;" + TextBoxMachineDescription.Text + "<br><br/>" + "Machine Location" + ":&nbsp;" + TextBoxMachineLocation.Text + "<br><br/>" + "Work Required" + ":&nbsp;" + TextBoxWorkRequired.Text + "<br><br/>" + "Status" + ":&nbsp;" + TextBoxStatus.Text;
  171.                         nn.IsBodyHtml = true;
  172.                         System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
  173.                         client.Host = ConfigurationManager.AppSettings["smtpServer"];
  174.                         captureuseremail();
  175.                     }
  176.                     else
  177.                     {
  178.                         System.Net.Mail.MailMessage nn = new System.Net.Mail.MailMessage();
  179.                         nn.From = new System.Net.Mail.MailAddress("abc@abc.com");//who send
  180.                         nn.To.Add(new System.Net.Mail.MailAddress("abc@abc.com"));
  181.  
  182.  
  183.  
  184.                         nn.Subject = "WorkOrders Type Quality";
  185.                         nn.Body = "DO NOT REPLY TO THIS EMAIL" + "<br><br/>" + "WorkOrderNumber" + ": &nbsp;" + "<a href=\"http://ioksv004/WorkOrder/QualityReport.aspx?WorkOrderNum=" + TextBox13.Text + "\">" + TextBox13.Text + "</a>" + "<-Click on the Work Order Number For Report" + "<br><br/>" + "WorkOrderNumber" + ": &nbsp;" + "<a href=\"http://ioksv004/WorkOrder/Quality.aspx?WorkOrderNum=" + TextBox13.Text + "\">" + TextBox13.Text + "</a>" + "<-Click on the Work Order Number To Enter Data" + "<br><br/>" + "Requestor" + ":&nbsp;" + TextBoxRequestor.Text + "<br><br/>" + "Date" + ":&nbsp;" + TextBoxDate.Text + "<br><br/>" + "Department" + ":&nbsp;" + TextBox14.Text + "<br><br/>" + "Completion Date" + ":&nbsp;" + TextBoxCompletionDate.Text + "<br><br/>" + "Machine Description" + ":&nbsp;" + TextBoxMachineDescription.Text + "<br><br/>" + "Machine Location" + ":&nbsp;" + TextBoxMachineLocation.Text + "<br><br/>" + "Work Required" + ":&nbsp;" + TextBoxWorkRequired.Text + "<br><br/>" + "Status" + ":&nbsp;" + TextBoxStatus.Text;
  186.                         //mm.Body = "WorkOrderNumber" + ": &nbsp;" + "<a href=\"http://localhost:49695/Safety.aspx?=WorkOrderNum=\">" + TextBox13.Text + "</a>" + "<-Click on the Work Order Number" + "<br><br/>" + "Requestor" + ":&nbsp;" + TextBoxRequestor.Text + "<br><br/>" + "Date" + ":&nbsp;" + TextBoxDate.Text + "<br><br/>" + "Department" + ":&nbsp;" + TextBoxDepartment.Text + "<br><br/>" + "Completion Date" + ":&nbsp;" + TextBoxCompletionDate.Text + "<br><br/>" + "Machine Description" + ":&nbsp;" + TextBoxMachineDescription.Text + "<br><br/>" + "Machine Location" + ":&nbsp;" + TextBoxMachineLocation.Text + "<br><br/>" + "Work Required" + ":&nbsp;" + TextBoxWorkRequired.Text + "<br><br/>" + "Status" + ":&nbsp;" + TextBoxStatus.Text;
  187.                         nn.IsBodyHtml = true;
  188.                         System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
  189.                         client.Host = ConfigurationManager.AppSettings["smtpServer"];
  190.                         client.Send(nn);
  191.                         captureuseremail();
  192.                     }
  193.  
  194.                 }
  195.                 if (TextBox9.Text == "General" && e.AffectedRows ==1)
  196.                 {
  197.                     bool isLocal = HttpContext.Current.Request.IsLocal;
  198.                     if (isLocal == true)
  199.                     {
  200.                         System.Net.Mail.MailMessage aa = new System.Net.Mail.MailMessage();
  201.                         aa.From = new System.Net.Mail.MailAddress("abc@abc.com");//who send
  202.                         aa.To.Add(new System.Net.Mail.MailAddress("abc@abc.com"));
  203.  
  204.  
  205.  
  206.                         aa.Subject = "WorkOrders Type General";
  207.                         aa.Body = "DO NOT REPLY TO THIS EMAIL" + "<br><br/>" + "WorkOrderNumber" + ": &nbsp;" + "<a href=\"http://localhost:49695/GeneralReport.aspx?WorkOrderNum=" + TextBox13.Text + "\">" + TextBox13.Text + "</a>" + "<-Click on the Work Order Number For Report"  +"<br><br/>" + "WorkOrderNumber" + ": &nbsp;" + "<a href=\"http://localhost:49695/General.aspx?WorkOrderNum=" + TextBox13.Text + "\">" + TextBox13.Text + "</a>" + "<-Click on the Work Order Number To Enter Data" + "<br><br/>"+ "Requestor" + ":&nbsp;" + TextBoxRequestor.Text + "<br><br/>" + "Date" + ":&nbsp;" + TextBoxDate.Text + "<br><br/>" + "Department" + ":&nbsp;" + TextBox14.Text + "<br><br/>" + "Completion Date" + ":&nbsp;" + TextBoxCompletionDate.Text + "<br><br/>" + "Machine Description" + ":&nbsp;" + TextBoxMachineDescription.Text + "<br><br/>" + "Machine Location" + ":&nbsp;" + TextBoxMachineLocation.Text + "<br><br/>" + "Work Required" + ":&nbsp;" + TextBoxWorkRequired.Text + "<br><br/>" + "Status" + ":&nbsp;" + TextBoxStatus.Text;
  208.                         //mm.Body = "WorkOrderNumber" + ": &nbsp;" + "<a href=\"http://localhost:49695/Safety.aspx?=WorkOrderNum=\">" + TextBox13.Text + "</a>" + "<-Click on the Work Order Number" + "<br><br/>" + "Requestor" + ":&nbsp;" + TextBoxRequestor.Text + "<br><br/>" + "Date" + ":&nbsp;" + TextBoxDate.Text + "<br><br/>" + "Department" + ":&nbsp;" + TextBoxDepartment.Text + "<br><br/>" + "Completion Date" + ":&nbsp;" + TextBoxCompletionDate.Text + "<br><br/>" + "Machine Description" + ":&nbsp;" + TextBoxMachineDescription.Text + "<br><br/>" + "Machine Location" + ":&nbsp;" + TextBoxMachineLocation.Text + "<br><br/>" + "Work Required" + ":&nbsp;" + TextBoxWorkRequired.Text + "<br><br/>" + "Status" + ":&nbsp;" + TextBoxStatus.Text;
  209.                         aa.IsBodyHtml = true;
  210.                         System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
  211.                         client.Host = ConfigurationManager.AppSettings["smtpServer"];
  212.                         client.Send(aa);
  213.                         captureuseremail();
  214.                     }
  215.                     else
  216.                     {
  217.                         System.Net.Mail.MailMessage aa = new System.Net.Mail.MailMessage();
  218.                         aa.From = new System.Net.Mail.MailAddress("abc@abc.com");//who send
  219.                         aa.To.Add(new System.Net.Mail.MailAddress("abc@abc.com"));
  220.  
  221.  
  222.  
  223.                         aa.Subject = "WorkOrders Type General";
  224.                         aa.Body = "DO NOT REPLY TO THIS EMAIL" + "<br><br/>" + "WorkOrderNumber" + ": &nbsp;" + "<a href=\"http://ioksv004/WorkOrder/GeneralReport.aspx?WorkOrderNum=" + TextBox13.Text + "\">" + TextBox13.Text + "</a>" + "<-Click on the Work Order Number For Report" + "<br><br/>" + "WorkOrderNumber" + ": &nbsp;" + "<a href=\"http://ioksv004/WorkOrder/General.aspx?WorkOrderNum=" + TextBox13.Text + "\">" + TextBox13.Text + "</a>" + "<-Click on the Work Order Number To Enter Data" + "<br><br/>" + "Requestor" + ":&nbsp;" + TextBoxRequestor.Text + "<br><br/>" + "Date" + ":&nbsp;" + TextBoxDate.Text + "<br><br/>" + "Department" + ":&nbsp;" + TextBox14.Text + "<br><br/>" + "Completion Date" + ":&nbsp;" + TextBoxCompletionDate.Text + "<br><br/>" + "Machine Description" + ":&nbsp;" + TextBoxMachineDescription.Text + "<br><br/>" + "Machine Location" + ":&nbsp;" + TextBoxMachineLocation.Text + "<br><br/>" + "Work Required" + ":&nbsp;" + TextBoxWorkRequired.Text + "<br><br/>" + "Status" + ":&nbsp;" + TextBoxStatus.Text;
  225.                        
  226.                         //mm.Body = "WorkOrderNumber" + ": &nbsp;" + "<a href=\"http://localhost:49695/Safety.aspx?=WorkOrderNum=\">" + TextBox13.Text + "</a>" + "<-Click on the Work Order Number" + "<br><br/>" + "Requestor" + ":&nbsp;" + TextBoxRequestor.Text + "<br><br/>" + "Date" + ":&nbsp;" + TextBoxDate.Text + "<br><br/>" + "Department" + ":&nbsp;" + TextBoxDepartment.Text + "<br><br/>" + "Completion Date" + ":&nbsp;" + TextBoxCompletionDate.Text + "<br><br/>" + "Machine Description" + ":&nbsp;" + TextBoxMachineDescription.Text + "<br><br/>" + "Machine Location" + ":&nbsp;" + TextBoxMachineLocation.Text + "<br><br/>" + "Work Required" + ":&nbsp;" + TextBoxWorkRequired.Text + "<br><br/>" + "Status" + ":&nbsp;" + TextBoxStatus.Text;
  227.                         aa.IsBodyHtml = true;
  228.                         System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
  229.                         client.Host = ConfigurationManager.AppSettings["smtpServer"];
  230.                         client.Send(aa);
  231.                         captureuseremail();
  232.  
  233.                     }
  234.                 }
  235.             }
  236.             else
  237.             {
  238.                 Label17.Text = "Insert Was Not Successful, Please Contact the Developer";
  239.             }
  240.  
  241.         }
  242.    
  243.         protected void captureuseremail()
  244.         {
  245.             TextBox email = new TextBox();
  246.             email.Text = HttpContext.Current.Request.LogonUserIdentity.Name.ToString();
  247.  
  248.             string username = email.Text.Split('\\')[1];
  249.  
  250.             string domain = email.Text.Split('\\')[0];
  251.  
  252.             DirectoryEntry entry = new DirectoryEntry("LDAP://" + domain);
  253.             DirectorySearcher adsearcher = new DirectorySearcher(entry);
  254.             adsearcher.SearchScope = SearchScope.Subtree;
  255.             adsearcher.Filter = "(&(objectClass=user)(samaccountname=" + username + "))";
  256.             SearchResult userObject = adsearcher.FindOne();
  257.             if (userObject != null)
  258.             {
  259.                 string[] props = new string[] {"mail" };
  260.                 foreach (string prop in props)
  261.                 {
  262.                     TextBox15.Text = userObject.Properties[prop][0].ToString();
  263.                 }
  264.  
  265.             }
  266.  
  267.             string con = ConfigurationManager.ConnectionStrings["WorkOrderConnectionString3"].ToString();
  268.             SqlConnection sqlcon = new SqlConnection(con);
  269.             sqlcon.Open();
  270.             using (SqlCommand cmd = new SqlCommand())
  271.             {
  272.                 cmd.Connection = sqlcon;
  273.                 cmd.CommandType = CommandType.Text;
  274.                 cmd.CommandText = "UPDATE [WorkOrder].[dbo].[Master] SET [ReqEmailAddress] = @Email WHERE WorkOrderNum =  @workordernum";
  275.                 cmd.Parameters.AddWithValue("@workordernum", TextBox13.Text);
  276.                 cmd.Parameters.AddWithValue("@Email", TextBox15.Text);
  277.                 cmd.ExecuteNonQuery();
  278.             }
  279.  
  280.         }
  281.  
  282.         protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
  283.         {
  284.             DropDownList list = (DropDownList)(DetailsView1.FindControl("DropDownList1"));
  285.             TextBox9.Text = list.SelectedValue;
  286.         }
  287.  
  288.         protected void DropDownList1_TextChanged(object sender, EventArgs e)
  289.         {
  290.             DropDownList list = (DropDownList)(DetailsView1.FindControl("DropDownList1"));
  291.             TextBox9.Text = list.SelectedValue;
  292.         }
  293.  
  294.  
  295.  
  296.         protected void TextBox2_TextChanged(object sender, EventArgs e)
  297.         {
  298.             //cusCustom_ServerValidateit();
  299.         }
  300.  
  301.  
  302.         protected void Validate(object sender, EventArgs e)
  303.         {
  304.        
  305.         }
  306.  
  307.         protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
  308.         {
  309.          
  310.             if (Page.IsValid)
  311.             {
  312.  
  313.                 //TextBox TextBoxWorkOrderNumber = (TextBox)(DetailsView1.FindControl("TextBox11"));
  314.                 TextBox TextBoxRequestor = (TextBox)(DetailsView1.FindControl("TextBox3"));
  315.                 TextBox TextBoxDate = (TextBox)(DetailsView1.FindControl("TextBox1"));
  316.                 //TextBoxDate.Text = DateTime.Now.ToShortDateString();
  317.                 TextBox TextBoxDepartment = (TextBox)(DetailsView1.FindControl("TextBox4"));
  318.                 TextBox TextBoxCompletionDate = (TextBox)(DetailsView1.FindControl("TextBox16"));
  319.                 TextBox TextBoxMachineDescription = (TextBox)(DetailsView1.FindControl("TextBox5"));
  320.                 TextBox TextBoxMachineLocation = (TextBox)(DetailsView1.FindControl("TextBox6"));
  321.                 TextBox TextBoxWorkRequired = (TextBox)(DetailsView1.FindControl("TextBox7"));
  322.                 // DropDownList status = (DropDownList)(DetailsView1.FindControl("DropDownList2"));
  323.                 TextBox TextBoxStatus = (TextBox)(DetailsView1.FindControl("TextBox12"));
  324.                 TextBoxStatus.Text = "Open";
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.                 DropDownList list = (DropDownList)(DetailsView1.FindControl("DropDownList1"));
  332.                 TextBox9.Text = list.SelectedValue;
  333.                 DropDownList lists = (DropDownList)(DetailsView1.FindControl("DropDownList2"));
  334.                 TextBox14.Text = lists.SelectedValue;
  335.  
  336.  
  337.                 if (TextBoxRequestor.Text.Length <= 0)
  338.                 {
  339.                     TextBoxRequestor.Text = "Not Applicable";
  340.                 }
  341.                 if (TextBox14.Text.Length <= 0)
  342.                 {
  343.                     TextBoxDepartment.Text = "Not Provided";
  344.                 }
  345.                 if (TextBoxCompletionDate.Text.Length <= 0)
  346.                 {
  347.                     TextBoxCompletionDate.Text = "Not Provided";
  348.                 }
  349.                 if (TextBoxMachineDescription.Text.Length <= 0)
  350.                 {
  351.                     TextBoxMachineDescription.Text = "Not Provided";
  352.                 }
  353.  
  354.                 if (TextBoxMachineLocation.Text.Length <= 0)
  355.                 {
  356.                     TextBoxMachineLocation.Text = "Not Provided";
  357.                 }
  358.                
  359.                 if (TextBoxWorkRequired.Text.Length <= 0)
  360.                 {
  361.                     TextBoxWorkRequired.Text = "Not Provided";
  362.                 }
  363.  
  364.                
  365.            
  366.            
  367.             successfull = true;
  368.         }
  369.         else
  370.             {
  371.                 e.Cancel = true;
  372.               successfull = false;
  373.             }
  374.            
  375.      
  376.         }
  377.  
  378.         protected void RequestorSource_Inserted(object sender, SqlDataSourceStatusEventArgs e)
  379.         {
  380.             if (successfull == true)
  381.             {
  382.                 try
  383.                 {
  384.                     int newid = (int)e.Command.Parameters["@NewId"].Value;
  385.                     TextBox13.Text = newid.ToString();
  386.                 }
  387.                 catch
  388.                 {
  389.                     successfull = false;
  390.                 }
  391.                if (e.AffectedRows == 1 && successfull == true)
  392.                {
  393.                    successfull = true;
  394.                }
  395.                else
  396.                {
  397.                    successfull = false;
  398.                }
  399.             }
  400.             else
  401.             {
  402.                 successfull = false;
  403.             }
  404.        
  405.          
  406.         }
  407.  
  408.         protected void DetailsView1_ItemCreated(object sender, EventArgs e)
  409.         {
  410.             TextBox TextBoxDate = (TextBox)(DetailsView1.FindControl("TextBox1"));
  411.             TextBoxDate.Text = DateTime.Now.ToString("MM/dd/yyyy");
  412.         }
  413.     }
  414. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement