Esempio n. 1
0
        private static void SaveTextToPath(string path, DataSet dataSet)
        {
            CsvImportExport exporter = new CsvImportExport();

            exporter.Export(path, dataSet);
        }
Esempio n. 2
0
        private void ImportAccounts()
        {
            fileDialog.InitialDirectory = Application.CommonAppDataPath;
            fileDialog.Filter           = @"CSV (*.csv)|*.csv|All files (*.*)|*.*";
            fileDialog.FilterIndex      = 1;
            fileDialog.RestoreDirectory = true;

            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    bool deleteRelated = Confirm(MultiLanguageStrings.GetString(Ressource.ChartOfAccountsForm, "ToDeleteTheChartOfAccounts.Text"));

                    CsvImportExport         importer    = new CsvImportExport();
                    string                  filePath    = fileDialog.FileName;
                    List <Account>          accounts    = new List <Account>();
                    ChartOfAccountsServices coaServices = ServicesProvider.GetInstance().GetChartOfAccountsServices();
                    if (deleteRelated)
                    {
                        IEnumerable <string> relatedDatas = coaServices.HasRelatedDatas();
                        if (relatedDatas != null && relatedDatas.Any())
                        {
                            string[] domainObjects =
                                relatedDatas
                                .Select(
                                    r => GetString(string.Format("RelatedData.{0}", r))
                                    ).Distinct().ToArray();

                            string message =
                                string.Format(
                                    GetString("RelatedDataExists.Text"),
                                    string.Join(",", domainObjects));
                            if (!Confirm(message))
                            {
                                return;
                            }
                        }
                    }
                    importer.Import(filePath, items =>
                    {
                        Account account = new Account
                        {
                            Id              = Convert.ToInt32(items[0]),
                            Number          = items[1],
                            Label           = items[2],
                            DebitPlus       = Convert.ToBoolean(items[3]),
                            TypeCode        = items[4],
                            AccountCategory = (OAccountCategories)(Convert.ToInt32(items[5])),
                            Type            = Convert.ToBoolean(items[6]),
                            ParentAccountId = items[5].ToUpper() == "0" ? null : (int?)Convert.ToInt32(items[7]),
                            Left            = Convert.ToInt32(items[8]),
                            Right           = Convert.ToInt32(items[9])
                        };
                        accounts.Add(account);
                    });

                    coaServices.InsertCoa(accounts.ToArray(), deleteRelated);
                    IntializeTreeViewChartOfAccounts();
                }
                catch (Exception ex)
                {
                    new frmShowError(CustomExceptionHandler.ShowExceptionText(ex)).ShowDialog();
                }
            }
        }