Example #1
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            OrmLiteConfig.DialectProvider = new FirebirdOrmLiteDialectProvider();
            using (IDbConnection db =
                       "User=SYSDBA;Password=masterkey;Database=employee.fdb;DataSource=localhost;Dialect=3;charset=ISO8859_1;"
                       .OpenDbConnection())
            {
                try
                {
                    var employees = db.Select <Employee>();
                    Console.WriteLine("Total Employees '{0}'", employees.Count);

                    Employee employee = new Employee()
                    {
                        FirstName         = "LILA",
                        LastName          = "FUTURAMA",
                        PhoneExtension    = "0002",
                        HireDate          = DateTime.Now,
                        DepartamentNumber = "900",
                        JobCode           = "Eng",
                        JobGrade          = 2,
                        JobCountry        = "USA",
                        Salary            = 75000
                    };
                    int count = employees.Count;

                    db.Insert(employee);
                    Console.WriteLine("Id for new employee : '{0}'", employee.Id);

                    employees = db.Select <Employee>();
                    Console.WriteLine("Total Employees '{0}' = '{1}'", employees.Count, count + 1);

                    Console.WriteLine("Executing 'DELETE_EMPLOYEE' for  '{0}' - {1}", employee.Id, employee.LastName);
                    ProcedureDeleteEmployee de = new ProcedureDeleteEmployee();
                    de.EmployeeNumber = employee.Id;
                    db.ExecuteProcedure(de);

                    employees = db.Select <Employee>();
                    Console.WriteLine("Total Employees '{0}'= '{1}' ", employees.Count, count);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }


                try
                {
                    ProcedureSubTotalBudgetParameters p = new ProcedureSubTotalBudgetParameters()
                    {
                        HeadDepartament = "000"
                    };

                    var results = db.SelectFromProcedure <ProcedureSubTotalBudgetResult>(p, "");


                    foreach (var r in results)
                    {
                        Console.WriteLine("r.Total:{0} r.Average:{1} r.Max:{2} r.Min:{3}", r.Total, r.Average, r.Max, r.Min);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }

                try
                {
                    ProcedureShowLangsParameters l = new ProcedureShowLangsParameters()
                    {
                        Code    = "Sales",
                        Grade   = 3,
                        Country = "England"
                    };

                    var ls = db.SelectFromProcedure <ProcedureShowLangsResult>(l, "");

                    foreach (var lr in ls)
                    {
                        Console.WriteLine(lr.Language);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }

                try
                {
                    ProcedureAllLangs l = new ProcedureAllLangs();

                    //var ls = db.SelectFromProcedure<ProcedureAllLangsResult>(l);
                    //db.SelectFromProcedure(l);


                    var ls = l.Execute(db);                     // better ?

                    foreach (var lr in ls)
                    {
                        Console.WriteLine("lr.Code:{0} lr.Country:{1} lr.Grade:{2}  lr.Language:{3}",
                                          lr.Code, lr.Country, lr.Grade, lr.Language);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }


                Console.WriteLine("This is The End my friend!");
            }
        }
Example #2
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            OrmLiteConfig.DialectProvider = new FirebirdOrmLiteDialectProvider();
            using (IDbConnection db =
			       "User=SYSDBA;Password=masterkey;Database=employee.fdb;DataSource=localhost;Dialect=3;charset=ISO8859_1;".OpenDbConnection())
            {
                try
                {

                    var employees = db.Select<Employee>();
                    Console.WriteLine("Total Employees '{0}'", employees.Count);

                    Employee employee = new Employee() {
                        FirstName = "LILA",
                        LastName = "FUTURAMA",
                        PhoneExtension = "0002",
                        HireDate = DateTime.Now,
                        DepartamentNumber = "900",
                        JobCode = "Eng",
                        JobGrade = 2,
                        JobCountry = "USA",
                        Salary = 75000
                    };
                    int count = employees.Count;

                    db.Insert(employee);
                    Console.WriteLine("Id for new employee : '{0}'", employee.Id);

                    employees = db.Select<Employee>();
                    Console.WriteLine("Total Employees '{0}' = '{1}'", employees.Count, count + 1);

                    Console.WriteLine("Executing 'DELETE_EMPLOYEE' for  '{0}' - {1}", employee.Id, employee.LastName);
                    ProcedureDeleteEmployee de = new ProcedureDeleteEmployee();
                    de.EmployeeNumber = employee.Id;
                    db.ExecuteProcedure(de);

                    employees = db.Select<Employee>();
                    Console.WriteLine("Total Employees '{0}'= '{1}' ", employees.Count, count);

                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }


                try
                {

                    ProcedureSubTotalBudgetParameters p = new ProcedureSubTotalBudgetParameters() {
                        HeadDepartament = "000"
                    };

                    var results = db.SqlProcedure<ProcedureSubTotalBudgetResult>(p, "");


                    foreach (var r in results)
                    {
                        Console.WriteLine("r.Total:{0} r.Average:{1} r.Max:{2} r.Min:{3}", r.Total, r.Average, r.Max, r.Min);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }

                try
                {

                    ProcedureShowLangsParameters l = new ProcedureShowLangsParameters() {
                        Code = "Sales",
                        Grade = 3,
                        Country = "England"
                    };

                    var ls = db.SqlProcedure<ProcedureShowLangsResult>(l, "");

                    foreach (var lr in ls)
                    {
                        Console.WriteLine(lr.Language);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }

                try
                {

                    ProcedureAllLangs l = new ProcedureAllLangs();

                    //var ls = db.SelectFromProcedure<ProcedureAllLangsResult>(l);
                    //db.SelectFromProcedure(l);


                    var ls = l.Execute(db);  // better ?

                    foreach (var lr in ls)
                    {
                        Console.WriteLine("lr.Code:{0} lr.Country:{1} lr.Grade:{2}  lr.Language:{3}",
                                          lr.Code, lr.Country, lr.Grade, lr.Language);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }


                Console.WriteLine("This is The End my friend!");
            }

        }