Exemplo n.º 1
0
 public ActionResult ChangePassword(string oldpassword, string password, string confirmPassword)
 {
     int id = BLL.UserInfo.CurUser.Id;
     if(password!=confirmPassword)
     {
         ModelState.AddModelError("confirmPassword","两次密码不一致");
         return View();
     }
     if(password.Trim()=="")
     {
         ModelState.AddModelError("password", "密码不能为空");
         return View();
     }
     using (OUContext db = new OUContext())
     {
         OUDAL.Supplier supplier = (from o in db.Suppliers where o.Id == id select o).First();
         if (supplier.Password == oldpassword)
         {
             supplier.Password = password;
             db.SaveChanges();
             return Redirect("~/Supplier/SupplierView");
         }
         else
         {
             ModelState.AddModelError("oldpassword", "旧密码错误");
         }
     }return View();
 }
Exemplo n.º 2
0
 public static void AddLog(OUContext db,string person, int id, string logClass, string logAction, string info)
 {
     AccessLog a = new AccessLog();
     a.KeyId = id;
     a.AccessClass = logClass;
     a.AccessAction = logAction;
     a.AccessInfo = info;
     a.AccessTime = DateTime.Now;
     a.AccessPerson = person;
     db.AccessLogs.Add(a);
     db.SaveChanges();
 }
Exemplo n.º 3
0
        public static void Add(decimal rate,DateTime date)
        {
            using (OUContext db = new OUContext())
            {
                var list = (from o in db.ExchangeRates where o.EndDate == null select o).ToList();

                list.ForEach(o=>o.EndDate=date.AddDays(-1));
                ExchangeRate r = new ExchangeRate {Rate = rate, BeginDate = date};
                db.ExchangeRates.Add(r);
                db.SaveChanges();
            }
        }
Exemplo n.º 4
0
 public ActionResult ChangePassword(string oldpassword,string password)
 {
     int id = BLL.UserInfo.CurUser.Id;
     if(password.Length==0)
     {
         ModelState.AddModelError("password", "密码不能为空");
     }
     using (OUContext db = new OUContext())
     {
         SystemUser user = (from o in db.SystemUsers where o.Id == id select o).First();
         if(user.CheckPassword(oldpassword)==true)
         {
             user.Password = password;
             user.Save(db);
             db.SaveChanges();
             return Redirect("ChangePasswordSuccess");
         }
         else
         {
             ModelState.AddModelError("oldpassword", "旧密码错误");
         }
     }return View();
 }
Exemplo n.º 5
0
        public ActionResult ChangePassword(string oldpassword, string password)
        {
            int id = BLL.UserInfo.CurUser.Id;
            if (password.Length == 0)
            {
                ModelState.AddModelError("password", "password can not be empty");
            }
            using (OUContext db = new OUContext())
            {
                Client s = (from o in db.Clients where o.Id == id select o).First();

                if (s.Password==oldpassword)
                {
                    s.Password = password;

                    db.SaveChanges();
                    return Redirect("ChangePasswordSuccess");
                }
                else
                {
                    ModelState.AddModelError("oldpassword", "wrong old password");
                }
            } return View();
        }
Exemplo n.º 6
0
        public ActionResult SupplierEdit( FormCollection collection)
        {
            int id = 0;
            int.TryParse(System.Web.HttpContext.Current.User.Identity.Name, out id);
            OUContext db = new OUContext();
            Supplier s = (from o in db.Suppliers where o.Id == id select o).FirstOrDefault();
            if(s==null)
            {
                return View(s);
            }
            if(s.State==(int)SupplierState.往来)
            {
                return View("ShowError", "", "已是往来供应商,不能修改资料");
            }
            //collection.Remove("");
            TryUpdateModel(s, "", new string[] { }, new string[] { "Name", "Password", "Level", "State","AuditRemark" ,"AccessCode"}, collection);
            if (ModelState.IsValid)
            {
                    s.Save(db);
                    db.SaveChanges();
                    if(id==0)
                    {
                        BLL.Utilities.AddLog(s.Id,Supplier.LogClass, "创建", "");

                    }
                    else
                    {
                        BLL.Utilities.AddLog(s.Id, Supplier.LogClass, "修改", "");
                    }
                return Redirect("SupplierView" );
            }

            return View(s);
        }
