protected void RadSaveButton_Click(object sender, EventArgs e)
        {
            DALPortalDataContext dc = new DALPortalDataContext();

            certificateBundle bundleOld = dc.certificateBundles.Where(c => c.businessPartnerId.Equals(businessPartnerId) && c.isActive.Equals(true)).SingleOrDefault();

            if (bundleOld != null)
            {
                if (this.modelId == bundleOld.modelId)
                {
                    bundleOld.startDate = DateTime.Now;
                    bundleOld.expireDate = validUntilDTP.SelectedDate;
                    bundleOld.previousCertQty = bundleOld.actualCertQty;
                    // bundle.orderedCertQty = (Int32)creditsLeftTxtBox.Value - bundle.previousCertQty;
                    bundleOld.actualCertQty = (Int32)creditsLeftTxtBox.Value;
                    bundleOld.certificatePrice = (Decimal)priceTextBox.Value;
                    bundleOld.isActive = true;
                    // bundleOud.modelId = modelId;
                    bundleOld.companyCode = "ZW";
                    bundleOld.businessPartnerId = businessPartnerId;
                }
                else
                {
                    bundleOld.isActive = false;
                    certificateBundle bundelNew = new certificateBundle();
                    bundelNew.startDate = DateTime.Now;
                    bundelNew.expireDate = validUntilDTP.SelectedDate;
                    bundelNew.previousCertQty = bundleOld.actualCertQty;
                    bundelNew.orderedCertQty = 0;
                    bundelNew.actualCertQty = (Int32)creditsLeftTxtBox.Value;
                    bundelNew.certificatePrice = (Decimal)priceTextBox.Value;
                    bundelNew.isActive = true;
                    bundelNew.modelId = modelId;
                    bundelNew.companyCode = "ZW";
                    bundelNew.businessPartnerId = businessPartnerId;
                    dc.certificateBundles.InsertOnSubmit(bundelNew);
                }
            }
            else
            {
                certificateBundle bundelNew = new certificateBundle();
                bundelNew.startDate = DateTime.Now;
                bundelNew.expireDate = validUntilDTP.SelectedDate;
                bundelNew.previousCertQty = 0;
                bundelNew.orderedCertQty = 0;
                bundelNew.actualCertQty = (Int32)creditsLeftTxtBox.Value;
                bundelNew.certificatePrice = (Decimal)priceTextBox.Value;
                bundelNew.isActive = true;
                bundelNew.modelId = modelId;
                bundelNew.companyCode = "ZW";
                bundelNew.businessPartnerId = businessPartnerId;
                dc.certificateBundles.InsertOnSubmit(bundelNew);
            }

            dc.SubmitChanges();

            Session["businessPartnerId"] = businessPartnerId;
            Response.Redirect("~/Pages/CustomerAccountDetails.aspx");
        }
