Ejemplo n.º 1
0
        public async Task <IHttpActionResult> Patch([FromODataUri] int key, Delta <user_group> patch)
        {
            Validate(patch.GetEntity());

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            user_group user_group = await db.user_group.FindAsync(key);

            if (user_group == null)
            {
                return(NotFound());
            }

            patch.Patch(user_group);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!user_groupExists(key))
                {
                    return(NotFound());
                }

                throw;
            }

            return(Updated(user_group));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 根据用户id删除对应的用户及该用户对应的分组和角色
        /// </summary>
        /// <param name="id">用户id</param>
        /// <returns></returns>
        public bool deleteuserRG(int id)
        {
            userRoleEx   ure          = new userRoleEx();
            List <role>  curroleList  = ure.getRoleList(id);
            userGroupEx  uge          = new userGroupEx();
            List <group> curgroupList = uge.getGroupList(id);
            user         u            = getUser(id);
            bool         uflag        = db.Delete <user>(u);

            if (curroleList.Count == 0 && curgroupList.Count == 0)
            {
                return(uflag);
            }
            else
            {
                bool urflag = true;
                bool ugflag = true;
                foreach (var item in curroleList)
                {
                    user_role ur = ure.getUserRole(id, item.id);
                    urflag = db.Delete <user_role>(ur);
                }
                foreach (var item in curgroupList)
                {
                    user_group ug = uge.getUserGroup(id, item.id);
                    ugflag = db.Delete <user_group>(ug);
                }
                return(uflag & urflag & ugflag);
            }
        }
