Exemplo n.º 1
0
        private static void TestAbstractFactory()
        {
            IDbFactory factory  = new AccessFactory();
            var        userRepo = factory.CreateUserRepo();
            var        deRepo   = factory.CreateDepartmentRepo();

            deRepo.CreateDepartment(null);
            userRepo.Insert(null);

            factory  = new SqlServerFactory();
            userRepo = factory.CreateUserRepo();
            userRepo.Insert(null);


            #region AbstractFactory + Reflection

            var departmentRepo = DataAccess.CreateDepartmentRepo();
            departmentRepo.CreateDepartment(null);

            #endregion AbstractFactory + Reflection

            #region AbstractFactory + DependencyInjection

            var builder = new ContainerBuilder();
            builder.RegisterType <SqlServerFactory>().As <IDbFactory>();
            var container = builder.Build();

            var dbFactory = container.Resolve <IDbFactory>();
            dbFactory.CreateDepartmentRepo().CreateDepartment(null);

            #endregion AbstractFactory + DependencyInjection
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            //抽象工厂实现方式
            User userModel = new User {
                Name = "zhangsan"
            };
            IUser    user    = null;
            IFactory factory = new AccessFactory();

            user = factory.CreateUser();

            user.AddUser(userModel);

            //简单工厂实现方式
            DataAccess  dataAccess = new DataAccess();
            IDepartment department = dataAccess.CreateDepartment();

            department.AddDepartment(new Department()
            {
                Name = "hahah", Remark = "测试"
            });

            //简单工厂的switch 替换为反射

            IUser Iuser2 = dataAccess.CreateUser();

            Iuser2.GetSingleUser(userModel);

            IUser         iuser = null;
            SqlServerUser user3 = new SqlServerUser();

            iuser = (IUser)user3;

            Console.ReadKey();
        }
Exemplo n.º 3
0
 public void OnAuthorization(AuthorizationContext filterContext)
 {
     if (!AccessFactory.IsSaleManagerLogined())
     {
         filterContext.Result = Constant.LoginPage;
     }
 }
Exemplo n.º 4
0
        public ActionResult LogOff()
        {
            AccessFactory.Logout();
            ClearCookie();

            return(RedirectToAction("LogOn", "Account"));
        }
Exemplo n.º 5
0
        static void AccessAction(IDbConnection connection)
        {
            using (var conn = AccessFactory.CreateDataConnection(connection))
            {
                conn.Execute(@"
					INSERT INTO AllTypes
					(
						bitDataType, decimalDataType, smallintDataType, intDataType,tinyintDataType, moneyDataType, floatDataType, realDataType,
						datetimeDataType,
						charDataType, varcharDataType, textDataType, ncharDataType, nvarcharDataType, ntextDataType,
						binaryDataType, varbinaryDataType, imageDataType, oleobjectDataType,
						uniqueidentifierDataType
					)
					VALUES
					(
						1, 2222222, 25555, 7777777, 100, 100000, 20.31, 16.2,
						@datetimeDataType,
						'1', '234', '567', '23233', '3323', '111',
						@binaryDataType, @varbinaryDataType, @imageDataType, @oleobjectDataType,
						@uniqueidentifierDataType
					)"                    ,
                             new
                {
                    datetimeDataType = new DateTime(2012, 12, 12, 12, 12, 12),

                    binaryDataType    = new byte[] { 1, 2, 3, 4 },
                    varbinaryDataType = new byte[] { 1, 2, 3, 5 },
                    imageDataType     = new byte[] { 3, 4, 5, 6 },
                    oleobjectDataType = new byte[] { 5, 6, 7, 8 },

                    uniqueidentifierDataType = new Guid("{6F9619FF-8B86-D011-B42D-00C04FC964FF}"),
                });
            }
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            User user = new User();
            //AbstractFactory factory = new SqlServerFactory();
            IFactory factory = new AccessFactory();

            IUser iu = factory.CreateUser();

            iu.Insert(user);
            iu.GetUser(1);

            Console.Read();
        }
Exemplo n.º 7
0
        private static void ConvertFile(AbsoluteFilePath path)
        {
            var factory = new AccessFactory();

            IFile  file    = factory.CreateFile();
            string content = file.ReadAllText(path);

            var converter = new Converter();

            string newContent = converter.Convert(content);

            file.WriteAllText(path, newContent);
        }
