コード例 #1
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            HttpRequest request = context.Request;

            XHD.BLL.ssn_role     role  = new XHD.BLL.ssn_role();
            XHD.BLL.ssn_art_menu menu  = new XHD.BLL.ssn_art_menu();
            XHD.Model.ssn_role   model = new XHD.Model.ssn_role();
            XHD.BLL.ssn_visit    visit = new XHD.BLL.ssn_visit();
            XHD.BLL.ssn_art      art   = new XHD.BLL.ssn_art();
            var    cookie     = context.Request.Cookies[FormsAuthentication.FormsCookieName];
            var    ticket     = FormsAuthentication.Decrypt(cookie.Value);
            string CoockiesID = ticket.UserData;

            XHD.BLL.hr_employee emp = new XHD.BLL.hr_employee();
            int     emp_id          = int.Parse(CoockiesID);
            DataSet dsemp           = emp.GetList("id=" + emp_id);
            string  empname         = string.Empty;
            string  uid             = string.Empty;
            string  factory_Id      = string.Empty;

            if (dsemp != null && dsemp.Tables[0].Rows.Count > 0)
            {
                empname    = dsemp.Tables[0].Rows[0]["name"].ToString();
                uid        = dsemp.Tables[0].Rows[0]["uid"].ToString();
                factory_Id = dsemp.Tables[0].Rows[0]["Factory_Id"].ToString();
            }

            //角色保存
            if (request["Action"] == "SysSave")
            {
                model.RoleName    = PageValidate.InputText(request["T_role"], 250);
                model.RoleSort    = int.Parse(request["T_RoleOrder"]);
                model.RoleDscript = PageValidate.InputText(request["T_Descript"], 255);
                model.Factory_Id  = factory_Id;

                string id = PageValidate.InputText(request["id"], 50);

                if (!string.IsNullOrEmpty(id) && id != "null")
                {
                    DataSet ds = role.GetList("RoleID=" + int.Parse(id));
                    DataRow dr = ds.Tables[0].Rows[0];
                    model.RoleID     = int.Parse(id);
                    model.UpdateDate = DateTime.Now;
                    model.UpdateID   = emp_id;
                    role.Update(model);
                }
                else
                {
                    model.CreateID   = emp_id;
                    model.CreateDate = DateTime.Now;
                    int rid = role.Add(model);
                }
            }

            //验证是否唯一
            else if (request["Action"] == "Exist")
            {
                DataSet ds1 = role.GetList(" RoleName='" + XHD.Common.PageValidate.InputText(request["T_role"], 250) + "'" + " and factory_Id='" + factory_Id + "'");
                context.Response.Write(ds1.Tables[0].Rows.Count > 0 ? "false" : "true");
            }

            //获取角色表格json
            else if (request["Action"] == "grid")
            {
                DataSet ds = role.GetList(0, "factory_Id='" + factory_Id + "'", " RoleSort");

                string dt = XHD.Common.GetGridJSON.DataTableToJSON(ds.Tables[0]);

                context.Response.Write(dt);
            }

            //获取角色信息
            else if (request["Action"] == "form")
            {
                DataSet ds = role.GetList(" RoleID=" + int.Parse(request["id"]));

                string dt = XHD.Common.DataToJson.DataToJSON(ds);

                context.Response.Write(dt);
            }
            //删除角色
            else if (request["Action"] == "del")
            {
                string rid   = request["id"];
                bool   isdel = role.Delete(int.Parse(rid));
                if (isdel)
                {
                    context.Response.Write("true");
                }
                else
                {
                    context.Response.Write("false");
                }

                //角色下员工删除
                XHD.BLL.ssn_role_emp rm = new XHD.BLL.ssn_role_emp();
                rm.Delete("RoleID=" + int.Parse(rid));

                //角色下数据权限删除
                XHD.BLL.ssn_visit data_auth = new XHD.BLL.ssn_visit();
                data_auth.DeleteByRole(int.Parse(rid));

                //角色下功能权限删除
                XHD.BLL.ssn_authority auth = new XHD.BLL.ssn_authority();
                auth.DeleteWhere("Role_id=" + int.Parse(rid));
            }

            #region 权限设置
            //auth
            else if (request["Action"] == "treegrid")
            {
                string appidstr = request["appid"];
                int    appid    = int.Parse(appidstr);

                //获取单位
                string ftyid = PageValidate.InputText(request["factory_id"], 60);
                //设置查询条件
                string wheretext  = "App_id=" + appid; //限制menu
                string wheretext2 = "";                //限制button

                DataTable dt = menu.GetList(wheretext).Tables[0];
                dt.Columns.Add(new DataColumn("Sysroler", typeof(string)));

                XHD.BLL.ssn_button btn = new XHD.BLL.ssn_button();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataSet ds    = btn.GetList(0, "Menu_id=" + dt.Rows[i]["Menu_id"].ToString() + wheretext2, "Btn_order");
                    string  roler = "";
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
                        {
                            roler += ds.Tables[0].Rows[j]["Btn_id"].ToString() + "|" + ds.Tables[0].Rows[j]["Btn_name"].ToString();
                            roler += ",";
                        }
                    }
                    dt.Rows[i][dt.Columns.Count - 1] = roler;
                }
                string dt1 = "{Rows:[" + GetTasksString(0, dt) + "]}";
                context.Response.Write(dt1);
                context.Response.End();
            }
            //get auth
            else if (request["Action"] == "getauth")
            {
                string postdata           = Convert.ToString(HttpContext.Current.Request.QueryString["postdata"]);
                JavaScriptSerializer json = new JavaScriptSerializer();
                save sa = json.Deserialize <save>(postdata);
                XHD.Model.ssn_authority modelauth = new XHD.Model.ssn_authority();
                modelauth.Role_id    = int.Parse(sa.role_id);
                modelauth.App_ids    = sa.app;
                modelauth.Menu_ids   = sa.menu;
                modelauth.Button_ids = sa.btn;

                XHD.BLL.ssn_authority sysau = new XHD.BLL.ssn_authority();

                string  roledata = "0|0";
                DataSet ds       = sysau.GetList("Role_id=" + modelauth.Role_id + " and App_ids='" + modelauth.App_ids + "'");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    DataRow dr = ds.Tables[0].Rows[0];
                    roledata = dr["Menu_ids"] + "|" + dr["Button_ids"];
                }
                context.Response.Write(roledata);
            }
            // save auth
            else if (request["Action"] == "saveauth")
            {
                string postdata           = Convert.ToString(HttpContext.Current.Request.QueryString["postdata"]);
                JavaScriptSerializer json = new JavaScriptSerializer();
                save sa = json.Deserialize <save>(postdata);
                XHD.Model.ssn_authority modelauth = new XHD.Model.ssn_authority();
                modelauth.Role_id    = int.Parse(sa.role_id);
                modelauth.App_ids    = PageValidate.InputText(sa.app, 50);
                modelauth.Menu_ids   = PageValidate.InputText(sa.menu, int.MaxValue);
                modelauth.Button_ids = PageValidate.InputText(sa.btn, int.MaxValue);
                modelauth.Factory_Id = factory_Id;

                XHD.BLL.ssn_authority sysau = new XHD.BLL.ssn_authority();
                //List<string> relstbtn = new List<string>();

                if (!string.IsNullOrEmpty(postdata))
                {
                    //给角色分配权限
                    sysau.DeleteWhere("Role_id=" + modelauth.Role_id + " and App_ids='" + modelauth.App_ids + "'");
                    if (modelauth.Menu_ids != "" || modelauth.Button_ids != ",,")
                    {
                        sysau.Add(modelauth);
                    }
                    context.Response.Write("{sucess:sucess}");
                }
            }
            #endregion

            #region 查看权限设置
            //菜单显示
            else if (request["Action"] == "menuList")
            {
                string appid   = request["appid"];
                string authtxt = PageValidate.InputText(request["auth"], 50);

                if (!string.IsNullOrEmpty(appid))
                {
                    string serchtxt = " App_id=" + int.Parse(appid);
                    //-context.Response.Write(authtxt);
                    DataSet       ds  = menu.GetList(0, serchtxt, " Menu_order");
                    StringBuilder str = new StringBuilder();
                    str.Append("[");
                    str.Append(GetTreeString(0, ds.Tables[0], authtxt));
                    str.Replace(",", "", str.Length - 1, 1);
                    str.Append("]");
                    context.Response.Write(str);
                }
            }

            //显示菜单下的文章
            else if (request["Action"] == "viewgrid")
            {
                //通过菜单id获取旗下的文章
                string menuid = request["menuid"];

                if (!string.IsNullOrEmpty(menuid))
                {
                    string  serchtxt = " Factory_Id='" + factory_Id + "' and Art_Menu_Id=" + int.Parse(menuid) + " and is_del=0 ";
                    DataSet ds       = art.GetList(serchtxt);

                    string dt = XHD.Common.GetGridJSON.DataTableToJSON(ds.Tables[0]);
                    context.Response.Write(dt);
                }
            }

            //保存查看权限
            else if (request["Action"] == "saveview")
            {
                string postdata           = Convert.ToString(HttpContext.Current.Request.QueryString["postdata"]);
                JavaScriptSerializer json = new JavaScriptSerializer();
                view sa = json.Deserialize <view>(postdata);
                XHD.Model.ssn_visit modelview = new XHD.Model.ssn_visit();
                modelview.Role_id     = int.Parse(sa.role_id);
                modelview.App_ids     = PageValidate.InputText(sa.app, 50);
                modelview.Menu_ids    = PageValidate.InputText(sa.menu, int.MaxValue);
                modelview.Art_id      = PageValidate.InputText(sa.art, int.MaxValue);
                modelview.Factory_Id  = factory_Id;
                modelview.Create_id   = emp_id;
                modelview.Create_date = DateTime.Now;

                if (!string.IsNullOrEmpty(postdata))
                {
                    //给角色分配权限
                    visit.DeleteWhere("Role_id=" + modelview.Role_id + " and Menu_ids='" + modelview.Menu_ids + "'");
                    if (modelview.Art_id != "")
                    {
                        visit.Add(modelview);
                    }
                    context.Response.Write("{sucess:sucess}");
                }
            }
            //获取当前角色的权限
            else if (request["Action"] == "getview")
            {
                string postdata           = Convert.ToString(HttpContext.Current.Request.QueryString["postdata"]);
                JavaScriptSerializer json = new JavaScriptSerializer();
                view sa = json.Deserialize <view>(postdata);
                XHD.Model.ssn_visit modelview = new XHD.Model.ssn_visit();
                modelview.Role_id  = int.Parse(sa.role_id);
                modelview.App_ids  = sa.app;
                modelview.Menu_ids = sa.menu;
                modelview.Art_id   = sa.art;

                string  roledata = "";
                DataSet ds       = visit.GetList("Role_id=" + modelview.Role_id + " and Menu_ids='" + modelview.Menu_ids + "'");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    DataRow dr = ds.Tables[0].Rows[0];
                    roledata = dr["Art_id"].ToString();
                }
                context.Response.Write(roledata);
            }

            #endregion
        }
