コード例 #1
0
        public void AtIndex_MultiCharacterSplit()
        {
            string s = "123abc456";

            Assert.Equal("123", StringSplit.AtIndex(s, "abc", 0));
            Assert.Equal("456", StringSplit.AtIndex(s, "abc", 1));
        }
コード例 #2
0
ファイル: StringHelper.cs プロジェクト: zh7262703/Emr_MySql
        public static string[] Split(string vStr, string[] separator, StringSplitOptions options)
        {
            return(vStr.Split(separator, options));

#if other
            return(StringSplit.Split(vStr, separator, options));
#endif
        }
コード例 #3
0
        public void AtIndex()
        {
            string s = "abc,1,hello,,";

            Assert.Equal("abc", StringSplit.AtIndex(s, ",", 0));
            Assert.Equal("1", StringSplit.AtIndex(s, ",", 1));
            Assert.Equal("hello", StringSplit.AtIndex(s, ",", 2));
            Assert.Equal("", StringSplit.AtIndex(s, ",", 3));
        }
コード例 #4
0
        public DataTable FromCsv(string strFilePath)
        {
            fileDelimiter = GetDelimiter(strFilePath);
            DataSet oDS = new DataSet();

            oDS.Tables.Add("Property");
            var oTable = oDS.Tables[0];

            using (var stream = new System.IO.FileStream(strFilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read))
            {
                var    oSR = UtilFunctions.CreateStreamReader(stream);
                string line;
                int    cellCount   = 0;
                var    stringSplit = new StringSplit(fileDelimiter);
                var    lineValues  = new List <string>(10);

                while ((line = oSR.ReadLine()) != null)
                {
                    stringSplit.Split(line, lineValues);

                    bool skipRow = false;
                    if (!hasHeaderColumnGenerated)
                    {
                        oTable.Columns.AddRange(GenerateColumnHeader(lineValues, out skipRow));
                    }

                    if (!skipRow)
                    {
                        int intCounter = 0;
                        var oRows      = oTable.NewRow();
                        var colCount   = Math.Min(oTable.Columns.Count, 20);
                        foreach (string str in lineValues)
                        {
                            if (intCounter < colCount)
                            {
                                oRows[intCounter] = str;
                                intCounter++;
                            }
                        }

                        if (cellCount < intCounter)
                        {
                            cellCount = intCounter;
                        }
                        oTable.Rows.Add(oRows);
                    }
                }

                //Removing if Extra Columns were created
                int colIndex = 20;
                while (cellCount < oTable.Columns.Count)
                {
                    oTable.Columns.RemoveAt(--colIndex);
                }
            }
            return(oTable);
        }
コード例 #5
0
        public MailChimpUriHelper(string apiKey)
        {
            var sp = new StringSplit(apiKey, '-');

            if (string.IsNullOrEmpty(sp.Value2))
            {
                throw new ArgumentException("Invalid API Key cannot determine Mailchimp Datacenter", apiKey);
            }

            Datacenter = sp.Value2;
        }
コード例 #6
0
        public void AtIndex_ExceedsBoundary_ThrowsException()
        {
            string s = "abc,1,hello,,";

            try
            {
                StringSplit.AtIndex(s, ",", 5);
                Assert.True(false, "Did not expect to execute this line!");
            }
            catch (ArgumentOutOfRangeException)
            {
                // pass
            }
        }
