市长热线演示版

FaxSend.aspx.cs 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Data;
  8. using HySoft.Common;
  9. using System.IO;
  10. namespace HySoft.BaseCallCenter.Web.faxmanage
  11. {
  12. public partial class FaxSend : System.Web.UI.Page
  13. {
  14. protected void Page_Load(object sender, EventArgs e)
  15. {
  16. if (!Page.IsPostBack)
  17. {
  18. BindBase();
  19. }
  20. }
  21. /// <summary>
  22. /// 时间绑定
  23. /// </summary>
  24. private void BindBase()
  25. {
  26. txtDate.Value = DateTime.Now.ToString("yyyy-MM-dd");
  27. selectHour.Items.Clear();
  28. for (int i = 0; i < 24; i++)
  29. {
  30. selectHour.Items.Add(new ListItem(i.ToString(), i.ToString()));
  31. }
  32. selectHour.Value = DateTime.Now.Hour.ToString();
  33. selectMin.Items.Clear();
  34. for (int i = 0; i < 60; i++)
  35. {
  36. selectMin.Items.Add(new ListItem(i.ToString(), i.ToString()));
  37. }
  38. selectMin.Value = DateTime.Now.Minute.ToString();
  39. }
  40. public void Button1_Click(object sender, EventArgs e)
  41. {
  42. if (!string.IsNullOrEmpty(txtTelephone.Value))
  43. {
  44. SaveSendFax();
  45. }
  46. }
  47. #region 验证传真号码
  48. public string[] CheckFaxTelephone(string arrtelephone)
  49. {
  50. string[] res = new string[3];
  51. res[0] = "";
  52. res[1] = "";
  53. res[2] = "";
  54. DataTable dt = new DataTable();
  55. try
  56. {
  57. //全角转半角
  58. arrtelephone = Common.StringUtil.ToDBC(arrtelephone).Replace("?", "").Replace("-", "");
  59. arrtelephone += "!@#";
  60. arrtelephone = arrtelephone.Replace(";!@#", "").Replace("!@#", "");
  61. if (arrtelephone.Trim() != "")
  62. {
  63. string[] arrtel = arrtelephone.Split(',');
  64. for (int arrindex = 0; arrindex < arrtel.Length; arrindex++)
  65. {
  66. string tel = arrtel[arrindex];
  67. if (VerificationFax(tel))
  68. {
  69. if (tel.Length > 6)
  70. {
  71. dt = new BLL.T_Cus_CustomerBase().GetList("F_Fax like '%" + tel + "%' ").Tables[0];
  72. if (dt.Rows.Count > 0)
  73. {
  74. res[0] += tel + ",";
  75. res[1] += dt.Rows[0]["F_CustomerID"].ToString().Replace(",", "") + ",";
  76. res[2] += dt.Rows[0]["F_CustomerName"].ToString().Replace(",", "") + ",";
  77. }
  78. else
  79. {
  80. res[0] += tel + ",";
  81. res[1] += ",";
  82. res[2] += ",";
  83. }
  84. dt.Clear();
  85. dt.Dispose();
  86. }
  87. else
  88. {
  89. res[0] += tel + ",";
  90. res[1] += ",";
  91. res[2] += ",";
  92. }
  93. }
  94. }
  95. }
  96. }
  97. catch
  98. { }
  99. finally
  100. {
  101. dt.Clear();
  102. dt.Dispose();
  103. }
  104. return res;
  105. }
  106. public static string RegexStringFax = "^[0-9]*$";
  107. public bool VerificationFax(string fax)
  108. {
  109. bool bl = false;
  110. bl = System.Text.RegularExpressions.Regex.IsMatch(fax, RegexStringFax, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
  111. return bl;
  112. }
  113. #endregion
  114. /// <summary>
  115. /// 保存传真
  116. /// </summary>
  117. private void SaveSendFax()
  118. {
  119. try
  120. {
  121. string path = txtF_FilePath.Value;
  122. if (path.Trim() == "")
  123. {
  124. MessageBoxToWindow("请选择传真文件", "提示!", "catch");
  125. }
  126. else
  127. {
  128. string arrtelephone = "";
  129. string arrcustomerid = "";
  130. string arrcustomername = "";
  131. //验证传真格式及获取客户信息
  132. var res = CheckFaxTelephone(txtTelephone.Value);
  133. if (res[0] != "")
  134. {
  135. arrtelephone = res[0];
  136. arrcustomerid = res[1];
  137. arrcustomername = res[2];
  138. string remark = txtRemark.Value;
  139. string filetype = tishi1.Value;
  140. string filesize = tishi2.Value;
  141. string type = "0";
  142. string date = "";
  143. if (rbSendType_1.Checked)
  144. {
  145. type = "1";
  146. date = txtDate.Value + " " + selectHour.Value + ":" + selectMin.Value + ":00";
  147. }
  148. arrtelephone += "!@#";
  149. arrtelephone = arrtelephone.Replace(",!@#", "").Replace("!@#", "");
  150. arrcustomerid += "!@#";
  151. arrcustomerid = arrcustomerid.Replace(",!@#", "").Replace("!@#", "");
  152. arrcustomername += "!@#";
  153. arrcustomername = arrcustomername.Replace(",!@#", "").Replace("!@#", "");
  154. string[] arrtel = arrtelephone.Split(',');
  155. string[] arrid = arrcustomerid.Split(',');
  156. string[] arrname = arrcustomername.Split(',');
  157. DataTable dt = new DataTable();
  158. try
  159. {
  160. byte[] filebytes = null;
  161. string filePath = null;
  162. try
  163. {
  164. string _FaxFileName = "";
  165. string _Path = "\\FaxSourceFile\\" + DateTime.Now.ToString("yyyyMM");
  166. string _SavePath = AppDomain.CurrentDomain.BaseDirectory + _Path;
  167. if (!Directory.Exists(_SavePath))
  168. {
  169. Directory.CreateDirectory(_SavePath);
  170. }
  171. filetype = path.Substring(path.LastIndexOf(".") + 1);
  172. string _xdPath = _Path + "\\" + Guid.NewGuid().ToString().Replace("-", "") + "." + filetype;
  173. _FaxFileName = AppDomain.CurrentDomain.BaseDirectory + _xdPath;
  174. //获得上传文件的大小
  175. filesize = txtF_FilePath.PostedFile.ContentLength.ToString();
  176. string sext = spanExt.InnerHtml.Trim();
  177. sext += "!@#";
  178. sext = sext.Replace(";!@#", "").Replace("!@#", "");
  179. string[] temp = sext.Split(';');
  180. //设置上传的文件是否是允许的格式
  181. bool flag = false;
  182. //判断上传的文件是否是允许的格式
  183. foreach (string data in temp)
  184. {
  185. if (data.ToLower() == filetype.ToLower())
  186. {
  187. flag = true;
  188. break;
  189. }
  190. }
  191. if (!flag)
  192. {
  193. MessageBoxToWindow("传真文件格式不正确,请选择正确格式文件" + spanExt.InnerHtml.Trim().ToUpper(), "提示!", "catch");
  194. }
  195. else
  196. {
  197. int l = Convert.ToInt32(spanSize.InnerHtml.Trim()) * 1024;
  198. if (Convert.ToInt32(filesize) < l)
  199. {
  200. txtF_FilePath.PostedFile.SaveAs(_FaxFileName);
  201. filePath = _FaxFileName;
  202. if (!string.IsNullOrEmpty(filePath))
  203. {
  204. FileInfo _file = new FileInfo(filePath);
  205. if (!_file.Exists)
  206. {
  207. MessageBoxToWindow("当前传真文件已不存在", "提示!", "catch");
  208. }
  209. else
  210. {
  211. try
  212. {
  213. FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
  214. byte[] data = new byte[fs.Length];
  215. fs.Read(data, 0, data.Length);
  216. filebytes = data;
  217. #region 上传传真文件
  218. int start = path.LastIndexOf("\\") + 1;
  219. int end = path.Length;
  220. string filename = path.Substring(start, end - start).Replace("|", "");
  221. //上传文件
  222. WebReferenceFax.FaxService ws = new WebReferenceFax.FaxService();
  223. string newfilepath = "";
  224. string newtiffilepath = "";
  225. string wsres = ws.UploadFile(filename, filebytes);
  226. if (wsres != "")
  227. {
  228. string[] arr = wsres.Split('|');
  229. if (arr.Length > 0)
  230. {
  231. if (arr[0] == "0")
  232. {
  233. newfilepath = arr[1];
  234. newtiffilepath = newfilepath.Substring(0, newfilepath.LastIndexOf(".")) + ".tif";
  235. newtiffilepath = newtiffilepath.Replace("\\LocalFile\\", "\\TifFile\\");
  236. int MaxSendCounts = 3;
  237. for (int arrindex = 0; arrindex < arrtel.Length; arrindex++)
  238. {
  239. string tel = arrtel[arrindex];
  240. string customerid = arrid[arrindex];
  241. string customername = arrname[arrindex];
  242. Model.T_Fax_SendFaxTask model = new Model.T_Fax_SendFaxTask();
  243. model.FaxID = 0;
  244. model.TelNum = tel;
  245. model.FilePath = newfilepath;
  246. model.TifFilePath = newtiffilepath;
  247. model.CommitTime = DateTime.Now;
  248. model.State = 0;
  249. model.SendTime = DateTime.Now;
  250. model.Info = "立即传真";
  251. if (type == "1")
  252. {
  253. model.SendTime = Convert.ToDateTime(date);
  254. model.Info = "定时传真";
  255. }
  256. model.LastSentTime = null;
  257. model.CurSentCount = 0;
  258. model.MaxSendCount = MaxSendCounts;
  259. model.F_UserID = null;
  260. LoginUser p_LoginUser = new LoginUser(this.Context);
  261. if (p_LoginUser != null)
  262. {
  263. model.F_UserID = p_LoginUser.UserID;
  264. }
  265. model.F_CustomerID = null;
  266. if (customerid.Trim() != "")
  267. {
  268. model.F_CustomerID = Convert.ToInt32(customerid);
  269. }
  270. model.F_Name = customername;
  271. model.FileSize = Convert.ToInt32(filesize);
  272. model.FileType = filetype;
  273. model.FileState = 0;
  274. model.Remark = remark;
  275. model.FileName = filename;
  276. int r = new BLL.T_Fax_SendFaxTask().Add(model);
  277. }
  278. MessageBoxToWindow("新增成功", "新增提示!", "success");
  279. }
  280. else
  281. {
  282. MessageBoxToWindow("上传传真文件失败:" + arr[1], "新增提示!", "error");
  283. }
  284. }
  285. else
  286. {
  287. MessageBoxToWindow("上传传真文件失败:返回失败", "新增提示!", "error");
  288. }
  289. }
  290. else
  291. {
  292. MessageBoxToWindow("上传传真文件失败:请求服务失败", "新增提示!", "error");
  293. }
  294. if (newfilepath == "" || newtiffilepath == "")
  295. {
  296. MessageBoxToWindow("上传传真文件失败:无法获取路径", "新增提示!", "error");
  297. }
  298. #endregion
  299. }
  300. catch
  301. {
  302. MessageBoxToWindow("读取传真文件失败", "提示!", "error");
  303. }
  304. }
  305. }
  306. else
  307. {
  308. MessageBoxToWindow("读取文件失败", "提示!", "error");
  309. }
  310. }
  311. else
  312. {
  313. MessageBoxToWindow("当前传真文件不能大于" + spanSize.InnerHtml.Trim() + "KB", "提示!", "catch");
  314. }
  315. }
  316. }
  317. catch
  318. {
  319. //异常
  320. }
  321. }
  322. catch
  323. {
  324. MessageBoxToWindow("发送传真异常:查看传真服务是否启动", "提示!", "catch");
  325. }
  326. finally
  327. {
  328. dt.Clear();
  329. dt.Dispose();
  330. }
  331. }
  332. else
  333. {
  334. MessageBoxToWindow("没有正确格式的传真号码", "提示!", "catch");
  335. }
  336. }
  337. }
  338. catch (Exception ex)
  339. {
  340. Common.SysLog.WriteLog(ex);
  341. MessageBoxToWindow("发送传真异常", "提示!", "catch");
  342. }
  343. }
  344. #region 弹出对话框
  345. /// <summary>
  346. /// 弹出对话框
  347. /// </summary>
  348. /// <param name="title"></param>
  349. /// <param name="content"></param>
  350. /// <param name="type"></param>
  351. public void MessageBoxToWindow(string title, string content, string type)
  352. {
  353. string script = "";
  354. switch (type)
  355. {
  356. case "error"://失败
  357. type = "error";
  358. script = "<script type='text/javascript'> $.ligerDialog.alert('" + title + "','" + content + "','" + type + "');</script>";
  359. break;
  360. case "success"://成功
  361. type = "info";
  362. script = "<script type='text/javascript'> $.ligerDialog.alert('" + title + "','" + content + "','" + type + "');</script>";
  363. break;
  364. case "catch"://异常
  365. type = "warning";
  366. script = "<script type='text/javascript'> $.ligerDialog.alert('" + title + "','" + content + "','" + type + "');</script>";
  367. break;
  368. default:
  369. type = "question";
  370. break;
  371. }
  372. ClientScript.RegisterClientScriptBlock(this.GetType(), "", script);
  373. }
  374. #endregion
  375. }
  376. }