using System; using System.Collections.Generic; using System.Data; using System.Data.Common; using System.Diagnostics; using System.Globalization; 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.Areas.Import.DAL.GridPanelShowDAL; using DSWeb.Areas.TruckMng.DAL; using DSWeb.Areas.TruckMng.DAL.MsKfJh; using DSWeb.Areas.TruckMng.DAL.MsKfLy; using DSWeb.Areas.TruckMng.DAL.MsKfWx; using DSWeb.Areas.TruckMng.DAL.MsWlBulkPc; using DSWeb.Areas.TruckMng.DAL.MsWlInsure; using DSWeb.Areas.TruckMng.DAL.MsWlTyreRep; using DSWeb.DataAccess; using DSWeb.EntityDA; using DSWeb.TruckMng.Comm.Cookie; using DSWeb.TruckMng.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); if(ywtype=="0") { dbResult.Data = MsKfJhDAL.GetHeadDataByBillNo(billno, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request)); }else if (ywtype=="1") { dbResult.Data = MsKfLyDAL.GetHeadDataByBillNo(billno, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request)); } else if (ywtype == "2") { dbResult.Data = MsKfJhDAL.GetHeadDataByBillNo(billno, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request)); } else if (ywtype == "3") { dbResult.Data = MsKfLyDAL.GetHeadDataByBillNo(billno, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request)); } else if (ywtype == "4") { dbResult.Data = MsWlTyreRepDAL.GetHeadDataByBillNo(billno, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request)); } else if (ywtype == "5") { dbResult.Data = MsKfWxDAL.GetHeadDataByBillNo(billno, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request)); } else if (ywtype == "0113") { //dbResult.Data = MsWlBulkDAL.GetData("BillNo='" + billno + "'", Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request)); } else if (ywtype=="0115") { dbResult.Data = MsWlBulkPcDAL.GetHeadDataByBillNo(billno, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request)); } else if (ywtype == "0116") { dbResult.Data = MsWlInsureDAL.GetHeadDataByBillNo(billno, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request)); } else if (ywtype == "0117") { dbResult.Data = MsWlDjDAL.GetData("BillNo='" + billno + "'", Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request)); } 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(); } [HttpPost] [ValidateInput(false)] public ActionResult ExcelRptIndex(string strCondition, string formname,string filename) { string strHeader = "";//中文名称 string strDataIndex = "";//字段名称 var gridlist = GridPanelShowDAL.GetDataList(Convert.ToString(Session["USERID"]), formname); if (gridlist == null || gridlist.Count == 0) { return Json(new { success = false, message = "请先保存列表样式!" }); //Response.Write(""); //return View(); } var columnwidthlist = ""; foreach (var column in gridlist) { if (column.hidden != "1" && column.hidden != "True" && column.sortable != "0" && column.sortable != "False"&& column.dataIndex!="") { if (strHeader.Trim() == "") strHeader = strHeader + column.header; else strHeader = strHeader + "\t" + column.header; if (strDataIndex.Trim() == "") { strDataIndex = strDataIndex + column.dataIndex; columnwidthlist = columnwidthlist + column.width.ToString(); } else { strDataIndex = strDataIndex + "," + column.dataIndex; columnwidthlist = columnwidthlist + "," + column.width.ToString(); } } } strCondition = strCondition.Replace("@@@", "+"); CompareInfo Compare = CultureInfo.InvariantCulture.CompareInfo; int orderByIndex = Compare.LastIndexOf(strCondition, "order by", CompareOptions.IgnoreCase); //最后一个orderby语句 string orderByStatments = ""; //主查询语句 string mainSql = strCondition; if (orderByIndex > 0) { orderByStatments = strCondition.Substring(orderByIndex, strCondition.Length - orderByIndex); // 判断最后一个orderby语句是否在某个子查询里 // 如果是,则取消新查询语句的orderby拼凑 // 如果否,则删除原SQL语句中的orderby语句,等待拼凑新orderby语句 if (orderByStatments.IndexOf(")") > 0) { orderByStatments = ""; } else { mainSql = strCondition.Substring(0, orderByIndex); } } orderByStatments = orderByStatments.Replace("B.", "").Replace("F.", "").Replace("C.", "").Replace("U.", ""); T_ALL_DA T_ALL_DA = new T_ALL_DA(); // strCondition = "select " + strDataIndex + " from (" + mainSql + ") as a " + orderByStatments; DataSet DS = T_ALL_DA.GetAllSQL(strCondition.Trim()); if (DS != null) { ExcelDA ExcelDA = new EntityDA.ExcelDA(); MemoryStream ms = ExcelDA.RenderToExcel(DS.Tables[0], strHeader.Trim(), columnwidthlist); // var tmpContent = Encoding.UTF8.GetString(ms.ToArray()); //Response.Write("<script>document.close();</script>"); //Response.Clear(); //Response.Buffer = true; //Response.ContentType = "application/vnd.ms-excel"; Response.AddHeader("Content-Disposition", "attachment;fileName=" + filename); Response.BinaryWrite(ms.ToArray()); //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(); var rangeDa = new RangeDA(); foreach (var range in rangeList) { var userRightRange = new UserRightRange(); userRightRange.RightName = range; var rangeType = rangeDa.GetOPERATERANGE(userId, range); if (string.IsNullOrEmpty(rangeType)) { userRightRange.HasRight = false; } else if (rangeType != "4") { userRightRange.HasRight = true; } 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.TruckMng.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 } }