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);
              }
        }
Esempio n. 2
0
		private void detach_usageReports(usageReport entity)
		{
			this.SendPropertyChanging();
			entity.contactPerson = null;
		}
        private void RegisterUsedCerts(List<vw_DeliveryLine> selectedLines, Int32 contactPersonId, Int32 businessPartnerId)
        {
            //Guid userId = (Guid)Membership.GetUser().ProviderUserKey;
              //contactPerson contactPerson = dc.contactPersons.Where(c => c.userId.Equals(userId)).SingleOrDefault();

              //if (contactPerson == null)
              //  return;

              //int bpId = contactPerson.businessPartnerId;

              //if (contactPerson.businessPartner.bpMother.HasValue)
              //  bpId = contactPerson.businessPartner.bpMother.Value;

              foreach (vw_DeliveryLine deliveryLine in selectedLines)
              {
            usageReport report = new usageReport();
            report.contactPersonId = contactPersonId;
            report.businessPartnerId = businessPartnerId;
            report.savedMark = DateTime.Now;
            report.companyCode =  deliveryLine.companyCode;
            report.baseLineNum = deliveryLine.DELLineNum;
            report.baseDocId = deliveryLine.DELDocId;
            report.baseDocType = "DL";
            report.batchId = deliveryLine.batchId;
            report.heatNumber = deliveryLine.HeatNumber;

            dc.usageReports.InsertOnSubmit(report);
              }

              dc.SubmitChanges();
        }
Esempio n. 4
0
 partial void DeleteusageReport(usageReport instance);
Esempio n. 5
0
 partial void UpdateusageReport(usageReport instance);
Esempio n. 6
0
 partial void InsertusageReport(usageReport instance);
Esempio n. 7
0
		private void detach_usageReports(usageReport entity)
		{
			this.SendPropertyChanging();
			entity.businessPartner = null;
		}
Esempio n. 8
0
		private void detach_usageReports(usageReport entity)
		{
			this.SendPropertyChanging();
			entity.delivery = null;
		}