コード例 #2
0
        public static string PostUrl = ConfigurationManager.AppSettings["WebReference.Service.PostUrl"];//短信接口地址
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";


            HttpRequest          request = context.Request;
            JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();

            XHD.Model.hr_employee empModel = new GetEmpInfo().GetEmpModel(request);

            string json   = null;
            string Action = request["Action"];

            switch (Action)
            {
            case "action":
                bool   success          = false;
                string filesVal         = request["filesVal"];
                string txtQuestionTitle = request["txtQuestionTitle"];
                if (string.IsNullOrEmpty(txtQuestionTitle))
                {
                    var result = new { success = success, text = "问题标题不能为空!" };
                    json = javaScriptSerializer.Serialize(result);
                    context.Response.Write(json);
                }
                string selQestionType = request["selQestionType"];
                if (selQestionType == "-1")
                {
                    var result = new { success = success, text = "请选择问题类型!" };
                    json = javaScriptSerializer.Serialize(result);
                    context.Response.Write(json);
                }
                string txtQestionContent = request["txtQestionContent"];
                string telPhone          = request["telPhone"];
                string radTime           = request["radTime"];
                string txtEmail          = request["txtEmail"];
                string sp_uid            = request["sp_uid"];

                XHD.Model.ssn_question question = new XHD.Model.ssn_question();
                question.att_file = filesVal;
                question.content  = txtQestionContent;
                question.e_mail   = txtEmail;
                question.type     = Convert.ToInt32(selQestionType);
                question.title    = txtQuestionTitle;
                question.tel      = telPhone;
                question.q_time   = DateTime.Now;
                question.q_uid    = empModel.ID;
                question.q_name   = empModel.name;
                question.sp_uid   = sp_uid;
                success           = new XHD.BLL.ssn_question().Add(question);
                if (success)
                {
                    #region 发送短信
                    //string account = "cf_denny";
                    //string password = "******";//密码可以使用明文密码或使用32位MD5加密
                    //string mobile = telPhone;
                    //Random rad = new Random();
                    ////int mobile_code = rad.Next(1000, 10000);
                    ////string content = "您的验证码是:" + mobile_code + " 。请不要把验证码泄露给其他人。";
                    //int int1 = 1;
                    //string strcontent = "你最近吃饭了吗?";
                    //string content = "你好," + int1 + "需采购以下产品," + strcontent + "。 ";
                    ////Session["mobile"] = mobile;
                    ////Session["mobile_code"] = mobile_code;

                    //string postStrTpl = "account={0}&password={1}&mobile={2}&content={3}";

                    //UTF8Encoding encoding = new UTF8Encoding();
                    //byte[] postData = encoding.GetBytes(string.Format(postStrTpl, account, password, mobile, content));

                    //HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(PostUrl);
                    //myRequest.Method = "POST";
                    //myRequest.ContentType = "application/x-www-form-urlencoded";
                    //myRequest.ContentLength = postData.Length;

                    //Stream newStream = myRequest.GetRequestStream();
                    //// Send the data.
                    //newStream.Write(postData, 0, postData.Length);
                    //newStream.Flush();
                    //newStream.Close();

                    //HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
                    #region 提示是否发送成功,暂时只管发送不验证成功与否
                    //if (myResponse.StatusCode == HttpStatusCode.OK)
                    //{
                    //    StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);

                    //    //Response.Write(reader.ReadToEnd());

                    //    string res = reader.ReadToEnd();
                    //    int len1 = res.IndexOf("</code>");
                    //    int len2 = res.IndexOf("<code>");
                    //    string code = res.Substring((len2 + 6), (len1 - len2 - 6));
                    //    //Response.Write(code);

                    //    int len3 = res.IndexOf("</msg>");
                    //    int len4 = res.IndexOf("<msg>");
                    //    string msg = res.Substring((len4 + 5), (len3 - len4 - 5));
                    //    context.Response.Write(msg);

                    //    //Response.End();

                    //}
                    //else
                    //{
                    //    //访问失败
                    //}
                    #endregion
                    #endregion
                    var dataResult = new { success = success, text = "提交成功!" };
                    json = javaScriptSerializer.Serialize(dataResult);
                }
                else
                {
                    var dataResult = new { success = success, text = "提交失败!" };
                    json = javaScriptSerializer.Serialize(dataResult);
                }
                context.Response.Write(json);
                break;

            case "deleteFile":
                string path      = string.Empty;
                string fileName  = request["fileName"];
                string targetDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + "File/question");
                path = System.IO.Path.Combine(targetDir, fileName);
                File.Delete(path);
                context.Response.Write("删除成功!");
                break;

            case "getAboutQuestionList":
                //获得相关问题列表
                string strWhere    = "1=1";
                string strWhereArt = "1=1";
                XHD.BLL.ssn_question questionBll = new XHD.BLL.ssn_question();
                XHD.BLL.ssn_art      artBll      = new XHD.BLL.ssn_art();
                string txtQuestionTitleEx        = request["txtQuestionTitle"];
                if (!string.IsNullOrEmpty(txtQuestionTitleEx))
                {
                    List <string> strList  = new List <string>();
                    char[]        charList = txtQuestionTitleEx.ToArray();
                    for (int i = 0; i < charList.Length; i++)
                    {
                        if (i == 0)
                        {
                            strWhere    += " and title like '%" + charList[i] + "%'";
                            strWhereArt += " and Art_title like '%" + charList[i] + "%'";
                        }
                        else
                        {
                            strWhere    += " or title like '%" + charList[i] + "%'";
                            strWhereArt += " or Art_title like '%" + charList[i] + "%'";
                        }
                        if (!strList.Contains(charList[i].ToString()))
                        {
                            strList.Add(charList[i].ToString());
                        }
                    }
                    Segment seg = new Segment();
                    seg.InitWordDics();
                    seg.EnablePrefix = true;
                    seg.Separator    = " ";
                    string Seg_Title = seg.SegmentText(txtQuestionTitleEx, false).Trim();

                    string[] titleArray = Seg_Title.Split(' ');
                    for (int i = 0; i < titleArray.Length; i++)
                    {
                        strWhere    += " or title like '%" + titleArray[i] + "%'";
                        strWhereArt += " or Art_title like '%" + titleArray[i] + "%'";
                    }
                    List <XHD.Model.ssn_question> questionList = new List <XHD.Model.ssn_question>();
                    questionList = questionBll.GetModelList(strWhere);

                    List <XHD.Model.ssn_art> artList = new List <XHD.Model.ssn_art>();
                    artList = artBll.GetModelList(strWhereArt);

                    List <XHD.Model.question> modelList = new List <XHD.Model.question>();
                    foreach (XHD.Model.ssn_question item in questionList)
                    {
                        XHD.Model.question model = new XHD.Model.question();
                        model.id     = item.id;
                        model.title  = item.title;
                        model.q_time = item.q_time;
                        model.status = 1;
                        modelList.Add(model);
                    }
                    foreach (XHD.Model.ssn_art item in artList)
                    {
                        XHD.Model.question model = new XHD.Model.question();
                        model.id     = item.Id;
                        model.title  = item.Art_title;
                        model.q_time = item.Create_Date;
                        model.status = 2;
                        modelList.Add(model);
                    }
                    for (int i = 0; i < modelList.Count; i++)
                    {
                        string temStr = modelList[i].title.ToString();
                        for (int j = 0; j < strList.Count; j++)
                        {
                            if (temStr.Contains(strList[j]))
                            {
                                modelList[i].title = modelList[i].title.ToString().Replace(strList[j], "<span style='color:red' >" + strList[j] + "</span>");
                            }
                        }
                    }
                    var data = new { rows = modelList };
                    json = javaScriptSerializer.Serialize(data);
                    context.Response.Write(json);
                }
                break;

            case "getQuestionType":
                XHD.BLL.ssn_art_menu          questionTypeBll  = new XHD.BLL.ssn_art_menu();
                List <XHD.Model.ssn_art_menu> questionTyleList = new List <XHD.Model.ssn_art_menu>();
                string strQuestionTypeWhere = "1=1";
                strQuestionTypeWhere += " and App_id=1 and parentid<>0";
                questionTyleList      = questionTypeBll.GetModelList(strQuestionTypeWhere);
                var questionTypeData = new { rows = questionTyleList };
                json = javaScriptSerializer.Serialize(questionTypeData);
                context.Response.Write(json);
                break;

            default:
                string pathFile = string.Empty;
                try
                {
                    //获取客户端上传的文件集合
                    HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
                    //判断是否存在文件
                    if (files.Count > 0)
                    {
                        //获取文件集合中的第一个文件(每次只上传一个文件)
                        HttpPostedFile file = files[0];
                        //定义文件存放的目标路径
                        string targetDirFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + "File/question");
                        if (!Directory.Exists(targetDirFile))
                        {
                            Directory.CreateDirectory(targetDirFile);
                        }
                        //组合成文件的完整路径
                        pathFile = System.IO.Path.Combine(targetDirFile, System.IO.Path.GetFileName(file.FileName));
                        //保存上传的文件到指定路径中
                        file.SaveAs(pathFile);
                        context.Response.Write(file.FileName);
                    }
                }
                catch
                {
                }
                break;
            }
        }
