using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace LYFZ.WeixinServers.LoginApi
{
public partial class industry : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.HttpMethod.ToUpper() == "GET")
return;
#if ff
Stream s = Request.InputStream;
byte[] b = new byte[s.Length];
s.Read(b, 0, (int)s.Length);
string post = Encoding.UTF8.GetString(b);
string xmlData = "";
try
{
Request.InputStream.Seek(0, SeekOrigin.Begin);//强制调整指针位置
using (var streamReader = new StreamReader(Request.InputStream))
{
var decryptMsg = string.Empty;
xmlData = streamReader.ReadToEnd();
System.Diagnostics.Debug.Write(xmlData, "加密的微信消息:");
}
}
catch (Exception ex)
{
}
#endif
if (Request.QueryString["type"] != null)
{
string strOptType = Request.QueryString["type"];
if (!string.IsNullOrEmpty(strOptType))
{
if (strOptType.StartsWith("sys-"))
{
string strUser, strUserPsw;
if (VerifySysParam(out strUser, out strUserPsw))
{
// 获取系统账号信息,是否有权限操作行业信息;
LoginModel.user model = GlobalCache.GetUserInfo(strUser, strUserPsw);
if (model == null)
{
Response.Write("{\"code\":201, \"msg\":\"账号或密码不对\"}");
return;
}
if (model.user_type != 0)
{
Response.Write("{\"code\":201, \"msg\":\"账号操作权限不足\"}");
return;
}
switch (strOptType)
{
case "sys-add":
{
OptSysAdd();
}
break;
case "sys-delete":
{
OptSysDelete();
}
break;
case "sys-modify":
{
OptSysModify();
}
break;
case "sys-query":
{
OptSysQuery();
}
break;
default:
break;
}
}
else
{
Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}");
}
}
else
{
}
}
else
{
Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}");
}
}
else
{
Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}");
}
}
// 获取POST返回来的数据
private string PostInput()
{
try
{
System.IO.Stream s = Request.InputStream;
int count = 0;
byte[] buffer = new byte[1024];
StringBuilder builder = new StringBuilder();
while ((count = s.Read(buffer, 0, 1024)) > 0)
{
builder.Append(Encoding.UTF8.GetString(buffer, 0, count));
}
s.Flush();
s.Close();
s.Dispose();
return builder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 参数校验
///
/// 企业id
/// app对象id
/// app对象类型
/// app对象的微信号
/// 若参数有效返回true,参数无效或空返回false
public bool VerifySysParam(out string strUser, out string strUserPsw)
{
strUser = strUserPsw = "";
if (this.Request.Form["user"] != null && this.Request.Form["user_psw"] != null )
{
strUser = Request.Form["user"];
strUserPsw = Request.Form["user_psw"];
if (string.IsNullOrEmpty(strUser) || string.IsNullOrEmpty(strUserPsw) )
return false;
return true;
}
return false;
}
///
/// 添加行业的操作
///
public void OptSysAdd()
{
if ( Request.Form["ind_name"] != null && Request.Form["ind_note"] != null )
{
LoginModel.industry model = new LoginModel.industry();
model.ind_id = GlobalCache.GuidString();
model.ind_name = Request.Form["ind_name"];
model.ind_note = Request.Form["ind_note"];
if ( !string.IsNullOrEmpty(model.ind_name) && !string.IsNullOrEmpty(model.ind_note) )
{// 参数有效;
try
{
LoginDal.industry dal = new LoginDal.industry();
dal.Add(model, "id");
Response.Write("{\"code\":200, \"msg\":\"添加行业成功\"}");
}
catch
{
Response.Write("{\"code\":201, \"msg\":\"添加行业失败\"}");
}
}
else
{// 参数无效;
Response.Write("{\"code\":201, \"msg\":\"行业参数无效\"}");
}
}
}
///
/// 删除行业的操作
///
public void OptSysDelete()
{
if (Request.Form["ind_name"] != null )
{
string strIndName = Request.Form["ind_name"];
if (!string.IsNullOrEmpty(strIndName))
{
try
{
LoginDal.industry dal = new LoginDal.industry();
LoginModel.industry model = new LoginModel.industry();
DataSet ds = dal.GetList("ind_name = '" + strIndName + "'", "id");
if ( ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0 )
{
model = dal.DataRowToModel(ds.Tables[0].Rows[0]);
dal.Delete(model.id);
Response.Write("{\"code\":200, \"msg\":\"删除行业成功\"}");
}
else
{
Response.Write("{\"code\":201, \"msg\":\"未找到该行业信息,可能已被删除\"}");
}
}
catch
{
Response.Write("{\"code\":201, \"msg\":\"数据库操作失败\"}");
}
}
else
{
Response.Write("{\"code\":201, \"msg\":\"行业名称未填\"}");
return;
}
}
}
///
/// 修改行业的操作(不必做)
///
public void OptSysModify()
{
}
///
/// 查询行业的操作
///
public void OptSysQuery()
{
LoginDal.industry dal = new LoginDal.industry();
LoginModel.industry model = new LoginModel.industry();
List ListModel = new List();
if (Request.Form["ind_name"] != null)
{// 查询某一个;
string strIndName = Request.Form["ind_name"];
try
{
DataSet ds = dal.GetList("ind_name = '" + strIndName + "'", "id");
if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
model = dal.DataRowToModel(ds.Tables[0].Rows[0]);
ListModel.Add(model);
string strJson = JsonConvert.SerializeObject(ListModel);
Response.Write(strJson);
}
else
{
Response.Write("{\"code\":201, \"msg\":\"没有该行业信息\"}");
}
}
catch
{
Response.Write("{\"code\":201, \"msg\":\"数据操作失败\"}");
}
}
else
{// 查询所有;
try
{
DataSet ds = dal.GetAllList("id");
if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
foreach ( DataRow dr in ds.Tables[0].Rows )
{
model = dal.DataRowToModel(dr);
ListModel.Add(model);
}
string strJson = JsonConvert.SerializeObject(ListModel);
Response.Write(strJson);
}
else
{
Response.Write("{\"code\":201, \"msg\":\"没有该行业信息\"}");
}
}
catch
{
Response.Write("{\"code\":201, \"msg\":\"数据操作失败\"}");
}
}
}
}
}