コード例 #7
0
        public static void StringSplit()
        {
            string      strContent = "!(140) ,!025 and !140,!253,!253 senza 352,!52Y,!CC 1300,!CC 1400,!CC 1600,!CC 900,!CNG,(!CC 1300)AND(!CC 1400),(!CC 1300)AND(!CC 1400)AND(!CC 1600),(!CC 900)AND(!CC 1300),(!CC 900)AND(!CC 1300)AND(!CC 1400),(!CC 900)AND(!CC 1600),(025) and (140),(025-)AND(140-)AND(52Y),(025)AND(52Y),(082-),(140),(150) Knee Bag,(508),(52Y) and (!140),(6DC),(Benz) and (Benz/Metan),(Benz) OR (Benz/Metan),(CC 1300 OR CC1600),(CC 1300 OR CC1600) !OPT253,(CC 1300 OR CC1600) and OPT253,(CC900 OR CC 1300 OR CC1600),025,1.4TJet,352 PC633,400 or 59E (Open roof),407,420,421,431,432,433,435,439,4JF,4WQ,55E,56J,59E,5A6,5DE or CC1900,5EQ,5ER,5EV,5FB,68P,6DM,6QB,all,Bombola metano,CC 0.9 OR 1.4Jet,CC 1.6 !025 !140,CC 1.6 OR 1.4Jet ,CC 1300,CC 1300 !407,CC 1300 !MTA,CC 1300 407,CC 1300 MTA,CC 1300 OR CC 1600,CC 1400,CC 1400 330 530 OPT_!140_!025,CC 1400 330 OPT_!025,CC 1400 330 OPT_!140,CC 1400 530 OPT_!025,CC 1400 530 OPT_!140,CC 1400 TUTTI_I_MODELLI,CC 1600,CC 1600 OPT 253,CC 900,CC 900 OPT_!025,CC 900 OPT_!025_!140,CC 900 OPT_!140,CC 900 OPT_025,CC 900 OPT_140,CC1.4 !352 ,CC1400 OPT025 OPT 140,Cerchi in Lega,CNG,Diesel,ECU_ETM,ECU_LTM,Ext Color 268,G_DX,G_SX,GUIDA51,MOD 330 and (CC1.3 or CC1.6),MOD 330 and Color 268,MOD 352 !(PC633) !(OPT222),MOD 352 (PC633) (OPT222),MOD 352 CC1.4,MOD 352 CC1.4 (C633),MOD 352 CC1.4 (C635),MOD 530 CC 1300 !407,MOD 530 CC 1300 OPT.407,MOD 530 CC1.4,MOD_351 with CAMERA,MODELLO 351 OPT087,MODELLO OMOLOGATIVO 330,No Body 104,No colore 268,OPT253 senza 352,P253,P365,P52Y,P52Y senza 352,P5DE,Ruote in Lamiera (404 OR 406),RUOTE_OPT_404,RUOTE_OPT_406,RUOTE_OPT_433,RUOTE_OPT_435,RUOTE_OPT_439,RUOTE_OPT_4WQ,RUOTE_OPT_4XE,RUOTE_OPT_55E,RUOTE_OPT_56J,RUOTE_OPT_5A6,RUOTE_OPT_5EQ,RUOTE_OPT_5FB,RUOTE_OPT_68P,RUOTE_OPT_6U4,RUOTE_OPT_6WR,RUOTE_OPT_6XN,RUOTE_OPT_6Y8,SeqMatCall-Test-201489,test_Marco_MaterialCall,Tetto Appribile (OPT400),TETTO_APERTO,TUTTI I TIPI - MODELLI 330 351 352 !OPT087,TUTTI I TIPI - MODELLI 330 e 351,TUTTI I TIPI - MODELLI 330 e 352 Passo Corto,TUTTI I TIPI - MODELLI 530 !OPT087,TUTTI I TIPI - MODELLO 330,TUTTI I TIPI - MODELLO 351,TUTTI I TIPI - MODELLO 352,TUTTI I TIPI - MODELLO 530";
            StringSplit sp         = new StringSplit(strContent, ",");

            int iNum = 0;

            foreach (string str in sp)
            {
                System.Console.WriteLine(str);
                iNum++;
            }

            System.Diagnostics.Debug.Assert(iNum == 143);
        }
コード例 #8
0
        async public Task <List <GLDailyJournalLineClient> > CreateJournalLines(FileStream fileStream)
        {
            var reader = Uniconta.ClientTools.Util.UtilFunctions.CreateStreamReader(fileStream);

            var sp   = new StringSplit(';');
            var line = new List <string>();

            var rawLine = reader.ReadLine();

            sp.Split(rawLine, line);
            if (!await ValidateHeader(line))
            {
                return(null);
            }

            var year   = GetYearFromHeader(line);
            var AccLen = SetLimits(line);

            var vats = VATCache.GetRecords as GLVat[];

            // After header we have an empty line.
            reader.ReadLine();

            var _journalLines = new List <GLDailyJournalLineClient>(2000);

            for (;;)
            {
                rawLine = await reader.ReadLineAsync().ConfigureAwait(false);

                if (rawLine == null)
                {
                    break;
                }

                sp.Split(rawLine, line);

                var account       = testAccount(line[6], AccLen);
                var contraAccount = testAccount(line[7], AccLen);

                string vatcode = null;
                var    extcode = line[8];
                if (!string.IsNullOrEmpty(extcode))
                {
                    for (int i = 0; (i < vats.Length); i++)
                    {
                        var v = vats[i];
                        if (string.Compare(v._ExternalCode, extcode, true) == 0)
                        {
                            vatcode = v._Vat;
                            break;
                        }
                    }
                }

                var journalLine = GetJournalLine(line, year, account, contraAccount, vatcode);
                journalLine.SetMaster(GLDailyJournal);
                _journalLines.Add(journalLine);
            }
            reader.Dispose();

            return(_journalLines);
        }
