//Get MultiLanguage
public static string GetLanguageString(string key)
{
if (null == languageHT[SessionUtil.LoginUserLanguageID])
{
languageHT.Add(SessionUtil.LoginUserLanguageID, new Hashtable());
}
Hashtable languageStringHT = (Hashtable)languageHT[SessionUtil.LoginUserLanguageID];
if (null == languageStringHT[key])
{
XmlDocument LanguageDoc = new XmlDocument(); //定义一个XmlDocument对象。
LanguageDoc.Load(HttpContext.Current.Server.MapPath(LanguageXmlFilePath));
XmlNode MeaasgeNode = LanguageDoc.SelectSingleNode("//Meaasge[ID='" + key + "']");
languageStringHT.Add(key, MeaasgeNode.ChildNodes.Item(SessionUtil.LoginUserLanguageID).InnerText);
}
return languageStringHT[key].ToString();
}
//Write log
public static void Write(string fileName, string messageID, string message, string userID)
{
String folder = ConstUtility.GetAppSettingsValue("LogOutputFolder");
if (userID == null || userID.Equals(String.Empty))
{
userID = "UNKNOWN";
}
if (!Directory.Exists(folder))
{
Directory.CreateDirectory(folder);
}
StringBuilder filePath = new StringBuilder(folder);
filePath.Append("//");
filePath.Append(fileName);
if (!File.Exists(filePath.ToString()))
{
using (StreamWriter sw = File.CreateText(filePath.ToString()))
{
sw.WriteLine("{0} {1} {2} {3}", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), userID, messageID, message);
}
}
else
{
using (StreamWriter w = File.AppendText(filePath.ToString()))
{
w.WriteLine("{0} {1} {2} {3}", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), userID, messageID, message);
}
}
}
//获取HTTP请求信息并处理
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text;
using System.Collections.Specialized;
using System.Collections;
/// <summary>
/// Summary description for HelloWorldHandler
/// </summary>
public class HelloWorldHandler : IHttpHandler
{
HttpRequest Request;
HttpResponse Response;
public HelloWorldHandler()
{
}
public void ProcessRequest(HttpContext context)
{
Request = context.Request;
Response = context.Response;
//获得请求的类型
int loop1, loop2;
NameValueCollection coll = Request.QueryString;
String[] arr1 = coll.AllKeys;
ArrayList list = new ArrayList();
for (loop1 = 0; loop1 < arr1.Length; loop1++)
{
String[] arr2 = coll.GetValues(arr1[loop1]);
for (loop2 = 0; loop2 < arr2.Length; loop2++)
{
list.Add(arr2[loop2]);
}
}
if (arr1.Length > 1)
{
if (arr1[0].Equals("action") && arr1[1].Equals("user"))
{
//获得请求的输入流内容
Stream str = Request.InputStream;
//接收消息主体字符串
string message = string.Empty;
//获得流长度
int strlen = Convert.ToInt32(str.Length);
//接收流的字节组
byte[] arr = new byte[strlen];
//解码实体
Encoding encoding = Encoding.GetEncoding("utf-8");
//获得字符组
char[] car;
string mobile = string.Empty;
string para = string.Empty;
switch (Convert.ToString(list[0]))
{
//登录
case "L1":
//读入字节组
str.Read(arr, 0, strlen);
//获得字符组
car = encoding.GetChars(arr);
//接收内容
message = new string(car);
mobile = Convert.ToString(list[1]);
try
{
//用户存在且在职
if (IsValidUser(mobile).Equals(2))
{
string time = DateTime.Now.ToString("yyyyMMdd");// Date.ToString().Replace("0:00:00", "");
Response.Write(time);
}
//用户存在且离职
else if (IsValidUser(mobile).Equals(1))
{
Response.Write("2");
}
//用户不存在
else
{
Response.Write("1");
}
}
catch (Exception ex)
{
Response.Write("1");
}
break;
case "U1":
//读入字节组
str.Read(arr, 0, strlen);
//获得字符组
car = encoding.GetChars(arr);
//接收内容
message = new string(car);
mobile = Convert.ToString(list[1]);
if (IsValidMobile(mobile))
{
//解析并插入数据
try
{
if (GetMessage(message, mobile).Equals(1))
{
Response.Write("0");
}
else
{
Response.Write("1");
}
}
catch (Exception ex)
{
Response.Write("1");
}
}
else
{
Response.Write("1");
}
break;
//获得竞争对手信息
case "U2":
//解析字节流
try
{
//读入字节组
str.Read(arr, 0, strlen);
//图片路径
string picPath = string.Empty;
if (strlen > 1)
{
if (Convert.ToInt32(arr[0]).Equals(0))//无图片
{
//获得字符组
car = encoding.GetChars(arr, 1, strlen - 1);
//接收内容
message = new string(car);
}
else if (Convert.ToInt32(arr[0]).Equals(1))//有图片
{
int count = BitConverter.ToInt32(arr, 1);
//获得字符组
car = encoding.GetChars(arr, 5, count);
//接收内容
message = new string(car);
//存储图片数组
byte[] pictureArr = new byte[strlen - 5 - count];
Array.Copy(arr, 5 + count, pictureArr, 0, strlen - 5 - count);
//图片路径
picPath = DateTime.Now.ToString("yyyyMMddHHmms") + ".jpeg";
//保存图片
string path = Request.MapPath("~" + "/UI/CompetitorImg/") + picPath;
System.IO.FileStream fs = System.IO.File.Create(path);
fs.Write(pictureArr, 0, pictureArr.Length);
fs.Close();
}
else
{
Response.Write("8");
}
mobile = Convert.ToString(list[1]);
if (IsValidMobile(mobile))
{
//解析并插入数据
if (GetCompetitionMessage(message, mobile, picPath).Equals(1))
{
Response.Write("0");
}
else
{
Response.Write("1");
}
}
else
{
Response.Write("1");
}
}
else
{
Response.Write("9");
}
}
catch (Exception ex)
{
Response.Write("1");
}
break;
case "D1":
if (arr1.Length.Equals(3))
{
if (arr1[2].Equals("para"))
{
mobile = Convert.ToString(list[1]);
para = Convert.ToString(list[2]);
Response.Write("Mobile is: " + mobile);
Response.Write("Para is: " + para);
}
}
break;
}
}
}
//Response.Write("</body>");
//Response.Write("</html>");
}
//解析数据
private int GetMessage(string message, string mobile)
{
//消息数组
string[] info = message.Split(new Char[] { ';' });
//电话
string mobileNo = mobile;
if (info.Length > 3)
{
//个数
int count = Convert.ToInt32(info[0]);
string time = info[1].Substring(0, 4) + "-" + info[1].Substring(4, 2) + "-" + info[1].Substring(6, 2);
//日期
DateTime date = Convert.ToDateTime(time);
//商品型号
string pCode = string.Empty;
//销售数量
int qTY = 0;
//是否结束
int flag = 1;
//发送成功标志
int succ = 1;
for (int i = 2; i < info.Length - 1; i++)
{
string[] detail = info[i].Split(new Char[] { ',' });
//判断是否最后一个
if (i.Equals(info.Length - 2))
{
if (detail.Length > 1)
{
pCode = detail[0];
qTY = Convert.ToInt32(detail[1]);
succ = InsertTable(mobile, date, count, pCode, qTY, 0);
if (succ.Equals(1))
{
return 1;//插入成功
}
}
}
else
{
if (detail.Length > 1)
{
pCode = detail[0];
qTY = Convert.ToInt32(detail[1]);
InsertTable(mobile, date, count, pCode, qTY, flag);
}
}
}
}
return 0;//失败
}
//验证手机号
private bool IsValidMobile(string mobile)
{
return new FacadeInterface().HaveMobilePhone(mobile);
}
//插入临时表
private int InsertTable(string mobile, DateTime date, int count, string proCode, int qTY, int flag)
{
return new FacadeInterface().InsertTable(mobile, date, count, proCode, qTY, flag);
}
public bool IsReusable
{
// To enable pooling, return true here.
// This keeps the handler in memory.
get { return false; }
}
//验证用户
private int IsValidUser(string mobile)
{
return new FacadeInterface().IsSaleAssistant(mobile);
}
//解析竞争对手信息
private int GetCompetitionMessage(string message, string mobile, string picPath)
{
//消息数组
string[] info = message.Split(new Char[] { '#' });
if (info.Length.Equals(5))
{
return InsertCompetition(mobile, info[0], info[1], Convert.ToDecimal(info[2]), info[3], picPath);
}
else
{
return 0;
}
//插入失败
return 0;
}
//插入竞争对手表
private int InsertCompetition(string mobile, string competitionName, string productName, decimal price, string remark, string picturePath)
{
//
return new FacadeInterface().InsertCompetition(competitionName, productName, price, remark, mobile, picturePath);
}
}
/// 读取Excel文件,并将读入的记录插入到悬案表中
public void InsertXuanAnFromExcel(ParameterT010B paraT010B)
{
//打开excel文件
OleDbConnection Excelconn =
new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" + paraT010B.ImportFilePath + "';Extended Properties='Excel 8.0;HDR=NO;IMEX=1'" + ";");
System.Data.OleDb.OleDbCommand cmd = null;
System.Data.OleDb.OleDbDataReader rdr = null;
try
{
//打开excel
Excelconn.Open();
cmd = Excelconn.CreateCommand();
//共有几个Sheet
DataTable dt = Excelconn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
int Sheetnum = dt.Rows.Count;
//弹出错误消息
string message = string.Empty;
//记录是否新增成功
bool succ = false;
//读取每个sheet
for (int i = 0; i < Sheetnum; i++)
{
//获取文件中的sheet名称
string sheetName = dt.Rows[i][2].ToString().Trim();
string newName = sheetName.Substring(0, sheetName.IndexOf("$")+2);
//.Print_Area,除去打印区域
if (sheetName.Trim().Equals(newName.Trim()))
{
cmd.CommandText = "SELECT * FROM " + "[" + sheetName + "]";
rdr = cmd.ExecuteReader();
rdr.Read();
//记录当前行
int countRow = 1;
//从第二行还是读取
while (rdr.Read())
{
countRow++;
//如果一行都为空,则返回执行下一行
if (rdr.GetValue(0).ToString().Trim().Equals(string.Empty) && rdr.GetValue(1).ToString().Trim().Equals(string.Empty) && rdr.GetValue(2).ToString().Trim().Equals(string.Empty) && rdr.GetValue(3).ToString().Trim().Equals(string.Empty) && rdr.GetValue(4).ToString().Trim().Equals(string.Empty) && rdr.GetValue(5).ToString().Trim().Equals(string.Empty) && rdr.GetValue(6).ToString().Trim().Equals(string.Empty) && rdr.GetValue(7).ToString().Trim().Equals(string.Empty))
{
continue;
}
//CustomerNo
if (rdr.GetValue(0).ToString().Trim() != string.Empty)
{
paraT010B.CustomerNO = rdr.GetValue(0).ToString().Trim();
}
else
{
paraT010B.CustomerNO = null;
}
//Proposer
if (rdr.GetValue(1).ToString().Trim() != string.Empty)
{
paraT010B.Presenter = rdr.GetValue(1).ToString();
}
else
{
message += "第"+countRow+"行中,单元格2不能为空!";
continue;//执行下一行
}
//ProposerDate
if (rdr.GetValue(2).ToString() != string.Empty)
{
try
{
DateTime presentTime = ConvertExcelDateToDate(rdr.GetValue(2).ToString());
paraT010B.PresentTime = presentTime;
}
catch
{
message += "第" + countRow + "行中,单元格3格式不对!";
continue;//执行下一行
}
}
else
{
message += "第" + countRow + "行中,单元格3格式不对!";
continue;//执行下一行
}
//DeadLineDate
if (rdr.GetValue(3).ToString() != string.Empty)
{
try
{
DateTime deadline = ConvertExcelDateToDate(rdr.GetValue(3).ToString());
paraT010B.Deadline = deadline;
}
catch
{
message += "第" + countRow + "行中,单元格4格式不对!";
continue;//执行下一行
}
}
else
{
message += "第" + countRow + "行中,单元格4格式不对!";
continue;//执行下一行
}
//Module
if (!rdr.GetValue(4).ToString().Equals(string.Empty))
{
paraT010B.ModuleID = Convert.ToInt32(rdr.GetValue(11));
}
else
{
message += "第" + countRow + "行中,单元格5不能为空!";
continue;//执行下一行
}
//IssueType
if (!rdr.GetValue(5).ToString().Equals(string.Empty))
{
paraT010B.ReportTypeID = Convert.ToInt32(rdr.GetValue(12));
}
else
{
message += "第" + countRow + "行中,单元格6不能为空!";
continue;//执行下一行
}
//Topic
if (rdr.GetValue(6).ToString().Trim() != string.Empty)
{
paraT010B.Subject = rdr.GetValue(6).ToString();
}
else
{
paraT010B.Subject = null;
message += "第" + countRow + "行中,单元格7不能为空!";
continue;//执行下一行
}
//Details
if (rdr.GetValue(7).ToString().Trim() != string.Empty)
{
paraT010B.Content = rdr.GetValue(7).ToString();
}
else
{
paraT010B.Content = null;
}
//插入新建的悬案
InsertXuanAnRecord(paraT010B);
succ = true;
}
rdr.Close();
}
}
if (message != string.Empty)
{
DeException dex = new DeException();
dex.Msg = "批量上载出错:"+message;
throw dex;
}
else if (message == string.Empty && succ)
{
DeException dex = new DeException();
dex.Msg = "批量上载成功!";
throw dex;
}
else
{
DeException dex = new DeException();
dex.Msg = "批量上载失败,请检查要上载的数据!";
throw dex;
}
}
catch (DeException dex)
{
//抛出异常
throw dex;
}
catch (Exception ex)
{
//抛出异常
throw new DeException(GetType().Name, ex.ToString(), MessageType.SystemError);
}
finally
{
//关闭连接
//rdr.Close();
Excelconn.Close();
}
}