コード例 #1
0
        protected void Deletedata(object s, GridViewDeleteEventArgs e)
        {
            dependants = GetExistingData();
            //DataSet ds = gv.DataSource as DataSet;
            //ds.Tables[0].Rows[gv.Rows[e.RowIndex].DataItemIndex].Delete();
            //ds.WriteXml(Server.MapPath("empdata.xml"));
            int id = dependants[e.RowIndex].IdStudentDependant;
            StudentDependant sp = entity.StudentDependants.Where(p => p.IdStudentDependant == id).FirstOrDefault();

            entity.StudentDependants.DeleteObject(sp);
            entity.SaveChanges();
            dependants.RemoveAt(e.RowIndex);
            BindData(dependants);
            Cache["Dependants"] = dependants;
        }
コード例 #2
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            lblError.Text = "";
            User user = entity.Users.Where(p => p.Username.ToLower() == tbUsername.Text.ToLower()).FirstOrDefault();

            if (user == null)
            {
                User newUser = new User
                {
                    UserEmail        = tbEmail.Text,
                    IsStudent        = true,
                    IsActive         = true,
                    Username         = tbUsername.Text.ToLower(),
                    Password         = tbPassword.Text,
                    RegistrationDate = DateTime.Today,
                    UserLevel        = 0,
                    DateCreated      = DateTime.Today
                };
                entity.AddToUsers(newUser);
                entity.SaveChanges();
                string toAddress = tbEmail.Text;
                string title     = "Member Registration on CompCare Website";
                string mailBody  = string.Format("You have been successfully registered on the StudentPlan website.  Your email address has been registered in the database as being {0}", tbEmail.Text);
                SendEmail(toAddress, title, mailBody);
                lblSuccess.Text = @"You have been successfully registered.  Please use your credentials to log onto the website.  Please <a href='Login.aspx'>click here</a> to return to the login page.";
            }
            else
            {
                lblError.Text = "Username taken";
            }
        }
コード例 #3
0
        protected void btnNextButton_Click(object sender, EventArgs e)
        {
            if (IAccept.Checked)
            {
                using (UniversalEntities entity = new UniversalEntities())
                {
                    Student student = entity.Students.Where(p => p.ReferenceNumber == hfReference.Value).FirstOrDefault();

                    if (cbBrokerAccept.Checked)
                    {
                        student.AppointedABSA = true;
                    }
                    else
                    {
                        student.AppointedABSA = false;
                    }
                    entity.SaveChanges();
                };

                RemotePost myremotepost = new RemotePost();
                myremotepost.Url = @"https://www.vcs.co.za/vvonline/ccform.asp";
                myremotepost.Add("p1", "2672");
                myremotepost.Add("p2", lblReference.Text);
                myremotepost.Add("p3", "CompCare NetworX StudentPlan Membership");
                myremotepost.Add("p4", contribution.Text.Remove(0, 2));
                myremotepost.Add("Hash", CalculateMD5Hash("2672", lblReference.Text, "CompCare NetworX StudentPlan Membership", contribution.Text.Remove(0, 2), ConfigurationManager.AppSettings.Get("MD5Key")));
                myremotepost.Post();
            }
            else
            {
                lblError.Text = @"You need to accept the <a href='TermsAndConditions.aspx' target='_blank'>Terms and Conditions</a>";
            }
        }
コード例 #4
0
 protected void btnSubmit_Click(object sender, EventArgs e)
 {
     if (Session["IdMember"] == null)
     {
         FormsAuthentication.RedirectToLoginPage();
     }
     else
     {
         try
         {
             using (UniversalEntities entity = new UniversalEntities())
             {
                 int       idMember  = int.Parse(Session["IdMember"].ToString());
                 Member    member    = entity.Members.Where(p => p.IdMember == idMember).SingleOrDefault();
                 User      user      = entity.Users.Where(i => i.IdMember == idMember).SingleOrDefault();
                 Dependant dependant = entity.Dependants.Where(p => p.IdMember == idMember && p.IdDependantType == 5).SingleOrDefault();
                 if (tbNewPassword.Text == "" || tbConfirmPassword.Text == "" || tbOldPassword.Text == "")
                 {
                     lblStatus.Text      = "Please provide a value for all three fields";
                     lblStatus.ForeColor = Color.Red;
                 }
                 else if (tbNewPassword.Text != tbConfirmPassword.Text)
                 {
                     lblStatus.Text      = "Your new password and confirm password does not match";
                     lblStatus.ForeColor = Color.Red;
                 }
                 else if (user.Password != tbOldPassword.Text)
                 {
                     lblStatus.Text      = "Your old password is different to what is saved in the database";
                     lblStatus.ForeColor = Color.Red;
                 }
                 else
                 {
                     user.Password = tbNewPassword.Text;
                     entity.SaveChanges();
                     lblStatus.Text      = "Password has been successfully changed";
                     lblStatus.ForeColor = Color.Blue;
                     string toAddress  = dependant.EmailAddress;
                     string toAddress2 = @"*****@*****.**";
                     string title      = "Password Changed on CompCare Website";
                     string mailBody   = string.Format("Dear {0}, you have successfully changed your website password on the CompCare Wellness Website.", dependant.DependantName);
                     string mailBody2  = string.Format("Dependant {0} changed password to {1}", member.MAMembershipNumber, tbNewPassword.Text);
                     SendEmail(toAddress2, title, mailBody2, member.MAMembershipNumber);
                     SendEmail(toAddress, title, mailBody, member.MAMembershipNumber);
                     ClearTextBoxes();
                 }
             }
         }
         catch (Exception ex)
         {
             lblStatus.Text      = @"The system was unable to change your password. The <a href='mailto:[email protected]'>webmaster</a> has been notified of this error.";
             lblStatus.ForeColor = Color.Red;
             SendEmailToWebmaster("*****@*****.**", @"Error encountered on the ExistingMembers/ChangePassword page", ex.ToString());
         }
     }
 }