Пример #2
0
        protected void RadSaveButton_Click(object sender, EventArgs e)
        {
            DALPortalDataContext dc = new DALPortalDataContext();
            certificateBundle bundleOld = dc.certificateBundles.Where(c => c.businessPartnerId.Equals(bpId) && c.isActive.Equals(true)).SingleOrDefault();

            if (bundleOld != null)
            {
                bundleOld.isActive = false;
            }
            certificateBundle bundelNew = new certificateBundle();
            if (bundleOld != null)
            {
                bundelNew.previousCertQty = bundleOld.actualCertQty;
                bundelNew.actualCertQty = (Int32)creditsOrderTxtBox.Value + bundleOld.actualCertQty;
                bundelNew.orderedCertQty = bundleOld.orderedCertQty + (Int32)creditsOrderTxtBox.Value;
                bundelNew.certificatePrice = bundleOld.certificatePrice;
            }
            else
            {
                bundelNew.previousCertQty = 0;
                bundelNew.actualCertQty = (Int32)creditsOrderTxtBox.Value;
                bundelNew.orderedCertQty = (Int32)creditsOrderTxtBox.Value;
                bundelNew.certificatePrice = (decimal)7.50;
            }

            bundelNew.startDate = DateTime.Now;
            bundelNew.expireDate = DateTime.Now.AddYears(1);

            bundelNew.isActive = true;
            bundelNew.modelId = 2;
            bundelNew.companyCode = "ZW";
            bundelNew.businessPartnerId = bpId;

            businessPartner bpProps = dc.businessPartners.Where(c => c.businessPartnerId.Equals(bpId)).Select(c => c).SingleOrDefault();

            DocumentCached cashed = new DocumentCached();
            cashed.CustomerCode = bpProps.bpCode;
            cashed.VLCompany = "ZW01";
            cashed.DocDate = DateTime.Now;
            cashed.Comment = "Certificate portal invoice";

            DocumentLineCached cashedLine = new DocumentLineCached();

            cashedLine.Currency = "EUR";
            cashedLine.LineNum = 1;
            cashedLine.ItemCode = "C";
            cashedLine.Quantity = (Int32)creditsOrderTxtBox.Value;
            cashedLine.UnitOfMeasure = "ST";
            cashedLine.Price = (decimal)bundelNew.certificatePrice;
            cashedLine.ShortText = creditsOrderTxtBox.Value + " ordered on " + DateTime.Now + ".";
            cashed.Lines.Add(cashedLine);
            dc.certificateBundles.InsertOnSubmit(bundelNew);

            dc.SubmitChanges();

            XmlToObject.ObjectToXml(cashed, HttpContext.Current.Server.MapPath(Path.Combine(@"~\Files\Outbox", "invoice " + DateTime.Now.Ticks.ToString() + ".xml")));

              MembershipUser membershipUser = Membership.GetUser();

              if (membershipUser != null)
              {
            String emailTemplate = HttpContext.Current.Server.MapPath(Path.Combine(@"~\Files\EmailTemplates", "OrderConfirmation.html"));

            StreamReader streamReader = new StreamReader(emailTemplate);
            String mailMessageBody = streamReader.ReadToEnd();

            String fromEmailAddress;
            String subject;
            String toEmailAddress;

            mailMessageBody = EmailClass.GetMailParams(mailMessageBody, out fromEmailAddress, out toEmailAddress, out subject);
            mailMessageBody = mailMessageBody.Replace("{Credits}", membershipUser.UserName);
            try
            {
              MailMessage mailMessage = new MailMessage();
              mailMessage.IsBodyHtml = true;
              mailMessage.From = new MailAddress(fromEmailAddress);
              mailMessage.To.Add(membershipUser.UserName);
              mailMessage.Subject = subject;
              mailMessage.Body = mailMessageBody;
              SmtpClient smtpClient = new SmtpClient();
              smtpClient.Send(mailMessage);

            }
            catch (Exception ex)
            {
              // TODO: Create errorpage for user
              Response.Redirect("~/Pages/OrderSuccess.aspx");
            }
              }

            Session["businessPartnerId"] = bpId;
            Response.Redirect("~/Pages/OrderSuccess.aspx");
        }
