protected void Page_Load(object sender, EventArgs e) { if (Session["LoginCompanyOperator"] == null) { //向数据中心记录登录信息 try { WCFServiceProxy <ILoginerManage> proxy = new WCFServiceProxy <ILoginerManage>(); string webCookie = Session.SessionID.ToString(); CompanyOperator dCLoginer = proxy.getChannel.GetLoginerByMd5Cookie(Md5.GetMd5(webCookie)); if (dCLoginer != null) { dCLoginer.Pwd = string.Empty; Session["LoginCompanyOperator"] = dCLoginer; } } catch (Exception) { return; } } if (Session["LoginCompanyOperator"] != null) { CompanyOperator Loginer = (CompanyOperator)Session["LoginCompanyOperator"]; try { LoadReport(Loginer); } catch { } } else { Response.Write("<script> window.top.location.href = '../Login.aspx';</script>"); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Session["LoginCompanyOperator"] == null) { //向数据中心记录登录信息 try { WCFServiceProxy <ILoginerManage> proxy = new WCFServiceProxy <ILoginerManage>(); string webCookie = Session.SessionID.ToString(); CompanyOperator dCLoginer = proxy.getChannel.GetLoginerByMd5Cookie(Md5.GetMd5(webCookie)); if (dCLoginer != null) { dCLoginer.Pwd = string.Empty; Session["LoginCompanyOperator"] = dCLoginer; } else { Response.Redirect("Login.aspx", true); } } catch { } } } }
private List <DefineMenu> GetDefineMenuByLoginOper(CompanyOperator info) { List <DefineMenu> list = new List <DefineMenu>(); try { List <DefineOperRight> defineOperRightList = GetCompanyDefineOperRight(info.CompanyID).Where(p => p.OperID == info.OperID && p.CompanyID == info.CompanyID).ToList(); List <DefineRightMenu> rightMenuList = new List <DefineRightMenu>(); //有权限分配给他才加载 if (defineOperRightList != null && defineOperRightList.Count > 0) { //遍历 defineOperRightList.ForEach(p => rightMenuList.AddRange(GetCompanyDefineRightMenu(info.CompanyID).Where(i => i.CompanyID == p.CompanyID && i.RightCode == p.RightCode))); } if (rightMenuList != null && rightMenuList.Count > 0) { var i = from c in GetCompanyDefineMenu(info.CompanyID) join p in rightMenuList on c.MenuCode equals p.MenuCode select c; list.AddRange(i.ToList()); } list = list.Distinct().ToList(); } catch { } finally { } return(list); }
protected void Page_Load(object sender, EventArgs e) { HttpContext context = Context; if (context.Session["LoginCompanyOperator"] != null) { CompanyOperator Loginer = (CompanyOperator)context.Session["LoginCompanyOperator"]; WCFServiceProxy <IAdInfoManage> proxy = new WCFServiceProxy <IAdInfoManage>(); int id = int.Parse(context.Request.QueryString["FileId"]); IoT_AdInfo adInfo = proxy.getChannel.GetAdInfoData(id); byte[] images = adInfo.FileData.ToArray(); MemoryStream ms = new MemoryStream(images); context.Response.ClearContent(); context.Response.ContentType = "image/jpeg"; context.Response.BinaryWrite(ms.ToArray());//这里的Write改成BinaryWrite即可 context.Response.End(); } }
public Message DeleteCompanyOperator(CompanyOperator info) { // 定义执行结果 Message m; string configName = System.Configuration.ConfigurationManager.AppSettings["defaultDatabase"]; //Linq to SQL 上下文对象 DataContext dd = new DataContext(System.Configuration.ConfigurationManager.ConnectionStrings[configName].ConnectionString); try { // 获得上下文对象中的表具信息表 Table <CompanyOperator> tbl = dd.GetTable <CompanyOperator>(); var s = tbl.Where(p => p.OperID == info.OperID && p.CompanyID == info.CompanyID).Single(); CompanyOperator dbinfo = s as CompanyOperator; if (s.OperType == 1) { m = new Message() { Result = false, TxtMessage = "删除失败!企业主账号不能被删除。" }; } else { tbl.DeleteOnSubmit(s as CompanyOperator); // 更新操作 dd.SubmitChanges(); m = new Message() { Result = true, TxtMessage = "删除成功!" }; SetOperatorNoRight(s as CompanyOperator); } } catch (Exception e) { m = new Message() { Result = false, TxtMessage = "删除失败!" + e.Message }; } return(m); }
public string LoadHiddenMenuCode(CompanyOperator info) { List <DefineMenu> list = GetDefineMenuByLoginOper(info).Where(p => p.Type == "02").ToList(); StringBuilder Json = new StringBuilder(); if (list != null && list.Count > 0) { foreach (DefineMenu p in list) { if (p.Type == "02") { Json.Append(","); Json.Append(p.MenuCode); } } } Json.Append(","); return(Json.ToString()); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; if (context.Session["LoginCompanyOperator"] == null) { GetLoginer(context); } if (context.Session["LoginCompanyOperator"] != null) { isLoginOn = true; loginOperator = (CompanyOperator)context.Session["LoginCompanyOperator"]; DoLoginedHandlerWork(context); } else { isLoginOn = false; loginOperator = null; DoNoLoginHandlerWork(context); } }
void GetLoginer(HttpContext context) { if (context.Session["LoginCompanyOperator"] == null) { //查询数据中心记录的登录者信息 WCFServiceProxy <ILoginerManage> proxy = null; try { proxy = new WCFServiceProxy <ILoginerManage>(); string webCookie = context.Session.SessionID.ToString(); CompanyOperator dCLoginer = null; dCLoginer = proxy.getChannel.GetLoginerByMd5Cookie(Md5.GetMd5(webCookie)); if (dCLoginer != null) { dCLoginer.Pwd = string.Empty; context.Session["LoginCompanyOperator"] = dCLoginer; } else { if (context.Request.Form["NO_COOKIE_SessionId"] != null && context.Request.Form["NO_COOKIE_SessionId"].ToString() != string.Empty) { webCookie = context.Request.Form["NO_COOKIE_SessionId"].ToString(); dCLoginer = proxy.getChannel.GetLoginerByMd5Cookie(webCookie); if (dCLoginer != null) { dCLoginer.Pwd = string.Empty; context.Session["LoginCompanyOperator"] = dCLoginer; } } } } catch { } finally { if (proxy != null) { proxy.CloseChannel(); } } } }
public CompanyOperator GetLoginerByMd5Cookie(string md5Cookie) { CompanyOperator dbinfo = null; LoginerInfo info = LoginerManageHelper.getInstance().List.Where(p => p.Md5Key == md5Cookie).SingleOrDefault(); if (info != null && info.OperID != null && info.OperID != string.Empty) { string configName = System.Configuration.ConfigurationManager.AppSettings["defaultDatabase"]; //Linq to SQL 上下文对象 DataContext dd = new DataContext(System.Configuration.ConfigurationManager.ConnectionStrings[configName].ConnectionString); dbinfo = dd.GetTable <CompanyOperator>().Where(p => p.CompanyID == info.Company && p.OperID == info.OperID).SingleOrDefault(); //账号已停用 if (dbinfo.State != null && dbinfo.State.ToString() == "1") { LoginerManageHelper.getInstance().Semaphore.WaitOne(); LoginerManageHelper.getInstance().List.RemoveAll(p => p.Md5Key == md5Cookie); LoginerManageHelper.getInstance().Semaphore.Release(); dbinfo = null; } } return(dbinfo); }
public static bool CheckMenuCode(CompanyOperator info, string menuCode) { bool result = false; WCFServiceProxy <IOperRightManage> proxy = null; try { proxy = new WCFServiceProxy <IOperRightManage>(); result = proxy.getChannel.CheckMenuCode(info, menuCode); } catch { result = false; } finally { if (proxy != null) { proxy.CloseChannel(); } } return(result); }
public static string GetHidMenuCode(CompanyOperator info) { string result = string.Empty; WCFServiceProxy <IOperRightManage> proxy = null; try { proxy = new WCFServiceProxy <IOperRightManage>(); result = proxy.getChannel.LoadHiddenMenuCode(info); } catch { return(string.Empty); } finally { if (proxy != null) { proxy.CloseChannel(); } } return(result); }
private string Login(string account, string pwd) { string LoginPsw = pwd; string CompanyID = string.Empty; string OperID = string.Empty; string[] acc = account.Replace("-", "").Split('@'); if (acc.Length != 2) { return("账号错误"); } OperID = acc[0]; CompanyID = acc[1]; //验证账号密码 CommonSearch <CompanyOperator> userInfoSearch = new CommonSearch <CompanyOperator>(); string Where = "1=1 "; Where += " AND OperID='" + OperID + "' AND CompanyID='" + CompanyID + "'"; SearchCondition sCondition = new SearchCondition() { TBName = "S_CompanyOperator", TFieldKey = "OperID", TTotalCount = -1, TWhere = Where }; CompanyOperator Loginer = userInfoSearch.GetFirstTModel(ref sCondition); if (sCondition.TTotalCount == -1) { return("账号错误"); } if (Loginer.Pwd != Md5.GetMd5(Loginer.CompanyID + LoginPsw)) { return("密码错误"); } return(""); }
protected void Page_Load(object sender, EventArgs e) { HttpContext context = Context; if (context.Session["LoginCompanyOperator"] != null) { CompanyOperator Loginer = (CompanyOperator)context.Session["LoginCompanyOperator"]; //文件路径 string physicNewFilePath = string.Format("{0}\\UserUpload\\", context.Server.MapPath("~")); if (Directory.Exists(physicNewFilePath)) { string rarName = physicNewFilePath + "template" + ".xls"; //如果文件存在 if (File.Exists(rarName)) { System.IO.FileInfo file = new System.IO.FileInfo(rarName); Response.Clear(); Response.Charset = "GB2312"; Response.ContentEncoding = System.Text.Encoding.UTF8; // 添加头信息,为"文件下载/另存为"对话框指定默认文件名 Response.AddHeader("Content-Disposition", "attachment; filename=template.xls"); // 添加头信息,指定文件大小,让浏览器能够显示下载进度 Response.AddHeader("Content-Length", file.Length.ToString()); // 指定返回的是一个不能被客户端读取的流,必须被下载 Response.ContentType = "application/ms-excel"; // 把文件流发送到客户端 Response.WriteFile(file.FullName); // 停止页面的执行 //Response.End(); HttpContext.Current.ApplicationInstance.CompleteRequest(); } } } }
private Message SetOperatorNoRight(CompanyOperator s) { OperRightManageService opRightService = new OperRightManageService(); return(opRightService.EditCompanyOperRight(s.CompanyID, s.OperID, new List <DefineRight>())); }
public List <DefineMenu> LoadDefineMenuByLoginOper(CompanyOperator info, bool withButtonMenuCode) { return(GetDefineMenuByLoginOper(info).Where(p => p.Type == "00" || p.Type == "01" || p.Type == "03" || (withButtonMenuCode && p.Type == "02")).ToList()); }
public override void DoLoginedHandlerWork(HttpContext context) { Message jsonMessage; //获取操作类型AType:ADD,EDIT,DELETE,QUERY string AjaxType = context.Request.QueryString["AType"] == null ? string.Empty : context.Request.QueryString["AType"].ToString().ToUpper(); CompanyOperator Info; string webCookie = context.Session.SessionID.ToString(); WCFServiceProxy <ICompanyOperatorManage> proxy; WCFServiceProxy <ILoginerManage> proxyLoginer; string Where = "1=1 "; SearchCondition sCondition; jsonMessage = new Message() { Result = false, TxtMessage = "权限验证失败,可能原因:\n1、数据中心通讯失败。\n2、系统管理员未与您分配对应操作权限。" }; switch (AjaxType) { case "QUERY": CommonSearch <CompanyOperator> CompanyOperatorSearch = new CommonSearch <CompanyOperator>(); Where += "AND CompanyID='" + base.loginOperator.CompanyID + "' "; if (context.Request.Form["TWhere"] != null && context.Request.Form["TWhere"].ToString().Trim() != string.Empty) { Where += context.Request.Form["TWhere"].ToString(); } sCondition = new SearchCondition() { TBName = "S_CompanyOperator", TFieldKey = "OperID,CompanyID", TTotalCount = -1, TPageCurrent = 1, TFieldOrder = "OperID ASC", TWhere = Where }; List <CompanyOperator> list = CompanyOperatorSearch.GetList(ref sCondition, context); //将密码设置为空 list.ForEach(p => p.Pwd = string.Empty); jsonMessage = new Message() { Result = true, TxtMessage = JSon.ListToJson <CompanyOperator>(list, sCondition.TTotalCount) }; break; case "LOADLOGINER": jsonMessage = new Message() { Result = true, TxtMessage = JSon.TToJson <CompanyOperator>(base.loginOperator) }; break; case "HEARTCOOKIE": //向数据中心更新登录信息 proxyLoginer = new WCFServiceProxy <ILoginerManage>(); try { proxyLoginer.getChannel.RegisterClient(Md5.GetMd5(webCookie), base.loginOperator.OperID, base.loginOperator.CompanyID); jsonMessage = new Message() { Result = true, TxtMessage = Md5.GetMd5(context.Session.SessionID.ToString()) }; } catch { } finally { proxyLoginer.CloseChannel(); } break; case "ADD": if (CommonOperRightHelper.CheckMenuCode(base.loginOperator, "tjczy")) { Info = new CommonModelFactory <CompanyOperator>().GetModelFromContext(context); Info.CompanyID = base.loginOperator.CompanyID; Info.Pwd = Md5.GetMd5(base.loginOperator.CompanyID + base.loginOperator.CompanyID); Info.OperType = 0; //0一般操作员:1企业主账号(每个企业仅一个); if (Info.PhoneLogin == true && Info.Phone == string.Empty) { jsonMessage = new Message() { Result = false, TxtMessage = string.Format("添加失败,请输入为操作员{0}绑定的手机号码。", Info.OperID) }; } else { WCFServiceProxy <ICompanyOperatorManage> proxyCompanyOperatorManage = new WCFServiceProxy <ICompanyOperatorManage>(); try { jsonMessage = proxyCompanyOperatorManage.getChannel.AddCompanyOperator(Info); } catch { } finally { proxyCompanyOperatorManage.CloseChannel(); } } } break; case "EDIT": if (CommonOperRightHelper.CheckMenuCode(base.loginOperator, "bjczy")) { Info = new CommonModelFactory <CompanyOperator>().GetModelFromContext(context); Info.Pwd = null; if (Info.CompanyID != base.loginOperator.CompanyID) { jsonMessage = new Message() { Result = false, TxtMessage = "操作员所属企业与登录账号所属企业不一致,编辑失败。" }; } else { if (Info.PhoneLogin == true && Info.Phone == string.Empty) { jsonMessage = new Message() { Result = false, TxtMessage = string.Format("编辑失败,请输入为操作员{0}绑定的手机号码。", Info.OperID) }; } else { proxy = new WCFServiceProxy <ICompanyOperatorManage>(); try { jsonMessage = proxy.getChannel.EditCompanyOperator(Info); } catch { } finally { proxy.CloseChannel(); } } } } break; //case "EDITOPERAREA": // if (CommonOperRightHelper.CheckMenuCode(base.loginOperator, "bjczy")) // { // Info = new CommonModelFactory<CompanyOperator>().GetModelFromContext(context); // Info.Pwd = null; // if (Info.CompanyID != base.loginOperator.CompanyID) // { // jsonMessage = new Message() // { // Result = false, // TxtMessage = "操作员所属企业与登录账号所属企业不一致,编辑失败。" // }; // } // else // { // proxy = new WCFServiceProxy<ICompanyOperatorManage>(); // try // { // string nodes = context.Request.Form["nodes"].ToString(); // jsonMessage = proxy.getChannel.EditOperatorArea(Info, nodes.Split(',')); // } // catch // { } // finally // { // proxy.CloseChannel(); // } // } // } // break; case "DELETE": if (CommonOperRightHelper.CheckMenuCode(base.loginOperator, "scczy")) { Info = new CommonModelFactory <CompanyOperator>().GetModelFromContext(context); if (Info.CompanyID != base.loginOperator.CompanyID) { jsonMessage = new Message() { Result = false, TxtMessage = "操作员所属企业与登录账号所属企业不一致,删除失败。" }; } else { proxy = new WCFServiceProxy <ICompanyOperatorManage>(); try { jsonMessage = proxy.getChannel.DeleteCompanyOperator(Info); } catch { } finally { proxy.CloseChannel(); } } } break; case "RESETPWD": if (CommonOperRightHelper.CheckMenuCode(base.loginOperator, "czmm")) { Info = new CommonModelFactory <CompanyOperator>().GetModelFromContext(context); if (Info.CompanyID != base.loginOperator.CompanyID) { jsonMessage = new Message() { Result = false, TxtMessage = "操作员所属企业与登录账号所属企业不一致,删除失败。" }; } else { CompanyOperator infoEditPwd = new CompanyOperator() { OperID = Info.OperID, CompanyID = Info.CompanyID, Pwd = Md5.GetMd5(Info.CompanyID + Info.CompanyID) }; proxy = new WCFServiceProxy <ICompanyOperatorManage>(); try { jsonMessage = proxy.getChannel.EditCompanyOperator(infoEditPwd); if (jsonMessage.Result) { jsonMessage.TxtMessage = "操作员密码已重置为初始密码:" + Info.CompanyID; } } catch { } finally { proxy.CloseChannel(); } } } break; case "EDITPWD": if (CommonOperRightHelper.CheckMenuCode(base.loginOperator, "xgmm")) { Info = new CommonModelFactory <CompanyOperator>().GetModelFromContext(context); if (Info.CompanyID != base.loginOperator.CompanyID) { jsonMessage = new Message() { Result = false, TxtMessage = "操作员所属企业与登录账号所属企业不一致,修改失败。" }; } else if (Info.OperID != base.loginOperator.OperID) { jsonMessage = new Message() { Result = false, TxtMessage = "当前登录者与您修改的账号不一致,修改失败。" }; } else { //验证输入旧密码 CommonSearch <CompanyOperator> userInfoSearch = new CommonSearch <CompanyOperator>(); Where = " OperID='" + Info.OperID + "' AND CompanyID='" + Info.CompanyID + "'"; sCondition = new SearchCondition() { TBName = "S_CompanyOperator", TFieldKey = "OperID", TTotalCount = -1, TWhere = Where }; CompanyOperator dbInfo = userInfoSearch.GetFirstTModel(ref sCondition); string OldPwd = context.Request.Form["OldPwd"] == null ? string.Empty : context.Request.Form["OldPwd"].ToString(); if (sCondition.TTotalCount == -1 || dbInfo == null) { jsonMessage = new Message() { Result = false, TxtMessage = "数据中心未返回信息,请稍候再试。" }; } else if (Md5.GetMd5(dbInfo.CompanyID + OldPwd.Trim()) != dbInfo.Pwd) { jsonMessage = new Message() { Result = false, TxtMessage = "原密码验证失败。" }; } else { CompanyOperator infoEditPwd = new CompanyOperator() { OperID = dbInfo.OperID, CompanyID = dbInfo.CompanyID, Pwd = Md5.GetMd5(dbInfo.CompanyID + Info.Pwd) }; proxy = new WCFServiceProxy <ICompanyOperatorManage>(); try { jsonMessage = proxy.getChannel.EditCompanyOperator(infoEditPwd); } catch { } finally { proxy.CloseChannel(); } } } } break; //case "LOADAREATREE": // string operID = context.Request.Form["OperID"].ToString(); // jsonMessage = new Message() { Result = true, TxtMessage = CreateAreaTreeToJson(base.loginOperator.CompanyID, operID) }; // break; default: jsonMessage = new Message() { Result = false, TxtMessage = "操作未定义。" }; break; } context.Response.Write(JSon.TToJson <Message>(jsonMessage)); }
public bool CheckMenuCode(CompanyOperator info, string menuCode) { return(GetDefineMenuByLoginOper(info).Exists(p => p.MenuCode == menuCode)); }
public static string MenuListToJson(CompanyOperator info) { List <DefineMenu> list = new List <DefineMenu>(); WCFServiceProxy <IOperRightManage> proxy = null; try { proxy = new WCFServiceProxy <IOperRightManage>(); list = proxy.getChannel.LoadDefineMenuByLoginOper(info, false); } catch { return(string.Empty); } finally { if (proxy != null) { proxy.CloseChannel(); } } List <DefineMenu> tmp = new List <DefineMenu>(); List <DefineMenu> tmp1 = new List <DefineMenu>(); StringBuilder Json = new StringBuilder(); int id = 0; if (list != null && list.Count > 0) { var vList = list.Where(p => p.Type == "00"); if (vList != null) { tmp = vList.OrderBy(p => p.OrderNum).ToList(); } else { tmp = null; } if (tmp != null) { //动态生成菜单:只解析两级菜单 Json.Append("["); for (int i = 0; i < tmp.Count; i++) { Json.Append("{"); Json.Append("\"id\":" + (id++)); Json.Append(","); Json.Append("\"text\":\"" + tmp[i].Name + "\""); //if (tmp[i].UrlClass != string.Empty) //{ Json.Append(","); Json.Append("\"attributes\":{\"url\":\"" + tmp[i].UrlClass + "\""); Json.Append(","); Json.Append("\"type\":\"" + tmp[i].Type + "\""); Json.Append(","); Json.Append("\"menucode\":\"" + tmp[i].MenuCode + "\""); Json.Append("}"); //} var vvList = list.Where(p => (p.Type == "01" || p.Type == "03") && p.FatherCode == tmp[i].MenuCode); if (vvList != null) { tmp1 = vvList.OrderBy(p => p.OrderNum).ToList(); } else { tmp1 = null; } if (tmp1 != null && tmp1.Count > 0) { Json.Append(","); Json.Append("\"children\":["); for (int j = 0; j < tmp1.Count; j++) { Json.Append("{"); Json.Append("\"id\":" + (id++)); Json.Append(","); Json.Append("\"text\":\"" + tmp1[j].Name + "\""); //if (tmp1[j].UrlClass != string.Empty) //{ Json.Append(","); Json.Append("\"attributes\":{\"url\":\"" + tmp1[j].UrlClass + "\""); Json.Append(","); Json.Append("\"type\":\"" + tmp1[j].Type + "\""); Json.Append(","); Json.Append("\"menucode\":\"" + tmp1[j].MenuCode + "\""); Json.Append("}"); //} Json.Append("}"); if (j != tmp1.Count - 1) { Json.Append(","); } } Json.Append("]"); } Json.Append("}"); if (i != tmp.Count - 1) { Json.Append(","); } } Json.Append("]"); } } return(Json.ToString()); }
public static string GetLeftMenu(CompanyOperator info) { List <DefineMenu> list = new List <DefineMenu>(); WCFServiceProxy <IOperRightManage> proxy = null; try { proxy = new WCFServiceProxy <IOperRightManage>(); list = proxy.getChannel.LoadDefineMenuByLoginOper(info, false); } catch { return(string.Empty); } finally { if (proxy != null) { proxy.CloseChannel(); } } List <DefineMenu> tmp = new List <DefineMenu>(); List <DefineMenu> tmp1 = new List <DefineMenu>(); var vList = list.Where(p => p.Type == "00"); if (vList != null) { tmp = vList.OrderBy(p => p.OrderNum).ToList(); } else { tmp = null; } StringBuilder menuApp = new StringBuilder(); menuApp.Append("["); foreach (DefineMenu node in tmp) { if (menuApp.Length > 1) { menuApp.Append(","); } menuApp.Append("{"); menuApp.Append("No:'" + node.MenuCode + "'"); menuApp.Append(",Name:'" + node.Name + "'"); menuApp.Append(",Img:'" + node.ImageUrl + "'"); menuApp.Append(",Url:'" + node.UrlClass + "'"); menuApp.Append(",Children:["); var vvList = list.Where(p => (p.Type == "01" || p.Type == "03") && p.FatherCode == node.MenuCode); if (vvList != null) { tmp1 = vvList.OrderBy(p => p.OrderNum).ToList(); } else { tmp1 = null; } if (tmp1.Count > 0) { string childrenMenu = ""; foreach (DefineMenu cNode in tmp1) { if (childrenMenu.Length > 0) { childrenMenu += ","; } childrenMenu += "{"; childrenMenu += "No:'" + cNode.MenuCode + "'"; childrenMenu += ",Name:'" + cNode.Name + "'"; childrenMenu += ",Img:'" + cNode.ImageUrl + "'"; childrenMenu += ",Url:'" + cNode.UrlClass + "'"; childrenMenu += ",Children:[]"; childrenMenu += "}"; } menuApp.Append(childrenMenu); } menuApp.Append("]}"); } menuApp.Append("]"); return(menuApp.ToString()); }
public Message AddCompanyOperator(CompanyOperator info) { // 定义执行结果 Message m; string configName = System.Configuration.ConfigurationManager.AppSettings["defaultDatabase"]; //Linq to SQL 上下文对象 DataContext dd = new DataContext(System.Configuration.ConfigurationManager.ConnectionStrings[configName].ConnectionString); try { if (info.CompanyID == string.Empty) { m = new Message() { Result = false, TxtMessage = "新增失败!企业编号不能为空。" }; } else { // 获得上下文对象中的用户信息表 Table <CompanyOperator> tbl = dd.GetTable <CompanyOperator>(); //判断账号是否存在。 int existsCount = (from p in tbl where p.CompanyID == info.CompanyID && p.OperID == info.OperID select p.OperID).Count(); if (existsCount > 0) { m = new Message() { Result = false, TxtMessage = string.Format("新增失败!操作员编号{0}已存在。", info.OperID) }; } else { //判断做为登陆手机号账号是否存在 if (info.PhoneLogin == true && info.Phone != string.Empty) { existsCount = (from p in tbl where p.Phone == info.Phone && p.PhoneLogin == true select p.OperID).Count(); if (existsCount > 0) { m = new Message() { Result = false, TxtMessage = string.Format("新增失败!该手机号{0}已被其他用户绑定,请更换手机号码进行绑定操作。", info.Phone) }; return(m); } } // 调用新增方法 tbl.InsertOnSubmit(info); // 更新操作 dd.SubmitChanges(); m = new Message() { Result = true, TxtMessage = JSon.TToJson <CompanyOperator>(info) }; if (info.State == null || (info.State != null && info.State.ToString() == "1")) { SetOperatorNoRight(info); } } } } catch (Exception e) { m = new Message() { Result = false, TxtMessage = "新增用户失败!" + e.Message }; } return(m); }
protected void Page_Load(object sender, EventArgs e) { WCFServiceProxy <IMeterGasBill> proxy = null; try { CompanyOperator dCLoginer = null; if (this.Context.Session["LoginCompanyOperator"] != null) { dCLoginer = (CompanyOperator)this.Context.Session["LoginCompanyOperator"]; } else { return; } string month = Request.QueryString["Month"]; string companyId = dCLoginer.CompanyID; Workbook workbook = new Workbook(); workbook.Worksheets.Add("气量表结算数据"); Worksheet sheet = (Worksheet)workbook.Worksheets[0]; sheet.Cells["A1"].PutValue("户号"); sheet.Cells["B1"].PutValue("户名"); sheet.Cells["C1"].PutValue("地址"); sheet.Cells["D1"].PutValue("表号"); sheet.Cells["E1"].PutValue("结算月份"); sheet.Cells["F1"].PutValue("上次表底"); sheet.Cells["G1"].PutValue("本次表底"); sheet.Cells["H1"].PutValue("用气量"); sheet.Cells["I1"].PutValue("气费"); sheet.Cells["J1"].PutValue("抄表时间"); proxy = new WCFServiceProxy <IMeterGasBill>(); List <View_MeterGasBill> listAll = proxy.getChannel.GetGasBillByMonth(month, companyId); int RowNo = 2; for (int i = 0; i < listAll.Count; i++) { sheet.Cells["A" + RowNo].PutValue(listAll[i].UserID); sheet.Cells["B" + RowNo].PutValue(listAll[i].UserName); sheet.Cells["C" + RowNo].PutValue(listAll[i].Address); sheet.Cells["D" + RowNo].PutValue(listAll[i].MeterNo); sheet.Cells["E" + RowNo].PutValue(listAll[i].UseMonth); sheet.Cells["F" + RowNo].PutValue(listAll[i].LastSum.ToString()); sheet.Cells["G" + RowNo].PutValue(listAll[i].ThisSum.ToString()); sheet.Cells["H" + RowNo].PutValue(listAll[i].UseGasSum.ToString()); sheet.Cells["I" + RowNo].PutValue(listAll[i].GasFee.ToString()); sheet.Cells["J" + RowNo].PutValue(listAll[i].ThisReadDate.ToString()); RowNo++; } String filename = string.Format("{0}{1}.xls", "气量表结算数据", month); Response.ContentType = "application/ms-excel;charset=utf-8"; Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode(filename, System.Text.Encoding.GetEncoding("utf-8"))); System.IO.MemoryStream memStream = workbook.SaveToStream(); Response.BinaryWrite(memStream.ToArray()); Response.End(); } catch (Exception) { } finally { if (proxy != null) { proxy.CloseChannel(); } } }
public Message ResetCompanyAdmin(CompanyInfo info) { // 定义执行结果 Message m; string configName = System.Configuration.ConfigurationManager.AppSettings["defaultDatabase"]; //Linq to SQL 上下文对象 DataContext dd = new DataContext(System.Configuration.ConfigurationManager.ConnectionStrings[configName].ConnectionString); try { if (info.CompanyID == string.Empty) { m = new Message() { Result = false, TxtMessage = "操作失败!企业编号不能为空。" }; } else { int existsCount = 0; Table <CompanyOperator> tb2 = dd.GetTable <CompanyOperator>(); existsCount = (from p in tb2 where p.CompanyID == info.CompanyID && p.OperID == info.CompanyID select p.CompanyID).Count(); if (existsCount == 0) { tb2.InsertOnSubmit(new CompanyOperator() { CompanyID = info.CompanyID, OperID = info.CompanyID, Pwd = Md5.GetMd5(info.CompanyID + info.CompanyID), Name = "默认账号", OperType = 1, State = '0' }); dd.SubmitChanges(); } else { CompanyOperator dbopinfo = dd.GetTable <CompanyOperator>().Where(p => p.CompanyID == info.CompanyID && p.OperID == info.CompanyID).SingleOrDefault(); dbopinfo.Pwd = Md5.GetMd5(info.CompanyID + info.CompanyID); dbopinfo.OperType = 1; dbopinfo.State = '0'; dd.SubmitChanges(); } // 获得上下文对象中的用户信息表 CompanyInfo dbinfo = dd.GetTable <CompanyInfo>().Where(p => p.CompanyID == info.CompanyID && p.CompanyName == info.CompanyName).SingleOrDefault(); //定义修改主键 string CompanyID = dbinfo.CompanyID; string sqlText = "SP_AddDefaultRight"; SqlParameter[] parms = new SqlParameter[] { new SqlParameter("CompanyID", dbinfo.CompanyID) }; SQLHelper.ExecuteNonQuery(SQLHelper.SchuleConnection, CommandType.StoredProcedure, sqlText, parms); m = new Message() { Result = true, TxtMessage = "操作成功。" }; //初始化后,清空权限缓存。 new OperRightManageService().RemoveCompanyRightCache(dbinfo.CompanyID); } } catch (Exception e) { m = new Message() { Result = false, TxtMessage = "操作失败!" + e.Message }; } return(m); }
private Message UserLogin(HttpContext context) { Message jMessage = new Message(); string LoginID = string.Empty; string LoginPsw = string.Empty; string CompanyID = string.Empty; string OperID = string.Empty; bool IsPhoneLogin = false; if (context.Request.Form["LoginID"] != null && context.Request.Form["LoginID"].ToString().Trim() != string.Empty) { LoginID = context.Request.Form["LoginID"].ToString().Trim(); if (LoginID.Split('@').Length == 2) { CompanyID = LoginID.Split('@')[1]; OperID = LoginID.Split('@')[0]; } else { if (LoginID.Length == 11) { IsPhoneLogin = true; } } } if (context.Request.Form["LoginPsw"] != null) { LoginPsw = context.Request.Form["LoginPsw"].ToString().Trim(); } if (LoginID == string.Empty) { jMessage = new Message() { Result = false, TxtMessage = "登录账号格式不正确。" }; } else { CommonSearch <CompanyOperator> userInfoSearch = new CommonSearch <CompanyOperator>(); string Where = "1=1 "; if (IsPhoneLogin) { Where += " AND PhoneLogin=1 and Phone='" + LoginID + "'"; } else { Where += " AND OperID='" + OperID + "' AND CompanyID='" + CompanyID + "'"; } SearchCondition sCondition = new SearchCondition() { TBName = "S_CompanyOperator", TFieldKey = "OperID", TTotalCount = -1, TWhere = Where }; CompanyOperator Loginer = userInfoSearch.GetFirstTModel(ref sCondition); //服务器错误 if (sCondition.TTotalCount == -1) { jMessage = new Message() { Result = false, TxtMessage = "数据中心未返回信息,请稍候再试。" }; } else if (Loginer != null && Loginer.OperID != string.Empty) { if (Loginer.State != null && Loginer.State.ToString() == "1") { jMessage = new Message() { Result = false, TxtMessage = string.Format("账号{0}已停用。", LoginID) }; } else if (Loginer.Pwd == Md5.GetMd5(Loginer.CompanyID + LoginPsw)) { jMessage = new Message() { Result = true, TxtMessage = "登录成功。" }; //向数据中心记录登录信息 WCFServiceProxy <ILoginerManage> proxy = new WCFServiceProxy <ILoginerManage>(); string webCookie = context.Session.SessionID.ToString(); try { proxy.getChannel.RegisterClient(Md5.GetMd5(webCookie), Loginer.OperID, Loginer.CompanyID); } catch { } finally { proxy.CloseChannel(); } Loginer.Pwd = string.Empty; context.Session["LoginCompanyOperator"] = Loginer; } else { jMessage = new Message() { Result = false, TxtMessage = "密码错误。" }; } } else { jMessage = new Message() { Result = false, TxtMessage = IsPhoneLogin ? "该手机号未绑定,请联系管理员操作[系统管理]->[操作员管理]界面进行绑定。" : "登录账号不存在。" }; } } return(jMessage); }
private void LoadReport(CompanyOperator Operator) { string rid = Request.QueryString["rid"]; if (this.Session["ReportID"] != null) { ird = this.Session["ReportID"].ToString(); } if (ird == null || ird.Trim() == "") { ird = "1"; // return; } TableRow dRow = null; TableCell tCell = null; if (!this.IsPostBack || rid != ird) { list = new List <FiledItem>(); report = new BaseReport(Convert.ToInt32(rid)); this.Session["ReportID"] = rid; bool isHaveCompany = false; bool isHaveOper = false; foreach (DefineSqlParameter par in report.DataSource.DbParameterCollection) { if (!par.ParameterName.StartsWith("_")) { dRow = new TableRow(); tCell = new TableCell(); tCell.Text = par.ParameterName; dRow.Cells.Add(tCell); this.tabCondition.Rows.Add(dRow); dRow = new TableRow(); tCell = new TableCell(); //创建输入 FiledItem item = new FiledItem(par); list.Add(item); tCell.Controls.Add(item.getFiled()); dRow.Cells.Add(tCell); this.tabCondition.Rows.Add(dRow); } else { switch (par.ParameterName) { case "_CompanyID": par.Value = Operator.CompanyID; break; case "_OperatorID": par.Value = Operator.OperID; break; default: par.Value = string.Empty; break; } } if (par.ParameterName == "_CompanyID") { isHaveCompany = true; } if (par.ParameterName == "_OperatorID") { isHaveOper = true; } } if (!isHaveCompany) { DefineSqlParameter parCompanyId = new DefineSqlParameter("_CompanyID", SqlDbType.VarChar, 50, ""); parCompanyId.Value = Operator.CompanyID; report.DataSource.DbParameterCollection.Add(parCompanyId); } if (!isHaveOper) { DefineSqlParameter parOperatorId = new DefineSqlParameter("_OperatorID", SqlDbType.VarChar, 50, ""); parOperatorId.Value = Operator.OperID; report.DataSource.DbParameterCollection.Add(parOperatorId); } this.Session["Rlist"] = list; this.Session.Add("Report", report); btnQuery_Click(null, null); } else { list = (List <FiledItem>) this.Session["Rlist"]; report = (BaseReport)this.Session["Report"]; //this.Table1.Rows.Clear(); if (list == null) { return; } foreach (FiledItem par in list) { if (!par.FiledName.StartsWith("_")) { dRow = new TableRow(); tCell = new TableCell(); tCell.Text = par.FiledName; dRow.Cells.Add(tCell); this.tabCondition.Rows.Add(dRow); dRow = new TableRow(); tCell = new TableCell(); tCell.Controls.Add(par.getFiled()); dRow.Cells.Add(tCell); this.tabCondition.Rows.Add(dRow); } } } }
public Message EditCompanyOperator(CompanyOperator info) { // 定义执行结果 Message m; string configName = System.Configuration.ConfigurationManager.AppSettings["defaultDatabase"]; //Linq to SQL 上下文对象 DataContext dd = new DataContext(System.Configuration.ConfigurationManager.ConnectionStrings[configName].ConnectionString); try { if (info.CompanyID == string.Empty) { m = new Message() { Result = false, TxtMessage = "编辑失败!企业编号不能为空。" }; } else { //判断做为登陆手机号账号是否存在 // 获得上下文对象中的用户信息表 Table <CompanyOperator> tbl = dd.GetTable <CompanyOperator>(); int existsCount = 0; if (info.PhoneLogin == true && info.Phone != string.Empty) { existsCount = (from p in tbl where p.Phone == info.Phone && p.PhoneLogin == true && !(p.OperID == info.OperID && p.CompanyID == info.CompanyID) select p.OperID).Count(); if (existsCount > 0) { m = new Message() { Result = false, TxtMessage = string.Format("编辑失败!该手机号{0}已被其他用户绑定,请更换手机号码进行绑定操作。", info.Phone) }; return(m); } } // 获得上下文对象中的用户信息表 CompanyOperator dbinfo = dd.GetTable <CompanyOperator>().Where(p => p.OperID == info.OperID && p.CompanyID == info.CompanyID).SingleOrDefault(); //定义修改主键 string CompanyID = dbinfo.CompanyID; string OperID = dbinfo.OperID; short? OperType = dbinfo.OperType; ConvertHelper.Copy <CompanyOperator>(dbinfo, info); dbinfo.CompanyID = CompanyID; dbinfo.OperID = OperID; dbinfo.OperType = OperType; // 更新操作 dd.SubmitChanges(); m = new Message() { Result = true, TxtMessage = JSon.TToJson <CompanyOperator>(dbinfo) }; if (dbinfo.State == null || (dbinfo.State != null && dbinfo.State.ToString() == "1")) { SetOperatorNoRight(dbinfo); } } } catch (Exception e) { m = new Message() { Result = false, TxtMessage = "编辑失败!" + e.Message }; } return(m); }