|
|
using grsvr6Lib; using NFine.Application.ProductManage; using NFine.Code; using NFine.Data.Extensions; using NFine.Domain.Entity.ProductManage; using NFine.Domain.Entity.SystemManage; using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Text; using System.Web.Mvc; using System.Xml;
namespace NFine.Web.Areas.ProductManage.Controllers { public class DiscountRateController : ControllerBase { private DiscountRateApp discountrateApp = new DiscountRateApp();
[HttpGet] [HandlerAjaxOnly] public ActionResult GetGridJson(Pagination pagination, string queryJson) { var data = new { rows = discountrateApp.GetList(pagination, queryJson), total = pagination.total, page = pagination.page, records = pagination.records }; return Content(data.ToJson()); } [HttpGet] [HandlerAjaxOnly] public ActionResult GetSelectJsonCustomer() { DataTable data = discountrateApp.GetListForCustomer(); List<object> list = new List<object>(); foreach (DataRow row in data.Rows) { list.Add(new { id = row["F_CusCode"], text = row["F_CusName"] }); } return Content(list.ToJson()); }
[HttpGet] [HandlerAjaxOnly] public ActionResult GetFormJson(string keyValue) { var data = discountrateApp.GetForm(keyValue); return Content(data.ToJson()); }
[HttpPost] [HandlerAjaxOnly] [ValidateAntiForgeryToken] public ActionResult SubmitForm(ICSDiscountRateListEntity discountrateListEntity, string keyValue) { List<ICSDiscountRateEntity> list = new List<ICSDiscountRateEntity>(); ICSDiscountRateEntity discountrateEntity1 = new ICSDiscountRateEntity(); discountrateEntity1.CusCode = discountrateListEntity.CusCode; discountrateEntity1.StartValue = 1.00M; discountrateEntity1.EndValue = 1.49M; discountrateEntity1.WHType = "10"; discountrateEntity1.Discount = discountrateListEntity.DiscountC1; list.Add(discountrateEntity1); ICSDiscountRateEntity discountrateEntity2 = new ICSDiscountRateEntity(); discountrateEntity2.CusCode = discountrateListEntity.CusCode; discountrateEntity2.StartValue = 1.50M; discountrateEntity2.EndValue = 1.99M; discountrateEntity2.WHType = "10"; discountrateEntity2.Discount = discountrateListEntity.DiscountC2; list.Add(discountrateEntity2); ICSDiscountRateEntity discountrateEntity3 = new ICSDiscountRateEntity(); discountrateEntity3.CusCode = discountrateListEntity.CusCode; discountrateEntity3.StartValue = 2.00M; discountrateEntity3.EndValue = 2.50M; discountrateEntity3.WHType = "10"; discountrateEntity3.Discount = discountrateListEntity.DiscountC3; list.Add(discountrateEntity3);
ICSDiscountRateEntity discountrateEntity4 = new ICSDiscountRateEntity(); discountrateEntity4.CusCode = discountrateListEntity.CusCode; discountrateEntity4.StartValue = 1.00M; discountrateEntity4.EndValue = 1.49M; discountrateEntity4.WHType = "12"; discountrateEntity4.Discount = discountrateListEntity.DiscountP1; list.Add(discountrateEntity4); ICSDiscountRateEntity discountrateEntity5 = new ICSDiscountRateEntity(); discountrateEntity5.CusCode = discountrateListEntity.CusCode; discountrateEntity5.StartValue = 1.50M; discountrateEntity5.EndValue = 1.99M; discountrateEntity5.WHType = "12"; discountrateEntity5.Discount = discountrateListEntity.DiscountP2; list.Add(discountrateEntity5); ICSDiscountRateEntity discountrateEntity6 = new ICSDiscountRateEntity(); discountrateEntity6.CusCode = discountrateListEntity.CusCode; discountrateEntity6.StartValue = 2.00M; discountrateEntity6.EndValue = 2.50M; discountrateEntity6.WHType = "12"; discountrateEntity6.Discount = discountrateListEntity.DiscountP3; list.Add(discountrateEntity6);
discountrateApp.SubmitForm(list, keyValue); return Success("Successful operation."); }
[HttpPost] [HandlerAjaxOnly] [ValidateAntiForgeryToken] public ActionResult SubmitForms(ICSDiscountRateEntity discountrateEntity, string keyValue) { discountrateApp.SubmitForm(discountrateEntity, keyValue); return Success("Successful operation."); }
[HttpPost] [HandlerAjaxOnly] [HandlerAuthorize] [ValidateAntiForgeryToken] public ActionResult DeleteForm(string keyValue) { discountrateApp.DeleteForm(keyValue); return Success("Delete success."); }
public ActionResult Forms() { return View(); }
[HttpPost] [HandlerAjaxOnly] [HandlerAuthorize] [ValidateAntiForgeryToken] public ActionResult chulingPrintForm(string keyValue) { var data = discountrateApp.GetForm(keyValue); string FileValue, PrintValue, ParaName, ParaValue;
FileValue = FileToString("/Frp/lot.fr3"); ParaName = "ShopName`~PrintDepositAdd`~PrintPaperNo`~Title"; //`~为各参数的分隔符
ParaValue = "测试酒楼" + "`~说明:本单据为贵客押金收取凭证,盖章有效。退房时请出示,遗失者自负,请妥善保存。退房时间为12:00时,延时退房18:00时以前按半天房费收取,18:00时以后算全天房价。押金单有效期为一个月,过期作废。 贵重物品请交前台寄存,未寄存丢失自负。 谢谢!" + "`~身份证:4325011980639512" + "`~押金单";
DataTable dt = SqlHelper.GetDataTableBySql("SELECT * FROM dbo.ICSDiscountRate where F_Id='" + keyValue + "'"); PrintValue = TableToXml(dt); string ScriptStr; string PictureStr=""; 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; } " + " ObjPrintMange.CheckReg('苏州智合诚信息科技有限公司', '1B98963EDF11C830F8918C3E0BE28ED8'); " //注册码
//+ "ObjPrintMange.MasterOptions(1, 'TransNO', 0 );" //主从关系,参数:主数据集序号,关联字段名,字段是否为数值型
// + PictureStr
//+ "ObjPrintMange.AddPicturePrint('PicTitle', 0, 'Title.bmp','1', 1 );" //增加单个图片打印,参数:报表中图片对象名,数据表的字段(为0),图片文件名,数据集序号,是否清除旧数据(第1次调用时为1,其它时候则为0)
//+ "ObjPrintMange.AddPicturePrint('PicMaterial', 0, '2013-01-18-272b936d03-7208-4452-9d01-1197fbb63bc3.jpg','1', 1 );" //增加数据表中的图片打印,参数:报表中图片对象名,数据表的字段(为1),图片文件名所对应的字段名,数据集序号,是否清除旧数据(第1次调用时为1,其它时候则为0)
//+ "ObjPrintMange.AddPicturePrint('Picture1', 1, 'EATTRIBUTE1','1', 1 );"
+ "ObjPrintMange.ShowReport('" + FileValue + "' , '" + ParaName + "', '" + ParaValue + "', '" //+ PrintValue + "', '"
+ PrintValue + "', '','', '', '', '');" + "ObjPrintMange = null; } </script>"; ScriptStr = ScriptStr.Replace(System.Environment.NewLine, string.Empty);
Response.Write(ScriptStr); return Success("Delete success."); }
private string FileToString(string FileName) { try { string[] ByteStr = new string[256]; for (int i = 0; i < 256; i++) { if (i == 0) ByteStr[i] = "00"; else if (i < 16) ByteStr[i] = "0" + Convert.ToString(i, 16).ToUpper(); else ByteStr[i] = Convert.ToString(i, 16).ToUpper(); }
if (System.IO.File.Exists(Server.MapPath(FileName)) == false) return "";
byte[] FileValue = System.IO.File.ReadAllBytes(Server.MapPath(FileName)); StringBuilder FileStr = new StringBuilder();
for (int FileRecn = 0; FileRecn < FileValue.Length; FileRecn++) { FileStr.Append(ByteStr[FileValue[FileRecn]]); } FileValue = null;
return FileStr.ToString(); } catch (Exception ex) { throw new Exception(ex.Message); } }
private string TableToXml(DataTable DtTable) { StringBuilder PrintStr = new StringBuilder(); XmlWriterSettings setting = new XmlWriterSettings(); setting.Indent = true; setting.OmitXmlDeclaration = true;
using (XmlWriter PrintXml = XmlWriter.Create(PrintStr, setting)) { PrintXml.WriteStartElement("xml"); PrintXml.WriteAttributeString("xmlns", "s", null, "u"); PrintXml.WriteAttributeString("xmlns", "dt", null, "u"); PrintXml.WriteAttributeString("xmlns", "rs", null, "u"); PrintXml.WriteAttributeString("xmlns", "z", null, "#R"); PrintXml.WriteStartElement("s", "Schema", null); PrintXml.WriteAttributeString("id", "RowsetSchema"); PrintXml.WriteStartElement("s", "ElementType", null); PrintXml.WriteAttributeString("name", "row"); PrintXml.WriteAttributeString("content", "eltOnly"); PrintXml.WriteAttributeString("rs", "updatable", null, "true");
foreach (DataColumn Column in DtTable.Columns) { if (Column.DataType.Name == "Int64" || Column.DataType.Name == "Boolean" || Column.DataType.Name == "String" || Column.DataType.Name == "DateTime" || Column.DataType.Name == "Decimal" || Column.DataType.Name == "Double" || Column.DataType.Name == "Int32" || Column.DataType.Name == "Single" || Column.DataType.Name == "Int16" || Column.DataType.Name == "Byte") { PrintXml.WriteStartElement("s", "AttributeType", null); PrintXml.WriteAttributeString("name", Column.ColumnName);
PrintXml.WriteAttributeString("rs", "number", null, (Column.Ordinal + 1).ToString()); PrintXml.WriteAttributeString("rs", "nullable", null, "true"); PrintXml.WriteAttributeString("rs", "maydefer", null, "true"); PrintXml.WriteAttributeString("rs", "writeunknown", null, "true"); PrintXml.WriteAttributeString("rs", "basetable", null, DtTable.TableName); PrintXml.WriteAttributeString("rs", "basecolumn", null, Column.ColumnName);
if (Column.DataType.Name == "Int64") { //bigint
PrintXml.WriteStartElement("s", "datatype", null); PrintXml.WriteAttributeString("dt", "type", null, "i8"); PrintXml.WriteAttributeString("dt", "maxLength", null, "8"); PrintXml.WriteEndElement(); } else if (Column.DataType.Name == "Boolean") { //bit
PrintXml.WriteStartElement("s", "datatype", null); PrintXml.WriteAttributeString("dt", "type", null, "boolean"); PrintXml.WriteAttributeString("dt", "maxLength", null, "2"); PrintXml.WriteEndElement(); } else if (Column.DataType.Name == "String") { //char
PrintXml.WriteStartElement("s", "datatype", null); PrintXml.WriteAttributeString("dt", "type", null, "string"); PrintXml.WriteAttributeString("dt", "maxLength", null, Column.MaxLength.ToString()); PrintXml.WriteEndElement(); } else if (Column.DataType.Name == "DateTime") { //dateTime
PrintXml.WriteStartElement("s", "datatype", null); PrintXml.WriteAttributeString("dt", "type", null, "dateTime"); PrintXml.WriteAttributeString("dt", "maxLength", null, "16"); PrintXml.WriteEndElement(); } else if (Column.DataType.Name == "Decimal") { //Decimal
PrintXml.WriteStartElement("s", "datatype", null); PrintXml.WriteAttributeString("dt", "type", null, "number"); PrintXml.WriteAttributeString("dt", "maxLength", null, "19"); PrintXml.WriteEndElement(); } else if (Column.DataType.Name == "Double") { //Float
PrintXml.WriteStartElement("s", "datatype", null); PrintXml.WriteAttributeString("dt", "type", null, "float"); PrintXml.WriteAttributeString("dt", "maxLength", null, "8"); PrintXml.WriteEndElement(); } else if (Column.DataType.Name == "Int32") { //int
PrintXml.WriteStartElement("s", "datatype", null); PrintXml.WriteAttributeString("dt", "type", null, "int"); PrintXml.WriteAttributeString("dt", "maxLength", null, "4"); PrintXml.WriteEndElement(); } else if (Column.DataType.Name == "Single") { //Real
PrintXml.WriteStartElement("s", "datatype", null); PrintXml.WriteAttributeString("dt", "type", null, "r4"); PrintXml.WriteAttributeString("dt", "maxLength", null, "4"); PrintXml.WriteEndElement(); } else if (Column.DataType.Name == "Int16") { //smallint
PrintXml.WriteStartElement("s", "datatype", null); PrintXml.WriteAttributeString("dt", "type", null, "i2"); PrintXml.WriteAttributeString("dt", "maxLength", null, "2"); PrintXml.WriteEndElement(); } else if (Column.DataType.Name == "Byte") { //tinyint
PrintXml.WriteStartElement("s", "datatype", null); PrintXml.WriteAttributeString("dt", "type", null, "ui1"); PrintXml.WriteAttributeString("dt", "maxLength", null, "1"); PrintXml.WriteEndElement(); } PrintXml.WriteEndElement(); } } PrintXml.WriteEndElement(); PrintXml.WriteEndElement();
PrintXml.WriteStartElement("rs", "data", null); foreach (DataRow Row in DtTable.Rows) { PrintXml.WriteStartElement("z", "row", null); foreach (DataColumn Column in DtTable.Columns) { if (Row.IsNull(Column) == true) continue;
if (Column.DataType.Name == "Int64" || Column.DataType.Name == "Boolean" || Column.DataType.Name == "String" || Column.DataType.Name == "DateTime" || Column.DataType.Name == "Decimal" || Column.DataType.Name == "Double" || Column.DataType.Name == "Int32" || Column.DataType.Name == "Single" || Column.DataType.Name == "Int16" || Column.DataType.Name == "Byte") { if (Column.DataType.Name == "DateTime") { DateTime TmpDateTime = System.Convert.ToDateTime(Row[Column]); string TmpStr = TmpDateTime.ToString("yyyy-MM-dd") + "T" + TmpDateTime.ToString("HH:mm:ss"); PrintXml.WriteAttributeString(Column.ColumnName, TmpStr); } else { PrintXml.WriteAttributeString(Column.ColumnName, Row[Column].ToString()); } } } PrintXml.WriteEndElement(); } PrintXml.WriteEndElement();
PrintXml.WriteEndElement(); }
return PrintStr.ToString(); } } }
|