public DeviceRegstrationTableRow(int id)
        {
            NameCell       = new TableCell();
            DeviceTypeCell = new TableCell();
            MacAddressCell = new TableCell();
            IPAddressCell  = new TableCell();
            ControllsCell  = new TableCell();

            CompletedCB = new CheckBox()
            {
                Text = "Request Completed", Checked = false
            };
            RejectedCB = new CheckBox()
            {
                Text = "Request Denied", Checked = false
            };
            ProctorCB = new CheckBox()
            {
                Text = "Is Proctor", Checked = false
            };

            ControllsCell.Controls.Add(CompletedCB);
            ControllsCell.Controls.Add(RejectedCB);
            ControllsCell.Controls.Add(ProctorCB);

            this.Cells.Add(NameCell);
            this.Cells.Add(DeviceTypeCell);
            this.Cells.Add(MacAddressCell);
            this.Cells.Add(IPAddressCell);
            this.Cells.Add(ControllsCell);

            RegistrationId = id;
            using (WebhostEntities db = new WebhostEntities())
            {
                WebhostMySQLConnection.RegistrationRequest request = db.RegistrationRequests.Where(req => req.id == id).Single();
                StudentName = String.Format("{0} {1} [{2}]", request.Student.FirstName, request.Student.LastName, request.Student.GraduationYear);
                DeviceType  = request.DeviceType;
                MacAddress  = request.MacAddress;
                Completed   = request.RequestCompleted;
                Rejected    = request.RequestDenied;
                isProctor   = PermissionControl.GetProctors().Contains(request.Student.ID);
                IPAddress   = Completed?"Already Assigned":Rejected?"Will Not Be Assigned":"";
            }
        }
        protected void GenerateImportBtn_Click(object sender, EventArgs e)
        {
            using (WebhostEntities db = new WebhostEntities())
            {
                List <WebhostMySQLConnection.RegistrationRequest> StudentRequests = new List <WebhostMySQLConnection.RegistrationRequest>();
                List <WebhostMySQLConnection.RegistrationRequest> ProctorRequests = new List <WebhostMySQLConnection.RegistrationRequest>();
                foreach (TableRow row in RegistrationRequestTable.Rows)
                {
                    if (!(row is DeviceRegstrationTableRow))
                    {
                        continue;
                    }

                    DeviceRegstrationTableRow reg = (DeviceRegstrationTableRow)row;
                    WebhostMySQLConnection.RegistrationRequest request = db.RegistrationRequests.Where(req => req.id == reg.RegistrationId).Single();
                    request.RequestDenied = reg.Rejected;
                    if (reg.Rejected)
                    {
                        request.RequestCompleted = true;
                        db.SaveChanges();
                        continue;
                    }

                    if (reg.isProctor)
                    {
                        ProctorRequests.Add(request);
                    }
                    else
                    {
                        StudentRequests.Add(request);
                    }
                }

                CSV csv = new CSV();

                List <String> proctorIps = DeviceRegistration.GetRangeOfFreeIPs(DeviceRegistration.ProctorSubnet, ProctorRequests.Count);
                List <String> studentIps = DeviceRegistration.GetRangeOfFreeIPs(DeviceRegistration.StudentSubnet, StudentRequests.Count);

                if (ProctorRequests.Count > 0)
                {
                    for (int i = 0; i < proctorIps.Count; i++)
                    {
                        String ip = proctorIps[i];
                        WebhostMySQLConnection.RegistrationRequest proctor = ProctorRequests[i];
                        proctor.RequestCompleted = true;
                        csv.Add(new Dictionary <string, string>()
                        {
                            { "ScopeId", DeviceRegistration.ProctorSubnet },
                            { "IPAddress", ip },
                            { "Name", String.Format("{0}{1}{2}", proctor.Student.FirstName, proctor.Student.LastName, proctor.DeviceType) },
                            { "ClientId", proctor.MacAddress },
                            { "Description", String.Format("{0} {1}:  {2}", proctor.Student.FirstName, proctor.Student.LastName, proctor.DeviceType) }
                        });
                    }
                }
                if (StudentRequests.Count > 0)
                {
                    for (int i = 0; i < studentIps.Count; i++)
                    {
                        String ip = studentIps[i];
                        WebhostMySQLConnection.RegistrationRequest student = StudentRequests[i];
                        student.RequestCompleted = true;
                        csv.Add(new Dictionary <string, string>()
                        {
                            { "ScopeId", DeviceRegistration.StudentSubnet },
                            { "IPAddress", ip },
                            { "Name", String.Format("{0}{1}{2}", student.Student.FirstName, student.Student.LastName, student.DeviceType) },
                            { "ClientId", student.MacAddress },
                            { "Description", String.Format("{0} {1}:  {2}", student.Student.FirstName, student.Student.LastName, student.DeviceType) }
                        });
                    }
                }


                csv.Save(Server.MapPath("~/Temp/dhcp_import.csv"));
                db.SaveChanges();
                Response.Redirect("~/Temp/dhcp_import.csv");
            }
        }