コード例 #9
0
        private async void ReadFromBilagscan(UnicontaBaseEntity selectedItem)
        {
#if !SILVERLIGHT
            if (!readingFromBilagscan)
            {
                readingFromBilagscan = true;

                bool processLines = false;
                var  accessToken  = await Bilagscan.Account.GetBilagscanAccessToken(api);

                var noOfVouchers    = 0;
                var companySettings = await api.Query <CompanySettingsClient>();

                var orgNo = companySettings.FirstOrDefault()._OrgNumber;

                var journal = dgGldailyJournal.SelectedItem as GLDailyJournalClient;

                //  UnicontaBaseEntity[] baseEntityArray = new UnicontaBaseEntity[1] { selectedItem };

                using (var client = new HttpClient())
                {
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
                    var response = await client.GetAsync($"https://api.bilagscan.dk/v1/organizations/" + orgNo.ToString() + "/vouchers?seen=false&count=100&offset=0&sorts=-upload_date&status=successful");

                    var content = await response.Content.ReadAsStringAsync();

                    var vouchers = Bilagscan.Voucher.GetVouchers(content);

                    var credCache = api.CompanyEntity.GetCache(typeof(Uniconta.DataModel.Creditor)) ?? await api.CompanyEntity.LoadCache(typeof(Uniconta.DataModel.Creditor), api);

                    var offsetCache = api.CompanyEntity.GetCache(typeof(Uniconta.DataModel.GLAccount)) ?? await api.CompanyEntity.LoadCache(typeof(Uniconta.DataModel.GLAccount), api);

                    var vouchersSeen = new CommaDelimitedStringCollection();

                    var master = new List <UnicontaBaseEntity>
                    {
                        journal
                    };

                    var newLines       = new List <UnicontaBaseEntity>();
                    var updateCreditor = new List <UnicontaBaseEntity>();

                    if (vouchers?.data != null)
                    {
                        var creditors = credCache.GetKeyStrRecords as Uniconta.DataModel.Creditor[];

                        foreach (var voucher in vouchers.data)
                        {
                            vouchersSeen.Add(NumberConvert.ToString(voucher.id));
                            var journalLine = new GLDailyJournalLineClient()
                            {
                                Approved        = false,
                                ForceSettlement = false
                            };

                            var postingType = BilagscanVoucherType.Invoice;

                            var hint = Bilagscan.Voucher.GetHint(voucher.note);

                            var bilagscanRefID = voucher.id;
                            journalLine.ReferenceNumber = bilagscanRefID != 0 ? NumberConvert.ToString(bilagscanRefID) : null;

                            var bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "voucher_number", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                journalLine.Invoice = bsItem.value;
                            }

                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "voucher_type", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                switch (bsItem.value)
                                {
                                case "invoice": postingType = BilagscanVoucherType.Invoice; break;

                                case "creditnote": postingType = BilagscanVoucherType.Creditnote; break;

                                case "receipt": postingType = BilagscanVoucherType.Receipt; break;
                                }
                            }

                            var creditorCVR = string.Empty;
                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "company_vat_reg_no", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                creditorCVR = bsItem.value;
                            }

                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "total_amount_incl_vat", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                journalLine.Amount = Math.Abs(NumberConvert.ToDoubleNoThousandSeperator(bsItem.value));

                                if (postingType != BilagscanVoucherType.Creditnote)
                                {
                                    journalLine.Amount = -journalLine.Amount;
                                }
                            }

                            CountryCode countryCode = CountryCode.Denmark;
                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "country", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                CountryISOCode countryISO;
                                countryCode = CountryCode.Denmark; //default
                                if (Enum.TryParse(bsItem.value, true, out countryISO))
                                {
                                    countryCode = (CountryCode)countryISO;
                                }
                            }

                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "invoice_date", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                var invoiceDate = bsItem.value == string.Empty ? GetSystemDefaultDate() : StringSplit.DateParse(bsItem.value, DateFormat.ymd);
                                journalLine.Date = invoiceDate;

                                if (journalLine.Date == DateTime.MinValue)
                                {
                                    journalLine.Date = GetSystemDefaultDate();
                                }
                            }

                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "payment_date", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                var paymentDate = bsItem.value == string.Empty ? DateTime.MinValue : StringSplit.DateParse(bsItem.value, DateFormat.ymd);
                                journalLine._DueDate = paymentDate;
                            }

                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "currency", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                Currencies currencyISO;
                                if (!Enum.TryParse(bsItem.value, true, out currencyISO))
                                {
                                    currencyISO = Currencies.DKK; //default
                                }
                                journalLine._Currency = (byte)currencyISO;
                            }

                            string bbanAcc = null;
                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "payment_account_number", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                bbanAcc = bsItem.value;
                            }

                            string bbanRegNum = null;
                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "payment_reg_number", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                bbanRegNum = bsItem.value;
                            }

                            string ibanNo = null;
                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "payment_iban", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                ibanNo = bsItem.value;
                            }

                            string swiftNo = null;
                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "payment_swift_bic", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                swiftNo = bsItem.value;
                            }

                            string paymentCodeId = null;
                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "payment_code_id", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                paymentCodeId = bsItem.value;
                            }

                            string paymentId = null;
                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "payment_id", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                paymentId = bsItem.value;
                            }

                            string jointPaymentId = null;
                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "joint_payment_id", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                jointPaymentId = bsItem.value;
                            }

                            var paymentMethod = PaymentTypes.VendorBankAccount;
                            switch (paymentCodeId)
                            {
                            case "71": paymentMethod = PaymentTypes.PaymentMethod3; break;

                            case "73": paymentMethod = PaymentTypes.PaymentMethod4; break;

                            case "75": paymentMethod = PaymentTypes.PaymentMethod5; break;

                            case "04":
                            case "4": paymentMethod = PaymentTypes.PaymentMethod6; break;
                            }

                            if (paymentMethod != PaymentTypes.VendorBankAccount && (paymentId != null || jointPaymentId != null))
                            {
                                journalLine._PaymentMethod = paymentMethod;
                                journalLine._PaymentId     = string.Format("{0} +{1}", paymentId, jointPaymentId);
                            }
                            else if (bbanRegNum != null && bbanAcc != null)
                            {
                                journalLine._PaymentMethod = PaymentTypes.VendorBankAccount;
                                journalLine._PaymentId     = string.Format("{0}-{1}", bbanRegNum, bbanAcc);
                            }
                            else if (swiftNo != null && ibanNo != null)
                            {
                                journalLine._PaymentMethod = PaymentTypes.IBAN;
                                journalLine._PaymentId     = ibanNo;
                            }

                            journalLine.SettleValue = "Voucher";

                            Uniconta.DataModel.Creditor creditor = null;

                            if (hint != null)
                            {
                                journalLine._DocumentRef = hint.RowId;
                                //if (hint.CreditorAccount != null)
                                //    creditor = (Uniconta.DataModel.Creditor)credCache.Get(hint.CreditorAccount);
                                //if (hint.Amount != 0)
                                //    journalLine.Amount = hint.Amount;
                                //if (hint.Currency != null && hint.Currency != "-")
                                //    journalLine.Currency = hint.Currency;
                                //if (hint.PaymentId != null)
                                //{
                                //    journalLine._PaymentId = hint.PaymentId;
                                //    journalLine.PaymentMethod = hint.PaymentMethod;
                                //}
                            }

                            journalLine._AccountType = 2;

                            var creditorCVRNum = Regex.Replace(creditorCVR, "[^0-9]", string.Empty);

                            if (creditorCVRNum != string.Empty)
                            {
                                creditor = creditors.Where(s => (Regex.Replace(s._LegalIdent ?? string.Empty, "[^0-9.]", "") == creditorCVRNum)).FirstOrDefault();
                            }

                            if (creditorCVRNum == string.Empty)
                            {
                                journalLine.Text = Uniconta.ClientTools.Localization.lookup("NotValidVatNo");
                            }
                            else if (creditor == null)
                            {
                                var newCreditor = new CreditorClient()
                                {
                                    _Account       = creditorCVR,
                                    _LegalIdent    = creditorCVR,
                                    _PaymentMethod = journalLine._PaymentMethod,
                                    _PaymentId     = journalLine._PaymentId,
                                    _SWIFT         = swiftNo
                                };

                                CompanyInfo companyInformation = null;
                                try
                                {
                                    companyInformation = await CVR.CheckCountry(creditorCVR, countryCode);
                                }
                                catch (Exception ex)
                                {
                                    UnicontaMessageBox.Show(ex);
                                    return;
                                }

                                if (companyInformation != null)
                                {
                                    if (companyInformation.life != null)
                                    {
                                        newCreditor._Name = companyInformation.life.name;
                                    }

                                    if (companyInformation.address != null)
                                    {
                                        newCreditor._Address1 = companyInformation.address.CompleteStreet;
                                        newCreditor._ZipCode  = companyInformation.address.zipcode;
                                        newCreditor._City     = companyInformation.address.cityname;
                                        newCreditor._Country  = companyInformation.address.Country;
                                    }

                                    if (companyInformation.contact != null)
                                    {
                                        newCreditor._Phone        = companyInformation.contact.phone;
                                        newCreditor._ContactEmail = companyInformation.contact.email;
                                    }

                                    journalLine.Text = newCreditor.Name;
                                }
                                else
                                {
                                    newCreditor.Name = Uniconta.ClientTools.Localization.lookup("NotValidVatNo");
                                }

                                await api.Insert(newCreditor);

                                journalLine.Account = creditorCVR;
                            }
                            else
                            {
                                if (!string.IsNullOrEmpty(creditor._PostingAccount))
                                {
                                    var account = (GLAccountClient)offsetCache.Get(creditor._PostingAccount);
                                    if (!string.IsNullOrEmpty(account.Vat))
                                    {
                                        var dailyJournal = (GLDailyJournalClient)master[0];
                                        if (dailyJournal.TwoVatCodes)
                                        {
                                            journalLine._OffsetVat = account.Vat;
                                        }
                                        else
                                        {
                                            journalLine._Vat = account.Vat;
                                        }
                                    }

                                    journalLine._OffsetAccount = creditor._PostingAccount;
                                }
                                else
                                {
                                    journalLine.Vat = creditor._Vat;
                                }


                                if (journalLine._DueDate == DateTime.MinValue && creditor._Payment != string.Empty)
                                {
                                    var paymentTermsCache = api.GetCache(typeof(PaymentTerm)) ?? await api.LoadCache(typeof(PaymentTerm));

                                    var paymentTerm = (PaymentTerm)paymentTermsCache.Get(creditor._Payment);

                                    if (paymentTerm != null)
                                    {
                                        journalLine._DueDate = paymentTerm.GetDueDate(journalLine.DueDate);
                                    }
                                }

                                journalLine.Account = creditor._Account;
                                journalLine.Text    = creditor._Name;

                                if (creditor._SWIFT == null && swiftNo != null)
                                {
                                    creditor._SWIFT = swiftNo;
                                    updateCreditor.Add(creditor);
                                }
                            }

                            journalLine.SetMaster(master[0]);
                            newLines.Add(journalLine);

                            noOfVouchers += 1;
                        }
                    }
                    var errorCode = await api.Insert(newLines);

                    api.UpdateNoResponse(updateCreditor);

                    if (vouchersSeen.Count != 0)
                    {
                        // Mark voucher as seen
                        string serializedRequest = "{ \"vouchers\": [ " + vouchersSeen.ToString() + " ] }";
                        var    vContent          = new StringContent(serializedRequest, Encoding.UTF8, "application/json");
                        response = await client.PostAsync($"https://api.bilagscan.dk/v1/organizations/" + NumberConvert.ToString(orgNo) + "/vouchers/seen", vContent);

                        var res = await response.Content.ReadAsStringAsync();
                    }
                }

                if (noOfVouchers == 0)
                {
                    UnicontaMessageBox.Show(string.Format(Uniconta.ClientTools.Localization.lookup("StillProcessingTryAgain"), Uniconta.ClientTools.Localization.lookup("Bilagscan")), Uniconta.ClientTools.Localization.lookup("Bilagscan"), MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else
                {
                    var messageText = string.Concat(string.Format("{0} {1}", Uniconta.ClientTools.Localization.lookup("NumberOfImportedVouchers"), noOfVouchers),
                                                    Environment.NewLine, Environment.NewLine,
                                                    string.Format(Uniconta.ClientTools.Localization.lookup("GoTo"), Uniconta.ClientTools.Localization.lookup("Journallines")), "?");
                    if (UnicontaMessageBox.Show(messageText, Uniconta.ClientTools.Localization.lookup("BilagscanRead"), MessageBoxButton.OKCancel, MessageBoxImage.Information) == MessageBoxResult.OK)
                    {
                        AddDockItem(TabControls.GL_DailyJournalLine, journal, null, null, true);
                    }
                }
                readingFromBilagscan = false;
            }
#endif
        }
