using System; using System.Collections.Generic; using System.Data; using System.Data.Common; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using System.Web; using System.Web.Mvc; using DSWeb.Areas.CommMng.DAL; using DSWeb.Areas.CommMng.Models; using DSWeb.EntityDA; using DSWeb.MvcShipping.Comm.Cookie; using DSWeb.MvcShipping.Helper; using HcUtility.Comm; using Microsoft.Practices.EnterpriseLibrary.Data; namespace DSWeb.Areas.CommMng.Controllers { [JsonRequestBehavior] public class PubSysController : Controller { // //GET: /CommMng/PubSys/GetEnumValueList public JsonResult GetEnumValueList(decimal enumTypeId) { return GetEnumValueListByCondition(enumTypeId, String.Empty); } public JsonResult GetEnumValueListByCondition(decimal enumTypeId, string sCondition) { List evList = PubSysDAL.GetEnumValueList(enumTypeId, sCondition); if (evList.Count == 0) { return Json(new { success = false }); } else { return Json(new { success = true, data = evList.ToList() }); } } public JsonResult RptPluInfoQryData(int start, int limit, string sql) { List dbparams = new List(); CustomDbParamter paramOrgcode = new CustomDbParamter(); paramOrgcode.ParameterName = "@PS_ORGCODE"; paramOrgcode.DbType = DbType.String; paramOrgcode.Direction = ParameterDirection.Input; paramOrgcode.Value = "001"; dbparams.Add(paramOrgcode); DBDataSetResult dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sp_Test", dbparams, "Result_Set"); return GetRptJsonResult(start, limit, dbRptResult, "Result_Set"); } public ContentResult Account(string billno,string ywtype) { var userId = Convert.ToString(CookieConfig.GetCookie_UserId(Request)); if (string.IsNullOrEmpty(userId)) userId = "0"; var userCode = CookieConfig.GetCookie_UserCode(Request); var userName = CookieConfig.GetCookie_UserName(Request); DBResult dbResult = PubSysDAL.Account(billno, ywtype, userId, userCode, userName); var json = JsonConvert.Serialize(dbResult); return new ContentResult() { Content = json }; } public ActionResult ExportGrid() { this.ValidateRequest = false; if (Request["ExportContent"] != "") { string tmpFileName = "export.xls"; string tmpContentIn = Request["ExportContent"];//获取传递上来的文件内容 string tmpContent = ""; byte[] inputByteArray = Convert.FromBase64String(tmpContentIn); MemoryStream mStream = new MemoryStream(); mStream.Write(inputByteArray, 0, inputByteArray.Length); mStream.Flush(); tmpContent = Encoding.UTF8.GetString(mStream.ToArray()); if (Request["ExportFile"] != "") { tmpFileName = Request["ExportFile"];//获取传递上来的文件名 tmpFileName = System.Web.HttpUtility.UrlEncode(Request.ContentEncoding.GetBytes(tmpFileName));//处理中文文件名的情况 } Response.Write("<script>document.close();</script>"); Response.Clear(); Response.Buffer = true; Response.ContentType = "application/vnd.ms-excel"; Response.AddHeader("Content-Disposition", "attachment;filename=\"" + tmpFileName + "\""); Response.Charset = ""; System.IO.StringWriter tmpSW = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter tmpHTW = new System.Web.UI.HtmlTextWriter(tmpSW); tmpHTW.WriteLine(tmpContent); Response.Write(tmpSW.ToString()); Response.End(); } return View(); } /// /// 返回所有 权限可操作范围 /// /// 模块列表名,以分号分割 /// public JsonResult GetUserRightRange(string rangeValues) { if (rangeValues == null) rangeValues = string.Empty; var rangeList = rangeValues.Split(';'); string userId = Convert.ToString(Session["USERID"]); var userRightRangeList = new List(); foreach (var range in rangeList) { var userRightRange = new UserRightRange(); userRightRange.RightName = range; userRightRangeList.Add(userRightRange); } if (userRightRangeList.Count == 0) { return Json(new { Success = false }); } else { return Json(new { Success = true, Data = userRightRangeList.ToList() }); } } #region 传入sql,返回Excel文件 public void setExcelReport(string Name,string strSql) { if (strSql != "") { T_ALL_DA T_ALL_DA = new T_ALL_DA(); DataSet DS = T_ALL_DA.GetAllSQL(strSql); if (DS != null) { ExcelDA ExcelDA = new EntityDA.ExcelDA(); MemoryStream ms = ExcelDA.RenderToExcel(DS.Tables[0], Name); //ExcelDA.RenderToBrowser(ms, Context, "report.xls"); } } } #endregion #region 私有函数 private JsonResult GetRptJsonResult(int start, int limit, DBDataSetResult dbRptResult, string tableName) { return GetRptJsonResult(start, limit, dbRptResult, tableName, true); } private JsonResult GetRptJsonResult(DBDataSetResult dbRptResult, string tableName) { return GetRptJsonResult(0, 0, dbRptResult, tableName, false); } private JsonResult GetRptJsonResult(int start, int limit, DBDataSetResult dbRptResult, string tableName, bool page) { List> jsonSetData = null; if (dbRptResult.Success) { DataTable dtSet = dbRptResult.DataSet.Tables[tableName]; jsonSetData = DSWeb.MvcShipping.Helper.JsonHelper.ToJson(dtSet); IEnumerable> listjson; if (page) { listjson = jsonSetData.Skip(start).Take(limit); } else { listjson = jsonSetData.AsEnumerable(); } return Json(new { success = dbRptResult.Success, message = dbRptResult.Message, totalCount = jsonSetData.Count, data = listjson.ToArray() }); } else { jsonSetData = new List>(); return Json(new { success = dbRptResult.Success, message = dbRptResult.Message, totalCount = jsonSetData.Count, data = jsonSetData.ToArray() }); } } #endregion } }