コード例 #3
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            HttpRequest request = context.Request;
            var         cookie  = context.Request.Cookies[FormsAuthentication.FormsCookieName];

            XHD.BLL.ssn_art_menu menu   = new XHD.BLL.ssn_art_menu();
            XHD.BLL.ssn_visit    _visit = new XHD.BLL.ssn_visit();
            XHD.BLL.ssn_art      _art   = new XHD.BLL.ssn_art();
            //判断是否登录
            if (cookie == null)
            {
                DataSet ds = new DataSet();
                ds = menu.GetList("1=2");
                string strRe = XHD.Common.GetGridJSON.DataTableToJSON(ds.Tables[0]);
                context.Response.Write(strRe);
                return;
            }

            var ticket = FormsAuthentication.Decrypt(cookie.Value);

            string CoockiesID = ticket.UserData;

            XHD.BLL.hr_employee emp = new XHD.BLL.hr_employee();
            int emp_id = int.Parse(CoockiesID);

            DataSet dsemp = emp.GetList("id=" + emp_id);

            XHD.Model.hr_employee employeeModel = emp.GetModel(emp_id); //当前员工

            string empname    = string.Empty;
            string uid        = string.Empty;
            string depid      = string.Empty;
            string roletype   = string.Empty;
            string factory_Id = string.Empty;

            if (employeeModel != null)
            {
                empname    = employeeModel.name;            //员工姓名
                uid        = employeeModel.uid;             //员工Uid
                depid      = employeeModel.d_id.ToString(); //员工所在部门
                factory_Id = employeeModel.factory_Id;      //员工所属工厂
                roletype   = employeeModel.roletype.ToString();
            }
            //获取一级菜单
            if (request["Action"] == "GetSysMenu1")
            {
                #region
                DataSet ds = new DataSet();

                int appid = int.Parse(request["appid"]);

                if (dsemp.Tables[0].Rows.Count > 0)
                {
                    if (dsemp.Tables[0].Rows[0]["uid"].ToString() == "admin")
                    {
                        ds = menu.GetList(0, "App_id=" + appid + " and parentid=0", "Menu_order");
                    }
                    else
                    {
                        DataSSN.SSN_GetAuthorityByUid getauth = new DataSSN.SSN_GetAuthorityByUid();
                        string menus = getauth.GetAuthority(emp_id.ToString(), "Menus");
                        //ds = menu.GetList(0, "App_id=" + appid + " and Menu_id in " + menus + " and menu_type='aft'", "Menu_order");
                        ds = menu.GetList(0, "App_id=" + appid + " and Id in " + menus + "  and parentid=0", "Menu_order");
                    }
                }

                string strRe = XHD.Common.GetGridJSON.DataTableToJSON(ds.Tables[0]);
                context.Response.Write(strRe);
                #endregion
            }

            //获取二级级菜单
            if (request["Action"] == "GetSysMenu2")
            {
                #region
                DataSet ds = new DataSet();

                int appid = int.Parse(request["appid"]);
                int pid   = int.Parse(request["pid"]);

                if (dsemp.Tables[0].Rows.Count > 0)
                {
                    if (dsemp.Tables[0].Rows[0]["uid"].ToString() == "admin")
                    {
                        ds = menu.GetList(0, "App_id=" + appid + " and parentid=" + pid, "Menu_order");
                    }
                    else
                    {
                        DataSSN.SSN_GetAuthorityByUid getauth = new DataSSN.SSN_GetAuthorityByUid();
                        string menus = getauth.GetAuthority(emp_id.ToString(), "Menus");
                        //ds = menu.GetList(0, "App_id=" + appid + " and Menu_id in " + menus + " and menu_type='aft'", "Menu_order");
                        ds = menu.GetList(0, "App_id=" + appid + " and Id in " + menus + "  and parentid=" + pid, "Menu_order");
                    }
                }

                string strRe = XHD.Common.GetGridJSON.DataTableToJSON(ds.Tables[0]);
                context.Response.Write(strRe);
                #endregion
            }

            //获取某个菜单下的值
            else if (request["Action"] == "grid")
            {
                DataSet dk       = new DataSet();
                string  title    = request["title"];
                string  strWhere = string.Empty;
                bool    num      = true;
                string  atr_id   = "";

                if (!string.IsNullOrEmpty(request["menuid"]))
                {
                    string menuId = request["menuid"];
                    if (menuId == "-1")
                    {
                        strWhere = "factory_Id='" + factory_Id + "' and is_del=0";
                        dk       = _visit.GetListAtrId("r.empID='" + emp_id + "' ");
                    }
                    else
                    {
                        strWhere = "factory_Id='" + factory_Id + "' and Art_Menu_Id='" + menuId + "' and is_del=0";
                        dk       = _visit.GetListAtrId("r.empID='" + emp_id + "'and v.Menu_ids='" + menuId + "' ");
                    }

                    if (uid != "admin")
                    {
                        foreach (DataRow row in dk.Tables[0].Rows)
                        {
                            //获取能访问的文章的id
                            atr_id += PageValidate.InputText(row["Art_id"].ToString(), int.MaxValue).Replace("a", "");

                            //string Menu_ids = row["Menu_ids"].ToString();
                            //if (!string.IsNullOrEmpty(Menu_ids))
                            //{
                            //    string[] listMenu = Menu_ids.Split(',');
                            //    foreach (var item in listMenu)
                            //    {
                            //        if (menuId == item)
                            //        {
                            //            num = true;
                            //            break;
                            //        }
                            //    }
                            //}
                        }

                        //准备查询条件
                        if (num == true)
                        {
                            if (atr_id != "")
                            {
                                atr_id    = atr_id.Substring(0, atr_id.Length - 1);
                                strWhere += " and Id in(" + atr_id + ")";
                            }
                            else
                            {
                                strWhere += " and 1=2";
                            }
                        }
                        else
                        {
                            strWhere += " and Id='-1'";
                        }
                    }


                    if (!string.IsNullOrEmpty(title))
                    {
                        List <string> strList  = new List <string>();
                        char[]        charList = title.ToArray();
                        for (int i = 0; i < charList.Length; i++)
                        {
                            if (i == 0)
                            {
                                strWhere += " and Art_title like '%" + charList[i] + "%'";
                            }
                            else
                            {
                                strWhere += " or Art_title like '%" + charList[i] + "%'";
                            }
                            if (!strList.Contains(charList[i].ToString()))
                            {
                                strList.Add(charList[i].ToString());
                            }
                        }
                        Segment seg = new Segment();
                        seg.InitWordDics();
                        seg.EnablePrefix = true;
                        seg.Separator    = " ";
                        string Seg_Title = seg.SegmentText(title, false).Trim();

                        string[] titleArray = Seg_Title.Split(' ');
                        for (int i = 0; i < titleArray.Length; i++)
                        {
                            strWhere += " or Art_title like '%" + titleArray[i] + "%'";
                            //if (!strList.Contains(titleArray[i]))
                            //{
                            //    strList.Add(titleArray[i]);
                            //}
                        }
                        //strWhere += " and Art_title like '%" + title + "%'";
                        DataSet ds = _art.GetList(strWhere);
                        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                        {
                            string temStr = ds.Tables[0].Rows[i]["Art_Title"].ToString();
                            for (int j = 0; j < strList.Count; j++)
                            {
                                if (temStr.Contains(strList[j]))
                                {
                                    ds.Tables[0].Rows[i]["Art_Title"] = ds.Tables[0].Rows[i]["Art_Title"].ToString().Replace(strList[j], "<span style='color:red' >" + strList[j] + "</span>");
                                }
                            }
                        }
                        string strRe = XHD.Common.GetGridJSON.DataTableToJSON(ds.Tables[0]);
                        context.Response.Write(strRe);
                    }
                    else
                    {
                        DataSet ds    = _art.GetList(strWhere);
                        string  strRe = XHD.Common.GetGridJSON.DataTableToJSON(ds.Tables[0]);
                        context.Response.Write(strRe);
                    }
                }
            }

            //获取文章内容
            if (request["Action"] == "form")
            {
                string urlList = string.Empty;

                if (!string.IsNullOrEmpty(request["flag"]))
                {
                    DataSet ds = _art.GetList("factory_Id='" + factory_Id + "' and Id=" + int.Parse(request["flag"]));
                    string  dt = XHD.Common.DataToJson.DataToJSON(ds);
                    context.Response.Write(dt);
                }
            }
        }