コード例 #10
0
        public void AtIndex_NonMatchingSeparator_ReturnsOriginalString()
        {
            string s = "abc,1,hello,,";

            Assert.Equal(s, StringSplit.AtIndex(s, "|", 0));
        }
コード例 #11
0
        public static Type GeneraterUserType(Type BaseType, List <DashboardUserField> flds)
        {
            try
            {
                AssemblyName    an = new AssemblyName("UserAssembly_" + BaseType.Name);
                AssemblyBuilder assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(an, AssemblyBuilderAccess.Run);
                ModuleBuilder   moduleBuilder   = assemblyBuilder.DefineDynamicModule("MainModule");

                TypeBuilder builder = moduleBuilder.DefineType(BaseType.Name + "Dashboard",
                                                               TypeAttributes.Public |
                                                               TypeAttributes.Class |
                                                               TypeAttributes.AutoClass |
                                                               TypeAttributes.AnsiClass |
                                                               TypeAttributes.BeforeFieldInit |
                                                               TypeAttributes.AutoLayout,
                                                               BaseType);
                foreach (var fld in flds)
                {
                    Type t;
                    switch (fld.DataType)
                    {
                    case 0:     // string
                        t = typeof(string);
                        break;

                    case 1:     // int
                        t = typeof(int);
                        break;

                    case 2:     // double
                        t = typeof(double);
                        break;

                    case 3:     // date time
                        t = typeof(DateTime);
                        break;

                    case 4:     // bool
                        t = typeof(bool);
                        break;

                    default:     // long
                        t = typeof(long);
                        break;
                    }
                    var getMethodBuilder =
                        builder.DefineMethod("get_" + fld.FieldName,
                                             MethodAttributes.Public |
                                             MethodAttributes.SpecialName |
                                             MethodAttributes.HideBySig,
                                             t, Type.EmptyTypes);

                    var getIL = getMethodBuilder.GetILGenerator();

                    switch (fld.DataType)
                    {
                    case 0:     // string
                        getIL.Emit(OpCodes.Ldstr, fld.Value);
                        break;

                    case 1:     // int
                        getIL.Emit(OpCodes.Ldc_I4, (int)NumberConvert.ToInt(fld.Value));
                        break;

                    case 2:     // double
                        getIL.Emit(OpCodes.Ldc_R8, NumberConvert.ToDoubleNoThousandSeperator(fld.Value));
                        break;

                    case 3:     // date time
                        getIL.Emit(OpCodes.Ldc_I8, StringSplit.DateParse(fld.Value, 0).Ticks);
                        getIL.Emit(OpCodes.Call, typeof(DashBoardViewerPage).GetMethod("MakeDate"));
                        break;

                    case 4:     // bool
                        getIL.Emit((fld.Value == "1" || string.Compare(fld.Value, "true", StringComparison.OrdinalIgnoreCase) == 0) ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0);
                        break;

                    default:     // long
                        getIL.Emit(OpCodes.Ldc_I8, NumberConvert.ToInt(fld.Value));
                        break;
                    }

                    getIL.Emit(OpCodes.Ret);

                    var propertyBuilder = builder.DefineProperty(fld.FieldName, System.Reflection.PropertyAttributes.HasDefault, t, null);
                    propertyBuilder.SetGetMethod(getMethodBuilder);
                }
                return(builder.CreateType());
            }
            catch
            {
                return(null);
            }
        }
