Esempio n. 1
0
        /// <summary>
        /// link the fields in the current ledger
        /// </summary>
        /// <param name="AFieldCSVFile"></param>
        public static void GenerateFieldsFinanceOnly(string AFieldCSVFile)
        {
            XmlDocument doc = TCsv2Xml.ParseCSV2Xml(AFieldCSVFile, ",");

            XmlNode RecordNode = doc.FirstChild.NextSibling.FirstChild;

            GLSetupTDS GLSetupDS = new GLSetupTDS();

            PCountryTable CountryTable = null;

            TDBTransaction Transaction = null;

            DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                                                                      TEnforceIsolationLevel.eilMinimum,
                                                                      ref Transaction,
                                                                      delegate
            {
                CountryTable = PCountryAccess.LoadAll(Transaction);
            });

            while (RecordNode != null)
            {
                long   id          = 100 + Convert.ToInt64(TXMLParser.GetAttribute(RecordNode, "id"));
                string CountryCode = TXMLParser.GetAttribute(RecordNode, "Name");
                string UnitName    = ((PCountryRow)CountryTable.Rows.Find(CountryCode)).CountryName;
                Int64  PartnerKey  = id * 1000000;

                // create cost centre
                ACostCentreRow CostCentreRow = GLSetupDS.ACostCentre.NewRowTyped();
                CostCentreRow.LedgerNumber         = FLedgerNumber;
                CostCentreRow.CostCentreCode       = (id * 100).ToString("0000");
                CostCentreRow.CostCentreName       = UnitName;
                CostCentreRow.CostCentreToReportTo = MFinanceConstants.INTER_LEDGER_HEADING;
                CostCentreRow.CostCentreType       = MFinanceConstants.FOREIGN_CC_TYPE;
                GLSetupDS.ACostCentre.Rows.Add(CostCentreRow);

                // create foreign ledger, cost centre link validledgernumber
                AValidLedgerNumberRow ValidLedgerNumber = GLSetupDS.AValidLedgerNumber.NewRowTyped();
                ValidLedgerNumber.LedgerNumber        = FLedgerNumber;
                ValidLedgerNumber.PartnerKey          = PartnerKey;
                ValidLedgerNumber.CostCentreCode      = CostCentreRow.CostCentreCode;
                ValidLedgerNumber.IltProcessingCentre = Convert.ToInt64(MFinanceConstants.ICH_COST_CENTRE) * 10000;
                GLSetupDS.AValidLedgerNumber.Rows.Add(ValidLedgerNumber);

                RecordNode = RecordNode.NextSibling;
            }

            GLSetupTDSAccess.SubmitChanges(GLSetupDS);
        }
        /// <summary>
        /// generate the units
        /// </summary>
        /// <param name="AFieldCSVFile"></param>
        public static void GenerateFields(string AFieldCSVFile)
        {
            XmlDocument doc = TCsv2Xml.ParseCSVFile2Xml(AFieldCSVFile, ",");

            XmlNode RecordNode = doc.FirstChild.NextSibling.FirstChild;

            PartnerImportExportTDS PartnerDS = new PartnerImportExportTDS();
            GLSetupTDS             GLSetupDS = new GLSetupTDS();

            PCountryTable CountryTable = null;

            TDBTransaction Transaction = new TDBTransaction();

            DBAccess.ReadTransaction(
                ref Transaction,
                delegate
            {
                CountryTable = PCountryAccess.LoadAll(Transaction);
            });

            while (RecordNode != null)
            {
                PUnitRow UnitRow = PartnerDS.PUnit.NewRowTyped();
                long     id      = 100 + Convert.ToInt64(TXMLParser.GetAttribute(RecordNode, "id"));
                UnitRow.PartnerKey = id * 1000000;
                string CountryCode = TXMLParser.GetAttribute(RecordNode, "Name");
                UnitRow.UnitName     = ((PCountryRow)CountryTable.Rows.Find(CountryCode)).CountryName;
                UnitRow.UnitTypeCode = "F";
                PartnerDS.PUnit.Rows.Add(UnitRow);

                PPartnerRow PartnerRow = PartnerDS.PPartner.NewRowTyped();
                PartnerRow.PartnerKey       = UnitRow.PartnerKey;
                PartnerRow.PartnerShortName = UnitRow.UnitName;
                PartnerRow.PartnerClass     = MPartnerConstants.PARTNERCLASS_UNIT;
                PartnerRow.StatusCode       = MPartnerConstants.PARTNERSTATUS_ACTIVE;
                PartnerDS.PPartner.Rows.Add(PartnerRow);

                // add empty location so that the partner can be found in the Partner Find screen
                PPartnerLocationRow PartnerLocationRow = PartnerDS.PPartnerLocation.NewRowTyped();
                PartnerLocationRow.PartnerKey  = UnitRow.PartnerKey;
                PartnerLocationRow.LocationKey = 0;
                PartnerLocationRow.SiteKey     = 0;
                PartnerDS.PPartnerLocation.Rows.Add(PartnerLocationRow);

                // create unit hierarchy
                UmUnitStructureRow UnitStructureRow = PartnerDS.UmUnitStructure.NewRowTyped();
                UnitStructureRow.ParentUnitKey = 1000000;
                UnitStructureRow.ChildUnitKey  = UnitRow.PartnerKey;
                PartnerDS.UmUnitStructure.Rows.Add(UnitStructureRow);

                // create special type
                PPartnerTypeRow PartnerTypeRow = PartnerDS.PPartnerType.NewRowTyped();
                PartnerTypeRow.PartnerKey = UnitRow.PartnerKey;
                PartnerTypeRow.TypeCode   = MPartnerConstants.PARTNERTYPE_LEDGER;
                PartnerDS.PPartnerType.Rows.Add(PartnerTypeRow);

                // create cost centre
                ACostCentreRow CostCentreRow = GLSetupDS.ACostCentre.NewRowTyped();
                CostCentreRow.LedgerNumber         = FLedgerNumber;
                CostCentreRow.CostCentreCode       = (id * 100).ToString("0000");
                CostCentreRow.CostCentreName       = UnitRow.UnitName;
                CostCentreRow.CostCentreToReportTo = MFinanceConstants.INTER_LEDGER_HEADING;
                CostCentreRow.CostCentreType       = MFinanceConstants.FOREIGN_CC_TYPE;
                GLSetupDS.ACostCentre.Rows.Add(CostCentreRow);

                // create foreign ledger, cost centre link validledgernumber
                AValidLedgerNumberRow ValidLedgerNumber = GLSetupDS.AValidLedgerNumber.NewRowTyped();
                ValidLedgerNumber.LedgerNumber        = FLedgerNumber;
                ValidLedgerNumber.PartnerKey          = UnitRow.PartnerKey;
                ValidLedgerNumber.CostCentreCode      = CostCentreRow.CostCentreCode;
                ValidLedgerNumber.IltProcessingCentre = Convert.ToInt64(MFinanceConstants.ICH_COST_CENTRE) * 10000;
                GLSetupDS.AValidLedgerNumber.Rows.Add(ValidLedgerNumber);

                RecordNode = RecordNode.NextSibling;
            }

            PartnerImportExportTDSAccess.SubmitChanges(PartnerDS);

            GLSetupTDSAccess.SubmitChanges(GLSetupDS);
        }
