using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
using System.Web;
using UAS_LabelMachine.Entity;
namespace UAS_LabelMachine.PublicMethod
{
public class HttpHandler : IHttpHandler
{
///
/// 您将需要在网站的 Web.config 文件中配置此处理程序
/// 并向 IIS 注册它,然后才能使用它。有关详细信息,
/// 请参见下面的链接: http://go.microsoft.com/?linkid=8101007
///
public bool IsReusable
{
// 如果无法为其他请求重用托管处理程序,则返回 false。
// 如果按请求保留某些状态信息,则通常这将为 false。
get { return true; }
}
public void ProcessRequest(HttpContext context)
{
}
public static bool CheckUserLogin(string UserName, string PassWord, string Master, out string oMsg)
{
oMsg = "";
try
{
string url = DataHelper.ERPAddesss + "mobile/login.action";//html调用的地址
HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(url);
if (webrequest == null)
{
return false;
}
webrequest.Method = "POST";
webrequest.Timeout = 1000;
webrequest.ContentType = "application/x-www-form-urlencoded";
System.Collections.Hashtable pars = new System.Collections.Hashtable();
pars.Add("username", UserName);
pars.Add("password", PassWord);
pars.Add("master", Master);
string buffer = "";
//发送POST数据
if (!(pars == null || pars.Count == 0))
{
foreach (string key in pars.Keys)
{
buffer = buffer + "&" + key + "=" + pars[key].ToString();
}
byte[] data = Encoding.UTF8.GetBytes(buffer);
using (Stream stream = webrequest.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
}
string[] values = webrequest.Headers.GetValues("Content-Type");
WebResponse myResponse = webrequest.GetResponse();
using (Stream resStream = myResponse.GetResponseStream())//得到回写的流
{
StreamReader newReader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
string Content = newReader.ReadToEnd();
Dictionary dic = new Dictionary();
dic = BaseUtil.ToDictionary(Content);
if (!dic.ContainsKey("erpaccount"))
{
oMsg = dic["reason"].ToString();
return false;
}
newReader.Close();
}
}
catch (Exception ex)
{
LogManager.DoLog(ex.Message.ToString());
}
return true;
}
public static bool GenDownLoadLinK(string Inoutno)
{
SystemInf.dh.ExecuteSql("delete from ProdDownLink where pl_inoutno='" + Inoutno + "'", "delete");
SystemInf.dh.ExecuteSql("insert into ProdDownLink(pl_inoutno,pl_outboxcode) select distinct '" + Inoutno + "',pib_outboxcode1 from prodiobarcode where pib_inoutno='" + Inoutno + "'", "insert");
SystemInf.dh.GetConfig("DownLoadLink", "Prodinout!Down");
string url = SystemInf.dh.GetConfig("DownLoadLink", "Prodinout!Down") + "/common/form/reqDemo.action?Pi_inoutno=" + Inoutno;//html调用的地址
HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(url);
try
{
if (webrequest == null)
{
return false;
}
WebResponse myResponse = webrequest.GetResponse();
}
catch (Exception e)
{
LogManager.DoLog(e.Message + e.StackTrace);
}
return true;
}
}
}