コード例 #12
0
        public static DataTable FromCsv(string strFilePath)
        {
            try
            {
                fileDelimiter = GetDelimiter(strFilePath);
                DataSet oDS = new DataSet();
                oDS.Tables.Add("Property");
                var oTable = oDS.Tables[0];
                hasHeaderColumnGenerated = false;
                using (var stream = new System.IO.FileStream(strFilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read))
                {
                    var    oSR = UtilFunctions.CreateStreamReader(stream);
                    string line;
                    int    cellCount   = 0;
                    var    stringSplit = new StringSplit(fileDelimiter);
                    var    lineValues  = new List <string>(10);

                    while ((line = oSR.ReadLine()) != null)
                    {
                        stringSplit.Split(line, lineValues);

                        bool skipRow = false;
                        if (!hasHeaderColumnGenerated)
                        {
                            oTable.Columns.AddRange(GenerateColumnHeader(lineValues, out skipRow));
                        }

                        if (!skipRow)
                        {
                            int intCounter = 0;
                            var oRows      = oTable.NewRow();
                            var colCount   = oTable.Columns.Count;
                            foreach (string str in lineValues)
                            {
                                if (intCounter < colCount)
                                {
                                    oRows[intCounter] = str;
                                    intCounter++;
                                }
                            }

                            if (cellCount < intCounter)
                            {
                                cellCount = intCounter;
                            }
                            oTable.Rows.Add(oRows);
                        }
                    }

                    //Removing Columns not required
                    int           colIndex       = 0;
                    List <string> coltoBeRemoved = new List <string>();;
                    while (colIndex < oTable.Columns.Count)
                    {
                        var col = oTable.Columns[colIndex].ColumnName;
                        if (col != "Action" && col != "Item" &&
                            col != "EAN" && col != "AlternativeItem" &&
                            col != "Name" && col != "SupplierItemId" &&
                            col != "Supplier" && col != "Unit" &&
                            col != "SalesPrice" && col != "SalesPrice" &&
                            col != "ItemGroup" && col != "DiscountGroup" &&
                            col != "WebArg")
                        {
                            coltoBeRemoved.Add(oTable.Columns[colIndex].ColumnName);
                        }
                        colIndex++;
                    }
                    foreach (var col in coltoBeRemoved)
                    {
                        oTable.Columns.Remove(col);
                    }
                }
                return(oTable);
            }
            catch
            {
                return(null);
            }
        }