Exemplo n.º 7
0
        public string Syn()
        {
            OUContext db=new OUContext();
            var users = (from o in db.SystemUsers select o).ToList();
            string sqlUsers = @" select a.nvarchar8 as company ,a.nvarchar21 as department ,a.nvarchar15 as subdepartment ,a.nvarchar7 as email,a.nvarchar6 as name ,nvarchar20 as loginname,nvarchar10 as title
            from AllUserData a where a.tp_ListId ='10236E7F-298D-4247-BEE3-1FEB8738784D' and nvarchar20 is not null and a.nvarchar8 is not null";
            System.Data.SqlClient.SqlConnection conn = SqlHelper.Conn();
            conn.Open();
            var OaUsers = conn.Query(sqlUsers);
            foreach (var oaUser in OaUsers)
            {
                bool found = false;
                string loginname = oaUser.loginname;
                foreach (var systemUser in users)
                {
                    if(loginname==systemUser.WorkNO)
                    {
                        found = true;
                        systemUser.Email = oaUser.email;
                        systemUser.Name = oaUser.name;
                    }
                }
                if(found==false)
                {
                    db.SystemUsers.Add(new SystemUser
                                           {
                                               Email = oaUser.email,
                                               Name = oaUser.name,
                                               Password = "******",
                                               WorkNO = loginname
                                           });
                }
                db.SaveChanges();
            }
            //找不到的账号禁用
            users.ForEach(o =>
            {
                if (o.Id > 1)
                {
                    if ((from u in OaUsers where u.loginname == o.WorkNO select o.Id).ToList().Count == 0)
                    {
                        o.State = 1;
                    }
                }
            });
            db.SaveChanges();
            var departments = (from o in db.Departments select o).ToList();

            var sqlDepart =@"select a.nvarchar1 as company ,a.nvarchar3 as department ,a.nvarchar4 as subdepartment ,u1.tp_Title as submanager,u2.tp_Title as manager
            from AllUserData a
            join UserInfo u1 on a.int1=u1.tp_deleted --and u1.tp_Login like 'glcp%'
            join UserInfo u2 on a.int2=u2.tp_deleted --and u2.tp_Login like 'glcp%'
            where a.tp_ListId ='40394CC4-40A8-4B8F-BF08-068DB9E90FB7' ";
            var OaDeparts = conn.Query(sqlUsers);
            var q1 = (from o in OaDeparts select o.company).Distinct();
            //公司一级
            foreach (string o in q1)
            {
                bool found = false;
                foreach (var department in departments)
                {
                    if(department.Name==o)
                    {
                        found = true;
                    }
                }
                if(!found&&(!string.IsNullOrEmpty(o)))
                {
                    db.Departments.Add(new Department {DepartmentType = "公司", Name = o, PId = 1});
                }
            }
            db.SaveChanges();
            //部门一级
            departments = (from o in db.Departments select o).ToList();
            var q2 = (from o in OaDeparts select new {company = o.company, department = o.department}).Distinct();
            foreach (var o in q2)
            {
                bool found = false;
                Department parent = (from d in departments where d.Name == o.company select d).FirstOrDefault();
                if(parent!=null)
                {
                    foreach (var department in departments)
                    {
                        if(department.Name==o.department && department.PId==parent.Id)
                        {
                            found = true;
                        }
                    }
                }

                if(!found)
                {

                    db.Departments.Add(new Department {DepartmentType = "部门", Name = o.department, PId = parent.Id});
                }
            }
            db.SaveChanges();
            //子部门一级
            departments = (from o in db.Departments select o).ToList();
            var q3 =
                (from o in OaDeparts
                 select new {company = o.company, department = o.department, subdepartment = o.subdepartment}).Distinct();
            foreach (var o in q3)
            {
                bool found = false;
                Department company = (from d in departments where d.Name == o.company select d).First();
                Department department =
                    (from d in departments where d.Name == o.department && d.PId == company.Id select d).First();
                foreach (var dept in departments)
                {
                    if(dept.Name==o.subdepartment )//-- 子部门名称唯一 && dept.PId==department.Id
                    {
                        found = true;
                    }

                }
                if(!found)
                {
                    db.Departments.Add(new Department
                                           {DepartmentType = "部门", Name = o.subdepartment, PId = department.Id});
                }
            }
            db.SaveChanges();
            //部门用户
            departments = (from o in db.Departments select o).ToList();
            users = (from o in db.SystemUsers select o).ToList();
            var departUsers = (from o in db.DepartmentUsers select o).ToList();
            foreach (var oaUser in OaUsers)
            {
                var dept = (from o in departments where o.Name == oaUser.subdepartment select o).First();
                var user= (from o in users where o.WorkNO==oaUser.loginname select o).First();
                var du =
                    (from o in departUsers where o.DepartmentId == dept.Id && o.UserId == user.Id select o).
                        FirstOrDefault();
                if(du==null)
                {
                    du=new DepartmentUser{DepartmentId = dept.Id,UserId = user.Id };
                    db.DepartmentUsers.Add(du);
                }
                if (oaUser.title != null && ((oaUser.title as string).Contains("经理") || (oaUser.title as string).Contains("领导")))
                {
                    du.IsManager = 1;
                }
                else
                {
                    du.IsManager = 0;
                }
                var delList =
                    (from o in departUsers where o.DepartmentId != dept.Id && o.UserId == user.Id select o).ToList();
                delList.ForEach(o=>db.DepartmentUsers.Remove(o));
            }
            db.SaveChanges();
            return "OK";
        }