Ejemplo n.º 3
0
        // POST: odata/UserGroup
        public async Task <IHttpActionResult> Post(user_group user_group)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.user_group.Add(user_group);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (user_groupExists(user_group.user_id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(Created(user_group));
        }
Ejemplo n.º 4
0
 public GroupInfo(user_group d)
 {
     gid         = d.gid;
     groupname   = d.groupname;
     create_time = d.create_time;
     update_time = d.update_time;
     profile     = d.profile;
 }
Ejemplo n.º 5
0
 public static void AddGroup(dbDataContext db, string ad_group, int access_level)
 {
     user_group ug = new user_group();
     ug.ad_group = ad_group;
     ug.security_level = access_level;
     db.user_groups.InsertOnSubmit(ug);
     db.SubmitChanges();
 }
Ejemplo n.º 6
0
        public static UserGroup ToModel(user_group model)
        {
            return(new UserGroup()
            {
                user_group_id = model.user_group_id.CheckValue(),

                user_group_name = model.user_group_name,

                father_id = model.father_id,
            });
        }
Ejemplo n.º 7
0
        //添加一个用户组
        public int AddUserGroup(string userGroupName)
        {
            using (VanchBgDataContext vdc = new VanchBgDataContext())
            {
                user_group userGroupObj = new user_group();
                userGroupObj.user_group_name = userGroupName;

                vdc.user_groups.InsertOnSubmit(userGroupObj);
                vdc.SubmitChanges();

                return(userGroupObj.user_group_id);
            }
        }
Ejemplo n.º 8
0
 //common lib
 public bool Insert(user_group entity)
 {
     try
     {
         db.user_group.Add(entity);
         db.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        ///保存用户的分组
        /// </summary>
        /// <param name="userid">用户id</param>
        /// <param name="permissionGroupIds">分组授权</param>
        public void SaveUserGroupMap(int userid, string permissionGroupIds)
        {
            string groupIdLists = permissionGroupIds;

            string[] strids  = groupIdLists.Split(',');//角色ID集合
            bool     flag    = false;
            int      intflag = 0;
            string   msg     = string.Empty;

            try
            {
                //保存用户组的权限关系
                List <group> oldgro       = IdalCommon.IuserGroupEx.getGroupList(userid);//用户的所有组对象
                user_group   newu_g       = new user_group();
                string       groupListStr = " ";
                foreach (group g in oldgro)
                {
                    if (!groupIdLists.Contains(g.id.ToString()))
                    {
                        IdalCommon.IuserGroupEx.deleteUserGroup(userid, g.id);
                    }
                }
                for (int i = 0; i < strids.Length; i++)//循环选中的分组
                {
                    if (int.Parse(strids[i]) != 0)
                    {
                        newu_g.userid  = userid;
                        newu_g.groupid = int.Parse(strids[i]);
                        intflag        = IdalCommon.IuserGroupEx.insert(newu_g);//在关联表中添加btn或者menu关系
                        if (-1 == intflag)
                        {
                            flag = true;
                        }
                        else
                        {
                            flag = false;
                        }
                        groupListStr += IdalCommon.IgroupEx.getEntityById(int.Parse(strids[i])).groupname + ',';
                    }
                    Dictionary <string, object> UserList = new Dictionary <string, object>();
                    UserList["grouplist"] = groupListStr.Trim(',');
                    IdalCommon.IuserEx.update(userid, UserList);
                }
            }
            catch (Exception ex)
            {
                msg = ex.Message;
            }
        }
Ejemplo n.º 10
0
        /// <summary> </summary>
        public void delete_group(int id)
        {
            user_group group = ActiveRecordBase <user_group> .Find(id);

            //Flash["error"] = "At the moment no one has rights to delete a group but the system.";
            try {
                Flash["message"] = "A group, <strong>" + group.name + "</strong>, has been <strong>deleted</strong>.";
                logger.writelog("Deleted group", getView(), getAction(), group.baseid);
                ActiveRecordMediator <user_group> .Delete(group);
            } catch (Exception ex) {
                Flash["message"] = "";
                logger.writelog("failed to Deleted", getView(), getAction(), group.baseid);
                Flash["error"] = ex.Message;
            }
            RedirectToAction("list_groups");
        }
Ejemplo n.º 11
0
        public bool Update(user_group entity)
        {
            try
            {
                var info = db.user_group.Find(entity.id);

                info.name      = entity.name;
                info.is_active = entity.is_active;
                db.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Ejemplo n.º 12
0
        public ActionResult Edit(user_group group)
        {
            if (ModelState.IsValid)
            {
                var dao    = new user_group_dao();
                var result = dao.Update(group);

                if (result)
                {
                    SetAlert(StaticResources.Resources.Pub_UpdateSucess, "success");
                    return(RedirectToAction("Index", "UserGroup"));
                }
                else
                {
                    ModelState.AddModelError("", StaticResources.Resources.UpdateUserGroupFailed);
                }
            }
            return(View());
        }
Ejemplo n.º 13
0
        //删除一个用户组
        public void DelUserGroup(int userGroupId)
        {
            using (VanchBgDataContext vdc = new VanchBgDataContext())
            {
                user_group userGrp = vdc.user_groups.First <user_group>(c => c.user_group_id == userGroupId);
                userGrp.delete_date = DateTime.Now;
                //vdc.user_groups.DeleteOnSubmit(userGrp);

                var linqUserGrpMenu = from c in vdc.user_group_menus
                                      where c.fk_user_group_id == userGroupId
                                      select c;

                foreach (user_group_menu userGrpMenu in linqUserGrpMenu)
                {
                    userGrpMenu.delete_date = DateTime.Now;
                }

                vdc.SubmitChanges();
            }
        }
Ejemplo n.º 14
0
        /// <summary> </summary>
        public void update_group([ARDataBind("group", Validate = true, AutoLoad = AutoLoadBehavior.NewRootInstanceIfInvalidKey)] user_group group
                                 , int[] privileges
                                 )
        {
            try {
                logger.writelog("Saving group", getView(), getAction(), group.baseid);
                Flash["message"] = "Saved group setings.";

                group.privileges.Clear();
                if (privileges != null)
                {
                    foreach (int id in privileges)
                    {
                        group.privileges.Add(ActiveRecordBase <privilege> .Find(id));
                    }
                }

                ActiveRecordMediator <user_group> .Save(group);

                if (group == userService.getUser().groups)
                {
                    userService.setUser();
                }
            } catch (Exception ex) {
                Flash["error"]       = ex.Message;
                Flash["accesslevel"] = group;
                logger.writelog("Failed to save group", getView(), getAction(), group.baseid);
                if (group.baseid > 0)
                {
                    RedirectToAction("edit_group", new string[] { "id", group.baseid.ToString() });
                }
                else
                {
                    RedirectToAction("new_group");
                }
                return;
            }
            RedirectToAction("list_groups");
        }
Ejemplo n.º 15
0
 partial void Deleteuser_group(user_group instance);
Ejemplo n.º 16
0
 partial void Updateuser_group(user_group instance);
Ejemplo n.º 17
0
 partial void Insertuser_group(user_group instance);
Ejemplo n.º 18
0
	private void detach_user_groups(user_group entity)
	{
		this.SendPropertyChanging();
		entity.security_level1 = null;
	}
Ejemplo n.º 19
0
        public async Task CreateGroup(Request request, Response response)
        {
            var userSession = await CheckAuth.Check(request, response, AuthLevel.Normal);

            if (userSession == null)
            {
                return;
            }

            var requestJson = request.Json <CreateGroupRequest>();

            //判断请求是否有效
            if (!Validation.Valid(requestJson, out var reason))
            {
                await response.BadRequest(reason);

                return;
            }

            //判断当前在允许新建组队的时间范围内
            var now = DateTime.Now;

            if (Config.Config.Options.RegDeadline > 0)
            {
                var regDeadline = UnixTimestamp.FromTimestamp(Config.Config.Options.RegDeadline);
                if (now > regDeadline)
                {
                    await response.BadRequest($"报名截止时间 ({regDeadline:yyyy-MM-dd HH:mm:ss}) 已过。");

                    return;
                }
            }

            //判断当前用户不属于任何组队
            var groupBindDb   = DbFactory.Get <UserGroupBind>();
            var groupBindList = await groupBindDb.SelectAllFromCache();

            var groupBindItem = groupBindList.FirstOrDefault(it => it.uid == userSession.uid);

            if (groupBindItem != null)
            {
                await response.BadRequest("Emmmmm, 请勿重复新建组队。");

                return;
            }

            //取得用户数据
            var userDb   = DbFactory.Get <User>();
            var userDict = (await userDb.SelectAllFromCache()).ToDictionary(it => it.uid, it => it);

            if (!userDict.ContainsKey(userSession.uid))
            {
                await response.Unauthorized("服务器提出了一个问题:你为何存在?");

                return;
            }

            if (string.IsNullOrWhiteSpace(requestJson.groupname))
            {
                await response.BadRequest("组队名称不能全为空白字符。");

                return;
            }

            if (requestJson.groupname.Length > 32)
            {
                await response.BadRequest("组队名称太长。");

                return;
            }

            if (requestJson.profile.Length > 350)
            {
                await response.BadRequest("队伍简介不能太长。");

                return;
            }

            var groupDb      = DbFactory.Get <UserGroup>();
            var groupNameSet = new HashSet <string>((await groupDb.SelectAllFromCache()).Select(it => it.groupname.ToLower()));

            if (groupNameSet.Contains(requestJson.groupname.ToLower()))
            {
                await response.BadRequest("队名不能重复");

                return;
            }


            //新建组队
            var newGroup = new user_group
            {
                groupname   = requestJson.groupname,
                profile     = requestJson.profile,
                create_time = now,
                update_time = now
            };

            var newGid = await groupDb.SimpleDb.AsInsertable(newGroup).ExecuteReturnIdentityAsync();

            await groupDb.InvalidateCache();

            //自动拒绝该用户所有未拒绝的邀请
            var inviteDb = DbFactory.Get <Invite>();
            await inviteDb.Db.Updateable <invite>().SetColumns(it => it.valid == 2)
            .Where(it => it.to_uid == userSession.uid && it.valid == 1).ExecuteCommandAsync();

            await inviteDb.InvalidateCache();


            //修改用户组队绑定
            var user = userDict[userSession.uid];

            user.roleid      = 3;
            user.update_time = now;
            await userDb.SimpleDb.AsUpdateable(user).ExecuteCommandAsync();

            await userDb.InvalidateCache();

            var newGroupBind = new user_group_bind
            {
                uid       = userSession.uid,
                gid       = newGid,
                is_leader = 1
            };
            await groupBindDb.SimpleDb.AsInsertable(newGroupBind).ExecuteCommandAsync();

            await groupBindDb.InvalidateCache();

            await response.OK();
        }
Ejemplo n.º 20
0
    public static string check_mamaro(string param1, string param2, string param3, string param4, string param5)
    {
        //test
        //int comid = 26;
        //List<int> comlist = new List<int>();
        //comlist.Add(comid);
        //comlist.Add(Convert.ToInt32( param6));

        string[] liness = param3.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);


        List <string> res_list = new List <string>();
        GCP_MYSQL     gc       = new GCP_MYSQL();
        string        Query    = "";
        int           QAcou    = 0;
        int           QAcou1   = 0;
        string        result   = "";
        DateTime      start    = Convert.ToDateTime(param1.Trim());
        DateTime      end      = Convert.ToDateTime(param2.Trim());

        if (param4 == "")
        {
            param4 = "30";
        }
        try
        {
            if (start != null && end != null)
            {
                string label = "";
                string res   = "";
                string res1  = "";
                for (int kk = 0; kk < liness.Length; kk++)
                {
                    state_group sg  = new state_group();
                    QA_group    qaa = new QA_group();

                    state_list      = new List <state_group>();
                    lock_state_list = new List <state_group>();

                    QA_list = new List <QA_group>();

                    string room_id = liness[kk];
                    //mamaro name
                    string mamaname = "";
                    Query = "select * from nursing_room where id='" + room_id + "';";
                    DataView ict = gc.select_cmd(Query);
                    if (ict.Count > 0)
                    {
                        mamaname = ict.Table.Rows[0]["name"].ToString();
                    }



                    //mamaro QA
                    Query = "select * from nursing_room_QA where nursing_room_id='" + room_id + "' and insert_time between '" + start.ToString("yyyy-MM-dd HH:mm:ss") + "' and '" + end.ToString("yyyy-MM-dd HH:mm:ss") + "';";
                    ict   = gc.select_cmd(Query);
                    QAcou = ict.Count;
                    if (ict.Count > 0)
                    {
                        for (int i = 0; i < ict.Count; i++)
                        {
                            qaa = new QA_group();
                            qaa.answer_datetime = Convert.ToDateTime(ict.Table.Rows[i]["insert_time"].ToString());
                            qaa.baby_m          = ict.Table.Rows[i]["Q1_baby_month"].ToString();
                            qaa.baby_y          = ict.Table.Rows[i]["Q1_baby_year"].ToString();
                            qaa.lan             = ict.Table.Rows[i]["language"].ToString();
                            qaa.parent          = ict.Table.Rows[i]["Q1_parent"].ToString();
                            qaa.Q2_choice       = ict.Table.Rows[i]["Q2_choice"].ToString();
                            qaa.Q3_choice       = ict.Table.Rows[i]["Q3_choice"].ToString();
                            qaa.Q4_choice       = ict.Table.Rows[i]["Q4_choice"].ToString();
                            qaa.Q5_choice       = ict.Table.Rows[i]["Q5_choice"].ToString();

                            QA_list.Add(qaa);
                        }
                    }

                    QA_group_1 qaa_1 = new QA_group_1();
                    QA_list_1 = new List <QA_group_1>();
                    //mamaro new QA
                    Query  = "select * from nursing_room_QA1 where nursing_room_id='" + room_id + "' and insert_time between '" + start.ToString("yyyy-MM-dd HH:mm:ss") + "' and '" + end.ToString("yyyy-MM-dd HH:mm:ss") + "';";
                    ict    = gc.select_cmd(Query);
                    QAcou1 = ict.Count;
                    if (ict.Count > 0)
                    {
                        for (int i = 0; i < ict.Count; i++)
                        {
                            qaa_1 = new QA_group_1();
                            qaa_1.answer_datetime = Convert.ToDateTime(ict.Table.Rows[i]["insert_time"].ToString());
                            qaa_1.baby_y_m        = ict.Table.Rows[i]["Q1_baby_year_month"].ToString();
                            qaa_1.lan             = ict.Table.Rows[i]["language"].ToString();
                            qaa_1.parent          = ict.Table.Rows[i]["Q1_parent"].ToString();
                            qaa_1.Q2_choice       = ict.Table.Rows[i]["Q2_choice"].ToString();
                            qaa_1.Q3_choice       = ict.Table.Rows[i]["Q3_choice"].ToString();
                            qaa_1.Q4_choice       = ict.Table.Rows[i]["Q4_choice"].ToString();
                            qaa_1.Q5_choice       = ict.Table.Rows[i]["Q5_choice"].ToString();
                            qaa_1.Q6_choice       = ict.Table.Rows[i]["Q6_choice"].ToString();
                            QA_list_1.Add(qaa_1);
                        }
                    }


                    //lock state time
                    Query = "select * from nursing_room_lock_state_time where nursing_room_id='" + room_id + "' and update_time between '" + start.ToString("yyyy-MM-dd HH:mm:ss") + "' and '" + end.ToString("yyyy-MM-dd HH:mm:ss") + "' order by update_time asc;;";
                    ict   = gc.select_cmd(Query);
                    if (ict.Count > 0)
                    {
                        if (room_id == "9")
                        {
                            for (int i = 0; i < ict.Count; i++)
                            {
                                sg = new state_group();
                                if (Convert.ToDateTime(ict.Table.Rows[i]["update_time"].ToString()).Year <= 2017 &&
                                    Convert.ToDateTime(ict.Table.Rows[i]["update_time"].ToString()).Month <= 11 &&
                                    Convert.ToDateTime(ict.Table.Rows[i]["update_time"].ToString()).Day <= 26)
                                {
                                    if (Convert.ToInt32(ict.Table.Rows[i]["lock_state"].ToString()) == 0)
                                    {
                                        sg.state = 1;
                                    }
                                    else
                                    {
                                        sg.state = 0;
                                    }
                                }
                                else
                                {
                                    sg.state = Convert.ToInt32(ict.Table.Rows[i]["lock_state"].ToString());
                                }
                                sg.update = Convert.ToDateTime(ict.Table.Rows[i]["update_time"].ToString());

                                lock_state_list.Add(sg);
                            }
                        }
                        else
                        {
                            for (int i = 0; i < ict.Count; i++)
                            {
                                sg        = new state_group();
                                sg.state  = Convert.ToInt32(ict.Table.Rows[i]["lock_state"].ToString());
                                sg.update = Convert.ToDateTime(ict.Table.Rows[i]["update_time"].ToString());

                                lock_state_list.Add(sg);
                            }
                        }
                    }


                    List <state_group> check_list1 = new List <state_group>();

                    for (int i = 0; i < lock_state_list.Count; i++)
                    {
                        if (lock_state_list[i].state == 0)
                        {
                            sg        = new state_group();
                            sg.state  = lock_state_list[i].state;
                            sg.update = lock_state_list[i].update;
                            check_list1.Add(sg);
                            int index = i + 1;
                            while (index < lock_state_list.Count)
                            {
                                if (lock_state_list[index].state == 1)
                                {
                                    sg        = new state_group();
                                    sg.state  = lock_state_list[index].state;
                                    sg.update = lock_state_list[index].update;
                                    check_list1.Add(sg);
                                    break;
                                }
                                index += 1;
                            }
                        }
                    }
                    //Chart1.Series.Clear();  //每次使用此function前先清除圖表
                    //Series series1 = new Series("use time(second)", 1200); //初始畫線條(名稱,最大值)
                    //series1.Color = Color.Blue; //設定線條顏色
                    //series1.Font = new System.Drawing.Font("新細明體", 10); //設定字型
                    //series1.ChartType = SeriesChartType.Line; //設定線條種類
                    //Chart1.ChartAreas[0].AxisY.Minimum = 0;//設定Y軸最小值
                    //Chart1.ChartAreas[0].AxisY.Maximum = 1200;//設定Y軸最大值
                    ////chart1.ChartAreas[0].AxisY.Enabled= AxisEnabled.False; //隱藏Y 軸標示
                    ////chart1.ChartAreas[0].AxisY.MajorGrid.Enabled= true;  //隱藏Y軸標線
                    //series1.IsValueShownAsLabel = true; //是否把數值顯示在線上
                    string monstr = "var MONTHS = [";
                    monstr += "];";
                    string monstt = "";
                    string arrva  = "";

                    double     avg = 0, coun = 0, hcou = 0, havg = 0;
                    double     compute_day = -1;
                    DateTime   first_d, second_d;
                    List <int> count_list = new List <int>();



                    usercou_list = new List <user_group>();
                    user_group ug         = new user_group();
                    int        basesec    = Convert.ToInt32(param4);
                    int        coun_start = 0;
                    int        coun_end   = basesec;
                    int        couuuu     = 0;


                    //Chart1.Series.Add(series1);//將線畫在圖上

                    //for (int i = 0; i < check_list.Count; i++)
                    //{
                    //    listBox1.Items.Add(check_list[i].state);
                    //    listBox2.Items.Add(check_list[i].update.ToString("yyyy-MM-dd HH:mm:ss"));
                    //}
                    Random rnd = new Random(Guid.NewGuid().GetHashCode());
                    int    r   = rnd.Next(256);
                    rnd = new Random(Guid.NewGuid().GetHashCode());
                    int g = rnd.Next(256);
                    rnd = new Random(Guid.NewGuid().GetHashCode());
                    int b = rnd.Next(256);



                    monstr  = "var MONTHS = [";
                    monstr += "];";
                    monstt  = "";
                    arrva   = "";

                    avg         = 0; coun = 0; hcou = 0; havg = 0;
                    compute_day = -1;
                    count_list  = new List <int>();
                    for (int i = 0; i < check_list1.Count; i++)
                    {
                        compute_day = -1;
                        if (check_list1[i].state == 0)
                        {
                            first_d = Convert.ToDateTime(check_list1[i].update);

                            int index = i + 1;
                            while (index < check_list1.Count)
                            {
                                if (check_list1[index].state == 1)
                                {
                                    second_d    = Convert.ToDateTime(check_list1[index].update);
                                    compute_day = (second_d - first_d).TotalSeconds;

                                    break;
                                }
                                index += 1;
                            }
                            if (compute_day > -1)
                            {
                                //monstt += check_list1[i].update.ToString("yyyyMMddHHmmss") + ",";
                                //arrva += compute_day + ",";

                                if (compute_day < 1801)
                                {
                                    coun += 1;
                                    avg  += compute_day;
                                    //monstt += check_list1[i].update.ToString("yyyyMMddHHmmss") + ",";
                                    //arrva += compute_day + ",";
                                    count_list.Add(Convert.ToInt32(compute_day));
                                }
                                if (compute_day >= Convert.ToInt32(param4) && compute_day < 1801)
                                {
                                    hcou += 1;
                                    havg += compute_day;
                                }
                                //series1.Points.AddXY(i.ToString(), compute_day);


                                //listBox3.Items.Add("Start time: " + check_list[i].update.ToString("yyyy-MM-dd HH:mm:ss") + " ~");
                                //listBox3.Items.Add("End time: " + check_list[index].update.ToString("yyyy-MM-dd HH:mm:ss"));
                                //listBox3.Items.Add("Total sec: " + compute_day);
                            }
                            else
                            {
                                //DateTime todate = DateTime.Now;
                                //double compute_day1 = (todate - first_d).TotalSeconds;
                                //listBox3.Items.Add("Start time: " + check_list[i].update.ToString("yyyy-MM-dd HH:mm:ss") + " ~");
                                //listBox3.Items.Add("End time: NO");
                                //listBox3.Items.Add("Total sec: NO");
                            }
                        }
                    }

                    usercou_list = new List <user_group>();
                    ug           = new user_group();
                    basesec      = Convert.ToInt32(param4);
                    coun_start   = 0;
                    coun_end     = basesec;
                    couuuu       = 0;
                    for (int i = 0; i < Convert.ToInt32(param5); i += basesec)
                    {
                        couuuu = 0;
                        ug     = new user_group();
                        ug.sec = i;
                        for (int ii = 0; ii < count_list.Count; ii++)
                        {
                            if (count_list[ii] > i)
                            {
                                couuuu += 1;
                            }
                            //if (count_list[ii] > i && count_list[ii] < (i + basesec))
                            //{
                            //    couuuu += 1;
                            //}
                        }
                        ug.total = couuuu;
                        usercou_list.Add(ug);
                    }
                    for (int i = 0; i < usercou_list.Count; i++)
                    {
                        //monstt += usercou_list[i].sec.ToString() + ",";
                        if (usercou_list[i].sec % 60 == 0)
                        {
                            monstt += (usercou_list[i].sec / 60).ToString() + ",";
                        }
                        else
                        {
                            monstt += " ,";
                        }

                        arrva += usercou_list[i].total.ToString() + ",";
                    }

                    if (monstt != "")
                    {
                        monstt = monstt.Substring(0, monstt.Length - 1);
                    }
                    if (arrva != "")
                    {
                        arrva = arrva.Substring(0, arrva.Length - 1);
                    }
                    rnd   = new Random(Guid.NewGuid().GetHashCode());
                    r     = rnd.Next(256);
                    rnd   = new Random(Guid.NewGuid().GetHashCode());
                    g     = rnd.Next(256);
                    rnd   = new Random(Guid.NewGuid().GetHashCode());
                    b     = rnd.Next(256);
                    res1 += @"{
                     label: '" + mamaname + @"',
                     fill: false,
                     backgroundColor: 'rgb(" + r + @", " + g + @", " + b + @")',
                     borderColor: 'rgb(" + r + @", " + g + @", " + b + @")',
                     data: [" + arrva + @"
                     ],
                     
                 },";
                    res   = @"{
                     label: '" + mamaname + @"',
                     fill: false,
                     backgroundColor: 'rgb(" + r + @", " + g + @", " + b + @")',
                     borderColor: 'rgb(" + r + @", " + g + @", " + b + @")',
                     data: [" + arrva + @"
                     ],
                     
                 },";
                    label = monstt;



                    string ress = @"<fieldset>
    <legend>" + mamaname + @"</legend><br/>
<script type='text/javascript'>
         var config" + kk + @" = {
             type: 'line',
             data: {
                 labels: [" + label + @"],
                 datasets: [" + res + @"]
             },
             options: {
                 responsive: true,
                 title: {
                     display: true,
                     text: '" + mamaname + @"'
                 },
                 tooltips: {
                     mode: 'index',
                     intersect: false,
                 },
                 hover: {
                     mode: 'nearest',
                     intersect: true
                 },
                 scales: {
                     xAxes: [{
                         display: true,
                         scaleLabel: {
                             display: true,
                             labelString: '滞在時間(分)'
                         }
                     }],
                     yAxes: [{
                         display: true,
                         scaleLabel: {
                             display: true,
                             labelString: '利用人数(人)'
                         }
                     }]
                 },
animation: {
    onComplete: function () {
        var ctx = this.chart.ctx;
        ctx.font = Chart.helpers.fontString(Chart.defaults.global.defaultFontFamily, 'normal', Chart.defaults.global.defaultFontFamily);
        ctx.fillStyle = 'black';
        ctx.textAlign = 'center';
        ctx.textBaseline = 'bottom';

        this.data.datasets.forEach(function (dataset)
        {
            for (var i = 0; i < dataset.data.length; i++) {
                for(var key in dataset._meta)
                {
                    var model = dataset._meta[key].data[i]._model;
                    ctx.fillText(dataset.data[i], model.x, model.y - 5);
                }
            }
        });
        done" + kk + @"();
    }
}
             }

         };
 var ctx" + kk + @" = document.getElementById('canvas" + kk + @"').getContext('2d');
             window.myLine = new Chart(ctx" + kk + @", config" + kk + @");

function done" + kk + @"(){
  var url_base64 = document.getElementById('canvas" + kk + @"').toDataURL('image/png');
  link" + kk + @".href = url_base64;
}
</script>
<canvas id='canvas" + kk + @"'></canvas>
<br/>
<a id='link" + kk + @"' download='" + mamaname + @".png'>Save as Image</a>
<br/>
  </fieldset>
";

                    res_list.Add(ress);
                    //                res += @"<script type='text/javascript'>
                    //
                    //</script>";


                    //result = res;


                    //result = "fail";
                }
                result = @"<fieldset>
    <legend>ALL mamaro</legend><br/>
<script type='text/javascript'>
         var config = {
             type: 'line',
             data: {
                 labels: [" + label + @"],
                 datasets: [" + res1 + @"]
             },
             options: {
                 responsive: true,
                 title: {
                     display: true,
                     text: 'ALL mamaro'
                 },
                 tooltips: {
                     mode: 'index',
                     intersect: false,
                 },
                 hover: {
                     mode: 'nearest',
                     intersect: true
                 },
                 scales: {
                     xAxes: [{
                         display: true,
                         scaleLabel: {
                             display: true,
                             labelString: '滞在時間(分)'
                         }
                     }],
                     yAxes: [{
                         display: true,
                         scaleLabel: {
                             display: true,
                             labelString: '利用人数(人)'
                         }
                     }]
                 },
                 animation: {
                     onComplete: done
                 }
             }
         };
 var ctx = document.getElementById('canvas').getContext('2d');
             window.myLine = new Chart(ctx, config);
function done(){
  var url_base64 = document.getElementById('canvas').toDataURL('image/png');
  link.href = url_base64;
}
</script>
<canvas id='canvas'></canvas>
<br/>
<a id='link' download='allmamaro.png'>Save as Image</a>
<br/><br/>
  </fieldset>
";

                for (int hh = 0; hh < res_list.Count; hh++)
                {
                    result += res_list[hh];
                }
            }
        }
        catch (Exception ex)
        {
            //result = "fail";

            //return result;
            throw ex;
        }
        return(result);
    }
Ejemplo n.º 21
0
 public static user_group AccessLevel()
 {
     dbDataContext db = new dbDataContext();
     try
     {
         try
         { return (from p in Permissions.List(db) where UserGroups().Contains(p.ad_group) orderby p.security_level descending select p).FirstOrDefault(); }
         catch
         { return db.user_groups.First(); }
     }
     catch
     {
         user_group dummy = new user_group();
         dummy.id = 0;
         return dummy;
     }
 }