コード例 #13
0
        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            if (customDataColumnSource == null || customDataColumnSource.Count == 0 || bankImportFormat == null)
            {
                DialogResult = true;
                return;
            }
            var bankformatPositionProps = UtilFunctions.GetDisplayAttributeNonReadOnlyPropertiesFromType(bankImportFormat.GetType(), true);

            var strSplit = new StringSplit('(');

            foreach (var propInfo in bankformatPositionProps)
            {
                if (propInfo.PropertyType == typeof(byte))
                {
                    var propName = propInfo.Name;

                    if (propName == "SkipLines")
                    {
                        continue;
                    }

                    CustomDataColumn selectedCustomCol = null;
                    foreach (var col in customDataColumnSource)
                    {
                        if (col.ActualDataColumnName != null && col.ActualDataColumnName.Contains(propName))
                        {
                            selectedCustomCol = col;
                            break;
                        }
                    }

                    if (selectedCustomCol != null)
                    {
                        var selectedItem = selectedCustomCol.ActualDataColumnName;
                        var propertyName = strSplit.Split(selectedItem).First();

                        var prop = bankImportFormat.GetType().GetProperty(propertyName);
                        if (prop != null)
                        {
                            prop.SetValue(bankImportFormat, (byte)selectedCustomCol.DataColumnIndex, null);
                        }
                    }
                    else
                    {
                        propInfo.SetValue(bankImportFormat, (byte)0, null); // reset the value
                    }
                }
            }

            //Setting the delimiter value from the file to the bankformat
            if (updateDelimiter)
            {
                var seperatorProp = bankImportFormat.GetType().GetProperty("Seperator");
                if (seperatorProp != null)
                {
                    var sepValue = (char)seperatorProp.GetValue(bankImportFormat);
                    if (sepValue.CompareTo(fileDelimiter) != 0)
                    {
                        seperatorProp.SetValue(bankImportFormat, fileDelimiter, null);
                    }
                }
            }

            DialogResult = true;
        }