Example #1
0
 //
 // GET: /data/Addressbook/
 public ActionResult self()
 {
     string UserID = this.User.Identity.Name;
     using (MyDB mydb = new MyDB())
     {
         IQueryable<EntityObjectLib.AddressBook> result = mydb.AddressBooks.Where(ab => ab.Owner.ID.Equals(UserID)).OrderBy(ab => ab.Name);
         return Json(result.Select(ab => new
             {
                 ab.ID,
                 ab.Name,
                 ab.Sex,
                 ab.Company,
                 ab.Department,
                 ab.Job,
                 ab.Address,
                 ab.HomePhone,
                 ab.OfficePhone,
                 ab.Mobile,
                 ab.QQ,
                 ab.MSN,
                 ab.Email,
                 ab.BirthDay,
                 ab.Remark,
                 Creator = ab.Creator.Name,
                 ab.CreateTime,
                 Owner = ab.Owner.Name,
                 ab.LastUpdateTime
             }).ToArray()
             , JsonRequestBehavior.AllowGet
             );
     }
 }
Example #2
0
        public ActionResult saveMemo()
        {
            string id = Request.Params["id"];

            using (MyDB mydb = new MyDB())
            {
                User user = mydb.Users.Find(this.User.Identity.Name);
                if (string.IsNullOrEmpty(id))
                {
                    Event ev = new Event
                    {
                        ID = Guid.NewGuid().ToString(),
                        Name = Request.Params["Name"],
                        Content = Request.Params["Content"],
                        Type = "便笺",
                        Master = user,
                        Proctor = user,
                        Creator = user,
                        CreateTime = DateTime.Now
                    };
                    mydb.Events.Add(ev);
                }
                else
                {
                    Event ev = mydb.Events.Find(id);
                    ev.Name = Request.Params["Name"];
                    ev.Content = Request.Params["Content"];
                }

                mydb.SaveChanges();
            }

            return Json(new { success = true });
        }
Example #3
0
 public static object[] getModuleResourceTreeData2()
 {
     using (MyDB mydb = new MyDB())
     {
         return mydb.Modules.OrderBy(m => m.orderNO).Select(
                 m => new
                 {
                     id = m.ID,
                     text = m.moduleName + "[" + m.moduleCode + "]",
                     type = "module",
                     expanded = true,
                     //@checked = true,//checked是C#关键字
                     children = m.resources.OrderBy(r => r.orderNO).Select(
                         r => new
                         {
                             id = r.ID,
                             text = r.resourceName + "[" + r.resourceCode + "]",
                             type = "resource",
                             expanded = true,
                             children = r.privileges.OrderBy(p => p.orderNO).Select(
                                 p => new
                                 {
                                     id = p.ID,
                                     text = p.privilegeName + "[" + p.privilegeCode + "]",
                                     type = "privilege",
                                     @checked = true,
                                     leaf = true,
                                 }
                                 )
                         }
                     )
                 }
             ).ToArray();
     }
 }
Example #4
0
        public void DynQuery()
        {
            //string queryString = "{代码}.Contains(\"l\") and {名称}.Contains(\"伟\")";  //"Code.Contains(\"l\") and Name.Contains(\"伟\")"
            string queryString = "{代码}==\"lilin\"";

            //string queryString = "1==1";

            Type t = typeof(User);
            PropertyInfo[] PropertyInfos = t.GetProperties().ToArray();
            foreach (PropertyInfo pi in PropertyInfos)
            {
                DisplayAttribute[] attrs = pi.GetCustomAttributes(typeof(DisplayAttribute), true) as DisplayAttribute[];
                if (attrs.Length > 0)
                {
                    //Console.WriteLine(pi.Name);
                    string Name = attrs[0].Name;

                    queryString = queryString.Replace(
                        string.Format("{{{0}}}", Name),
                        pi.Name
                        );
                }
            }

            using (MyDB mydb = new MyDB())
            {
                IQueryable<User> users = mydb.Users.Where(queryString);
            }
        }
