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 list = new List(); 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 list = new List(); 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 = ""; 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(); } } }