private void ImportData(Company co)
 {
     //Create a new ExcelReader
     using (utilities.ExcelReader exr = new utilities.ExcelReader { ExcelFilename = @"Maintenance.xls", Headers = true, MixedData = true, SheetName = "AccountType", KeepConnectionOpen = true })
     {
         //Create a datable to get the data
         DataTable accountTypeDTable = new DataTable("AccountType");
         accountTypeDTable = exr.GetTable();
         //Iterate the data and create the objects
         foreach (DataRow accountTypeRow in accountTypeDTable.Rows)
         {
             using (AccountType accountType = new AccountType(Session) { Acronym = accountTypeRow["Acronym"].ToString().Trim(), Description = accountTypeRow["Description"].ToString().Trim(), IsActive = true })
             {
                 accountType.Save();
             }
         }
         //Create a datable to get the data
         DataTable bankDTable = new DataTable("Bank");
         exr.SheetName = "Bank";
         bankDTable = exr.GetTable();
         //Iterate the data and create the objects
         foreach (DataRow bankRow in bankDTable.Rows)
         {
             using (Bank bank = new Bank(Session) { Acronym = bankRow["Acronym"].ToString().Trim(), BankName = bankRow["BankName"].ToString().Trim(), IsActive = true })
             {
                 bank.Save();
             }
         }
         DataTable bpartnerDTable = new DataTable("BusinessPartnerType");
         exr.SheetName = "BusinessPartnerType";
         bpartnerDTable = exr.GetTable();
         //Iterate the data and create the objects
         foreach (DataRow bpTypeRow in bpartnerDTable.Rows)
         {
             using (BusinessPartnerType bpType = new BusinessPartnerType(Session) { Description = bpTypeRow["Description"].ToString().Trim(), IsActive = true })
             {
                 bpType.Save();
             }
         }
         DataTable chartOfAcctTable = new DataTable("ChartOfAccounts");
         exr.SheetName = "ChartOfAccounts";
         chartOfAcctTable = exr.GetTable();
         //Iterate the data and create the objects
         foreach (DataRow cohRow in chartOfAcctTable.Rows)
         {
             using (ChartOfAccounts chartOfAccounts = new ChartOfAccounts(Session) { Description = cohRow["Description"].ToString().Trim(), AccountId = cohRow["AccountId"].ToString().Trim() })
             {
                 if ("Y" == cohRow["IsParent"].ToString().Trim())
                     chartOfAccounts.IsParent = true;
                 else
                     chartOfAccounts.IsParent = false;
                 chartOfAccounts.IsActive = true;
                 chartOfAccounts.Company = co;
                 chartOfAccounts.Save();
             }
         }
         //Create a datable to get the data
         DataTable termDTable = new DataTable("Term");
         exr.SheetName = "Term";
         termDTable = exr.GetTable();
         //Iterate the data and create the objects
         foreach (DataRow termRow in termDTable.Rows)
         {
             using (Term term = new Term(Session) { Acronym = termRow["NumOfDays"].ToString().Trim(), TermDescription = termRow["Description"].ToString().Trim(), NumOfDays = Convert.ToDecimal(termRow["NumOfDays"]), IsActive = true })
             {
                 term.Save();
             }
         }
         //Create a datable to get the data
         DataTable uomDTable = new DataTable("UOM");
         exr.SheetName = "UOM";
         uomDTable = exr.GetTable();
         //Iterate the data and create the objects
         foreach (DataRow uomRow in uomDTable.Rows)
         {
             using (UnitOfMeasure unitOfMeasure = new UnitOfMeasure(Session) { Acronym = uomRow["Acronym"].ToString().Trim(), Description = uomRow["Description"].ToString().Trim(), IsActive = true })
             {
                 unitOfMeasure.Save();
             }
         }
     }
 }