Example #5
0
        public string fileUpload()
        {
            // 保存传来的文件
            HttpPostedFileBase file = Request.Files["Filedata"]; // 在FileData里
            FileInfo fi = new FileInfo(file.FileName);
            string fileID = Guid.NewGuid().ToString();
            string uploadDir = WebConfigurationManager.AppSettings["uploadDir"];
            file.SaveAs(Server.MapPath(uploadDir + fileID + fi.Extension));

            using (MyDB mydb = new MyDB())
            {
                EntityObjectLib.File f = new EntityObjectLib.File
                {
                    ID = fileID,
                    CreateDate = DateTime.Now,
                    Name = file.FileName,
                    Creator = mydb.Users.Find(HttpContext.User.Identity.Name),
                    UploadPath = uploadDir,
                    Suffix = fi.Extension
                };
                mydb.Files.Add(f);
                mydb.SaveChanges();
            }

            //System.Threading.Thread.Sleep(3000);

            //// 回传
            Response.StatusCode = 200; //成功
            return fileID;
        }
Example #6
0
 public void exeSQL()
 {
     using (MyDB mydb = new MyDB())
     {
         User u = mydb.Database.SqlQuery<User>("select s.*,u.* from users u left join subjects s on u.id=s.id").First();
     }
 }
Example #7
0
        /// <summary>
        /// URL: /workflow/Instance/create/id
        /// id: 模板ID
        /// 发起流程
        /// </summary>
        /// <returns></returns>
        public ActionResult create(string id)
        {
            using (MyDB mydb = new MyDB())
            {
                WFTemplate template = mydb.WFTemplates.Find(id);
                WFNodeStart start = template.Nodes.OfType<WFNodeStart>().First();
                WFNodeHandle next = start.Next as WFNodeHandle;
                if (next is WFNodeHandle)
                {
                    ((WFNodeHandle)next).Actions.Select(a=>a);
                }

                Type t = getType(template);
                EntityObjectLib.WFInst inst = Activator.CreateInstance(t) as EntityObjectLib.WFInst;
                inst.WFTemplate = template;
                inst.State = "处理中";
                inst.WFInstNodes = new WFInstNode[]{
                    new WFInstNode
                    {
                        WFNode = next,
                        State = "处理中",
                        EntryTime = DateTime.Now,
                        WFInst = inst
                    }
                };
                // 这里有一个设计约束:开始节点后一定是个处理节点
                return View("toHandle", inst.CurrentNode);
            }
        }
Example #8
0
        public void TestMethod1()
        {
            MyDB mydb = new MyDB();

            OrganizationExt m = mydb.OrganizationExts.FirstOrDefault();
            Debug.WriteLine(m.Name);
        }
Example #9
0
        private static void SendRemind(User user, string title, string Content, MyDB db)
        {
            User sender = db.Users.First(u => u.Code.Equals("remindRobot")); //后台模拟用户
            Info info = new Info()
            {
                ID = Guid.NewGuid().ToString(),
                Title = "[提醒]"+title,
                Content = Content,
                CreateDate = DateTime.Now,
                SendDate = DateTime.Now,
                Creator = sender,
                SendTypes = "",
                Type = "提醒",
                Receivers = new InfoInbox[]
                    {
                        new InfoInbox {
                        ID = Guid.NewGuid().ToString(),
                        Receiver = user,
                        ReceiveTypes = ""
                        }
                    }
            };

            db.Infos.Add(info);
        }