Exemplo n.º 8
0
        private void ImportVisit(SqlConnection conn)
        {
            List<visitrecord> listVisitRecord = conn.Query<visitrecord>(visitrecord.sql).ToList();
            int count = 0;
            OUContext db = new OUContext();
            db.Configuration.ValidateOnSaveEnabled = false;
            db.Configuration.AutoDetectChangesEnabled = false;
            foreach (var record in listVisitRecord)
            {
                if (record.l_MemID == 0) continue;

                ShineConsume sc = new ShineConsume();
                int asset = GetAsset(db, record.l_MsgID);
                sc.ShineType = "日晒机";
                sc.AssetId = asset;
                sc.CardId = GetCard(db, record.l_MemID);
                if (record.l_PurchaseCerterID == 1)
                {
                    sc.ChargeStoreId = 3;
                }
                else if (record.l_PurchaseCerterID == 2)
                {
                    sc.ChargeStoreId = 4;
                }
                else
                {
                    sc.ChargeStoreId = StoreId;
                }
                if (record.l_VisitCerterID == 1)
                {
                    sc.StoreId = 3;
                }
                else if (record.l_VisitCerterID == 2)
                {
                    sc.StoreId = 4;
                }
                else
                {
                    sc.StoreId = StoreId;
                }
                sc.ConsumeTime = record.l_CreateTime;
                sc.Minutes = Convert.ToDecimal(record.l_SessionTime);
                sc.RelativeMinutes = Convert.ToDecimal(record.l_Minutes);
                sc.SalesId = 1;
                sc.Remark = record.l_VisitID.ToString();
                db.ShineConsumes.Add(sc);
                count++;
                if (count%500 == 0)
                {
                    db.SaveChanges();
                }
                if (count%1000 == 0)
                {
                    Console.WriteLine(string.Format("{0} {1} ", count, DateTime.Now));
                    //db = new OUContext();
                    //db.Configuration.ValidateOnSaveEnabled = false;
                    //GC.Collect();
                }
            }
            db.SaveChanges();
        }
Exemplo n.º 9
0
        private void ImportPurchase(SqlConnection conn)
        {
            List<purchase> listPurchase = conn.Query<purchase>(purchase.sql).ToList();
            using (OUContext db = new OUContext())
            {
                db.Configuration.ValidateOnSaveEnabled = false;
                db.Configuration.AutoDetectChangesEnabled = false;
                foreach (var pur in listPurchase)
                {
                    ProductSale p = new ProductSale();
                    p.StoreId = StoreId;
                    p.SalesId = 1;
                    p.Remark = pur.cnname + " " + pur.l_purchaseid.ToString();
                    int cardid = GetCard(db, pur.l_memid);
                    p.CardId = cardid;
                    p.Num = Convert.ToDecimal(pur.l_uints);
                    if (p.Num == 0) p.Num = 1;
                    p.Price = Convert.ToDecimal(pur.l_price);
                    p.UnitPrice = p.Price/p.Num;
                    if (pur.l_uints == 0f)
                    {
                        p.MarkPrice = Convert.ToDecimal(pur.l_grossprice);
                    }
                    else
                    {
                        p.MarkPrice = Convert.ToDecimal(pur.l_grossprice/pur.l_uints);
                    }

                    Product _product = GetProduct(db, pur.l_productid);
                    if (_product != null)
                    {
                        p.ProductId = _product.Id;
                    }

                    p.SaleTime = pur.l_createtime;
                    db.ProductSales.Add(p);
                    try
                    {
                        db.SaveChanges();
                        if (_product.Catalog == "日晒时长")
                        {
                            ShineRecharge sr = new ShineRecharge();
                            sr.ChargeStoreId = StoreId;
                            sr.CardId = cardid;
                            sr.Minutes = p.Num;
                            sr.RechargeTime = p.SaleTime;
                            sr.SaleId = p.Id;
                            sr.ShineType = "日晒机";
                            db.ShineRecharges.Add(sr);
                            db.SaveChanges();
                        }
                    }
                    catch (Exception exp)
                    {
                        throw exp;
                    }
                }
                //}
                //transcope.Complete();
            }

            Console.WriteLine(DateTime.Now.ToLongTimeString());
        }