コード例 #5
0
 protected void btnSubmit_Click(object sender, EventArgs e)
 {
     using (UniversalEntities entity = new UniversalEntities())
     {
         Member member = entity.Members.Where(i => i.MAMembershipNumber == tbMembershipNumber.Text).SingleOrDefault();
         if (member == null)
         {
             lblChangePasswordError.Text = "Membership Number does not exist in database.";
         }
         else
         {
             Dependant dependant = entity.Dependants.Where(i => i.IdMember == member.IdMember && i.IdDependantType == 5).SingleOrDefault();
             User      user      = entity.Users.Where(i => i.IdMember == member.IdMember).SingleOrDefault();
             if (dependant.IdentityNumber != tbIdnumber.Text)
             {
                 lblChangePasswordError.Text = "ID Number you provided does not match with the ID Number associated with the Membership Number in the database.";
             }
             else if (tbPassword1.Text == "")
             {
                 lblChangePasswordError.Text = "Please provide a value for the password field.";
             }
             else if (tbPassword1.Text != tbPassword2.Text)
             {
                 lblChangePasswordError.Text = "Your passwords doesn't match";
             }
             else
             {
                 user.Password = tbPassword1.Text;
                 entity.SaveChanges();
                 lblChangePasswordError.Text      = "Your password has been changed.  Click here to return to the <a href='Default.aspx'>login page</a>.";
                 lblChangePasswordError.ForeColor = Color.Blue;
                 string toAddress  = dependant.EmailAddress;
                 string toAddress2 = @"*****@*****.**";
                 string title      = "Password Changed on CompCare Website";
                 string mailBody   = string.Format(" Dear {0}, you have successfully changed your website password.", dependant.DependantName);
                 string mailBody2  = string.Format("Member {0} changed password on the CompCare website to {1}", member.MAMembershipNumber, tbPassword1.Text);
                 SendEmail(toAddress2, title, mailBody2);
                 ClearFields();
                 try
                 {
                     SendEmail(toAddress, title, mailBody);
                 }
                 catch (Exception ex)
                 {
                     lblChangePasswordError.Text = string.Format(@"Your password has been changed, however, we encountered a problem sending confirmation of this transaction to your email address.  In case your address has changed, please update your profile at the membership department <a href='mailto:[email protected]?subject=Please update my profile, membership number {0}'", member.MAMembershipNumber);
                 }
             }
         }
     }
 }