Example #10
0
        public void Append()
        {
            using (MyDB mydb = new MyDB())
            {
                #region "创建通讯录记录"
                AddressBook AddressBook = new AddressBook
                {
                    ID = Guid.NewGuid().ToString(),
                    Name = "陈宏伟",
                    Sex = "男",
                    BirthDay = new DateTime(1971, 9, 10),
                    Company = "manbuit",
                    Department = "R&D",
                    Job = "developer",
                    Creator = mydb.Users.First(s => s.Code.Equals("lilin")),
                    Owner = mydb.Users.First(s => s.Code.Equals("lilin")),
                    AddressBookShares = new AddressBookShare[] {
                        new AddressBookShare
                        {
                            ID = Guid.NewGuid().ToString(),
                            Subject = mydb.Subjects.OfType<User>().First(s=>s.Code.Equals("lilin"))
                        },
                        new AddressBookShare
                        {
                            ID = Guid.NewGuid().ToString(),
                            Subject = mydb.Subjects.OfType<User>().First(s=>s.Code.Equals("chw"))
                        }
                    }
                };
                #endregion

                mydb.AddressBooks.Add(AddressBook);
                mydb.SaveChanges();
            }
        }
Example #11
0
 public void getSQL()
 {
     using (MyDB mydb = new MyDB())
     {
         IQueryable<User> users = mydb.Users.Where(u => u.Code.Contains("lx"));
         string sql = users.ToString();
     }
 }
Example #12
0
 public ActionResult getEvent()
 {
     using (MyDB mydb = new MyDB())
     {
         EntityObjectLib.Event p = mydb.Events.Find(Request.Params["ID"]);
         return Json(new { p.ID, p.Name, p.Content, p.Type });
     }
 }
Example #13
0
        public static void CheckALL()
        {
            using (MyDB mydb = new MyDB())
            {
                // 检出需要提醒的事件
                IQueryable<EventRemind> eventReminds =
                    mydb.EventReminds
                    .Where(er => er.SendTime == null && er.RemindTime <= DateTime.Now)
                    .Select(er => er);

                foreach (EventRemind eventRemind in eventReminds)
                {
                    string[] sendTypes = string.IsNullOrEmpty(eventRemind.ReceiverType)
                            ? new string[]{}
                            :eventRemind.ReceiverType.Split(",".ToArray());
                    foreach (string sendType in sendTypes)
                    {
                        switch (sendType)
                        {
                            case "责任人":
                                if (eventRemind.Event.Master != null)
                                {
                                    SendRemind(eventRemind.Event.Master, eventRemind.Event.Name, eventRemind.Event.Content, mydb);
                                }
                                break;
                            case "督办人":
                                if (eventRemind.Event.Master != null)
                                {
                                    SendRemind(eventRemind.Event.Proctor, eventRemind.Event.Name, eventRemind.Event.Content, mydb);
                                }
                                break;
                            case "共享人":
                                foreach (Subject subject in eventRemind.Event.EventShares.Select(es => es.Subject).Distinct())
                                {
                                    if (subject is User)
                                    {
                                        SendRemind(subject as User, eventRemind.Event.Name, eventRemind.Event.Content, mydb);
                                    }
                                    if (subject is Organization)
                                    {
                                        foreach (User u in (subject as Organization).Users)
                                        {
                                            SendRemind(u, eventRemind.Event.Name, eventRemind.Event.Content, mydb);
                                        }
                                    }
                                }
                                break;
                            default: break;
                        }
                    }

                    eventRemind.SendTime = DateTime.Now;
                }

                mydb.SaveChanges();
                return;
            }
        }
Example #14
0
 public static object[] getListByResource(string ResourceID)
 {
     using (MyDB mydb = new MyDB())
     {
         return mydb.Privileges.Where(p => p.resource.ID.Equals(ResourceID))
             .Select(p => new { p.ID, p.resource.resourceName, p.resource.module.moduleName, p.privilegeName, p.privilegeCode, p.needAuth, p.isMenuEntry, p.createdTime, p.orderNO }) //快速匿名对象
             //.Select(p => p) //是否可以通过判断类型来取属性,例如只取简单类型的属性
             .ToArray();
     }
 }
Example #15
0
        public ActionResult UpdateResource()
        {
            using (MyDB mydb = new MyDB())
            {
                EntityObjectLib.Resource p = getResource(Request, mydb);
                mydb.SaveChanges();
            }

            return Json(new { success = true });
        }