Пример #3
0
        protected void RadGridCertificate_ItemCommand(object sender, GridCommandEventArgs e)
        {
            if (e.CommandName == "Outsource")
              {
            int rowindex = e.Item.ItemIndex;
            GridDataItem item = (GridDataItem)e.Item;

            string certificateLink = item["CertificateLink"].Text.ToString();
            string heatNumber = item["HeatNumber"].Text.ToString();
            string companyCode = item["CardCode"].Text.ToString();
            string delLineNum = item["DELLineNum"].Text.ToString();
            string delDocNum = item["DELDocNum"].Text.ToString();
            string batchIdString = item["batchId"].Text.ToString();
            string customerReference = item["CustomerReference"].Text.ToString();

            string url = ResolveUrl(certificateLink);
            string filePath = HttpContext.Current.Server.MapPath(certificateLink);
            double daysLeft = 0;

            if (!File.Exists(filePath))
            {
              ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "myalert", "alert('This file does not exist.');", true);
              return;
            }

            // Copy file to Temp folder and rename
            String newFileName = String.Format("{0}-{1}-{2}.pdf", delDocNum, customerReference, heatNumber);
            String tempPath = HttpContext.Current.Server.MapPath(Path.Combine(@"~\Files\Temp", newFileName));
            File.Copy(filePath, tempPath, true);
            String tempUrl = ResolveUrl("../Files/Temp/" + newFileName);

            Guid userId = GetUserId();
            contactPerson contactPerson = ContactPersonClass.GetContactPerson(userId, dc);
            businessPartner bpMother = new businessPartner();
            certificateBundle currentBundle = new certificateBundle() { modelId = 0 };

            if (contactPerson != null)
            {
              bpMother = BusinessPartnerClass.GetBusinessPartnerMother(userId, dc);
              currentBundle = CertificateBundleClass.GetCurrentBundle(bpMother.businessPartnerId, dc);
            }

            int batchId = Convert.ToInt32(batchIdString);

            vw_DeliveryLine delLine = dc.vw_DeliveryLines.Where(c => c.batchId.Equals(batchId) && c.DELDocNum.Equals(delDocNum) && c.DELLineNum.Equals(delLineNum)).Select(c => c).SingleOrDefault();
            List<usageReport> reports = dc.usageReports.Where(c => c.batchId.Equals(batchId) && c.baseDocId.Equals(delLine.DELDocId) && c.baseLineNum.Equals(delLine.DELLineNum)).Select(c => c).ToList();

            int newCreditsUsed = 0;

            if (contactPerson != null)
            {
              if (reports.Count == 0)
              {
            newCreditsUsed = 1;
            usageReport report = new usageReport();

            report.heatNumber = heatNumber;
            report.contactPersonId = contactPerson.contactPersonId;
            report.businessPartnerId = bpMother.businessPartnerId;
            report.savedMark = DateTime.Now;
            report.companyCode = delLine.companyCode;
            report.batchId = batchId;//
            report.baseLineNum = delLine.DELLineNum;
            report.baseDocId = delLine.DELDocId;
            report.baseDocType = delLine.DELDocType;

            dc.usageReports.InsertOnSubmit(report);
            dc.SubmitChanges();
              }

              switch (currentBundle.modelId)
              {
            case 0:

              List<userRole> roles = dc.userRoles.Where(c => c.userId.Equals(userId)).ToList();
              if (roles.Any(c => c.roleCode.Equals("CERT_ACTMNG")) || roles.Any(c => c.roleCode.Equals("CERT_VLUSER")))
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "openNewTab", "window.open('" + tempUrl + "','_blank');", true);
              else
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "myalert", "alert('No bundle active.');", true);

              break;

            case 1:

              daysLeft = (currentBundle.expireDate.Value - DateTime.Now).TotalDays;

              if (daysLeft < 0)
              {
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "myalert", "alert('The bundle has expired.');", true);
              }
              else
              {
                UpdateCredits(newCreditsUsed, currentBundle);
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "openNewTab", "window.open('" + tempUrl + "','_blank');", true);
              }
              break;

            case 2:

              int certCount = currentBundle.actualCertQty.Value;
              daysLeft = (currentBundle.expireDate.Value - DateTime.Now).TotalDays;

              if (certCount < 1 && daysLeft < 0)
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "myalert", "alert('Insufficient credits and the bundle has expired.');", true);
              else if (certCount < 1)
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "myalert", "alert('Insufficient credits.');", true);
              else if (daysLeft < 0)
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "myalert", "alert('The bundle has expired.');", true);
              else
              {
                UpdateCredits(newCreditsUsed, currentBundle);
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "openNewTab", "window.open('" + tempUrl + "','_blank');", true);
              }

              break;

            case 4:

              UpdateCredits(newCreditsUsed, currentBundle);
              ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "openNewTab", "window.open('" + tempUrl + "','_blank');", true);

              break;

            default:

              ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "openNewTab", "window.open('" + tempUrl + "','_blank');", true);
              break;
              }
            }
            else
            {
              UpdateCredits(newCreditsUsed, currentBundle);
              ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "openNewTab", "window.open('" + tempUrl + "','_blank');", true);
            }

            UpdateModelInfo();
            ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "registerNewCred", "setContentHeader()", true);
              }
        }
Пример #4
0
        protected void UpdateCredits(int usedCredits, certificateBundle bundle)
        {
            if (bundle.modelId == 2)
              {
            int newCreds = (int)bundle.actualCertQty - usedCredits;
            bundle.actualCertQty = bundle.actualCertQty - usedCredits;

            if (bundle.usedCertQty == null)
              bundle.usedCertQty = usedCredits;
            else
              bundle.usedCertQty = bundle.usedCertQty + usedCredits;

            dc.SubmitChanges();
              }
              else if (bundle.modelId == 4)
              {
            if (bundle.usedCertQty == null)
              bundle.usedCertQty = usedCredits;
            else
              bundle.usedCertQty = bundle.usedCertQty + usedCredits;

            dc.SubmitChanges();
              }
        }