コード例 #6
0
 protected void btnSubmit_Click(object sender, EventArgs e)
 {
     using (UniversalEntities entity = new UniversalEntities())
     {
         User user = entity.Users.Where(i => i.Username == tbUsername.Text).SingleOrDefault();
         if (user == null)
         {
             lblChangePasswordError.Text = "User does not exist in database.";
         }
         else
         {
             Student student = entity.Students.Where(i => i.IDPassport == tbIdnumber.Text).SingleOrDefault();
             if (student.IDPassport.ToLower() != tbUsername.Text.ToLower())
             {
                 lblChangePasswordError.Text = "Please provide a vaild ID /Passport number.";
             }
             else if (tbPassword1.Text == "")
             {
                 lblChangePasswordError.Text = "Please provide a value for the password field.";
             }
             else if (tbPassword1.Text != tbPassword2.Text)
             {
                 lblChangePasswordError.Text = "Your passwords doesn't match";
             }
             else
             {
                 user.Password = tbPassword1.Text;
                 entity.SaveChanges();
                 lblChangePasswordError.Text      = "Your password has been changed.  Click here to return to the <a href='Default.aspx'>login page</a>.";
                 lblChangePasswordError.ForeColor = Color.Blue;
                 string toAddress  = student.Email;
                 string toAddress2 = @"*****@*****.**";
                 string title      = "Password Changed on CompCare Website";
                 string mailBody   = string.Format(" Dear {0}, you have successfully changed your website password on the StudentPlan website.", student.FirstNames);
                 string mailBody2  = string.Format("Student {0} changed password to {1}", student.IdStudent, tbPassword1.Text);
                 SendEmail(toAddress2, title, mailBody2);
                 try
                 {
                     SendEmail(toAddress, title, mailBody);
                 }
                 catch (Exception ex)
                 {
                     lblChangePasswordError.Text = @"The system encountered a problem sending your confirmation email.  Have you supplied us your correct Email Address?  If you believe this is in error please report this problem to the <a href='mailto:[email protected]'>webmaster</a>.";
                 }
             }
         }
     }
 }
コード例 #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string referenceNumber = Request.QueryString["p2"];

            lblReferenceNumber.Text     = referenceNumber;
            lblReason.Text              = Request.QueryString["p3"] != null ? Request.QueryString["p3"].Remove(0, 5) : "";
            lblAuthorisationNumber.Text = Request.QueryString["p3"] != null ? Request.QueryString["p3"].Remove(6, 10): "";
            lblCardHolderName.Text      = Request.QueryString["p5"];
            lblAmount.Text              = Request.QueryString["p6"];
            lblCartType.Text            = Request.QueryString["p7"];
            lblDescriptionOfGoods.Text  = Request.QueryString["p8"];
            lblCardHolderEmail.Text     = Request.QueryString["p9"];
            lblMaskedCardNumber.Text    = Request.QueryString["MaskedCardNumber"];

            using (UniversalEntities entity = new UniversalEntities())
            {
                Student student = entity.Students.Where(p => p.ReferenceNumber == referenceNumber).FirstOrDefault();
                student.TransactionSuccess = false;
                entity.SaveChanges();
            }
        }