Esempio n. 3
0
        public static bool RunFirstSetup(
            string AUserID,
            string AFirstName,
            string ALastName,
            string ALanguageCode,
            string AEmailAddress,
            List <string> AInitialModulePermissions,
            string AInitialPassword,
            Int64 ASiteKey,
            bool AEnableSelfSignup,
            out TVerificationResultCollection AVerificationResult)
        {
            bool result = true;

            AVerificationResult = new TVerificationResultCollection();
            TVerificationResult           VerificationResult           = null;
            TVerificationResultCollection VerificationResultCollection = new TVerificationResultCollection();

            if (AInitialPassword != String.Empty)
            {
                // check if password is valid, it meets the criteria
                if (!TSharedSysManValidation.CheckPasswordQuality(AInitialPassword, out VerificationResult))
                {
                    AVerificationResult.Add(VerificationResult);
                    return(false);
                }
            }

            result = TMaintenanceWebConnector.SaveUserAndModulePermissions(
                AUserID, AFirstName, ALastName, AEmailAddress, ALanguageCode,
                false, false, false, AInitialModulePermissions, 0,
                out VerificationResultCollection);

            if (result != false)
            {
                TDBTransaction t        = new TDBTransaction();
                TDataBase      db       = DBAccess.Connect("RunFirstSetup");
                bool           SubmitOK = false;

                db.WriteTransaction(ref t,
                                    ref SubmitOK,
                                    delegate
                {
                    if (AInitialPassword != String.Empty)
                    {
                        result = TMaintenanceWebConnector.SetUserPassword(AUserID, AInitialPassword, false, false,
                                                                          String.Empty, String.Empty, out VerificationResultCollection);
                    }
                    else
                    {
                        // TODO send welcoming Email, with link for setting the password
                    }

                    if (result)
                    {
                        TSystemDefaults defaults = new TSystemDefaults(db);
                        defaults.SetSystemDefault(SharedConstants.SYSDEFAULT_SITEKEY, ASiteKey.ToString(), db);
                        defaults.SetSystemDefault(SharedConstants.SYSDEFAULT_SELFSIGNUPENABLED, AEnableSelfSignup.ToString(), db);

                        GLSetupTDS GLMainDS = new GLSetupTDS();
                        SubmitOK            = TGLSetupWebConnector.CreateSite(ref GLMainDS, "Default Site", ASiteKey, t);

                        if (SubmitOK)
                        {
                            GLSetupTDSAccess.SubmitChanges(GLMainDS, db, t);
                        }
                    }
                });

                db.CloseDBConnection();
            }

            if (!result)
            {
                if (VerificationResultCollection.HasCriticalErrors)
                {
                    AVerificationResult = VerificationResultCollection;
                }
                else
                {
                    AVerificationResult.Add(VerificationResult);
                }
            }

            return(result);
        }