Exemplo n.º 10
0
 private void ImportProduct(TransactionScopeOption option, SqlConnection conn)
 {
     using (TransactionScope transcope = new TransactionScope(option, TimeSpan.FromMinutes(5)))
     {
         using (OUContext db = new OUContext())
         {
             db.Configuration.ValidateOnSaveEnabled = false;
             List<megasun> listMegasun = conn.Query<megasun>(megasun.sql).ToList();
             foreach (var mega in listMegasun)
             {
                 Asset asset = new Asset();
                 asset.AssetType = "日晒机";
                 asset.Name = mega.l_mgsname + " " + mega.l_roomnum;
                 asset.Rate = Convert.ToDecimal(mega.l_usage);
                 asset.StoreId = StoreId;
                 asset.Remark = mega.l_mgsid.ToString();
                 db.Assets.Add(asset);
             }
             db.SaveChanges();
             List<product> listProduct = conn.Query<product>(product.sql).ToList();
             foreach (var prod in listProduct)
             {
                 Product p = new Product();
                 p.Name = prod.l_productname;
                 p.UnitPrice = Convert.ToDecimal(prod.l_productprice);
                 p.StoreId = StoreId;
                 p.Remark = prod.l_productid.ToString();
                 switch (prod.l_typename)
                 {
                     case "Minute":
                         p.Catalog = "日晒时长";
                         if (prod.l_productname.Contains("单次"))
                             p.Catalog = "单次日晒";
                         break;
                     case "Health":
                         p.Catalog = "健康产品";
                         break;
                     case "Lotion":
                         p.Catalog = "护肤液";
                         break;
                     case "Cloth":
                         p.Catalog = "服装";
                         break;
                 }
                 db.Products.Add(p);
             }
             db.SaveChanges();
             transcope.Complete();
         }
     }
     Console.WriteLine(DateTime.Now.ToLongTimeString());
 }
Exemplo n.º 11
0
 private void ImportCustomer(SqlConnection conn)
 {
     using (TransactionScope transcope = new TransactionScope())
     {
         using (OUContext db = new OUContext())
         {
             db.Configuration.ValidateOnSaveEnabled = false;
             db.Configuration.AutoDetectChangesEnabled = false;
             List<customer> listCustomer = conn.Query<customer>(customer.sql).ToList();
             foreach (var cust in listCustomer)
             {
                 Card card = new Card();
                 card.StoreId = StoreId;
                 card.ActiveDate = cust.l_createtime;
                 card.Birthday = cust.l_birth;
                 card.CardCode = "旧"+cust.l_memnum;
                 card.OldCode = cust.l_memnum;
                 card.CardId = "旧"+cust.l_cardnum;
                 switch (cust.l_membergradeid)
                 {
                     case 1:
                         card.CardType = "普通卡";
                         break;
                     case 2:
                         card.CardType = "金卡";
                         break;
                     case 3:
                         card.CardType = "白金卡";
                         break;
                 }
                 string email = cust.l_email1;
                 if (string.IsNullOrEmpty(cust.l_email1))
                 {
                     email = cust.l_email2;
                 }
                 else if (string.IsNullOrEmpty(cust.l_email2) == false)
                 {
                     email += " " + cust.l_email2;
                 }
                 card.Email = email;
                 if (cust.l_sex == "女" || cust.l_sex == "F")
                 {
                     card.Gender = GenderEnum.女;
                 }
                 else
                 {
                     card.Gender = GenderEnum.男;
                 }
                 string tel = "";
                 if (!string.IsNullOrEmpty(cust.l_hometel))
                 {
                     tel = cust.l_hometel;
                 }
                 if (!string.IsNullOrEmpty(cust.l_officetel))
                 {
                     tel += " " + cust.l_officetel;
                 }
                 if (!string.IsNullOrEmpty(cust.l_othertel))
                 {
                     tel += " " + cust.l_othertel;
                 }
                 card.Mobile = cust.l_mobile;
                 card.Phone = tel;
                 card.Remark = cust.l_standby;
                 card.OldSpendTotal = Convert.ToDecimal(cust.l_spenttotal);
                 switch (cust.l_status)
                 {
                     case 1:
                         card.State = ClientState.正常;
                         break;
                     case 2:
                         card.State = ClientState.冻结;
                         break;
                     case 3:
                         card.State = ClientState.失效;
                         break;
                 }
                 string name = string.Format("{0} {1} {2} {3} {4}", cust.l_givenname, cust.l_surname,
                                             cust.l_mandaringivenname, cust.l_mandarinsurname,
                                             string.IsNullOrEmpty(cust.l_spousename)
                                             ?"": string.Format("({0})", cust.l_spousename)
                                                 );
                 card.UserName = name;
                 db.Cards.Add(card);
                 db.SaveChanges();
             }
         }
         transcope.Complete();
     }
     Console.WriteLine(DateTime.Now.ToLongTimeString());
 }
