Ejemplo n.º 1
0
        public ActionResult PriCheckdo()
        {
            string bid = Request["bid"];

            //權限角色同步
            if (Request["fsubmit"].ToString() == "1")
            {
                string        msid  = bid;
                NDcommon      dbobj = new NDcommon();
                SqlConnection conn  = dbobj.get_conn("Aitag_DBContext");

                SqlDataReader dr;
                SqlCommand    sqlsmd = new SqlCommand();
                sqlsmd.Connection = conn;

                string sqlstr = "select * from employee where msid = '" + msid + "'";
                //string sqlstr = "select * from Privtb where bid = '" + Request["id"].ToString() + "'";
                sqlsmd.CommandText = sqlstr;
                dr = sqlsmd.ExecuteReader();

                while (dr.Read())
                {
                    dbobj.dbexecute("Aitag_DBContext", "DELETE FROM Privtb where bid = '" + dr["empid"].ToString() + "'");
                    dbobj.addPrivtb(msid, dr["empid"].ToString());
                }
                dr.Close();
                dr.Dispose();
                conn.Close();
                conn.Dispose();



                return(new ContentResult()
                {
                    Content = @"<script>alert('完成權限角色同步!!');location.href='/Privrole/PriCheck?msid=" + bid + "&psid=2'</script>"
                });
            }
            else
            {//修改權限
                string psid = Request["psid"].ToString();
                if (Request["privdata"] != null)
                {
                    NDcommon dbobj = new NDcommon();
                    dbobj.dbexecute("Aitag_DBContext", "DELETE FROM Privtb where bid = '" + bid + "' and psid = '" + psid + "'");
                    string   privstr = Request["privdata"];
                    string[] pvarr   = privstr.Split(',');

                    //NDcommon dbobj = new NDcommon();
                    SqlConnection conn   = dbobj.get_conn("Aitag_DBContext");
                    SqlCommand    sqlsmd = new SqlCommand();
                    sqlsmd.Connection = conn;
                    for (int i = 0; i < pvarr.Length; i++)
                    {
                        //string psid = dbobj.get_dbvalue(conn, "select distinct psid from sublevel1 where sid = '" + pvarr[i].ToString().Trim() + "'");
                        if (pvarr[i].ToString().Trim() != "")
                        {
                            sqlsmd.CommandText = "insert into Privtb(sid,bid,psid,chk,subread,subadd,submod,subdel,Bmodid,Bmoddate) values('" + pvarr[i].ToString().Trim() + "','" + bid + "','" + psid + "','1','1','1','1','1','" + Session["empid"].ToString() + "',getdate())";
                            sqlsmd.ExecuteNonQuery();
                        }
                    }
                    conn.Close();
                    conn.Dispose();

                    //系統LOG檔 //================================================= //
                    // iMedia.Models.NDcommon dbobj = new iMedia.Models.NDcommon();
                    string        syssubname = "系統管理作業 > 使用者管理作業(權限)";
                    string        sysnote    = "帳號:" + bid;
                    string        sysflag    = "M";
                    SqlConnection sysconn    = dbobj.get_conn("Aitag_DBContext");
                    dbobj.systemlog(sysconn, syssubname, sysnote, Session["tempid"].ToString(), Session["sldate"].ToString(), Session["sfip"].ToString(), sysflag);
                    sysconn.Close();
                    sysconn.Dispose();
                    //=================================================
                    //var oldPolicyManagement = con.Privtbs.Where(r => r.bid == "adm" && data.PolicyManagement.Contains(r.sid)).ToList();

                    return(new ContentResult()
                    {
                        Content = @"<script>alert('權限修改成功!!');location.href='/Privrole/PriCheck/?msid=" + bid + "&psid=2'</script>"
                    });
                }
                else
                {
                    return(new ContentResult()
                    {
                        Content = @"<script>alert('請挑選功能權限!!');location.href='/Privrole/PriCheck/?msid=" + bid + "&psid=2'</script>"
                    });
                }
                //return RedirectToAction("PriCheck");
            }
        }