示例#3
0
        protected void SubmitBtn_Click(object sender, EventArgs e)
        {
            ShortRequest shreq = new ShortRequest()
            {
                StudentName = user.Name, DeviceType = DeviceType, MACAddress = MACAddrInput.Text
            };

            if (!ValidateMAC())
            {
                ErrorMessage.Text = "The MAC Address you entered is not valid--please check to make sure it is correct.";
                LogError("Invalid MAC Address for {0}", shreq.ToString());
                ErrorPanel.Visible = true;
                return;
            }
            using (WebhostEntities db = new WebhostEntities())
            {
                //Check for Existing Mac Address Request.
                if (db.RegistrationRequests.Where(req => req.MacAddress.Equals(MACAddress)).Count() > 0)
                {
                    WebhostMySQLConnection.RegistrationRequest request = db.RegistrationRequests.Where(req => req.MacAddress.Equals(MACAddress)).Single();
                    if (request.RequestCompleted)
                    {
                        ErrorMessage.Text = "This Device has already been registered.  If you are experiencing difficulties, email Mr. Cox or Mr. Harrison.";
                        LogError("The device has already been registered: {0}", shreq.ToString());
                        MailControler.MailToUser("Your Registration Request has already been registered.", shreq.ToString(), user);
                    }
                    else if (request.RequestDenied)
                    {
                        ErrorMessage.Text = "This device has been rejected.  Please see Mr. Cox or Mr. Harrison for details.";
                        LogError("Registration Request has been rejected: {0}", shreq.ToString());
                        MailControler.MailToUser("Your Registration Request has been rejected.", shreq.ToString(), user);
                    }
                    else
                    {
                        ErrorMessage.Text = "This Device is pending registration.  Don't worry--we'll get to it soon =)";
                        LogError("Impatient User: {0}", shreq);
                        MailControler.MailToUser("Your Registration Request is pending review.", shreq.ToString(), user);
                    }

                    ErrorPanel.Visible = true;
                    return;
                }

                int reqid = db.RegistrationRequests.Count() > 0 ? db.RegistrationRequests.OrderBy(req => req.id).ToList().Last().id + 1 : 0;
                WebhostMySQLConnection.RegistrationRequest nrequest = new WebhostMySQLConnection.RegistrationRequest()
                {
                    id               = reqid,
                    StudentId        = ((BasePage)Page).user.IsStudent?((BasePage)Page).user.ID:10,
                    MacAddress       = MACAddress,
                    DeviceType       = DeviceType,
                    RequestCompleted = false,
                    RequestDenied    = false
                };

                db.RegistrationRequests.Add(nrequest);
                db.SaveChanges();

                LogInformation("New Request submitted: {0}", shreq.ToString());
                if (EmailEnabled)
                {
                    MailControler.MailToWebmaster("New Device Registration Request.", shreq.ToString(), user);
                    MailControler.MailToUser("New Device Registration Request.", shreq.ToString(), "*****@*****.**", "Jeff Harrison", user);
                    MailControler.MailToUser("Your Registration Request has been successfully submitted.", shreq.ToString(), user);
                }
                SuccessPanel.Visible = true;
            }
        }