Exemple #1
0
        partial void InsertbusinessPartner(businessPartner instance)
        {
            instance.timeStampCreated = DateTime.Now;

            String companyGroupCode = this.companyGroupForBps.Where(c => c.companyCode.Equals(instance.companyCode)).Select(c => c.companyGroupCode).FirstOrDefault();

            if (!String.IsNullOrEmpty(companyGroupCode))
            {
                instance.companyCode      = null;
                instance.companyGroupCode = companyGroupCode;
            }

            this.ExecuteDynamicInsert(instance);
        }
Exemple #2
0
partial         void InsertbusinessPartner(businessPartner instance)
        {
            instance.timeStampCreated = DateTime.Now;

            String companyGroupCode = this.companyGroupForBps.Where(c => c.companyCode.Equals(instance.companyCode)).Select(c => c.companyGroupCode).FirstOrDefault();

            if (!String.IsNullOrEmpty(companyGroupCode))
            {
                instance.companyCode = null;
                instance.companyGroupCode = companyGroupCode;
            }

            this.ExecuteDynamicInsert(instance);
        }
        public static Boolean ProcessCustomer(string fileContent, out businessPartner businessPartner, out String outCompanyCode)
        {
            businessPartner = new businessPartner();

            DALPortalDataContext dc = new DALPortalDataContext();
            Boolean update;
            String companyCode = String.Empty;
            outCompanyCode = String.Empty;

            try
            {
                XDocument xmldoc = XDocument.Parse(fileContent);
                XElement docTypeElement = xmldoc.Element("DEBMAS03");
                XElement iDocElement = docTypeElement.Element("IDOC");
                var customerHeaderElement = iDocElement.Element("E1KNA1M");
                //Int32 CardCode;

                // Remove unused elements
                iDocElement.Element("EDI_DC40").Remove();

                // BpCode, remove leading zero's from Cardcode
                String bpCode = Convert.ToInt32(customerHeaderElement.Element("KUNNR").Value).ToString();
                String sectionCode = customerHeaderElement.Element("E1KNVVM").Element("VKORG").Value;

                companyCode = CompanyClass.GetCompanyBasedOnSection(sectionCode, dc);
                outCompanyCode = companyCode;

                // Check if bp Already exists
                businessPartner = BusinessPartnerClass.GetBusinessPartner(bpCode, companyCode, dc);
                if (businessPartner == null)
                {
                    businessPartner = new businessPartner();
                    update = false;
                }
                else
                {
                    update = true;
                }

                if (!update)
                {
                    String companyGroupCode = dc.companyGroupForBps.Where(c => c.companyCode.Equals(companyCode)).Select(c => c.companyGroupCode).FirstOrDefault();

                    if (String.IsNullOrEmpty(companyGroupCode))
                        businessPartner.companyCode = companyCode;
                    else
                        businessPartner.companyGroupCode = companyGroupCode;
                }

                // Mapp customer header data
                businessPartner.bpCode = bpCode;
                businessPartner.bpType = 'C';
                businessPartner.bpName = customerHeaderElement.Elements().Where(c => c.Name.ToString().Equals("NAME1")).FirstOrDefault().Value;
                businessPartner.address = customerHeaderElement.Elements().Where(c => c.Name.ToString().Equals("STRAS")).FirstOrDefault().Value;

                if (customerHeaderElement.Elements().Any(c => c.Name.ToString().Equals("TELF1")))
                    businessPartner.telephone = customerHeaderElement.Elements().Where(c => c.Name.ToString().Equals("TELF1")).FirstOrDefault().Value;

                if(customerHeaderElement.Elements().Any(c => c.Name.ToString().Equals("TELFX")))
                    businessPartner.fax = customerHeaderElement.Elements().Where(c => c.Name.ToString().Equals("TELFX")).FirstOrDefault().Value;

                businessPartner.countryCode = customerHeaderElement.Elements().Where(c => c.Name.ToString().Equals("LAND1")).FirstOrDefault().Value;
                businessPartner.languageCode = customerHeaderElement.Elements().Where(c => c.Name.ToString().Equals("SPRAS_ISO")).FirstOrDefault().Value;

                // Mapp contactperson data
                foreach (var contactpersonElement in customerHeaderElement.Elements("E1KNVKM").ToList())
                {
                    contactPerson contact;

                    // Contact Id
                    String contactPersonCode = Convert.ToInt32(contactpersonElement.Elements().Where(c => c.Name.ToString().Equals("PARNR")).FirstOrDefault().Value).ToString();
                    Boolean newContact = false;

                    if (update && businessPartner.contactPersons.Any(c => c.contactPersonCode.Equals(contactPersonCode)))
                    {
                        contact = businessPartner.contactPersons.Where(c => c.contactPersonCode.Equals(contactPersonCode)).FirstOrDefault();
                    }
                    else
                    {
                        contact = new contactPerson();
                        contact.contactPersonCode = contactPersonCode;
                        newContact = true;
                    }

                    // Email
                    var emailAddress = contactpersonElement.Elements().Where(c => c.Name.ToString().Equals("PARAU")).FirstOrDefault();
                    if (emailAddress != null)
                        contact.eMail = emailAddress.Value.ToLower();

                    // Title
                    var title = contactpersonElement.Elements().Where(c => c.Name.ToString().Equals("ANRED")).FirstOrDefault();
                    if (title != null)
                        contact.title = title.Value;

                    // FirstName
                    var firstName = contactpersonElement.Elements().Where(c => c.Name.ToString().Equals("NAMEV")).FirstOrDefault();
                    if (firstName != null)
                        contact.firstName = firstName.Value;

                    // LastName
                    var lastName = contactpersonElement.Elements().Where(c => c.Name.ToString().Equals("NAME1")).FirstOrDefault();
                    if (lastName != null)
                        contact.lastName = lastName.Value;

                    // WebUser
                    var webUserType = contactpersonElement.Elements().Where(c => c.Name.ToString().Equals("AKVER")).FirstOrDefault();
                    if (webUserType != null)
                    {
                        contact.isWebContact = (webUserType.Value == "02") ? false : true;
                        contact.TMP_PortalAccess = webUserType.Value;
                    }

                    // Add CardCode to contactperson
                    if (newContact)
                        businessPartner.contactPersons.Add(contact);
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(String.Format("Error converting customer {0} for company {1} from SAP ECC6 XML format. Error: {2}", businessPartner.bpCode, companyCode, ex.Message), "MapCustomerFromECC6");
                return false;
            }

            if (update)
            {
                try
                {
                    dc.SubmitChanges();
                    Trace.WriteLine(String.Format("Updating Customer {0} for company {1} Successfull.", businessPartner.bpCode, companyCode), "MapCustomerFromECC6");
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(String.Format("Error Updating Customer {0} for company {1}. Error: {2}", businessPartner.bpCode, companyCode, ex.Message), "MapCustomerFromECC6");
                    return false;
                }
            }
            else
            {
                try
                {
                    dc.businessPartners.InsertOnSubmit(businessPartner);
                    dc.SubmitChanges();
                    Trace.WriteLine(String.Format("Creating Customer {0} for company {1} Successfull.", businessPartner.bpCode, companyCode), "MapCustomerFromECC6");
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(String.Format("Error Creating Customer {0} for company {1}. Error: {2}", businessPartner.bpCode, companyCode, ex.Message), "MapCustomerFromECC6");
                    return false;
                }
            }

            return true;
        }
Exemple #4
0
 partial void UpdatebusinessPartner(businessPartner instance)
 {
     instance.timeStampLastUpdate = DateTime.Now;
     this.ExecuteDynamicUpdate(instance);
 }
Exemple #5
0
partial         void UpdatebusinessPartner(businessPartner instance)
        {
            instance.timeStampLastUpdate = DateTime.Now;
            this.ExecuteDynamicUpdate(instance);
        }
        public Boolean ProcessDataFromXML(String databaseName, String fileContent)
        {
            Boolean returnValue = true;

              try
              {
            // Check xml type

            // SAPECC6
            if (fileContent.Contains("IDOC"))
            {
              businessPartner customer = new businessPartner();
              DALPortalDataContext dc = new DALPortalDataContext();
                    String companyCode;

              //Customer
              if (fileContent.Contains("DEBMAS03"))
              {
            if (!XMLSAPECC6Processor.ProcessCustomer(fileContent, out customer, out companyCode))
              return false;

            CreateUsers(customer, companyCode, dc);
              }
              //SalesOrder
              if (fileContent.Contains("ORDERS05"))
              {
            salesOrder document = new salesOrder();

            if (!XMLSAPECC6Processor.ProcessSalesOrder(fileContent, out document))
              return false;
              }
              //Delivery
              if (fileContent.Contains("DELVRY03"))
              {
            delivery document = new delivery();

            if (!XMLSAPECC6Processor.ProcessDelivery(fileContent, out document))
              return false;
              }

                    //Item
                    if (fileContent.Contains("MATMAS05"))
                    {
                        if (!XMLSAPECC6Processor.ProcessItem(fileContent))
                            return false;
                    }
            }
              }
              catch (Exception ex)
              {
            Trace.WriteLine(String.Format("Process XML file Failed. Error: {0}", ex.Message), "ProcessDataFromXML");
            return false;
              }

              return returnValue;
        }
        public void CreateUsers(businessPartner customer, String companyCode, DALPortalDataContext dc)
        {
            foreach (var contactPerson in customer.contactPersons.Where(c => c.businessPartnerId.Equals(customer.businessPartnerId)))
              {
                try
                {
                    if (contactPerson.eMail == null)
                        continue;

                    MembershipUser user = Membership.GetUser(contactPerson.eMail);

                    Boolean newUser = (user == null);
                    Guid newUserId;
                    String password = String.Empty;

                    if (newUser && contactPerson.isWebContact)
                    {
                        object akey = Guid.NewGuid();
                        password = GeneratePassword.Generate(10, 10);

                        Membership.CreateUser(contactPerson.eMail, password, contactPerson.eMail);
                        Roles.AddUserToRole(contactPerson.eMail, "User");
                    }

                    if (contactPerson.userId == null && contactPerson.isWebContact)
                    {
                        newUserId = dc.Users.Where(c => c.UserName.ToLower().Equals(contactPerson.eMail.ToLower())).Select(c => c.UserId).FirstOrDefault();

                        contactPerson.userId = newUserId;

                        dc.contactPersons.Where(c => c.contactPersonCode.Equals(contactPerson.contactPersonCode)).FirstOrDefault().userId = newUserId;
                        dc.SubmitChanges();
                    }

                    // Contact person in database, but not in xml file
                    if (contactPerson.TMP_PortalAccess == null)
                    {
                        dc.contactPersons.Where(c => c.contactPersonCode.Equals(contactPerson.contactPersonCode)).FirstOrDefault().isWebContact = false;
                        dc.SubmitChanges();
                    }

                    // Deactivate the user account
                    // Existing user which is not a webcontact anymore or when user is not in file anymore.
                    if ((!newUser && !contactPerson.isWebContact) || contactPerson.TMP_PortalAccess == null)
                        if(user != null)
                            if (user.IsApproved == true)
                            {
                                user.IsApproved = false;
                                Membership.UpdateUser(user);
                            }

                    // Activate the user account
                    if (!newUser && contactPerson.isWebContact && contactPerson.TMP_PortalAccess != null)
                        if (user.IsApproved == false)
                        {
                            user.IsApproved = true;
                            Membership.UpdateUser(user);
                        }

                    if(contactPerson.userId.HasValue)
                        UpdateApplicationRoles(contactPerson, dc);

                    if (newUser && contactPerson.isWebContact)
                    {
                        // Send Email
                        SendMail(contactPerson.eMail, password, companyCode);
                    }

                }
                catch (Exception ex)
                {
                    Trace.WriteLine("An error occurred while creating user: "******". Error: " + ex.Message, "CreateUsers");
                }
              }
        }
        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;
        }
        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);
              }
        }
		private void attach_businessPartners(businessPartner entity)
		{
			this.SendPropertyChanging();
			entity.country = this;
		}
		private void detach_businessPartners(businessPartner entity)
		{
			this.SendPropertyChanging();
			entity.language = null;
		}
		private void detach_businessPartners(businessPartner entity)
		{
			this.SendPropertyChanging();
			entity.contactPerson = null;
		}
		private void detach_businessPartners(businessPartner entity)
		{
			this.SendPropertyChanging();
			entity.companyGroup = null;
		}
 partial void DeletebusinessPartner(businessPartner instance);
 partial void UpdatebusinessPartner(businessPartner instance);
 partial void InsertbusinessPartner(businessPartner instance);