Exemplo n.º 12
0
        private void ImportCardMinutes(SqlConnection conn)
        {
            OUContext db;

            List<cardminute> listCardMinutes = conn.Query<cardminute>(cardminute.sql).ToList();
            db = new OUContext();
            db.Configuration.ValidateOnSaveEnabled = false;
            db.Configuration.AutoDetectChangesEnabled = false;
            foreach (var cardMinute in listCardMinutes)
            {
                CardMinute cm = new CardMinute();
                if (cardMinute.l_memNum != null)
                {
                    int memid = int.Parse(cardMinute.l_memNum);
                    cm.CardId = GetCard(db, memid);
                }
                cm.Minutes = Convert.ToDecimal(cardMinute.l_balanceminutes);
                if (cardMinute.l_centerID == 1)
                {
                    cm.StoreId = 3;
                }
                else if (cardMinute.l_centerID == 2)
                {
                    cm.StoreId = 4;
                }
                else if (cardMinute.l_centerID == 3)
                {
                    cm.StoreId = 2;
                }
                cm.oldId = Convert.ToInt16(cardMinute.l_Minuteid);
                db.CardMinutes.Add(cm);
                db.SaveChanges();
            }
        }
Exemplo n.º 13
0
 /// <summary>
 /// 修改密码或用户名时候调用。调用时password应该是加密前password
 /// </summary>
 /// <param name="db"></param>
 /// <returns></returns>
 public bool Save(OUContext db)
 {
     Name = Name.Trim();
     int count =
         db.Database.SqlQuery<int>("select count(1) from systemusers where id!={0} and (name={1} )", Id,
                                   Name).FirstOrDefault();
     if (count > 0)
     {
         return false;
     }
     Password = EncryptPassword(Name.ToLower(), Password);
     if (Id == 0) db.SystemUsers.Add(this);
     db.SaveChanges();
     return true;
 }
Exemplo n.º 14
0
 public string RequestImportItem(OUContext db, string code, int foodId, decimal num, DateTime date, string remark, string action)
 {
     FoodMaterialRequest req = (from o in db.FoodMaterialRequests where o.Code == code select o).FirstOrDefault();
     if (action == "删除")
     {
         if (req == null) return "找不到可以删除的申请";
         if (req.TypeId != foodId) return "要删除的记录与原记录不匹配,原料不同";
         if(req.State!=(int)FoodMaterialRequestState.未提交)return "要删除的记录状态不允许删除";
         req.State = (int)FoodMaterialRequestState.作废;
         db.SaveChanges();
         return "";
     }
     if (action == "修改")
     {
         if (req == null) return "找不到可以修改的申请";
         if (req.TypeId != foodId) return "要修改的记录与原记录不匹配,原料不同";
         if(req.State!=(int)FoodMaterialRequestState.未提交)return "要修改的记录状态不允许修改";
     }
     if (req == null)
     {
         req = new FoodMaterialRequest();
         db.FoodMaterialRequests.Add(req);
         req.Code = code;
         req.TypeId=foodId;
     }
     req.Num = num;
     req.OrderDate = date;
     req.Remark = remark;
     req.PersonId = UserInfo.CurUser.Id;
     req.RequestTime = DateTime.Now;
     db.SaveChanges();
     return "";
 }