Exemplo n.º 8
0
        public static void AbstractFactoryPattern()
        {
            User       user = new User();
            Department dept = new Department();

            AbstractFactoryPattern.IFactory factory = new AccessFactory();
            IUser iu = factory.CreateUser();

            iu.Insert(user);
            iu.GetUser(1);

            IDepartment id = factory.createDepartment();

            id.Insert(dept);
            id.GetDepartment(1);
            Console.Read();
        }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            User       user = new User();
            Department dept = new Department();

            //AbstractFactory factory = new SqlServerFactory();
            IFactory factory = new AccessFactory();
            IUser    iu      = factory.CreateUser();

            iu.Insert(user);
            iu.GetUser(1);

            IDepartment id = factory.CreateDepartment();

            id.Insert(dept);
            id.GetDepartment(1);

            Console.Read();
        }
        public void Run()
        {
            Console.WriteLine("***普通抽象工厂***");
            IFactory sqlFactory  = new SqlserverFactory();
            var      userService = sqlFactory.CreateUserService();
            var      user        = userService.GetUserById(100);

            IFactory accessFactory     = new AccessFactory();
            var      departmentService = accessFactory.CreateDepartmentService();
            var      department        = departmentService.GetDepartmentById(200);

            Console.WriteLine("***反射+抽象工厂***");
            var userSer = DataAccess.CreateUserService();

            userSer.GetUserById(5566);

            var depSer = DataAccess.CreateDepartmentService();

            depSer.GetDepartmentById(8899);
        }
Exemplo n.º 11
0
        public ActionResult LogOn(LogOnModel model)
        {
            if (ModelState.IsValid)
            {
                //check user & password
                if (CheckLogin(model.UserName, model.Password))
                {
                    AccessFactory.Login(model.UserName);
                    //save cookie
                    if (model.RememberMe)
                    {
                        AddCookie(model);
                    }
                    else
                    {
                        ClearCookie();
                    }

                    if (AccessFactory.CurrentUserRole == (int)UserGroup.SALE)
                    {
                        return(RedirectToAction("Index", "Customer"));
                    }
                    else if (AccessFactory.CurrentUserRole == (int)UserGroup.SALE_MANAGER)
                    {
                        return(RedirectToAction("CustomerList", "Sale"));
                    }
                    else if (AccessFactory.CurrentUserRole == (int)UserGroup.COMPANY_OWNER)
                    {
                        return(RedirectToAction("SaleManager", "Manager"));
                    }
                }
                else
                {
                    model.Errors = "Tài khoản hoặc mật khẩu không chính xác.";
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            User       user = new User();
            Department dept = new Department();

            // IFactory factory = new SqlServerFactory();
            IFactory factory = new AccessFactory();
            IUser    iu      = factory.CreateUser();

            iu.Insert(user);
            iu.GetUser(1);

            IDepartment id = factory.CreateDepartment();

            id.Insert(dept);
            id.GetDepartment(1);

            Console.WriteLine(ConfigurationSettings.AppSettings["DB"]);


            Console.ReadKey();
        }
Exemplo n.º 13
0
        public ActionResult SearchOrder()
        {
            try
            {
                var    table = new StringBuilder();
                var    datefrom = DateTime.ParseExact(Request["DateFrom"], "dd/MM/yyyy", null);
                var    dateto = DateTime.ParseExact(Request["DateTo"], "dd/MM/yyyy", null);
                var    oService = new OrderService();
                var    cService = new CustomerService();
                var    orders = oService.GetOrderByDate(datefrom, dateto);
                var    totalcount = orders.Count();
                var    newcount = orders.Count(c => c.IsSeen == false);
                double totalsum = 0, newsum = 0;


                table.Append("<table id='table1' class='table1'>");
                table.Append("<thead>");
                table.Append("<tr>");
                table.Append("<th>Mã đơn hàng</th>");
                table.Append("<th>Giá đơn hàng</th>");
                table.Append("<th>Tỉnh/thành khách hàng</th>");
                table.Append("<th>Trạng thái đơn hàng</th>");
                table.Append("</tr>");
                table.Append("</thead>");

                table.Append("<tbody>");
                foreach (var order in orders)
                {
                    var total    = oService.GetOrderDetailByOrderid(order.Id).Sum(c => c.TotalQuantity);
                    var customer = cService.GetCustomerById(order.CustomerId);
                    if (order.IsSeen == false)
                    {
                        table.Append("<tr style='background:grey'>");
                    }
                    else
                    {
                        table.Append("<tr>");
                    }
                    table.AppendFormat("<td>{0}</td>", order.Code);
                    table.AppendFormat("<td>{0}</td>", Constant.ConvertCurrency(total));
                    table.AppendFormat("<td>{0}</td>", customer.City.Name);
                    table.AppendFormat("<td>{0}</td>", AccessFactory.GetStatus(order.Status));
                    table.Append("</tr>");

                    totalsum += total;
                    if (order.IsSeen == false)
                    {
                        newsum += total;
                    }
                }


                table.Append("</tbody>");
                table.Append("</table>");
                oService.UpdateOrderInSeen(orders);

                return(Json(new
                {
                    finish = true,
                    data = table.ToString(),
                    totalCount = totalcount,
                    totalSum = Constant.ConvertCurrency(totalsum),
                    newCount = newcount,
                    newSum = Constant.ConvertCurrency(newsum)
                }));
            }
            catch (Exception e)
            {
                return(Json(new { finish = false, data = e.ToString() }));
            }
        }