コード例 #8
0
        private void SendCertificateAndNotifyABSA()
        {
            Student student = entity.Students.Where(p => p.ReferenceNumber == lblReferenceNumber.Text).FirstOrDefault();

            student.TransactionSuccess = true;
            //student.PreferredSupplier = hfSupplierSelected.Value != "" ? int.Parse(hfSupplierSelected.Value) : null;
            entity.SaveChanges();

            //
            string fileNameExisting = ConfigurationManager.AppSettings.Get("FilePath") + "certificateTemplate.pdf";
            string fileNameNew      = ConfigurationManager.AppSettings.Get("FilePath") + "Cert_" + student.ReferenceNumber + ".pdf";

            // open the reader
            PdfReader reader   = new PdfReader(fileNameExisting);
            Rectangle size     = reader.GetPageSizeWithRotation(1);
            Document  document = new Document(size);

            // open the writer
            FileStream fs     = new FileStream(fileNameNew, FileMode.Create, FileAccess.Write);
            PdfWriter  writer = PdfWriter.GetInstance(document, fs);

            document.Open();

            // the pdf content
            PdfContentByte cb = writer.DirectContent;

            // select the font properties
            BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

            cb.SetColorFill(BaseColor.DARK_GRAY);
            cb.SetFontAndSize(bf, 10);

            // write the text in the pdf content
            cb.BeginText();
            //line1
            cb.ShowTextAligned(3, DateTime.Today.ToShortDateString(), 140, 575, 0);
            cb.ShowTextAligned(3, student.CommencementDate.Value.ToShortDateString(), 430, 575, 0);
            //line2
            cb.ShowTextAligned(3, student.FirstNames, 140, 555, 0);
            cb.ShowTextAligned(3, student.EndDate.Value.ToShortDateString(), 430, 555, 0);
            //line3
            cb.ShowTextAligned(3, student.Surname, 140, 530, 0);
            cb.ShowTextAligned(3, student.MembershipNumber, 430, 530, 0);
            //line4
            cb.ShowTextAligned(3, student.StudentNumber, 140, 510, 0);
            cb.ShowTextAligned(3, "R " + student.Contribution.ToString() + ".00", 430, 510, 0);
            //line5
            cb.ShowTextAligned(3, student.IDPassport, 140, 488, 0);
            cb.ShowTextAligned(3, student.StudyDuration.ToString(), 430, 488, 0);
            //line6
            Institution ins = entity.Institutions.Where(p => p.IdInstitution == student.StudyInstitution).FirstOrDefault();

            cb.ShowTextAligned(3, ins.InstitutionName, 140, 468, 0);
            cb.EndText();
            //add template to content
            PdfImportedPage page = writer.GetImportedPage(reader, 1);

            cb.AddTemplate(page, 0, 0);
            // close the streams and voilá the file should be changed :)
            document.Close();
            fs.Close();
            writer.Close();
            reader.Close();

            //

            //create pdf Document
            //var pdf = new Document(PageSize.A4, 50, 50, 0, 0);
            //string filename = ConfigurationManager.AppSettings.Get("FilePath") + student.ReferenceNumber + ".pdf";
            //PdfWriter writer = PdfWriter.GetInstance(pdf, new FileStream(filename, FileMode.Create));
            //pdf.Open();

            ////Fonts----//
            //var titleFont = FontFactory.GetFont("Calibri", 13, Font.BOLD);
            //var bodyFont = FontFactory.GetFont("Calibri", 11, Font.NORMAL);

            ////Header and Footer
            //var header = iTextSharp.text.Image.GetInstance(Server.MapPath("~/Images/DocHeader.jpg"));
            //header.SetAbsolutePosition(0, 750);
            //header.ScaleAbsolute(600, 100);
            //pdf.Add(header);
            //var footer = iTextSharp.text.Image.GetInstance(Server.MapPath("~/Images/DocFooter.jpg"));
            //footer.SetAbsolutePosition(0, 0);
            //footer.ScaleAbsolute(600, 100);
            //pdf.Add(footer);

            //populate document
            //pdf.Add(new Paragraph(" ", bodyFont));
            //pdf.Add(new Paragraph(" ", bodyFont));
            //pdf.Add(new Paragraph(" ", bodyFont));
            //pdf.Add(new Paragraph(" ", bodyFont));
            //pdf.Add(new Paragraph(" ", bodyFont));
            //pdf.Add(new Paragraph(" ", bodyFont));
            //pdf.Add(new Paragraph("Date: " + DateTime.Today.ToShortDateString(), bodyFont));
            //pdf.Add(new Paragraph("Name: " + student.FirstNames, bodyFont));
            //pdf.Add(new Paragraph("Surname: " + student.Surname, bodyFont));
            //pdf.Add(new Paragraph("Student No: " + student.StudentNumber, bodyFont));
            //pdf.Add(new Paragraph("Passport No: " + student.IDPassport, bodyFont));
            //pdf.Add(new Paragraph(" ", bodyFont));
            //pdf.Add(new Paragraph("Membership Application", titleFont));
            //pdf.Add(new Paragraph(" ", bodyFont));
            //pdf.Add(new Paragraph("We are pleased to welcome you to the CompCare Wellness NetworX option for students with effect from " + student.CommencementDate.Value.ToShortDateString() + " to " + student.EndDate.Value.ToShortDateString() + ". CompCare Wellness is a Registered Medical Scheme and qualifies as an approved Medical Insurance product for foreign students as required by the Department of Home affairs.", bodyFont));
            //pdf.Add(new Paragraph(" ", bodyFont));
            //pdf.Add(new Paragraph("Your medical aid number is " + student.MembershipNumber + ". Your new medical aid card, which shows your medical aid number, will follow shortly.", bodyFont));
            //pdf.Add(new Paragraph(" ", bodyFont));
            //pdf.Add(new Paragraph("We acknowledge receipt of your contribution of ZAR" + student.Contribution + ", which covers membership of the Scheme for " + student.StudyDuration + " months.", bodyFont));
            //pdf.Add(new Paragraph(" ", bodyFont));
            //pdf.Add(new Paragraph("Please note the following:", titleFont));
            //pdf.Add(new Paragraph(" ", bodyFont));
            //pdf.Add(new Paragraph("1. This cover will not be cancelled for any reason unless we are requested to do so by the Institution at which you are studying.", bodyFont));
            //pdf.Add(new Paragraph("2. Please ensure that you consult your selected contracted Universal Healthcare Doctor for all your medical requirements. Two out-of-area visits per beneficiary will be covered per annum. The member is required to pay the out-of-area provider in cash and claim back. Reimbursement is at 80% of the cost of the claim to a maximum of R750 per event (i.e. for the GP consultation and all related costs).", bodyFont));
            //pdf.Add(new Paragraph("3. If your contracted Doctor refers you to a Hospital or a Specialist, please ensure that you contact us for an authorisation. If you are referred without an authorisation, the account will not be paid.", bodyFont));
            //pdf.Add(new Paragraph("4. In the rare case that you receive an account from a Doctor, please send it to us and we will reimburse your costs at the agreed rate.", bodyFont));
            //pdf.Add(new Paragraph("5. Should you wish to change your selected Doctor, please contact us at least 30 days in advance of the change.", bodyFont));
            //pdf.Add(new Paragraph("6. A 12 month exclusion applies to pregnancy and related claims if applicable.", bodyFont));
            //pdf.Add(new Paragraph("We sincerely hope that your membership of the Scheme will be long and mutually beneficial. Please contact us by phone, fax or e-mail should you have any query.", bodyFont));
            //pdf.Add(new Paragraph(" ", bodyFont));
            //pdf.Add(new Paragraph("Yours sincerely", bodyFont));
            //pdf.Add(new Paragraph(" ", bodyFont));
            //pdf.Add(new Paragraph("CompCare Wellness Medical Scheme", titleFont));


            //string filename = @"C:\\Users\\jaco.kleynhans\\Documents\\Visual Studio 2010\\Projects\\CompCare\\StudentPlan\\Certificates\\" + student.IDPassport + "-" + DateTime.Today + ".pdf";
            //iTextSharp.text.Image header = iTextSharp.text.Image.GetInstance(ConfigurationManager.AppSettings.Get("FilePath") + "header.jpg");
            //iTextSharp.text.Image footer = iTextSharp.text.Image.GetInstance(ConfigurationManager.AppSettings.Get("FilePath") + "footer.jpg");

            //pdf.Close();

            NotifyNetworks(student);
            NotifyABSA(student);
            NotiFyMembership(student, fileNameNew);
            NotifyEsther(student);
            NotifyNewBiz(student);
            NotifyWebmaster(student);
            SendApplicationForm(student);
            string toAddress = student.Email;
            string mailTitle = "StudentPlan Membership Certificate";
            string mailBody  = string.Format("Dear {0}, please find your membership certificate attached. \r\n Kind Regards. \r\n StudentPlan Webmaster.", student.FirstNames);

            SendEmail(toAddress, mailTitle, mailBody, fileNameNew);

            btnAccept.Enabled   = false;
            SuccessText.Text    = "Certificate emailed.";
            gvProviders.Visible = false;
            dvSuppliers.Visible = false;
            Response.Redirect("ThankYou.aspx");
        }