Пример #5
0
        protected void RadButtonSelectedInZip_Click(object sender, EventArgs e)
        {
            //List<String> certificateLinks = GetCertificateLinks();

              List<vw_DeliveryLine> selectedLines = GetSelectedVwLines();
              Int32 newCreditsUsed = 0;

              if (selectedLines.Count != 0)
              {
            int usedCreds = selectedLines.Count();
            double daysLeft = 0;

            Guid userId = GetUserId();
            contactPerson contactPerson = ContactPersonClass.GetContactPerson(userId, dc);
            businessPartner bpMother = new businessPartner();
            certificateBundle currentBundle = new certificateBundle() { modelId = 0 };

            if(contactPerson != null)
            {
              bpMother = BusinessPartnerClass.GetBusinessPartnerMother(userId, dc);
              currentBundle = CertificateBundleClass.GetCurrentBundle(bpMother.businessPartnerId, dc);
            }

            switch (currentBundle.modelId)
            {
              // Van Leeuwen User
              case 0:

            List<userRole> roles = dc.userRoles.Where(c => c.userId.Equals(userId)).ToList();
            Boolean siteAdmin = dc.userSettings.Any(c => c.siteAdmin && c.userId.Equals(userId));
            if (siteAdmin || roles.Any(c => c.roleCode.Equals("CERT_ACTMNG")) || roles.Any(c => c.roleCode.Equals("CERT_VLUSER")))
            {
              CreateZipFile(selectedLines);
            }
            else
            {
              ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "myalert", "alert('No bundle active.');", true);
            }

            break;

              // One Year Access
              case 1:

            daysLeft = (currentBundle.expireDate.Value - DateTime.Now).TotalDays;
            if (daysLeft < 0)
            {
              ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "myalert", "alert('The bundle has expired.');", true);
            }
            else
            {
              CreateZipFile(selectedLines);
              newCreditsUsed = CalculateCreditsUsed(selectedLines);
              RegisterUsedCerts(selectedLines, contactPerson.contactPersonId, bpMother.businessPartnerId);
              UpdateCredits(newCreditsUsed, currentBundle);
            }

            break;

              // Certificate Credit x times 50
              case 2:

            newCreditsUsed = CalculateCreditsUsed(selectedLines);

            int certCount = currentBundle.actualCertQty.Value;
            daysLeft = (currentBundle.expireDate.Value - DateTime.Now).TotalDays;

            if (certCount < 1 && daysLeft < 0)
            {
              ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "myalert", "alert('Insufficient credits and the bundle as expired.');", true);
            }
            else if (certCount < newCreditsUsed)
            {
              ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "myalert", "alert('Insufficient credits.');", true);
            }
            else if (daysLeft < 0)
            {
              ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "myalert", "alert('The bundle has expired.');", true);
            }
            else
            {
              CreateZipFile(selectedLines);
              RegisterUsedCerts(selectedLines, contactPerson.contactPersonId, bpMother.businessPartnerId);
              UpdateCredits(newCreditsUsed, currentBundle);
            }

            break;

              default:

            CreateZipFile(selectedLines);
            newCreditsUsed = CalculateCreditsUsed(selectedLines);
            RegisterUsedCerts(selectedLines, contactPerson.contactPersonId, bpMother.businessPartnerId);
            UpdateCredits(newCreditsUsed, currentBundle);

            break;
            }

            UpdateModelInfo();
              }
              else
            LiteralNoCertificatesSelected.Visible = true;
        }
Пример #6
0
 partial void DeletecertificateBundle(certificateBundle instance);
Пример #7
0
 partial void UpdatecertificateBundle(certificateBundle instance);
Пример #8
0
 partial void InsertcertificateBundle(certificateBundle instance);
Пример #9
0
		private void detach_certificateBundles(certificateBundle entity)
		{
			this.SendPropertyChanging();
			entity.businessPartner = null;
		}