Example #16
0
        public void TestCrossTable()
        {
            MyDB mydb = new MyDB();

            Organization[] orgs1 = mydb.Roles.SelectMany(r => r.Subjects).OfType<Organization>().ToArray();

            //Organization[] orgs2 = mydb.Roles.SelectMany(r => r.Organizations).ToArray();

            return;
        }
Example #17
0
 public ActionResult DeleteModule()
 {
     using (MyDB mydb = new MyDB())
     {
         EntityObjectLib.Module p = mydb.Modules.Find(Request.Form["ID"]);
         mydb.Modules.Remove(p);
         mydb.SaveChanges();
     }
     return Json(new { success = true });
 }
Example #18
0
 public ActionResult CreatePrivilege()
 {
     using (MyDB mydb = new MyDB())
     {
         EntityObjectLib.Privilege p = getPrivilege(Request, mydb);
         p.ID = Guid.NewGuid().ToString();
         mydb.Privileges.Add(p);
         mydb.SaveChanges();
     }
     return Json(new { success = true });
 }
Example #19
0
        public ActionResult mydesk()
        {
            string userID = this.User.Identity.Name;
            using (MyDB mydb = new MyDB())
            {
                EntityObjectLib.User user = mydb.Users.Find(userID);
                TempData["layoutData"] = string.IsNullOrEmpty(user.LayoutData) ? "[[],[],[]]" : user.LayoutData;
            }

            return View();
        }
Example #20
0
 public static object[] getListByModule(string ModuleID)
 {
     using (MyDB mydb = new MyDB())
     {
         return mydb.Privileges.Where(p => p.resource.module.ID.Equals(ModuleID))
             .OrderBy(p => p.resource.module.orderNO)
             .OrderBy(p => p.resource.orderNO)
             .OrderBy(p => p.orderNO)
             .Select(p => new { p.ID, p.resource.resourceName, p.resource.module.moduleName, p.privilegeName, p.privilegeCode, p.needAuth, p.isMenuEntry, p.createdTime, p.orderNO }) //快速匿名对象
             .ToArray();
     }
 }
Example #21
0
        public JsonResult Index()
        {
            DateTime monthBegin = DateTime.Parse(Request.Params["from"]);
            DateTime monthEnd = DateTime.Parse(Request.Params["to"]);
            // 当前只取当前月的,以后要改为根据用户指定年月生成
            //DateTime monthBegin = new DateTime(year, month, 1);
            //DateTime monthEnd = monthBegin.AddMonths(1).AddDays(-1);

            List<Day> monthDays = new List<Day>();
            DateTime i = monthBegin;
            for (; i <= monthEnd; )
            {
                monthDays.Add(new Day { day = i });
                i = i.AddDays(1);
            }
            using (MyDB mydb = new MyDB())
            {
                object[] result =
                    mydb.Events
                    .Include("Master")
                    .Include("Proctor")
                    .Where(ev => (ev.FinishTime > monthEnd ? monthEnd : ev.FinishTime) >= (ev.StartTime > monthBegin ? ev.StartTime : monthBegin))
                    .ToList()
                    .AsQueryable()
                    .Join( //笛卡尔积
                        monthDays,
                        r => 1,
                        e => 1,
                        (r, e) => new Day { ev = r, day = e.day }
                    )
                    .Where(d => d.day >= d.ev.StartTime.Date && d.day <= d.ev.FinishTime.Date)
                    .Select(d =>
                        new
                        {
                            d.day,
                            d.ev.ID,
                            d.ev.Name,
                            d.ev.Content,
                            d.ev.StartTime,
                            d.ev.FinishTime,
                            d.ev.Type,
                            Master = d.ev.Master.Name,
                            Proctor = d.ev.Proctor.Name
                        }
                    ).ToArray();

                return Json(
                        result
                        , JsonRequestBehavior.AllowGet
                        );
            }
        }
