行 1: using System;
行 2: using System.Data;
行 3: using System.Collections;
行 4: using System.Collections.Generic;
行 5: using System.Collections.Specialized;
行 6: using System.Configuration;
行 7: using System.Web;
行 8: using System.Web.Security;
行 9: using System.Web.UI;
行 10: using System.Web.UI.HtmlControls;
行 11: using System.Web.UI.WebControls;
行 12: using System.Web.UI.WebControls.WebParts;
行 13: using System.Net.Mail;
行 14: using Dcms.Orm;
行 15: using Dcms.Utility;
行 16:
行 17: namespace Dcms.BasePage
行 18: {
行 19: /// <summary>
行 20: ///ManagePage 的摘要说明
行 21: /// </summary>
行 22: public class ManagePage : System.Web.UI.Page
行 23: {
行 24: public SqlDb.Dcms_Admin adminInfo = null;
行 25: public string[] superUser = ConfigurationManager.AppSettings["superUser"].ToUpper().Split(new char[] { ',' });
行 26: static string _mflangflag;
行 27: public static string mflangflag
行 28: {
行 29: get { return _mflangflag; }
行 30: set { _mflangflag = value; }
行 31: }
行 32: static int _mfroleid;
行 33: public static int mfroleid
行 34: {
行 35: get { return _mfroleid; }
行 36: set { _mfroleid = value; }
行 37: }
行 38: protected override void OnInit(EventArgs e)
行 39: {
行 40: //进行的操作select,getone,insert,update,delete
行 41: string Action = IRequest.GetQueryString("action");
行 42: //权限栏目Id
行 43: int PermCateId = IRequest.GetQueryInt("PermCateId", 0);
行 44: //权限栏目Id
行 45: int SysPermCateId = IRequest.GetQueryInt("SysPermCateId", 0);
行 46: //文件名
行 47: string FileName = IRequest.GetPageName();
行 48:
行 49:
行 50: if (SessionHelper.Exists("adminInfo"))
行 51: {
行 52: adminInfo = (SqlDb.Dcms_Admin)SessionHelper.Get("adminInfo");
行 53: //如果是超级用户登录,把角色定义为0,拥有超级权限
行 54: for (int i = 0; i < superUser.Length; i++)
行 55: {
行 56: if (superUser[i].Equals(adminInfo.Admin_Name.ToUpper()))
行 57: {
行 58: adminInfo.Admin_RoleId = 0;
行 59: break;
行 60: }
行 61: }
行 62: }
行 63: else
行 64: {
行 65: int Admin_Id = Utils.StrToInt(Utils.GetCookie("Admin_Id"), 0);
行 66: if (Admin_Id > 0)
行 67: {
行 68: using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession())
行 69: {
行 70: SqlDb.Dcms_Admin admin = new SqlDb.Dcms_Admin();
行 71: admin.Admin_Id = Admin_Id;
行 72: IQuery query = session.GetQuery(admin).Where(SqlDb.Dcms_Admin._ADMIN_ID_.EqulesExp());
行 73: List<SqlDb.Dcms_Admin> adminList = query.GetList<SqlDb.Dcms_Admin>();
行 74: if (adminList.Count == 1)
行 75: {
行 76: string AuthId = Utils.GetCookie("AuthId");
行 77: if (Utils.MD5(Utils.SHA256(adminList[0].Admin_Pwd + adminList[0].Admin_Name)).Equals(AuthId))
行 78: {
行 79: SessionHelper.Add("adminInfo", adminList[0]);
行 80: SessionHelper.Add("LangFlag", Utils.UrlDecode(Utils.GetCookie("LangFlag")));
行 81: SessionHelper.Add("LangName", Utils.UrlDecode(Utils.GetCookie("LangName")));
行 82:
行 83: adminInfo = (SqlDb.Dcms_Admin)SessionHelper.Get("adminInfo");
行 84: //如果是超级用户登录,把角色定义为0,拥有超级权限
行 85: for (int i = 0; i < superUser.Length; i++)
行 86: {
行 87: if (superUser[i].Equals(adminInfo.Admin_Name.ToUpper()))
行 88: {
行 89: adminInfo.Admin_RoleId = 0;
行 90: break;
行 91: }
行 92: }
行 93: }
行 94: else
行 95: {
行 96: Response.Redirect("../adminlogin.aspx?ErrorInfo=未登录或登录超时,请登录!");
行 97: return;
行 98: }
行 99: }
行 100: else
行 101: {
行 102: Response.Redirect("../adminlogin.aspx?ErrorInfo=你的操作已经记录在案,请放弃偿试!");
行 103: return;
行 104: }
行 105: }
行 106: }
行 107: else
行 108: {
行 109: Response.Redirect("../adminlogin.aspx?ErrorInfo=未登录或登录超时,请登录!");
行 110: return;
行 111: }
行 112: }
行 113: if ((adminInfo.Admin_RoleId > 0) && (PermCateId>0))
行 114: {
行 115: int checkActionRight = 0;
行 116: switch (Action.ToLower())
行 117: {
行 118: case "select":
行 119: checkActionRight = chkRight(adminInfo.Admin_RoleId, PermCateId, "select");
行 120: break;
行 121: case "insert":
行 122: checkActionRight = chkRight(adminInfo.Admin_RoleId, PermCateId, "insert");
行 123: break;
行 124: case "update":
行 125: checkActionRight = chkRight(adminInfo.Admin_RoleId, PermCateId, "update");
行 126: break;
行 127: case "delete":
行 128: checkActionRight = chkRight(adminInfo.Admin_RoleId, PermCateId, "delete");
行 129: break;
行 130: }
行 131: if (checkActionRight <= 0)
行 132: {
行 133: Response.Redirect("../Error.aspx?ErrorInfo=你没有进行此操作的权限,请联系管理员申请相关权限再进行操作!");
行 134: return;
行 135: }
行 136: }
行 137: //Response.Write(PermCateId.ToString());
行 138: base.OnInit(e);
行 139: }
行 140:
行 141: /// <summary>
行 142: /// 检测Action的权限
行 143: /// </summary>
行 144: /// <param name="roleid"></param>
行 145: /// <param name="cateid"></param>
行 146: /// <param name="action"></param>
行 147: /// <returns></returns>
行 148: public int chkRight(int roleid, int cateid, string action)
行 149: {
行 150: int hasRight = 0;
行 151: using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession())
行 152: {
行 153: string sql = "select Permissions_" + action + " from Dcms_Permissions where Permissions_RoleId=" + roleid.ToString() + " and Permissions_CateId=" + cateid.ToString() + "";
行 154: hasRight = Utils.StrToInt(session.ExecuteScalar(sql), 0);
行 155: }
行 156: return hasRight;
行 157: }
行 158:
行 159: /// <summary>
行 160: /// 格式化Json数据
行 161: /// </summary>
行 162: /// <param name="srcString"></param>
行 163: /// <returns></returns>
行 164: public string FormatJsonData(string sourceStr)
行 165: {
行 166: sourceStr = sourceStr.Replace("\\", "\\\\");
行 167: sourceStr = sourceStr.Replace("\b", "\\b");
行 168: sourceStr = sourceStr.Replace("\t", "\\t");
行 169: sourceStr = sourceStr.Replace("\n", "\\n");
行 170: sourceStr = sourceStr.Replace("\n", "\\n");
行 171: sourceStr = sourceStr.Replace("\f", "\\f");
行 172: sourceStr = sourceStr.Replace("\r", "\\r");
行 173: return sourceStr.Replace("\"", "\\\"");
行 174: }
行 175: /// <summary>
行 176: /// 初使化控件(为控件赋值)
行 177: /// </summary>
行 178: /// <param name="model">Model</param>
行 179: /// <param name="Controls">控件集合</param>
行 180: public void InitControl(object model, ControlCollection Controls)
行 181: {
行 182: //取得model的所有属性
行 183: System.Reflection.PropertyInfo[] arrProperty = model.GetType().GetProperties();
行 184:
行 185: foreach (System.Reflection.PropertyInfo property in arrProperty)
行 186: {
行 187: foreach (Control ctl in Controls)
行 188: {
行 189: string strControlID = ctl.ID == null ? "" : ctl.ID;
行 190: //将控件的名称去除前三个字母(例如:txtPro_Name --> Pro_Name这个将以数据库中的字段一致)
行 191: if (strControlID != "" && strControlID.ToLower().IndexOf("js_") >= 0)
行 192: {
行 193: string strFieldID = strControlID;
行 194: //是否有存在此属性(不区分大小写)
行 195: if (string.Compare(strFieldID, property.Name, true) == 0)
行 196: {
行 197: aInitSetValue(ctl, property.GetValue(model, null));
行 198: }
行 199: }
行 200: }
行 201: }
行 202: }
行 203:
行 204: /// <summary>
行 205: /// 为不同的控件赋值
行 206: /// </summary>
行 207: /// <param name="ctl">控件</param>
行 208: /// <param name="oValue">值</param>
行 209: public void aInitSetValue(Control ctl, object oValue)
行 210: {
行 211: string thisValue = string.Empty;
行 212: if (oValue != null)
行 213: {
行 214: thisValue = oValue.ToString();
行 215: }
行 216: else
行 217: {
行 218: thisValue = "null";
行 219: }
行 220: switch (ctl.GetType().ToString())
行 221: {
行 222: case "System.Web.UI.WebControls.Literal":
行 223: Literal lit = (Literal)ctl;
行 224: lit.Text = thisValue;
行 225: break;
行 226: case "System.Web.UI.WebControls.TextBox":
行 227: TextBox txt = (TextBox)ctl;
行 228: txt.Text = thisValue;
行 229: break;
行 230: case "System.Web.UI.WebControls.RadioButtonList":
行 231: RadioButtonList rbl = (RadioButtonList)ctl;
行 232: rbl.SelectedValue = thisValue;
行 233: break;
行 234: case "System.Web.UI.WebControls.DropDownList":
行 235: break;
行 236: }
行 237: }
行 238: /// <summary>
行 239: /// 通过反射给Model实体赋值
行 240: /// </summary>
行 241: /// <param name="model"></param>
行 242: /// <param name="fm"></param>
行 243: public void UpdateModelByForm(object model, NameValueCollection fm)
行 244: {
行 245: System.Reflection.PropertyInfo[] arrProperty = model.GetType().GetProperties();
行 246: foreach (System.Reflection.PropertyInfo property in arrProperty)
行 247: {
行 248: string colName = property.Name;
行 249: if ((colName.Length > 0))// && (!string.IsNullOrEmpty(fm[colName])))
行 250: {
行 251: //数据转化
行 252: switch (property.PropertyType.ToString())
行 253: {
行 254: case "System.DateTime":
行 255: property.SetValue(model, Convert.ToDateTime(fm[colName]), null);
行 256: break;
行 257: case "System.Int32":
行 258: if(colName!="Cate_HasChild")
行 259: {
行 260: property.SetValue(model, Utils.StrToInt(fm[colName], 0), null);
行 261: }
行 262:
行 263: break;
行 264: default:
行 265: property.SetValue(model, fm[colName], null);
行 266: break;
行 267: }
行 268: }
行 269: }
行 270: }
行 271: /// <summary>
行 272: /// 邮件发送程序
行 273: /// </summary>
行 274: /// <param name="to">接收者</param>
行 275: /// <param name="title">标题</param>
行 276: /// <param name="content">内容</param>
行 277: /// <param name="strFrom">发送者</param>
行 278: /// <param name="strAccount">帐号</param>
行 279: /// <param name="strPwd">密码码</param>
行 280: /// <param name="strHost">smtp服务器</param>
行 281: /// <returns></returns>
行 282: public bool sendMail(string to, string title, string content, string strFrom, string strAccount, string strPwd, string strHost)
行 283: {
行 284: SmtpClient _smtpClient = new SmtpClient();
行 285: _smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;//指定电子邮件发送方式
行 286: _smtpClient.Host = strHost; //指定SMTP服务器
行 287: _smtpClient.Credentials = new System.Net.NetworkCredential(strAccount, strPwd);//用户名和密码
行 288:
行 289: MailMessage _mailMessage = new MailMessage(strFrom, to);
行 290: _mailMessage.Subject = title;//主题
行 291: _mailMessage.Body = content;//内容
行 292: _mailMessage.BodyEncoding = System.Text.Encoding.UTF8;//正文编码
行 293: _mailMessage.IsBodyHtml = true;//设置为HTML格式
行 294: _mailMessage.Priority = MailPriority.High;//优先级
行 295:
行 296: try
行 297: {
行 298: _smtpClient.Send(_mailMessage);
行 299: return true;
行 300: }
行 301: catch (Exception ex)
行 302: {
行 303: return false;
行 304: }
行 305: }
行 306: }
行 307: }
|