示例#2
0
 private void ImportData(Company co)
 {
     //Create a new ExcelReader
     using (utilities.ExcelReader exr = new utilities.ExcelReader {
         ExcelFilename = @"Maintenance.xls", Headers = true, MixedData = true, SheetName = "AccountType", KeepConnectionOpen = true
     })
     {
         //Create a datable to get the data
         DataTable accountTypeDTable = new DataTable("AccountType");
         accountTypeDTable = exr.GetTable();
         //Iterate the data and create the objects
         foreach (DataRow accountTypeRow in accountTypeDTable.Rows)
         {
             using (AccountType accountType = new AccountType(Session)
             {
                 Acronym = accountTypeRow["Acronym"].ToString().Trim(), Description = accountTypeRow["Description"].ToString().Trim(), IsActive = true
             })
             {
                 accountType.Save();
             }
         }
         //Create a datable to get the data
         DataTable bankDTable = new DataTable("Bank");
         exr.SheetName = "Bank";
         bankDTable    = exr.GetTable();
         //Iterate the data and create the objects
         foreach (DataRow bankRow in bankDTable.Rows)
         {
             using (Bank bank = new Bank(Session)
             {
                 Acronym = bankRow["Acronym"].ToString().Trim(), BankName = bankRow["BankName"].ToString().Trim(), IsActive = true
             })
             {
                 bank.Save();
             }
         }
         DataTable bpartnerDTable = new DataTable("BusinessPartnerType");
         exr.SheetName  = "BusinessPartnerType";
         bpartnerDTable = exr.GetTable();
         //Iterate the data and create the objects
         foreach (DataRow bpTypeRow in bpartnerDTable.Rows)
         {
             using (BusinessPartnerType bpType = new BusinessPartnerType(Session)
             {
                 Description = bpTypeRow["Description"].ToString().Trim(), IsActive = true
             })
             {
                 bpType.Save();
             }
         }
         DataTable chartOfAcctTable = new DataTable("ChartOfAccounts");
         exr.SheetName    = "ChartOfAccounts";
         chartOfAcctTable = exr.GetTable();
         //Iterate the data and create the objects
         foreach (DataRow cohRow in chartOfAcctTable.Rows)
         {
             using (ChartOfAccounts chartOfAccounts = new ChartOfAccounts(Session)
             {
                 Description = cohRow["Description"].ToString().Trim(), AccountId = cohRow["AccountId"].ToString().Trim()
             })
             {
                 if ("Y" == cohRow["IsParent"].ToString().Trim())
                 {
                     chartOfAccounts.IsParent = true;
                 }
                 else
                 {
                     chartOfAccounts.IsParent = false;
                 }
                 chartOfAccounts.IsActive = true;
                 chartOfAccounts.Company  = co;
                 chartOfAccounts.Save();
             }
         }
         //Create a datable to get the data
         DataTable termDTable = new DataTable("Term");
         exr.SheetName = "Term";
         termDTable    = exr.GetTable();
         //Iterate the data and create the objects
         foreach (DataRow termRow in termDTable.Rows)
         {
             using (Term term = new Term(Session)
             {
                 Acronym = termRow["NumOfDays"].ToString().Trim(), TermDescription = termRow["Description"].ToString().Trim(), NumOfDays = Convert.ToDecimal(termRow["NumOfDays"]), IsActive = true
             })
             {
                 term.Save();
             }
         }
         //Create a datable to get the data
         DataTable uomDTable = new DataTable("UOM");
         exr.SheetName = "UOM";
         uomDTable     = exr.GetTable();
         //Iterate the data and create the objects
         foreach (DataRow uomRow in uomDTable.Rows)
         {
             using (UnitOfMeasure unitOfMeasure = new UnitOfMeasure(Session)
             {
                 Acronym = uomRow["Acronym"].ToString().Trim(), Description = uomRow["Description"].ToString().Trim(), IsActive = true
             })
             {
                 unitOfMeasure.Save();
             }
         }
     }
 }