コード例 #4
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            HttpRequest request = context.Request;

            XHD.BLL.ssn_art       _art       = new XHD.BLL.ssn_art();
            XHD.BLL.ssn_authority _authority = new XHD.BLL.ssn_authority();
            XHD.BLL.ssn_art_menu  _menu      = new XHD.BLL.ssn_art_menu();
            XHD.BLL.ssn_role      _role      = new XHD.BLL.ssn_role();
            XHD.BLL.ssn_visit     _visit     = new XHD.BLL.ssn_visit();

            C_Sys_log log = new C_Sys_log();

            XHD.Model.ssn_art model = new XHD.Model.ssn_art();

            var    cookie     = context.Request.Cookies[FormsAuthentication.FormsCookieName];
            var    ticket     = FormsAuthentication.Decrypt(cookie.Value);
            string CoockiesID = ticket.UserData;

            XHD.BLL.hr_employee emp = new XHD.BLL.hr_employee();
            int     emp_id          = int.Parse(CoockiesID);
            DataSet dsemp           = emp.GetList("id=" + emp_id);
            string  empname         = string.Empty;
            string  uid             = string.Empty;
            string  factory_Id      = string.Empty;

            if (dsemp != null && dsemp.Tables[0].Rows.Count > 0)
            {
                empname    = dsemp.Tables[0].Rows[0]["name"].ToString();
                uid        = dsemp.Tables[0].Rows[0]["uid"].ToString();
                factory_Id = dsemp.Tables[0].Rows[0]["Factory_Id"].ToString();
            }

            #region 加载数据grid
            if (request["Action"] == "grid")
            {
                int    PageIndex = int.Parse(request["page"] == null ? "1" : request["page"]);
                int    PageSize  = int.Parse(request["pagesize"] == null ? "30" : request["pagesize"]);
                string Total     = string.Empty;

                string filedOrder = " Art_order desc,Id desc ";
                string strWhere   = " ";

                strWhere += " factory_id ='" + factory_Id + "' and is_del=0 ";

                if (!string.IsNullOrEmpty(request["Art_Menu_Id"]))
                {
                    strWhere += " and  Art_Menu_Id = '" + request["Art_Menu_Id"] + "'";
                }


                DataSet ds = _art.GetList(PageSize, PageIndex, strWhere, filedOrder, out Total);
                string  dt = XHD.Common.GetGridJSON.DataTableToJSON1(ds.Tables[0], Total);
                context.Response.Write(dt);
            }
            #endregion

            #region  加载员工的所能操作的页面 tree
            else if (request["Action"] == "tree")
            {
                DataSet dk = null;
                if (uid != "admin")
                {
                    string serchtxt = " a.factory_Id = '" + factory_Id + "' and  a.App_ids='1' ";

                    serchtxt += "and r.empID='" + emp_id + "'";


                    DataSet ds = _authority.GetListAuth(serchtxt);
                    if (ds != null && ds.Tables[0].Rows.Count > 0)
                    {
                        string menu_ids = "";
                        foreach (DataRow item in ds.Tables[0].Rows)
                        {
                            menu_ids += item["Menu_ids"].ToString();
                        }
                        menu_ids = PageValidate.InputText(menu_ids, int.MaxValue).Replace("m", "");
                        menu_ids = menu_ids.Substring(0, menu_ids.Length - 1);
                        dk       = _menu.GetList(0, " factory_Id='" + factory_Id + "' and  Id in (" + menu_ids + ")", "Menu_order");
                    }
                }
                else
                {
                    dk = _menu.GetList(0, " factory_Id='" + factory_Id + "' and app_id=1", "Menu_order");
                }

                StringBuilder str = new StringBuilder();
                str.Append("[");
                str.Append(GetTreeString(0, dk.Tables[0]));
                str.Replace(",", "", str.Length - 1, 1);
                str.Append("]");
                context.Response.Write(str);
            }
            #endregion

            #region 保存save
            else if (request["Action"] == "save")
            {
                model.Art_title    = XHD.Common.PageValidate.InputText(request["T_title"], 250);
                model.Art_Content  = PageValidate.InputText(request["T_content"], int.MaxValue);
                model.Art_Content  = HttpUtility.HtmlDecode(model.Art_Content);
                model.Art_title_en = GetSpellCode(model.Art_title);;
                model.image_lst    = PageValidate.InputText(request["images"], int.MaxValue);
                model.Art_order    = int.Parse(request["T_Order"]);
                model.factory_Id   = factory_Id;
                model.Art_Menu_Id  = Convert.ToInt32(PageValidate.InputText(request["art_Menu_Id"], 50));

                string id = PageValidate.InputText(request["nid"], 50);
                if (!string.IsNullOrEmpty(id) && id != "null")
                {
                    DataSet ds = _art.GetList("Id=" + int.Parse(id));
                    DataRow dr = ds.Tables[0].Rows[0];


                    model.Id = int.Parse(id);

                    if (_art.Update(model))
                    {
                        #region 修改访问权限

                        //查询该文章原来属于哪些角色下
                        DataSet dm = _visit.GetList(" Factory_Id='" + factory_Id + "' and find_in_set('a" + model.Id + "', Art_id)");
                        if (dm != null && dm.Tables[0].Rows.Count > 0)
                        {
                            //此次修改的文章以前已分配过角色
                            string oldRoleId = string.Empty;                                //原来所属的角色
                            string newRoleId = string.Empty;
                            for (int i = 0; i < dm.Tables[0].Rows.Count; i++)
                            {
                                if (i == dm.Tables[0].Rows.Count - 1)
                                {
                                    oldRoleId += dm.Tables[0].Rows[i]["Role_id"].ToString();
                                }
                                else
                                {
                                    oldRoleId += dm.Tables[0].Rows[i]["Role_id"].ToString() + ',';
                                }
                            }

                            string artId = "a" + model.Id + ",";
                            if (!string.IsNullOrEmpty(request["role_Id"].ToString()))
                            {
                                newRoleId = request["role_Id"].ToString();
                                newRoleId = newRoleId.Substring(0, newRoleId.Length - 1);
                                _visit.UpdateN(oldRoleId, newRoleId, artId, factory_Id, model.Art_Menu_Id.Value, emp_id);
                            }
                            else
                            {
                                _visit.UpdateN(oldRoleId, "", artId, factory_Id, model.Art_Menu_Id.Value, emp_id);
                            }

                            log.Add_log(emp_id, empname, request.UserHostAddress, "访问权限修改", "访问权限修改", model.Id, "访问权限修改", oldRoleId, newRoleId, factory_Id);
                        }
                        else
                        {
                            //若所修改的文章原来没有分配角色,若传进来的role_Id不为空,则进行添加
                            if (!string.IsNullOrEmpty(request["role_Id"].ToString()))
                            {
                                string roleId = request["role_Id"].ToString();
                                roleId = roleId.Substring(0, roleId.Length - 1);
                                string[] listRole = roleId.Split(',');
                                foreach (var item in listRole)
                                {
                                    DataSet df = _visit.GetList("Role_id='" + item + "'and Menu_ids='" + model.Art_Menu_Id + "' and Factory_Id='" + factory_Id + "'");
                                    if (df != null && df.Tables[0].Rows.Count > 0)
                                    {
                                        //修改
                                        int    rId    = Convert.ToInt32(df.Tables[0].Rows[0]["id"].ToString());
                                        string art_id = df.Tables[0].Rows[0]["Art_id"].ToString();
                                        art_id += "a" + model.Id + ",";
                                        _visit.Updates(rId, art_id);
                                    }
                                    else
                                    {
                                        //保存
                                        XHD.Model.ssn_visit modelVisit = new XHD.Model.ssn_visit();
                                        modelVisit.Factory_Id  = factory_Id;
                                        modelVisit.Role_id     = Convert.ToInt32(item);
                                        modelVisit.App_ids     = "1";
                                        modelVisit.Menu_ids    = model.Art_Menu_Id.ToString();
                                        modelVisit.Art_id      = "a" + model.Id + ",";
                                        modelVisit.Create_id   = emp_id;
                                        modelVisit.Create_date = DateTime.Now;
                                        _visit.Add(modelVisit);
                                    }
                                }
                            }
                        }
                        #endregion

                        #region 日志

                        int    UserID     = emp_id;
                        string UserName   = empname;
                        string IPStreet   = request.UserHostAddress;
                        string EventTitle = "ssn资料修改";
                        string EventType  = "ssn资料修改";
                        int    EventID    = model.Id;

                        if (dr["Art_title"].ToString() != request["T_title"])
                        {
                            log.Add_log(UserID, UserName, IPStreet, EventTitle, EventType, EventID, "资料名", dr["Art_title"].ToString(), request["T_title"].ToString(), factory_Id);
                        }

                        if (dr["Art_Content"].ToString() != request["T_content"])
                        {
                            log.Add_log(UserID, UserName, IPStreet, EventTitle, EventType, EventID, "内容", dr["Art_Content"].ToString(), model.Art_Content, factory_Id);
                        }

                        if (dr["image_lst"].ToString() != request["images"])
                        {
                            log.Add_log(UserID, UserName, IPStreet, EventTitle, EventType, EventID, "图片", dr["image_lst"].ToString(), request["images"].ToString(), factory_Id);
                        }

                        if (dr["Art_Menu_Id"].ToString() != request["art_Menu_Id"])
                        {
                            log.Add_log(UserID, UserName, IPStreet, EventTitle, EventType, EventID, "页面Id", dr["Art_Menu_Id"].ToString(), request["art_Menu_Id"].ToString(), factory_Id);
                        }

                        #endregion

                        context.Response.Write("2"); //修改成功
                    }
                    else
                    {
                        context.Response.Write("3"); //修改失败
                    }
                }
                else
                {
                    model.is_del       = 0;
                    model.Creater_Uid  = uid;
                    model.Creater_Name = empname;
                    model.Create_Date  = DateTime.Now;
                    model.Creater_Id   = emp_id;
                    int artId = _art.Add(model);

                    if (artId > 0)
                    {
                        #region 保存访问权限
                        if (!string.IsNullOrEmpty(request["role_Id"].ToString()))
                        {
                            string roleId = request["role_Id"].ToString();
                            roleId = roleId.Substring(0, roleId.Length - 1);
                            string[] listRole = roleId.Split(',');
                            foreach (var item in listRole)
                            {
                                //查询该角色是否已有分配的文章记录
                                DataSet df = _visit.GetList("Role_id='" + item + "'and Menu_ids='" + model.Art_Menu_Id + "' and Factory_Id='" + factory_Id + "'");
                                if (df != null && df.Tables[0].Rows.Count > 0)
                                {
                                    //若已经记录,则修改
                                    int    rId    = Convert.ToInt32(df.Tables[0].Rows[0]["id"].ToString());
                                    string art_id = df.Tables[0].Rows[0]["Art_id"].ToString();
                                    art_id += "a" + artId + ",";
                                    if (_visit.Updates(rId, art_id))
                                    {
                                        context.Response.Write("1"); //保存成功
                                    }
                                    else
                                    {
                                        _art.Delete(artId);
                                        context.Response.Write("0"); //保存失败
                                    }
                                }
                                else
                                {
                                    //若没有记录,则保存
                                    XHD.Model.ssn_visit modelVisit = new XHD.Model.ssn_visit();
                                    modelVisit.Factory_Id  = factory_Id;
                                    modelVisit.Role_id     = Convert.ToInt32(item);
                                    modelVisit.App_ids     = "1";
                                    modelVisit.Menu_ids    = model.Art_Menu_Id.ToString();
                                    modelVisit.Art_id      = "a" + artId + ",";
                                    modelVisit.Create_id   = emp_id;
                                    modelVisit.Create_date = DateTime.Now;

                                    if (_visit.Add(modelVisit))
                                    {
                                        context.Response.Write("1"); //保存成功
                                    }
                                    else
                                    {
                                        _art.Delete(artId);
                                        context.Response.Write("0"); //保存失败
                                    }
                                }
                            }
                        }
                        else
                        {
                            context.Response.Write("1"); //保存成功
                        }
                        #endregion
                    }
                    else
                    {
                        context.Response.Write("0"); //保存失败
                    }
                }
            }
            #endregion

            #region form
            else if (request["Action"] == "form")
            {
                string artId = PageValidate.InputText(request["nid"], 50);
                string dt;

                if (PageValidate.IsNumber(artId))
                {
                    DataSet ds = _art.GetList("Id=" + artId);

                    dt = XHD.Common.DataToJson.DataToJSON(ds);
                }
                else
                {
                    dt = "{}";
                }

                context.Response.Write(dt);
            }
            #endregion

            #region  除del
            else if (request["Action"] == "del")
            {
                string artId = PageValidate.InputText(request["id"], 50);

                bool num = _art.Delete(Convert.ToInt32(artId));
                if (num)
                {
                    context.Response.Write("true");
                }
            }
            #endregion

            #region 文章修改时获得查看权限 getRoleLiit
            else if (request["Action"] == "getRoleLiit")
            {
                string dt = string.Empty;

                string artId = PageValidate.InputText(request["nid"], 50);
                artId = "a" + artId;
                DataSet ds = _visit.GetList(" Factory_Id='" + factory_Id + "' and find_in_set('" + artId + "', Art_id)");

                if (ds != null && ds.Tables[0].Rows.Count > 0)
                {
                    dt = XHD.Common.GetGridJSON.DataTableToJSON1(ds.Tables[0], "Total");
                }
                else
                {
                    dt = "{'Rows':[{'id':-9999}],'Total':'Total'}";
                }
                context.Response.Write(dt);
            }
            #endregion

            #region GetRole 获得所有角色
            else if (request["Action"] == "GetRole")
            {
                string dt = string.Empty;

                DataSet ds = _role.GetList(" Factory_Id='" + factory_Id + "'");

                if (ds != null && ds.Tables[0].Rows.Count > 0)
                {
                    dt = XHD.Common.GetGridJSON.DataTableToJSON1(ds.Tables[0], "Total");
                }
                else
                {
                    dt = "{'Rows':[{'id':-9999}],'Total':'Total'}";
                }
                context.Response.Write(dt);
            }
            #endregion

            #region  产文章图片
            else if (request["Action"] == "album")
            {
                string photo        = request["photo"]; //文件路径goods_gallery  商品相册表
                string nowfileName1 = string.Empty;
                if (!string.IsNullOrEmpty(photo))
                {
                    photo = photo.Substring(photo.LastIndexOf('\\') + 1);
                    string   sExt1 = photo.Substring(photo.LastIndexOf(".")).ToLower();
                    DateTime now1  = DateTime.Now;
                    nowfileName1 = XHD.Common.TimeParser.GenerateTimeStamp(DateTime.Now) + sExt1;
                }
                if (request.Files.Count > 0 && (!string.IsNullOrEmpty(photo)))
                {
                    HttpPostedFile uploadFile = request.Files[0];
                    ////生成缩略图
                    //SmallImg(uploadFile.InputStream, uploadFile.FileName, context, nowfileName1);
                    ////生成主图
                    //MainImg(uploadFile.InputStream, uploadFile.FileName, context, nowfileName1);
                    uploadFile.SaveAs(context.Server.MapPath(@"~/file/ssn_artImg/" + nowfileName1));
                }
                context.Response.Write("file/ssn_artImg/" + nowfileName1);
            }
            #endregion

            #region 移除图片
            else if (request["Action"] == "remove")
            {
                string src  = request["srcvalue"];
                string file = System.Web.HttpContext.Current.Server.MapPath("../" + src);
                if (System.IO.File.Exists(file))
                {
                    File.Delete(file);
                }
            }
            #endregion

            #region 判断标题是否重复
            else if (request["Action"] == "validate")
            {
                string title      = request["T_title"];
                string id         = request["T_cid"];
                string artMenu_Id = request["art_Menu_Id"];
                if (string.IsNullOrEmpty(id) || id == "null")
                {
                    id = "0";
                }

                DataSet ds = _art.GetList("Art_title = '" + PageValidate.InputText(title, 255) + "' and Art_Menu_Id='" + artMenu_Id + "' and factory_Id='" + factory_Id + "' and Id!=" + int.Parse(id) + " and is_del=0");

                if (ds.Tables[0].Rows.Count > 0)
                {
                    context.Response.Write("false");
                }
                else
                {
                    context.Response.Write("true");
                }
            }

            #endregion


            //#region 获取文章图片
            //else if (request["Action"] == "formGallery")
            //{
            //    string goods_id = request["goods_id"];
            //    if (!string.IsNullOrEmpty(goods_id))
            //    {
            //        DataSet ds = null;
            //        if (request["type"] == "1")
            //            ds = gallery.GetList(" goods_id='" + goods_id + "'");
            //        else if (request["type"] == "2")
            //            ds = gallery.GetListCopy(" goods_id='" + goods_id + "'");
            //        string dt = Common.GetGridJSON.DataTableToJSON(ds.Tables[0]);
            //        context.Response.Write(dt);
            //    }
            //}
            //#endregion
        }