Exemplo n.º 1
0
        public async Task <ActionResult> AddEmployee(empData newemp)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser
                {
                    UserName       = newemp.remp.Email,
                    Email          = newemp.remp.Email,
                    Fname          = newemp.remp.Fname,
                    Lname          = newemp.remp.Lname,
                    BDate          = newemp.remp.BDate,
                    Address        = newemp.remp.Address,
                    PhoneNumber    = newemp.remp.PhoneNumber,
                    EmailConfirmed = true
                };
                UserManager <ApplicationUser> us = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db));
                var res = await us.CreateAsync(user, newemp.remp.Password);

                if (res.Succeeded)
                {
                    db.Employees.Add(new Employee()
                    {
                        Id = user.Id, Salary = newemp.emp.Salary, HireDate = newemp.emp.HireDate
                    });
                    db.SaveChanges();
                    await us.AddToRoleAsync(user.Id, "Employee");

                    return(PartialView("EmployeeRowpartial", newemp));
                }
                else
                {
                    ModelState.AddModelError("", "invalid password");
                    return(PartialView(newemp));
                }
            }
            return(PartialView(newemp));
        }
Exemplo n.º 2
0
        public ActionResult 銷售報表()
        {//暫時完成
            if (Session[CSession關鍵字.SK_LOGINED_EMPLOYEE] == null)
            {
                return(RedirectToAction("員工登入", "Employee"));
            }
            MotaiDataEntities dbContext = new MotaiDataEntities();
            //var empd = from i in dbContext.tOrders
            //           join j in dbContext.tOrderDetails on i.OrderId equals j.oOrderId
            //           join k in dbContext.tEmployees on i.oEmployeeId equals k.EmployeeId
            //           join m in dbContext.tProducts on j.oProductId equals m.ProductId
            //           group i by new { i.oEmployeeId,i.oDate.Month,
            //               j.oProductQty,m.pPrice,k.eName } into dataE
            //           select new empData
            //           {
            //               eName=dataE.Key.eName,
            //               tem =new temData{  oDate = dataE.Key.Month,
            //                   Sale =(dataE.Key.oProductQty)*(int)dataE.Key.pPrice,},
            //           };
            //void R(IQueryable<temData> tems)
            //{
            //    List<string> load = new List<string>();
            //    foreach (var item in tems)
            //    {
            //        if (load.Find(x => x.Contains(item.eName)) != null)
            //        {
            //            load.Add(item.eName);
            //            var q = from i in tems
            //                    where i.eName == item.eName
            //                    group i by i.oDate into j
            //                    select j;
            //            empData E = new empData();
            //            E.eName = item.eName;
            //        }
            //    }
            //}

            //List<tOrderDetail> tOrderDetails = dbContext.tOrderDetails.ToList();
            //List<empData> empDatas = new List<empData>();
            //foreach(tOrderDetail item in tOrderDetails)
            //{
            //    List<string> load = new List<string>();
            //    if (load.Find(x => x.Contains(item.tOrder.tEmployee.eName)) != null)
            //    {
            //        load.Add(item.tOrder.tEmployee.eName);
            //        empData emp = new empData();
            //        emp.eName = item.tOrder.tEmployee.eName;


            //        emp.tem = new temData
            //        {
            //            Sale = (item.oProductQty) * ((int)item.tProduct.pPrice),
            //            oDate = item.tOrder.oDate.Month,
            //            eName = emp.eName
            //        };
            //        empDatas.Add(emp);
            //    }
            //}

            List <tOrderDetail> tOrderDetails = dbContext.tOrderDetails.ToList();
            empData             emp           = new empData();

            emp.tem = new Dictionary <string, Dictionary <int, int> >();
            List <string> load = new List <string>();

            foreach (tOrderDetail item in tOrderDetails)
            {
                string ENAME = item.tOrder.tEmployee.eName;
                if (load.Find(x => x.Contains(ENAME)) == null)//抓人
                {
                    load.Add(ENAME);
                    Dictionary <int, int> temD = new Dictionary <int, int>();
                    //int K = item.tOrder.oDate.Month;
                    //int V = (item.oProductQty) * ((int)item.tProduct.pPrice);
                    for (int i = 1; i < 13; i++)
                    {//抓月份
                        var q = from search in tOrderDetails
                                where search.tOrder.oDate.Month == i && search.tOrder.tEmployee.eName == ENAME && search.tOrder.oCheck == "checked" && search.tOrder.oDate.Year == DateTime.Now.Year
                                select(search.oProductQty) * ((int)search.tProduct.pPrice);

                        int V = q.Sum();
                        temD.Add(i, V);
                    }
                    emp.tem.Add(ENAME, temD);
                }
            }
            return(View(emp));
        }