123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392 |
- using SysBaseLibs;
- using SysDataLibs;
- using SysDataLibs.TableClass;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- namespace GSMarketSys.SystemModule
- {
- public partial class PowerUI : System.Web.UI.Page
- {
- UserSession _UserSession;
- private DataSet objPowerDs;
- private string userID;
- private string groupID;
- private string as_UserTypeA;
- private string ErrCode;
- protected void Page_Load(object sender, EventArgs e)
- {
- _UserSession = WebLibs.CheckLogin();
- string PrimaryKey;
- as_UserTypeA = (Request["as_UserType"].Trim()).ToLower();
- PrimaryKey = Utils.AreaToSQLcs(((Request["PrimaryKey"]).Trim()).ToLower());
- if (as_UserTypeA == "")
- {
- ErrCode = "-311121";
- Response.Redirect("../Pub/PubShowMessage.aspx?as_ErrText=&al_ErrCode=" + ErrCode + "&as_ReturnType=C");
- }
- if (PrimaryKey == "")
- {
- ErrCode = "-311121";
- Response.Redirect("../Pub/PubShowMessage.aspx?as_ErrText=&al_ErrCode=" + ErrCode + "&as_ReturnType=C");
- }
- //判断操作类型
- if (as_UserTypeA == "user")
- {
- //Sys_Users_info loUsers = new Sys_Users_info(PrimaryKey, _UserSession.DBConn);
- userID = PrimaryKey;
- if (!IsPostBack)
- {
- UserNotPostBack();
- }
- }else if(as_UserTypeA == "group")
- {
- groupID = PrimaryKey;
- if (!IsPostBack)
- {
- GroupNotPostBack();
- }
- }
- }
- public string GetFunctionTree(DataGridItem dgItem)
- {
- int i = dgItem.ItemIndex;
- DataRowView dataRowView;
- string outStr;
- dataRowView = (DataRowView)dgItem.DataItem;
- outStr = "<img height=1 src='../images/space.gif' width=" + 20 * Utils.ValI(UtilStr.StrFromObj(dataRowView["Depth"])) + ">";
- //'设置CheckBox权限的值
- SetPowerCheckBox(dgItem);
- return outStr;
- }
- //'---设置Checkbox
- private void SetPowerCheckBox(DataGridItem item)
- {
- // '绑定DataGridItem
- CheckBox ckBox;
- DataRowView dataRowView;
- DataRowCollection objFunctionRowColl;
- Boolean[] HasFunctionBool = new Boolean[6];
- System.Web.UI.HtmlControls.HtmlInputCheckBox ckInputBox;
- // ' 从全局变量中取得(objPowerDs)
- objFunctionRowColl = objPowerDs.Tables[0].Rows;
- dataRowView = (DataRowView)item.DataItem;
- if (Utils.ObjToBool(dataRowView["IsLeaf"]))
- {
- SetHasFunctionBool(objFunctionRowColl, ref HasFunctionBool, UtilStr.StrFromObj(dataRowView["FunctionID"]));
- if (Utils.ObjToBool(dataRowView["IsBrowse"]))
- {
- ckBox = (CheckBox)item.FindControl("ckIsBrowse");
- ckBox.Checked = HasFunctionBool[0];
- }
- else
- {
- ckBox = (CheckBox)item.FindControl("ckIsBrowse");
- ckBox.Enabled = false;
- }
- if (Utils.ObjToBool(dataRowView["IsAdd"]))
- {
- ckBox = (CheckBox)item.FindControl("ckIsAdd");
- ckBox.Checked = HasFunctionBool[1];
- }
- else
- {
- ckBox = (CheckBox)item.FindControl("ckIsAdd");
- ckBox.Enabled = false;
- }
- if (Utils.ObjToBool(dataRowView["IsUpdate"]))
- {
- ckBox = (CheckBox)item.FindControl("ckIsUpdate");
- ckBox.Checked = HasFunctionBool[2];
- }
- else
- {
- ckBox = (CheckBox)item.FindControl("ckIsUpdate");
- ckBox.Enabled = false;
- }
- if (Utils.ObjToBool(dataRowView["IsDelete"]))
- {
- ckBox = (CheckBox)item.FindControl("ckIsDelete");
- ckBox.Checked = HasFunctionBool[3];
- }
- else
- {
- ckBox = (CheckBox)item.FindControl("ckIsDelete");
- ckBox.Enabled = false;
- }
- if (Utils.ObjToBool(dataRowView["IsPrint"]))
- {
- ckBox = (CheckBox)item.FindControl("ckIsPrint");
- ckBox.Checked = HasFunctionBool[4];
- }
- else
- {
- ckBox = (CheckBox)item.FindControl("ckIsPrint");
- ckBox.Enabled = false;
- }
- if (Utils.ObjToBool(dataRowView["IsAudit"]))
- {
- ckBox = (CheckBox)item.FindControl("ckIsOwner");
- ckBox.Checked = HasFunctionBool[5];
- }
- else
- {
- ckBox = (CheckBox)item.FindControl("ckIsOwner");
- ckBox.Enabled = false;
- }
- }
- else
- {
- ckInputBox = (System.Web.UI.HtmlControls.HtmlInputCheckBox)item.FindControl("ckItemAll");
- ckInputBox.Visible = false;
- ckBox = (CheckBox)item.FindControl("ckIsBrowse");
- ckBox.Visible = false;
- ckBox = (CheckBox)item.FindControl("ckIsAdd");
- ckBox.Visible = false;
- ckBox = (CheckBox)item.FindControl("ckIsUpdate");
- ckBox.Visible = false;
- ckBox = (CheckBox)item.FindControl("ckIsDelete");
- ckBox.Visible = false;
- ckBox = (CheckBox)item.FindControl("ckIsPrint");
- ckBox.Visible = false;
- ckBox = (CheckBox)item.FindControl("ckIsOwner");
- ckBox.Visible = false;
- }
- }
- //' 用户类型 非提交
- private void UserNotPostBack()
- {
- Sys_Users_info loUsers = new Sys_Users_info(userID, _UserSession.DBConn);
- //'获取用户姓名
- //labTitle.Text = "用户: " + loUsers.UserNo;
- //'设置objPowerDs值
- String Sql = "select uf." + Sys_UserHasFunction_info.cFunctionId + ", uf." + Sys_UserHasFunction_info.cIsBrowse + " ,uf." + Sys_UserHasFunction_info.cIsAdd + ", uf." + Sys_UserHasFunction_info.cIsUpdate + " ,uf." + Sys_UserHasFunction_info.cIsDelete + " ,uf." + Sys_UserHasFunction_info.cIsAudit + ",uf." + Sys_UserHasFunction_info.cIsPrint + " ";
- Sql += "from " + Tn.Sys_UserHasFunction + " as uf join " + Tn.Sys_Users + " as u on(u." + Sys_Users_info.cUserID + "=uf." + Sys_UserHasFunction_info.cUserId + ") where u." + Sys_Users_info.cUserID + "='" + userID + "'";
- objPowerDs = _UserSession.DBConn.OpenDataSet(Sql);
- if (!string.IsNullOrEmpty(ErrCode))
- {
- Response.Redirect("../Pub/PubShowMessage.aspx?as_ErrText=&al_ErrCode=" + ErrCode + "&as_ReturnType=C");
- }
- //'把数据绑定到控件"
- DataGridBind();
- }
- // ' 用户组类型 非提交
- private void GroupNotPostBack()
- {
- //Dim groupPowerDs As DataSet
-
- String sql = "select * from " + Tn.Sys_Groups + " where " + Sys_Groups_info.cGroupID + "='" + groupID + "'";
- //'获取用户组名称
- rsQuery loQuery = _UserSession.DBConn.OpenQuery(sql);
- if(!loQuery.IsOpened||loQuery.RecCount<1)
- {
- ErrCode = "-311131";
- Response.Redirect("../Pub/PubShowMessage.aspx?as_ErrText=&al_ErrCode=" +ErrCode + "&as_ReturnType=C");
- }
- loQuery.MoveFirst();
- labTitle.Text = "用户组: " + UtilStr.StrFromObj(loQuery.GetString(Sys_Groups_info.cNames));
- sql = " select uf." + Sys_GroupHasFunction_info.cFunctionID + ", uf." + Sys_GroupHasFunction_info.cIsBrowse + " ,uf." + Sys_GroupHasFunction_info.cIsAdd + ", uf." + Sys_GroupHasFunction_info.cIsUpdate + " ,uf." + Sys_GroupHasFunction_info.cIsDelete + " ,uf." + Sys_GroupHasFunction_info.cIsAudit + ",uf." + Sys_GroupHasFunction_info.cIsPrint + " ";
- sql += "from " + Tn.Sys_GroupHasFunction + " as uf join " + Tn.Sys_Groups + " as g on(g." + Sys_Groups_info.cGroupID + "=uf." + Sys_GroupHasFunction_info.cGroupID + ") where g." + Sys_Groups_info.cGroupID + "='" + groupID + "' ";
- objPowerDs = _UserSession.DBConn.OpenDataSet(sql);
- //'把数据绑定到控件"
- DataGridBind();
- }
- // '绑定DataGrid
- private void DataGridBind()
- {
- DataSet functionDs;
- String sql = " select FunctionID ,FunctionName , FatherID ,Depth,IsLeaf ,IsBrowse ,IsAdd ,IsUpdate , IsDelete ,IsAudit ,IsPrint,Sort from [Sys_Functions] where IsBack ='Y' order by Sort asc ";
- functionDs = _UserSession.DBConn.OpenDataSet(sql);
- gridPower.DataSource = functionDs.Tables[0].DefaultView;
- gridPower.DataBind();
- }
- private void SetHasFunctionBool(DataRowCollection drc, ref Boolean[] HasFunctionBool, String functionID)
- {
- //DataRow dRow;
- HasFunctionBool[0] = false;
- HasFunctionBool[1] = false;
- HasFunctionBool[2] = false;
- HasFunctionBool[3] = false;
- HasFunctionBool[4] = false;
- HasFunctionBool[5] = false;
- functionID = UtilStr.UAndT(functionID);
- foreach (DataRow dRow in drc)
- {
- string lcFcId = UtilStr.UAndT(dRow["FunctionID"]);
- if (lcFcId == functionID)
- {
- HasFunctionBool[0] = Utils.ObjToBool(dRow["IsBrowse"]);
- HasFunctionBool[1] = Utils.ObjToBool(dRow["IsAdd"]);
- HasFunctionBool[2] = Utils.ObjToBool(dRow["IsUpdate"]);
- HasFunctionBool[3] = Utils.ObjToBool(dRow["IsDelete"]);
- HasFunctionBool[4] = Utils.ObjToBool(dRow["IsPrint"]);
- HasFunctionBool[5] = Utils.ObjToBool(dRow["IsAudit"]);
- }
- }
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- //DataGridItem item;
- CheckBox ck;
- String functionStr = "";
- Boolean IsLeaf = false;
- String insertHeadSqlStr = "";
- String insertSqlStr = "";
- String insertTempStr = "";
- String deleteSqlStr = "";
- String FunctionColl = "";
- Boolean IsHasFunctionFlag;
- String ObjectID = "";
- if (as_UserTypeA == "user")
- {
- insertHeadSqlStr = " INSERT INTO " + Tn.Sys_UserHasFunction + "( " + Sys_UserHasFunction_info.cUserId + "," + Sys_UserHasFunction_info.cFunctionId + "," + Sys_UserHasFunction_info.cIsAdd + "," + Sys_UserHasFunction_info.cIsUpdate + "," + Sys_UserHasFunction_info.cIsDelete + "," + Sys_UserHasFunction_info.cIsPrint + "," + Sys_UserHasFunction_info.cIsAudit + "," + Sys_UserHasFunction_info.cIsBrowse + ") values('" + userID + "'";
- deleteSqlStr = " delete " + Tn.Sys_UserHasFunction + " where " + Sys_UserHasFunction_info.cUserId + "='" + userID + "' ";
- ObjectID = userID;
- }else if (as_UserTypeA == "group")
- {
- //'组
- insertHeadSqlStr = " insert into " + Tn.Sys_GroupHasFunction + "(" + Sys_GroupHasFunction_info.cGroupID + "," + Sys_GroupHasFunction_info.cFunctionID + "," + Sys_GroupHasFunction_info.cIsAdd + "," + Sys_GroupHasFunction_info.cIsUpdate + "," + Sys_GroupHasFunction_info.cIsDelete + "," + Sys_GroupHasFunction_info.cIsPrint + "," + Sys_GroupHasFunction_info.cIsAudit + "," + Sys_GroupHasFunction_info.cIsBrowse + ") values('" + groupID + "'";
- deleteSqlStr = " delete " + Tn.Sys_GroupHasFunction + " where " + Sys_GroupHasFunction_info.cGroupID + "='" + groupID + "'";
- ObjectID = groupID;
- }else
- {
- ErrCode = "-311121";
- Response.Redirect("../Pub/PubShowMessage.aspx?as_ErrText=&al_ErrCode=" + ErrCode + "&as_ReturnType=C");
- }
- FunctionColl = "";
- insertSqlStr = "";
- foreach (DataGridItem item in gridPower.Items)
- {
- functionStr = ((System.Web.UI.HtmlControls.HtmlInputHidden)item.FindControl("hid_FunctionID")).Value;
- IsLeaf = Utils.ObjToBool(((System.Web.UI.HtmlControls.HtmlInputHidden)item.FindControl("hid_IsLeaf")).Value);
- insertTempStr = "";
- insertTempStr = insertHeadSqlStr + ",'" + functionStr + "' ";
- IsHasFunctionFlag = false;
- if (IsLeaf)
- {
- ck = (CheckBox)item.FindControl("ckIsAdd");
- if (ck.Checked)
- {
- insertTempStr = insertTempStr + ",'Y'";
- IsHasFunctionFlag = true;
- }
- else
- {
- insertTempStr = insertTempStr + ",'N'";
- }
- ck = (CheckBox)item.FindControl("ckIsUpdate");
- if (ck.Checked)
- {
- insertTempStr = insertTempStr + ",'Y'";
- IsHasFunctionFlag = true;
- }
- else
- {
- insertTempStr = insertTempStr + ",'N'";
- }
- ck = (CheckBox)item.FindControl("ckIsDelete");
- if (ck.Checked)
- {
- insertTempStr = insertTempStr + ",'Y'";
- IsHasFunctionFlag = true;
- }
- else
- {
- insertTempStr = insertTempStr + ",'N'";
- }
- ck = (CheckBox)item.FindControl("ckIsPrint");
- if (ck.Checked)
- {
- insertTempStr = insertTempStr + ",'Y'";
- IsHasFunctionFlag = true;
- }
- else
- {
- insertTempStr = insertTempStr + ",'N'";
- }
- ck = (CheckBox)item.FindControl("ckIsOwner");
- if (ck.Checked)
- {
- insertTempStr = insertTempStr + ",'Y'";
- IsHasFunctionFlag = true;
- }
- else
- {
- insertTempStr = insertTempStr + ",'N'";
- }
- //'有增 删 改 打印 看自己 就有浏览权
- if (IsHasFunctionFlag)
- {
- insertTempStr = insertTempStr + ",'Y'";
- }
- else
- {
- ck = (CheckBox)item.FindControl("ckIsBrowse");
- if (ck.Checked)
- {
- insertTempStr = insertTempStr + ",'Y'";
- IsHasFunctionFlag = true;
- }
- else
- {
- insertTempStr = insertTempStr + ",'N'";
- }
- }
- if (IsHasFunctionFlag)
- {
- insertSqlStr = insertSqlStr + insertTempStr + ") ";
- FunctionColl = FunctionColl + "'" + functionStr + "',";
- }
- }
- }
- if (!string.IsNullOrEmpty(FunctionColl))
- {
- FunctionColl = FunctionColl.Substring(0, FunctionColl.Length - 1);
- }
- if (!Sys_Functions_info.UpdatePowerOfGroupAndUser(insertSqlStr, deleteSqlStr, FunctionColl, ObjectID, as_UserTypeA, _UserSession.DBConn))
- {
- JSComm.ShowMessage(_UserSession.DBConn.ErrorMsg);
- }
- JSComm.CloseMe();
- }
- }
- }
|