NGToolsCSharp/NGTools/ASHX/APPTools.ashx.cs
2024-09-13 16:44:30 +08:00

245 lines
8.7 KiB
C#

using NGTools.Tools;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
namespace NGTools.ASHX
{
/// <summary>
/// APPTools 的摘要说明
/// </summary>
public class APPTools : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
if (context.Request["action"] == "getJldMobile") //手机端select使用
{
string strPhoneNo = context.Request.Form["phoneNo"];
DataTable dtUser = MySQLHelper.ExecuteDataTable(stringSQL.strSQL_User + strPhoneNo + "' or user_account='" + strPhoneNo + "' or phoneNo='" + strPhoneNo + "'");
if (dtUser.Rows.Count < 1)
{
context.Response.Write(dtUser.Rows.Count);
context.Response.End();
}
string strUserName = dtUser.Rows[0]["user_name"].ToString();
string strORG_Parent_ID = dtUser.Rows[0]["ORG_ID"].ToString();
DataTable dtTree = new DataTable(); ;
if (strUserName == "廖德云")
{
dtTree = _GetTable();
}
else
{
dtTree = _GetTable(strORG_Parent_ID);
}
DataView dv = dtTree.DefaultView;
dv.RowFilter = "ORG_PARENT_ID <> 'MS00'";
DataTable dtTemp = dv.ToTable(false, "ORG_ID", "ORG_NAME");
string jsonDWZC = JSONConvert.ToJson(dtTemp, "DWZC");
DataTable dtTreeTemp = dtTemp.Copy();
string JSONJLd = "\"JLD\":[{";
DataTable dtJld = MySQLHelper.ExecuteDataTable("select * from jld");
for (int i = 0; i < dtTreeTemp.Rows.Count; i++)
{
dv = dtJld.DefaultView;
dv.RowFilter = "ORG_ID='" + dtTreeTemp.Rows[i]["ORG_ID"] + "'";
dtTemp = dv.ToTable(false, "ID", "JLD_Name");
if (dtTemp.Rows.Count == 0)
{
JSONJLd += "{},";
continue;
}
else
{
JSONJLd += JSONConvert.ToJson(dtTemp, dtTreeTemp.Rows[i]["ORG_ID"].ToString());
}
JSONJLd = JSONJLd.TrimEnd(',') + ",";
}
JSONJLd = JSONJLd.TrimEnd(',') + "}]";
string json = "[{" + jsonDWZC + "},{" + JSONJLd + "}]";
context.Response.Write(json);
context.Response.End();
}
if (context.Request["action"] == "getJldPar")
{
string jldID = context.Request.Form["jldid"];
string strGN = context.Request.Form["gnmk"];
DataTable dtJldPar = MySQLHelper.ExecuteDataTable("select * from jldpar where JLD_ID='" + jldID + "' and gnmk='" + strGN + "'");
string json = JSONConvert.DataTableToJsonList(dtJldPar);
context.Response.Write(json);
context.Response.End();
}
if (context.Request["action"] == "getJldMobilePicker") //手机端select使用
{
string strPhoneNo = context.Request.Form["phoneNo"];
DataTable dtUser = MySQLHelper.ExecuteDataTable(stringSQL.strSQL_User + strPhoneNo + "' or user_account='" + strPhoneNo + "' or phoneNo='" + strPhoneNo + "'");
if (dtUser.Rows.Count < 1)
{
context.Response.Write(dtUser.Rows.Count);
context.Response.End();
}
string strUserName = dtUser.Rows[0]["user_name"].ToString();
string strORG_Parent_ID = dtUser.Rows[0]["ORG_ID"].ToString();
DataTable dtTree = new DataTable(); ;
if (strUserName == "廖德云")
{
dtTree = _GetTable();
}
else
{
dtTree = _GetTable(strORG_Parent_ID);
}
DataView dv = dtTree.DefaultView;
dv.RowFilter = "ORG_PARENT_ID <> 'MS00'";
DataTable dtDWZC = dv.ToTable(false, "ORG_ID", "ORG_NAME");
DataTable dtJld = MySQLHelper.ExecuteDataTable("select * from jld");
string json = "[";
for (int i = 0; i < dtDWZC.Rows.Count; i++)
{
json += "{\"value\":\"" + dtDWZC.Rows[i]["ORG_ID"] + "\",\"text\":\"" + dtDWZC.Rows[i]["ORG_NAME"] + "\"";
dv = dtJld.DefaultView;
dv.RowFilter = "ORG_ID='" + dtDWZC.Rows[i]["ORG_ID"] + "'";
DataTable dtTemp = dv.ToTable(false, "ID", "JLD_Name");
if (dtTemp.Rows.Count > 0)
{
json += ",\"children\": [";
for (int j = 0; j < dtTemp.Rows.Count; j++)
{
json += "{" + "\"value\":\"" + dtTemp.Rows[j]["ID"] + "\",\"text\":\"" + dtTemp.Rows[j]["JLD_Name"] + "\"},";
}
json = json.TrimEnd(',') + "]},";
}
}
json = json.TrimEnd(',') + "]";
context.Response.Write(json);
context.Response.End();
}
if (context.Request["action"] == "APPLogin")
{
JsEncryptHelper jsHelper = new JsEncryptHelper();
string userName = context.Request.Form["account"];
string passWord = context.Request.Form["password"];
string strtemp = "";
DataTable dtUser = MySQLHelper.ExecuteDataTable(stringSQL.strSQL_User + userName + "' or user_account='" + userName + "' or phoneNo='" + userName + "'");
if (dtUser.Rows.Count > 0)
{
//if (dtUser.Rows[0]["loginflag"].ToString() == "0" || dtUser.Rows[0]["loginflag"].ToString() == "")
//{
strtemp = dtUser.Rows[0]["pswd"].ToString();
if (dtUser.Rows[0]["pswd"].ToString() == passWord)
{
string strSQL = "insert into loginrecord (user_id,login_DateTime,IP) values (" + "'" + dtUser.Rows[0]["user_account"].ToString() + "','" + DateTime.Now + "')";
int num = MySQLHelper.ExecuteNonQuery(strSQL);
//string Json = "[{";
//Json += "\"statue\":\"OK\"," + "\"userName\":\"" + dtUser.Rows[0]["user_name"].ToString() + "\",";
//Json += "\"userAccount\":\"" + dtUser.Rows[0]["user_account"].ToString() + "\",";
//Json += "\"userOrgID\":\"" + dtUser.Rows[0]["ORG_ID"].ToString() + "\",";
//Json += "\"regDateTime\":\"" + dtUser.Rows[0]["regDateTime"].ToString() + "\"}]";
context.Response.Write("OK");
context.Response.End();
}
else
{
context.Response.Write("密码错误,请仔细想想....");
context.Response.End();
}
//}
//else
//{
// context.Response.Write("这个账户在别的客户端已登录");
// context.Response.End();
//}
}
else
{
context.Response.Write("没有这个用户,请仔细想想你注册时用名字....");
context.Response.End();
}
}
}
/// <summary>
/// 查询组织结构数据库表
/// </summary>
/// <returns></returns>
public DataTable _GetTable(string strORG_PARENT_ID = "MS00")
{
DataTable dtOrg = new DataTable();
if (strORG_PARENT_ID == "MS00")
{
dtOrg = MySQLHelper.ExecuteDataTable("select * from organization order by ID");
}
else
{
dtOrg = MySQLHelper.ExecuteDataTable("select * from organization where ORG_ID='" + strORG_PARENT_ID + "' or ORG_PARENT_ID='" + strORG_PARENT_ID + "'");
}
return dtOrg;
}
public bool IsReusable
{
get
{
return false;
}
}
}
}