Example #22
0
        public ActionResult imgSend()
        {
            using (MyDB mydb = new MyDB())
            {
                HttpPostedFileBase file = Request.Files[0];
                FileInfo fi = new FileInfo(file.FileName);
                string fileName = string.Format("{0}{1}", Guid.NewGuid().ToString(), fi.Extension);
                file.SaveAs(Server.MapPath("~/" + fileName));

                Response.Clear();
                return Json(new { success = true, fileName }, "text/html");
            }
        }
Example #23
0
 public ActionResult getResource()
 {
     using (MyDB mydb = new MyDB())
     {
         EntityObjectLib.Resource p = mydb.Resources.Find(Request.Form["ID"]);
         return Json(new
         {
             success = true,
             data = new { p.ID, p.resourceCode, p.resourceName, moduleID=p.module.ID, p.resourceDescription }
         }
         );
     }
 }
Example #24
0
File: User.cs Project: uwitec/mb-oa
        public ActionResult UpdateUser()
        {
            using (MyDB mydb = new MyDB())
            {
                EntityObjectLib.User p = getUser(Request, mydb);
                ////mydb.Modules.Attach(p);
                //mydb.Entry<EntityObjectLib.User>(p).State = System.Data.EntityState.Modified;
                //mydb.Entry<EntityObjectLib.Organization>(p.Organization).State = System.Data.EntityState.Modified;
                mydb.SaveChanges();
            }

            return Json(new { success = true });
        }
Example #25
0
File: User.cs Project: uwitec/mb-oa
 public ActionResult getUser()
 {
     using (MyDB mydb = new MyDB())
     {
         EntityObjectLib.User p = mydb.Users.Find(Request.Form["ID"]);
         return Json(new
         {
             success = true,
             data = new { p.ID, p.Code, p.Name, p.Password, mobile = p.Mobile, p.MSN, p.QQ, p.OfficePhone, p.HomePhone, p.Email, p.ExpireDate, p.Description, OrgID = p.Organization.ID, Orgname = p.Organization.Name }
         }
         );
     }
 }
Example #26
0
        public void clear()
        {
            using (MyDB mydb = new MyDB())
            {
                mydb.AddressBookShares.Load();
                mydb.AddressBooks.Load();

                mydb.AddressBookShares.Local.Clear();
                mydb.AddressBooks.Local.Clear();

                mydb.SaveChanges();
            }
        }
Example #27
0
        public ActionResult save()
        {
            string userID = this.User.Identity.Name;
            using (MyDB mydb = new MyDB())
            {
                EntityObjectLib.User user = mydb.Users.Find(userID);
                user.LayoutData = Request.Params["LayoutData"];

                mydb.SaveChanges();
            }

            return Json(new { success = true });
        }
Example #28
0
 public ActionResult getModule()
 {
     using (MyDB mydb = new MyDB())
     {
         EntityObjectLib.Module p = mydb.Modules.Find(Request.Form["ID"]);
         return Json(new
         {
             success = true,
             data = new { ID = p.ID, moduleCode = p.moduleCode, moduleName = p.moduleName, moduleDescription = p.moduleDescription }
         }
         );
     }
 }
Example #29
0
        public void cast()
        {
            Subject s;
            MyDB mydb = new MyDB();
            {
                s = mydb.Subjects.First();
            }
            Convert.ChangeType(s, s.GetType());

            System.Reflection.Assembly ass = System.Reflection.Assembly.LoadFrom("EntityObjectLib.dll");
            Type t = ass.GetType("EntityObjectLib.Subject");
            object so = Convert.ChangeType(s, t.GetType());
        }
Example #30
0
        public ActionResult CreateModule()
        {
            //将JSON格式转换为Module类型
            //return Json(new { success = false, errors = new { clientCode = "", portOfLoading = "" } });
            EntityObjectLib.Module p = getModule(Request);
            using (MyDB mydb = new MyDB())
            {
                p.ID = Guid.NewGuid().ToString();
                mydb.Modules.Add(p);
                mydb.SaveChanges();
            }

            return Json(new { success = true });
        }