纽威
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

363 lines
18 KiB

3 years ago
  1. using grsvr6Lib;
  2. using NFine.Application.ProductManage;
  3. using NFine.Code;
  4. using NFine.Data.Extensions;
  5. using NFine.Domain.Entity.ProductManage;
  6. using NFine.Domain.Entity.SystemManage;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Configuration;
  10. using System.Data;
  11. using System.Data.SqlClient;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Web.Mvc;
  15. using System.Xml;
  16. namespace NFine.Web.Areas.ProductManage.Controllers
  17. {
  18. public class DiscountRateController : ControllerBase
  19. {
  20. private DiscountRateApp discountrateApp = new DiscountRateApp();
  21. [HttpGet]
  22. [HandlerAjaxOnly]
  23. public ActionResult GetGridJson(Pagination pagination, string queryJson)
  24. {
  25. var data = new
  26. {
  27. rows = discountrateApp.GetList(pagination, queryJson),
  28. total = pagination.total,
  29. page = pagination.page,
  30. records = pagination.records
  31. };
  32. return Content(data.ToJson());
  33. }
  34. [HttpGet]
  35. [HandlerAjaxOnly]
  36. public ActionResult GetSelectJsonCustomer()
  37. {
  38. DataTable data = discountrateApp.GetListForCustomer();
  39. List<object> list = new List<object>();
  40. foreach (DataRow row in data.Rows)
  41. {
  42. list.Add(new { id = row["F_CusCode"], text = row["F_CusName"] });
  43. }
  44. return Content(list.ToJson());
  45. }
  46. [HttpGet]
  47. [HandlerAjaxOnly]
  48. public ActionResult GetFormJson(string keyValue)
  49. {
  50. var data = discountrateApp.GetForm(keyValue);
  51. return Content(data.ToJson());
  52. }
  53. [HttpPost]
  54. [HandlerAjaxOnly]
  55. [ValidateAntiForgeryToken]
  56. public ActionResult SubmitForm(ICSDiscountRateListEntity discountrateListEntity, string keyValue)
  57. {
  58. List<ICSDiscountRateEntity> list = new List<ICSDiscountRateEntity>();
  59. ICSDiscountRateEntity discountrateEntity1 = new ICSDiscountRateEntity();
  60. discountrateEntity1.CusCode = discountrateListEntity.CusCode;
  61. discountrateEntity1.StartValue = 1.00M;
  62. discountrateEntity1.EndValue = 1.49M;
  63. discountrateEntity1.WHType = "10";
  64. discountrateEntity1.Discount = discountrateListEntity.DiscountC1;
  65. list.Add(discountrateEntity1);
  66. ICSDiscountRateEntity discountrateEntity2 = new ICSDiscountRateEntity();
  67. discountrateEntity2.CusCode = discountrateListEntity.CusCode;
  68. discountrateEntity2.StartValue = 1.50M;
  69. discountrateEntity2.EndValue = 1.99M;
  70. discountrateEntity2.WHType = "10";
  71. discountrateEntity2.Discount = discountrateListEntity.DiscountC2;
  72. list.Add(discountrateEntity2);
  73. ICSDiscountRateEntity discountrateEntity3 = new ICSDiscountRateEntity();
  74. discountrateEntity3.CusCode = discountrateListEntity.CusCode;
  75. discountrateEntity3.StartValue = 2.00M;
  76. discountrateEntity3.EndValue = 2.50M;
  77. discountrateEntity3.WHType = "10";
  78. discountrateEntity3.Discount = discountrateListEntity.DiscountC3;
  79. list.Add(discountrateEntity3);
  80. ICSDiscountRateEntity discountrateEntity4 = new ICSDiscountRateEntity();
  81. discountrateEntity4.CusCode = discountrateListEntity.CusCode;
  82. discountrateEntity4.StartValue = 1.00M;
  83. discountrateEntity4.EndValue = 1.49M;
  84. discountrateEntity4.WHType = "12";
  85. discountrateEntity4.Discount = discountrateListEntity.DiscountP1;
  86. list.Add(discountrateEntity4);
  87. ICSDiscountRateEntity discountrateEntity5 = new ICSDiscountRateEntity();
  88. discountrateEntity5.CusCode = discountrateListEntity.CusCode;
  89. discountrateEntity5.StartValue = 1.50M;
  90. discountrateEntity5.EndValue = 1.99M;
  91. discountrateEntity5.WHType = "12";
  92. discountrateEntity5.Discount = discountrateListEntity.DiscountP2;
  93. list.Add(discountrateEntity5);
  94. ICSDiscountRateEntity discountrateEntity6 = new ICSDiscountRateEntity();
  95. discountrateEntity6.CusCode = discountrateListEntity.CusCode;
  96. discountrateEntity6.StartValue = 2.00M;
  97. discountrateEntity6.EndValue = 2.50M;
  98. discountrateEntity6.WHType = "12";
  99. discountrateEntity6.Discount = discountrateListEntity.DiscountP3;
  100. list.Add(discountrateEntity6);
  101. discountrateApp.SubmitForm(list, keyValue);
  102. return Success("Successful operation.");
  103. }
  104. [HttpPost]
  105. [HandlerAjaxOnly]
  106. [ValidateAntiForgeryToken]
  107. public ActionResult SubmitForms(ICSDiscountRateEntity discountrateEntity, string keyValue)
  108. {
  109. discountrateApp.SubmitForm(discountrateEntity, keyValue);
  110. return Success("Successful operation.");
  111. }
  112. [HttpPost]
  113. [HandlerAjaxOnly]
  114. [HandlerAuthorize]
  115. [ValidateAntiForgeryToken]
  116. public ActionResult DeleteForm(string keyValue)
  117. {
  118. discountrateApp.DeleteForm(keyValue);
  119. return Success("Delete success.");
  120. }
  121. public ActionResult Forms()
  122. {
  123. return View();
  124. }
  125. [HttpPost]
  126. [HandlerAjaxOnly]
  127. [HandlerAuthorize]
  128. [ValidateAntiForgeryToken]
  129. public ActionResult chulingPrintForm(string keyValue)
  130. {
  131. var data = discountrateApp.GetForm(keyValue);
  132. string FileValue, PrintValue, ParaName, ParaValue;
  133. FileValue = FileToString("/Frp/lot.fr3");
  134. ParaName = "ShopName`~PrintDepositAdd`~PrintPaperNo`~Title"; //`~为各参数的分隔符
  135. ParaValue = "测试酒楼"
  136. + "`~说明:本单据为贵客押金收取凭证,盖章有效。退房时请出示,遗失者自负,请妥善保存。退房时间为12:00时,延时退房18:00时以前按半天房费收取,18:00时以后算全天房价。押金单有效期为一个月,过期作废。 贵重物品请交前台寄存,未寄存丢失自负。 谢谢!"
  137. + "`~身份证:4325011980639512"
  138. + "`~押金单";
  139. DataTable dt = SqlHelper.GetDataTableBySql("SELECT * FROM dbo.ICSDiscountRate where F_Id='" + keyValue + "'");
  140. PrintValue = TableToXml(dt);
  141. string ScriptStr;
  142. string PictureStr="";
  143. ScriptStr = "<script language='javascript'>window.onload = function() { try { var ObjPrintMange = new ActiveXObject('WebPrint.WebPrintUnit'); } catch(e) { if( confirm('打印控件未安装,现在下载吗?') ) { window.location='../Frp/PrintActivex.exe'; } return; } var OldVersion=ObjPrintMange.Version; NewVerion='5.0(2011-08-01)'; if(OldVersion < NewVerion) { ObjPrintMange = null; alert('打印控件需升级。请先进行下载,下载后关闭IE,然后安装升级版。'); window.location='../Frp/PrintActivex.exe'; return; } "
  144. + " ObjPrintMange.CheckReg('苏州智合诚信息科技有限公司', '1B98963EDF11C830F8918C3E0BE28ED8'); " //注册码
  145. //+ "ObjPrintMange.MasterOptions(1, 'TransNO', 0 );" //主从关系,参数:主数据集序号,关联字段名,字段是否为数值型
  146. // + PictureStr
  147. //+ "ObjPrintMange.AddPicturePrint('PicTitle', 0, 'Title.bmp','1', 1 );" //增加单个图片打印,参数:报表中图片对象名,数据表的字段(为0),图片文件名,数据集序号,是否清除旧数据(第1次调用时为1,其它时候则为0)
  148. //+ "ObjPrintMange.AddPicturePrint('PicMaterial', 0, '2013-01-18-272b936d03-7208-4452-9d01-1197fbb63bc3.jpg','1', 1 );" //增加数据表中的图片打印,参数:报表中图片对象名,数据表的字段(为1),图片文件名所对应的字段名,数据集序号,是否清除旧数据(第1次调用时为1,其它时候则为0)
  149. //+ "ObjPrintMange.AddPicturePrint('Picture1', 1, 'EATTRIBUTE1','1', 1 );"
  150. + "ObjPrintMange.ShowReport('"
  151. + FileValue + "' , '"
  152. + ParaName + "', '"
  153. + ParaValue + "', '"
  154. //+ PrintValue + "', '"
  155. + PrintValue + "', '','', '', '', '');"
  156. + "ObjPrintMange = null; } </script>";
  157. ScriptStr = ScriptStr.Replace(System.Environment.NewLine, string.Empty);
  158. Response.Write(ScriptStr);
  159. return Success("Delete success.");
  160. }
  161. private string FileToString(string FileName)
  162. {
  163. try
  164. {
  165. string[] ByteStr = new string[256];
  166. for (int i = 0; i < 256; i++)
  167. {
  168. if (i == 0)
  169. ByteStr[i] = "00";
  170. else if (i < 16)
  171. ByteStr[i] = "0" + Convert.ToString(i, 16).ToUpper();
  172. else
  173. ByteStr[i] = Convert.ToString(i, 16).ToUpper();
  174. }
  175. if (System.IO.File.Exists(Server.MapPath(FileName)) == false)
  176. return "";
  177. byte[] FileValue = System.IO.File.ReadAllBytes(Server.MapPath(FileName));
  178. StringBuilder FileStr = new StringBuilder();
  179. for (int FileRecn = 0; FileRecn < FileValue.Length; FileRecn++)
  180. {
  181. FileStr.Append(ByteStr[FileValue[FileRecn]]);
  182. }
  183. FileValue = null;
  184. return FileStr.ToString();
  185. }
  186. catch (Exception ex)
  187. {
  188. throw new Exception(ex.Message);
  189. }
  190. }
  191. private string TableToXml(DataTable DtTable)
  192. {
  193. StringBuilder PrintStr = new StringBuilder();
  194. XmlWriterSettings setting = new XmlWriterSettings();
  195. setting.Indent = true;
  196. setting.OmitXmlDeclaration = true;
  197. using (XmlWriter PrintXml = XmlWriter.Create(PrintStr, setting))
  198. {
  199. PrintXml.WriteStartElement("xml");
  200. PrintXml.WriteAttributeString("xmlns", "s", null, "u");
  201. PrintXml.WriteAttributeString("xmlns", "dt", null, "u");
  202. PrintXml.WriteAttributeString("xmlns", "rs", null, "u");
  203. PrintXml.WriteAttributeString("xmlns", "z", null, "#R");
  204. PrintXml.WriteStartElement("s", "Schema", null);
  205. PrintXml.WriteAttributeString("id", "RowsetSchema");
  206. PrintXml.WriteStartElement("s", "ElementType", null);
  207. PrintXml.WriteAttributeString("name", "row");
  208. PrintXml.WriteAttributeString("content", "eltOnly");
  209. PrintXml.WriteAttributeString("rs", "updatable", null, "true");
  210. foreach (DataColumn Column in DtTable.Columns)
  211. {
  212. if (Column.DataType.Name == "Int64" || Column.DataType.Name == "Boolean"
  213. || Column.DataType.Name == "String" || Column.DataType.Name == "DateTime"
  214. || Column.DataType.Name == "Decimal" || Column.DataType.Name == "Double"
  215. || Column.DataType.Name == "Int32" || Column.DataType.Name == "Single"
  216. || Column.DataType.Name == "Int16" || Column.DataType.Name == "Byte")
  217. {
  218. PrintXml.WriteStartElement("s", "AttributeType", null);
  219. PrintXml.WriteAttributeString("name", Column.ColumnName);
  220. PrintXml.WriteAttributeString("rs", "number", null, (Column.Ordinal + 1).ToString());
  221. PrintXml.WriteAttributeString("rs", "nullable", null, "true");
  222. PrintXml.WriteAttributeString("rs", "maydefer", null, "true");
  223. PrintXml.WriteAttributeString("rs", "writeunknown", null, "true");
  224. PrintXml.WriteAttributeString("rs", "basetable", null, DtTable.TableName);
  225. PrintXml.WriteAttributeString("rs", "basecolumn", null, Column.ColumnName);
  226. if (Column.DataType.Name == "Int64")
  227. { //bigint
  228. PrintXml.WriteStartElement("s", "datatype", null);
  229. PrintXml.WriteAttributeString("dt", "type", null, "i8");
  230. PrintXml.WriteAttributeString("dt", "maxLength", null, "8");
  231. PrintXml.WriteEndElement();
  232. }
  233. else if (Column.DataType.Name == "Boolean")
  234. { //bit
  235. PrintXml.WriteStartElement("s", "datatype", null);
  236. PrintXml.WriteAttributeString("dt", "type", null, "boolean");
  237. PrintXml.WriteAttributeString("dt", "maxLength", null, "2");
  238. PrintXml.WriteEndElement();
  239. }
  240. else if (Column.DataType.Name == "String")
  241. { //char
  242. PrintXml.WriteStartElement("s", "datatype", null);
  243. PrintXml.WriteAttributeString("dt", "type", null, "string");
  244. PrintXml.WriteAttributeString("dt", "maxLength", null, Column.MaxLength.ToString());
  245. PrintXml.WriteEndElement();
  246. }
  247. else if (Column.DataType.Name == "DateTime")
  248. { //dateTime
  249. PrintXml.WriteStartElement("s", "datatype", null);
  250. PrintXml.WriteAttributeString("dt", "type", null, "dateTime");
  251. PrintXml.WriteAttributeString("dt", "maxLength", null, "16");
  252. PrintXml.WriteEndElement();
  253. }
  254. else if (Column.DataType.Name == "Decimal")
  255. { //Decimal
  256. PrintXml.WriteStartElement("s", "datatype", null);
  257. PrintXml.WriteAttributeString("dt", "type", null, "number");
  258. PrintXml.WriteAttributeString("dt", "maxLength", null, "19");
  259. PrintXml.WriteEndElement();
  260. }
  261. else if (Column.DataType.Name == "Double")
  262. { //Float
  263. PrintXml.WriteStartElement("s", "datatype", null);
  264. PrintXml.WriteAttributeString("dt", "type", null, "float");
  265. PrintXml.WriteAttributeString("dt", "maxLength", null, "8");
  266. PrintXml.WriteEndElement();
  267. }
  268. else if (Column.DataType.Name == "Int32")
  269. { //int
  270. PrintXml.WriteStartElement("s", "datatype", null);
  271. PrintXml.WriteAttributeString("dt", "type", null, "int");
  272. PrintXml.WriteAttributeString("dt", "maxLength", null, "4");
  273. PrintXml.WriteEndElement();
  274. }
  275. else if (Column.DataType.Name == "Single")
  276. { //Real
  277. PrintXml.WriteStartElement("s", "datatype", null);
  278. PrintXml.WriteAttributeString("dt", "type", null, "r4");
  279. PrintXml.WriteAttributeString("dt", "maxLength", null, "4");
  280. PrintXml.WriteEndElement();
  281. }
  282. else if (Column.DataType.Name == "Int16")
  283. { //smallint
  284. PrintXml.WriteStartElement("s", "datatype", null);
  285. PrintXml.WriteAttributeString("dt", "type", null, "i2");
  286. PrintXml.WriteAttributeString("dt", "maxLength", null, "2");
  287. PrintXml.WriteEndElement();
  288. }
  289. else if (Column.DataType.Name == "Byte")
  290. { //tinyint
  291. PrintXml.WriteStartElement("s", "datatype", null);
  292. PrintXml.WriteAttributeString("dt", "type", null, "ui1");
  293. PrintXml.WriteAttributeString("dt", "maxLength", null, "1");
  294. PrintXml.WriteEndElement();
  295. }
  296. PrintXml.WriteEndElement();
  297. }
  298. }
  299. PrintXml.WriteEndElement();
  300. PrintXml.WriteEndElement();
  301. PrintXml.WriteStartElement("rs", "data", null);
  302. foreach (DataRow Row in DtTable.Rows)
  303. {
  304. PrintXml.WriteStartElement("z", "row", null);
  305. foreach (DataColumn Column in DtTable.Columns)
  306. {
  307. if (Row.IsNull(Column) == true)
  308. continue;
  309. if (Column.DataType.Name == "Int64" || Column.DataType.Name == "Boolean"
  310. || Column.DataType.Name == "String" || Column.DataType.Name == "DateTime"
  311. || Column.DataType.Name == "Decimal" || Column.DataType.Name == "Double"
  312. || Column.DataType.Name == "Int32" || Column.DataType.Name == "Single"
  313. || Column.DataType.Name == "Int16" || Column.DataType.Name == "Byte")
  314. {
  315. if (Column.DataType.Name == "DateTime")
  316. {
  317. DateTime TmpDateTime = System.Convert.ToDateTime(Row[Column]);
  318. string TmpStr = TmpDateTime.ToString("yyyy-MM-dd") + "T" + TmpDateTime.ToString("HH:mm:ss");
  319. PrintXml.WriteAttributeString(Column.ColumnName, TmpStr);
  320. }
  321. else
  322. {
  323. PrintXml.WriteAttributeString(Column.ColumnName, Row[Column].ToString());
  324. }
  325. }
  326. }
  327. PrintXml.WriteEndElement();
  328. }
  329. PrintXml.WriteEndElement();
  330. PrintXml.WriteEndElement();
  331. }
  332. return PrintStr.ToString();
  333. }
  334. }
  335. }