コード例 #9
0
        static void Main(string[] args)
        {
            //List<Supplier> suppliers = entity.Suppliers.Where(p => p.IsNetworkSupplier.Value).ToList();
            List <SupplierAddress> supplierAddresses = entity.SupplierAddresses.Where(p => !p.IsPostalAddress.Value).ToList();

            Console.WriteLine("Found " + supplierAddresses.Count() + " Network Suppliers");
            try
            {
                int i = 0;
                int d = 0;
                foreach (var item in supplierAddresses)
                {
                    i++;
                    Console.WriteLine(i + "Getting GeoLocation for " + item.IdSupplier);

                    Console.WriteLine(i + "Getting GeoLoc for " + item.Address2 + "," + item.Address3 + "," + item.Address4);
                    Province prov = entity.Provinces.Where(p => p.IdProvince == item.IdProvince).FirstOrDefault();
                    GeoLoc?  loc  = Geocoder.LocateGoogle(item.Address2 + "," + item.Address3 + "," + item.Address4 + "," + prov.Name);
                    if (loc.HasValue)
                    {
                        Console.WriteLine(i + "Supplier " + item.IdSupplier + loc.Value.ToString());
                        item.Latitude  = loc.Value.Lat;
                        item.Longitude = loc.Value.Lon;
                        d++;
                    }
                    else
                    {
                        Console.WriteLine(i + "No co-ordinates found for supplier " + item.IdSupplier);
                    }
                }

                /*
                 * //SupplierAddress address = entity.SupplierAddresses.Where(p => !p.IsPostalAddress.Value && p.IdSupplier == item.IdSupplier).FirstOrDefault();
                 * // if (address != null)
                 * //{
                 *  //Province prov = entity.Provinces.Where(p => p.IdProvince == address.IdProvince).FirstOrDefault();
                 *  //if (prov != null)
                 *  //{
                 *  //    if (prov.IdProvince == 11)
                 *  /*    {
                 *          prov = null;
                 *      }
                 *  }
                 *  if (!address.Latitude.HasValue)
                 *  {
                 *
                 *      Console.WriteLine(i + "Getting GeoLoc for " + address.Address1 + "," + address.Address2 + "," + (prov != null ? prov.Name: "") + "," + (address.PostalCode != null ? address.PostalCode.Trim(): ""));
                 *      GeoLoc? loc = Geocoder.LocateGoogle(address.Address1 + "," + address.Address2 + "," + (prov != null ? prov.Name : "") + "," + (address.PostalCode != null ? address.PostalCode.Trim() : ""));
                 *      if (loc.HasValue)
                 *      {
                 *          Console.WriteLine(i + "Supplier " + item.SupplierName + loc.Value.ToString());
                 *          item.Latitude = loc.Value.Lat;
                 *          item.Longitude = loc.Value.Lon;
                 *          d++;
                 *      }
                 *      else
                 *      {
                 *          Console.WriteLine(i + "No co-ordinates found for supplier " + item.SupplierName);
                 *      }
                 *  }
                 *  else
                 *  {
                 *      Console.WriteLine(i + "Supplier " + item.SupplierName + " has co-ordinates and is skipped");
                 *  }
                 * }
                 * else
                 * {
                 *  Console.WriteLine(i + "Could not find an address for " + item.SupplierName);
                 * }
                 * }
                 * */
                entity.SaveChanges();
                Console.WriteLine(d + "has been updated");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            // List<CareCrossDoctors> doctors = entity.CareCrossDoctors.ToList();
        }
コード例 #10
0
        protected void btnNext_Click(object sender, EventArgs e)
        {
            using (UniversalEntities entity = new UniversalEntities())
            {
                DateTime dob;
                DateTime commencementDate = new DateTime(int.Parse(lbStartYear.SelectedValue), ConvertToInt(lbStartMonth.SelectedValue), 01);
                DateTime endDate          = new DateTime(int.Parse(lbEndYear.SelectedValue), ConvertToInt(lbEndMonth.SelectedValue), GetLastDayOfTheMonth(lbEndMonth.SelectedValue));
                User     user             = entity.Users.Where(p => p.Username == tbUsername.Text).FirstOrDefault();

                if (!DateTime.TryParse(DateOfBirth.Text, out dob))
                {
                    lblError.Text = "Please enter a valid Date of Birth";
                }
                else if (!CheckIfLongerThanSixMonths(endDate, commencementDate))
                {
                    lblError.Text = "We can unfortunately only consider cover of periods longer than 6 months.";
                }
                else if (rblGettingIncome.SelectedValue == "yes" && GrossIncome.Text == "")
                {
                    lblError.Text = "Please specify the approximate income amount you will be receiving during your study.";
                }
                else if (user != null)
                {
                    lblError.Text = "Username taken. Please supply a different username";
                }
                else if (tbPassword.Text != tbConfirmPassword.Text)
                {
                    lblError.Text = "Password fields does not match";
                }
                else
                {
                    string   reference        = tbIdNumber.Text + DateTime.Today.ToShortDateString().Replace("/", "") + DateTime.Now.ToShortTimeString().Replace(":", "").Remove(4, 3);
                    TimeSpan duration         = endDate - commencementDate;
                    int      s                = int.Parse(lbStudyInstitution.SelectedValue);
                    int      ins              = entity.Institutions.Where(p => p.IdInstitution == s).FirstOrDefault().IdInstitution;
                    double   months           = Math.Round(duration.TotalDays / 30.4);
                    double   contribution     = Math.Round(months * 336);
                    int      idTitle          = int.Parse(lbTitles.SelectedItem.Value);
                    int      idMaritalStatus  = int.Parse(lbMaritalStatus.SelectedItem.Value);
                    int      idCountryofIssue = int.Parse(lbCountryOfIssue.SelectedItem.Value);
                    int      idAccountType    = rblAccountType.SelectedItem != null?int.Parse(rblAccountType.SelectedItem.Value) : 1;

                    string membershipNumber = "";
                    bool   isExistingMember = false;

                    if (hfIsExisting.Value == "true")
                    {
                        isExistingMember = true;
                        membershipNumber = tbExistingMembershipNumber.Text;
                    }
                    else
                    {
                        List <Student> students = entity.Students.Where(p => !p.IsExistingMember.Value).OrderByDescending(p => p.MembershipNumber).ToList();
                        if (students.Count < 1)
                        {
                            membershipNumber = "4900000";
                        }
                        else
                        {
                            membershipNumber = (int.Parse(students[0].MembershipNumber) + 1).ToString();
                            if (membershipNumber.StartsWith("48"))
                            {
                                membershipNumber = "4900000";
                            }
                        }
                    }
                    bool    isGettingIncome = false;
                    decimal incomeAmount    = 0;
                    if (rblGettingIncome.SelectedValue == "yes")
                    {
                        isGettingIncome = true;
                        incomeAmount    = decimal.Parse(GrossIncome.Text);
                    }
                    int     idGender = int.Parse(listbGenders.SelectedValue);
                    Student student  = new Student
                    {
                        Surname           = surname.Text,
                        FirstNames        = firstNames.Text,
                        DateOfBirth       = dob,
                        RegistrationDate  = DateTime.Today,
                        CommencementDate  = commencementDate,
                        EndDate           = endDate,
                        StudyInstitution  = ins,
                        StudentNumber     = studentNumber.Text,
                        Email             = email.Text,
                        StudyDuration     = months,
                        Contribution      = contribution,
                        IDPassport        = tbIdNumber.Text,
                        IdTitle           = idTitle,
                        IdMaritalStatus   = idMaritalStatus,
                        CountryOfIssue    = idCountryofIssue,
                        BusinessTelephone = workTel.Text,
                        HomeTelephone     = homeTel.Text,
                        Facsimile         = fax.Text,
                        Cellular          = cell.Text,
                        AccountHolderName = AccountHolderName.Text,
                        BankName          = BankName.Text,
                        BranchCode        = BranchCode.Text,
                        AccountNumber     = AccountNumber.Text,
                        IdAccountType     = idAccountType,
                        ReferenceNumber   = reference,
                        MembershipNumber  = membershipNumber,
                        IsExistingMember  = isExistingMember,
                        IsGettingIncome   = isGettingIncome,
                        IncomeAmount      = incomeAmount,
                        IdGender          = idGender
                    };
                    entity.AddObject("Students", student);
                    entity.SaveChanges();

                    Student savedStudent   = entity.Students.Where(p => p.ReferenceNumber == reference).FirstOrDefault();
                    int     postalProvince = int.Parse(lbOProvinces.SelectedItem.Value);
                    int     physProvince   = int.Parse(lbPProvinces.SelectedItem.Value);

                    StudentAddress postal = new StudentAddress
                    {
                        Address1        = OAddress1.Text,
                        Address2        = OAddress2.Text,
                        Address3        = OAddress3.Text,
                        Address4        = OAddress4.Text,
                        IdProvince      = postalProvince,
                        IdStudent       = savedStudent.IdStudent,
                        PostalCode      = OPostal.Text,
                        IsPostalAddress = true,
                        Country         = "South Africa",
                        DateCreated     = DateTime.Today
                    };

                    StudentAddress phys = new StudentAddress
                    {
                        Address1        = PAddress1.Text,
                        Address2        = PAddress2.Text,
                        Address3        = PAddress3.Text,
                        Address4        = PAddress4.Text,
                        IdProvince      = physProvince,
                        IdStudent       = savedStudent.IdStudent,
                        PostalCode      = PPostal.Text,
                        IsPostalAddress = false,
                        Country         = "South Africa",
                        DateCreated     = DateTime.Today
                    };

                    User newUser = new User
                    {
                        Username     = tbUsername.Text,
                        Password     = tbPassword.Text,
                        DateCreated  = DateTime.Today,
                        IdStudent    = savedStudent.IdStudent,
                        IsActive     = true,
                        IsAdmin      = false,
                        IsBCIMA      = false,
                        IsBroker     = false,
                        IsCompany    = false,
                        IsCompCare   = true,
                        IsGrintek    = false,
                        IsLifestyle  = false,
                        IsNHBRCFLI   = false,
                        IsPartner    = false,
                        IsStudent    = true,
                        IsSupplier   = false,
                        IsTiger      = false,
                        IsWorkerPlan = false,
                        UserLevel    = 0
                    };

                    entity.AddObject("Users", newUser);
                    entity.AddObject("StudentAddresses", postal);
                    entity.AddObject("StudentAddresses", phys);
                    entity.SaveChanges();

                    User savedUser = entity.Users.Where(p => p.IdStudent == savedStudent.IdStudent).FirstOrDefault();
                    SendEmail(savedStudent.Email, "You have been successfully registered on the CompCare StudentPlan website", string.Format("Dear {0}, \r\n You have been successfully registered on the CompCare StudentPlan website.  Your Username have been saved to the database as {1}. \r\n Kind regards, \r\n CompCare Webmaster", savedStudent.FirstNames, savedUser.Username));

                    if (hfIsSaNational.Value == "false")
                    {
                        Response.Redirect("DependantMedical.aspx?Reference=" + reference);
                    }
                    else
                    {
                        Response.Redirect("ConfirmDetails.aspx?Reference=" + reference);
                    }
                }
            }
        }
コード例 #11
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            Member member = entity.Members.Where(i => i.MAMembershipNumber == tbMembershipNumber.Text).SingleOrDefault();

            if (member == null)
            {
                lblMembershipNumber.Text = "Membership Number does not exist in database.";
            }
            else
            {
                Dependant dependant = entity.Dependants.Where(p => p.IdMember == member.IdMember && p.IdDependantType == 5).FirstOrDefault();
                User      user      = entity.Users.Where(i => i.IdMember == member.IdMember).FirstOrDefault();
                if (dependant.IdentityNumber != tbIdNumber.Text)
                {
                    lblError.Text = "Please provide a valid ID Number";
                }
                else if (user != null && user.Password != "")
                {
                    lblError.Text = "You have already been registered on the website";
                }
                else if (user != null && user.Password == "")
                {
                    user.UserEmail        = dependant.EmailAddress;
                    user.IsCompCare       = true;
                    user.IdMember         = member.IdMember;
                    user.IsActive         = true;
                    user.Username         = tbUsername.Text;
                    user.Password         = tbPassword.Text;
                    user.RegistrationDate = DateTime.Today;
                    user.UserLevel        = 0;
                    user.DateCreated      = DateTime.Today;
                    entity.SaveChanges();
                    string toAddress  = dependant.EmailAddress;
                    string toAddress2 = @"*****@*****.**";
                    string title      = "Member Registration on CompCare Website";
                    string mailBody   = string.Format("Dear {0}, you have been successfully registered on the CompCare website.  Your email address has been registered in the database as being {1}", dependant.DependantName, dependant.EmailAddress);
                    string mailBody2  = string.Format("CompCare user dependant ID {0} registered. username {1} password {2}", dependant.IdDependant, user.Username, user.Password);
                    SendEmail(toAddress2, title, mailBody2);
                    SendEmail(toAddress, title, mailBody);
                    lblSuccess.Text            = @"You have been successfully registered.  Please use your credentials to log onto the website.  Please <a href='Default.aspx'>click here</a> to return to the login page.";
                    tbMembershipNumber.Text    = member.MAMembershipNumber;
                    tbMembershipNumber.Enabled = false;
                    tbIdNumber.Text            = dependant.IdentityNumber;
                    tbIdNumber.Enabled         = false;
                    trName.Visible             = true;
                    trSurname.Visible          = true;
                    trEmail.Visible            = true;
                    lblName.Text       = dependant.DependantName;
                    lblName.Enabled    = false;
                    lblSurname.Text    = dependant.DependantSurname;
                    lblSurname.Enabled = false;
                    tbEmail.Text       = dependant.EmailAddress;
                    tbEmail.Enabled    = false;
                    trButton.Visible   = false;
                    btnSubmit.Enabled  = false;
                    trPsword.Visible   = false;
                    trPsword2.Visible  = false;
                    tbUsername.Enabled = false;
                }
                else
                {
                    User newUser = new User
                    {
                        UserEmail        = dependant.EmailAddress,
                        IsCompCare       = true,
                        IdMember         = member.IdMember,
                        IsActive         = true,
                        Username         = tbUsername.Text,
                        Password         = tbPassword.Text,
                        RegistrationDate = DateTime.Today,
                        UserLevel        = 0,
                        DateCreated      = DateTime.Today
                    };
                    entity.AddToUsers(newUser);
                    entity.SaveChanges();
                    string toAddress2 = @"*****@*****.**";
                    string toAddress  = dependant.EmailAddress;
                    string title      = "Member Registration on CompCare Website";
                    string mailBody   = string.Format(" Dear {0}, you have been successfully registered on the CompCare website.  Your email address has been registered in the database as being {1}", dependant.DependantName, dependant.EmailAddress);
                    string mailBody2  = string.Format("CompCare user dependant ID {0} registered. username {1} password {2}", dependant.IdDependant, user.Username, user.Password);
                    SendEmail(toAddress2, title, mailBody2);
                    SendEmail(toAddress, title, mailBody);
                    lblSuccess.Text            = @"You have been successfully registered.  Please use your credentials to log onto the website.  Please <a href='Default.aspx'>click here</a> to return to the login page.";
                    tbMembershipNumber.Text    = member.MAMembershipNumber;
                    tbMembershipNumber.Enabled = false;
                    tbIdNumber.Text            = dependant.IdentityNumber;
                    tbIdNumber.Enabled         = false;
                    trName.Visible             = true;
                    trSurname.Visible          = true;
                    trEmail.Visible            = true;
                    lblName.Text       = dependant.DependantName;
                    lblName.Enabled    = false;
                    lblSurname.Text    = dependant.DependantSurname;
                    lblSurname.Enabled = false;
                    tbEmail.Text       = dependant.EmailAddress;
                    tbEmail.Enabled    = false;
                    trButton.Visible   = false;
                    btnSubmit.Enabled  = false;
                    trPsword.Visible   = false;
                    trPsword2.Visible  = false;
                    tbUsername.Enabled = false;
                }
            }
        }