using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Web ;
using System.Web.Mvc ;
using DSWeb.EntityDA ;
using DSWeb.Models ;
using DSWeb.TruckMng.Comm.Cookie ;
using DSWeb.TruckMng.Helper ;
using WebSqlHelper ;
using System.Web.Configuration ;
using System.IO ;
using DSWeb.Areas.CommMng.DAL ;
using DSWeb.SoftMng.Filter ;
using DSWeb.Areas.CommMng.Models ;
using DSWeb.Areas.Dispatch.Models ;
using System.Text ;
using DSWeb.Areas.RptMng.Comm ;
using HcUtility.Comm ;
using System.Data ;
namespace DSWeb.Areas.CommMng.Controllers
{
[JsonRequestBehavior]
public class PrintController : Controller
{
/ /
// GET: /CommMng/Print/
public ActionResult Index ( )
{
return View ( ) ;
}
[ValidateInput(false)]
public ContentResult GetPrintInfo ( string type , string sql1 , string sql2 , string sql3 , string sql4 , string sql5 , string sql6 , string billno = "" , string RpID = "" , string RptMode = "" , string bsno = "" )
{
//var companyId = string.Empty;
//var userId =Convert.ToString(CookieConfig.GetCookie_UserId(Request));
int iTempStatus = 0 ;
//var strResult = string.Empty;
////先获取用户所在的公司信息GID
//CompanyEntity companyEntity = new CompanyEntity();
//CompanyDA companyDA = new CompanyDA();
//companyEntity = companyDA.GetCompanyByUserID(userId);
//if (companyEntity.GID != null)
//{
// companyId = companyEntity.GID;
//}
if ( ! string . IsNullOrEmpty ( bsno ) )
{
var evList = PubSysDAL . GetEnumValueList ( 83002 , "EnumValueName='" + type + "'" ) ;
if ( evList . Count > 1 ) {
var opbs = MvcShipping . DAL . MsOpBillDAL . GetData ( "BSNO='" + bsno + "'" ) ;
if ( ! string . IsNullOrEmpty ( opbs . BSNO ) )
{
foreach ( var ev in evList )
{
if ( ! string . IsNullOrEmpty ( ev . EnumValueName_2 ) )
{
billno = ev . EnumValueName_2 ;
var propArr = opbs . GetType ( ) . GetProperties ( ) ;
foreach ( var prop in propArr ) {
if ( prop ! = null & & prop . GetValue ( opbs ) ! = null )
billno = billno . Replace ( "[" + prop . Name . ToUpper ( ) + "]" , prop . GetValue ( opbs ) . ToString ( ) ) ;
else billno = billno . Replace ( "[" + prop . Name . ToUpper ( ) + "]" , "" ) ;
}
}
}
}
}
}
var userId = Convert . ToString ( Session [ "USERID" ] ) ;
var companyId = Convert . ToString ( CookieConfig . GetCookie_CompanyId ( Request ) ) ;
ReportDBSourceDA reportDbSourceDa = new ReportDBSourceDA ( ) ;
ReportDBSourceEntity reportDBSourceEntity = new ReportDBSourceEntity ( ) ;
reportDBSourceEntity = reportDbSourceDa . GetReportDBSourceByUserIDAndType ( userId , type ) ;
//业务数据集, 共6个
reportDBSourceEntity . SqlString_1 = sql1 ;
reportDBSourceEntity . SqlString_2 = sql2 ;
reportDBSourceEntity . SqlString_3 = sql3 ;
reportDBSourceEntity . SqlString_4 = sql4 ;
reportDBSourceEntity . SqlString_5 = sql5 ;
reportDBSourceEntity . SqlString_6 = sql6 ;
reportDBSourceEntity . Description = billno ;
reportDBSourceEntity . Name = bsno ;
//如果有相似的值则直接获取
if ( reportDBSourceEntity . GID ! = null )
{
//以下每一个打印都是一样的,可不改
reportDBSourceEntity . SqlString_7 = "SELECT [user].USERNAME,[user].CODENAME,[user].PASSWORD,[user].SHOWNAME,[user].ENROLLTIME,[user].CREATEUSER,[user].MODIFIEDUSER, [user].MODIFIEDTIME, [user].ISDELETED, [user].ISDISABLE, user_baseinfo.GID,user_baseinfo.USERID,user_baseinfo.COMPANYNAME, user_baseinfo.DEPTNAME, user_baseinfo.OFFICEPHONE, user_baseinfo.HOMEPHONE, user_baseinfo.MOBILE, user_baseinfo.FAX, user_baseinfo.EMAIL1, user_baseinfo.EMAIL2, user_baseinfo.HOMEADDRESS, user_baseinfo.REMARK, user_baseinfo.EMERGUSER, user_baseinfo.EMERGPHONE,user_baseinfo.EMERGEMAIL, user_baseinfo.POSTCODE, user_baseinfo.QQ, user_baseinfo.MSN, user_baseinfo.FINANCESOFTCODE FROM [user] INNER JOIN user_baseinfo ON [user].GID = user_baseinfo.USERID where user_baseinfo.USERID='" + userId + "'" ; //登录人的信息(每一个打印都是一样的,可不改)
reportDBSourceEntity . SqlString_8 = " SELECT * FROM [company] WHERE GID = '" + companyId + "'" ; //登录人的企业信息(每一个打印都是一样的,可不改)
iTempStatus = reportDbSourceDa . UpdateReportSql ( reportDBSourceEntity ) ;
}
else
{
reportDBSourceEntity . GID = Guid . NewGuid ( ) . ToString ( ) ;
reportDBSourceEntity . ReportID = "" ;
reportDBSourceEntity . Name = bsno ;
reportDBSourceEntity . Description = billno ;
reportDBSourceEntity . Type = type ;
reportDBSourceEntity . CreateUser = userId ;
reportDBSourceEntity . UserID = userId ;
reportDBSourceEntity . SqlString_7 = "SELECT [user].USERNAME,[user].CODENAME,[user].PASSWORD,[user].SHOWNAME,[user].ENROLLTIME,[user].CREATEUSER,[user].MODIFIEDUSER, [user].MODIFIEDTIME, [user].ISDELETED, [user].ISDISABLE, user_baseinfo.GID,user_baseinfo.USERID,user_baseinfo.COMPANYNAME, user_baseinfo.DEPTNAME, user_baseinfo.OFFICEPHONE, user_baseinfo.HOMEPHONE, user_baseinfo.MOBILE, user_baseinfo.FAX, user_baseinfo.EMAIL1, user_baseinfo.EMAIL2, user_baseinfo.HOMEADDRESS, user_baseinfo.REMARK, user_baseinfo.EMERGUSER, user_baseinfo.EMERGPHONE,user_baseinfo.EMERGEMAIL, user_baseinfo.POSTCODE, user_baseinfo.QQ, user_baseinfo.MSN, user_baseinfo.FINANCESOFTCODE FROM [user] INNER JOIN user_baseinfo ON [user].GID = user_baseinfo.USERID where user_baseinfo.USERID='" + userId + "'" ;
reportDBSourceEntity . SqlString_8 = " SELECT * FROM [company] WHERE GID = '" + companyId + "'" ;
iTempStatus = reportDbSourceDa . InsertReportDBSource ( reportDBSourceEntity ) ;
}
if ( iTempStatus = = 1 )
{
var sqlstr = SqlHelper . ConnectionStringLocalTransaction ;
var RemoteServer = "" ;
var NewPrint = "" ;
var PrintServer = "" ;
var PrintPort = "" ;
try
{
RemoteServer = WebConfigurationManager . AppSettings [ "RemoteServer" ] . ToString ( ) ;
}
catch
{
}
try
{
PrintServer = WebConfigurationManager . AppSettings [ "PrintServer" ] . ToString ( ) ;
PrintPort = WebConfigurationManager . AppSettings [ "PrintPort" ] . ToString ( ) ;
}
catch
{
}
var json = JsonConvert . Serialize (
new { Success = false , Message = "取得打印数据失败" } ) ;
if ( RemoteServer = = "" )
{
json = JsonConvert . Serialize (
// new { Success = true, Message = "查询成功", CompanyID = companyId, DbSourceID = reportDBSourceEntity.GID, UserId = userId, PrServer = RemoteServer, dbStr = sqlstr });
new { Success = true , Message = "查询成功" , CompanyID = companyId , DbSourceID = reportDBSourceEntity . GID , UserId = userId , PrServer = PrintServer , dbStr = PrintPort } ) ;
}
else {
json = JsonConvert . Serialize (
new { Success = true , Message = "查询成功" , CompanyID = companyId , DbSourceID = reportDBSourceEntity . GID , UserId = userId , PrServer = RemoteServer , dbStr = sqlstr , RpID = RpID , RptMode = RptMode } ) ;
}
return new ContentResult ( ) { Content = json } ;
}
else
{
var json = JsonConvert . Serialize (
new { Success = false , Message = "取得打印数据失败" } ) ;
return new ContentResult ( ) { Content = json } ;
}
}
[HttpPost]
public ContentResult UploadMailFile ( )
{
var jsonRespose = new JsonResponse { Success = false , Message = "" } ;
if ( Request . Files . Count ! = 1 )
{
jsonRespose . Success = false ;
jsonRespose . Message = "请选择上传的文件" ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
var file = Request . Files [ "LoadFile" ] ;
if ( file = = null )
{
jsonRespose . Success = false ;
jsonRespose . Message = "上传文件发生未知错误,请重新上传" ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
string ext = Path . GetExtension ( file . FileName ) . ToLower ( ) ;
if ( ext = = ".asp" | | ext = = ".aspx" | | ext = = ".js" | | ext = = ".exe" )
{
jsonRespose . Success = false ;
jsonRespose . Message = "不允许上传此文件类型文件" ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
var path = Server . MapPath ( "../../UploadFiles/MailFile" ) ;
if ( ! Directory . Exists ( path ) )
{
Directory . CreateDirectory ( path ) ;
}
var size = file . ContentLength ;
var name = Path . GetFileName ( file . FileName ) ;
var bsno = Request . Form [ "bsno" ] ;
var usercode = CookieConfig . GetCookie_UserCode ( Request ) ;
string filename = path + "\\" + usercode + DateTime . Now . ToString ( "yyyyMMddHHmmssfff" ) + name ;
if ( System . IO . File . Exists ( filename ) )
{
System . IO . File . Delete ( filename ) ;
}
file . SaveAs ( filename ) ;
if ( ! System . IO . File . Exists ( filename ) )
{
jsonRespose . Success = false ;
jsonRespose . Message = "上传文件出错" ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
filename = Path . GetFileName ( filename ) ;
var urlfilename = "../../UploadFiles/MailFile/" + filename ;
try
{
var json = JsonConvert . Serialize ( new { success = true , Message = "上传成功" , data = urlfilename } ) ;
return new ContentResult ( ) { Content = json } ;
}
catch ( Exception )
{
jsonRespose . Success = false ;
jsonRespose . Message = "上传文件出错" ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
}
[HttpPost]
public ContentResult GetReportList ( )
{
RespCommon resp = new RespCommon ( ) ;
StreamReader sr = new StreamReader ( Request . InputStream , Encoding . UTF8 ) ;
var strJson = sr . ReadToEnd ( ) ;
var JFVou = DSWeb . MvcShipping . Helper . JsonConvert . Deserialize < ReportDa > ( strJson ) ;
if ( string . IsNullOrEmpty ( JFVou . rptprop ) ) {
var json1 = DSWeb . MvcShipping . Helper . JsonConvert . Serialize (
new { success = false , Message = "没有报表格式" } ) ;
return new ContentResult ( ) { Content = json1 } ;
}
var strSql = new StringBuilder ( ) ;
strSql . Append ( "select GID,RPTNAME from sys_report " ) ;
strSql . Append ( "where RPTPROP='" + JFVou . rptprop + "' and COMPANYID='" + JFVou . companyid + "' and GID NOT IN (SELECT RPTGID FROM sys_report_userrange WHERE USERID='" + JFVou . userid + "') " ) ;
var dbparams = new List < CustomDbParamter > ( ) ;
var paramps_sSQL = new CustomDbParamter ( ) ;
paramps_sSQL . ParameterName = "@sSQL" ;
paramps_sSQL . DbType = DbType . String ;
paramps_sSQL . Direction = ParameterDirection . Input ;
paramps_sSQL . Value = strSql . ToString ( ) ;
dbparams . Add ( paramps_sSQL ) ;
var dbRptResult = PubSysDAL . GetMsSqlPrcDataSet ( "sMsExesqlQry" , dbparams , "Result_Set" ) ;
var json = RptHelper . GetRptJsonResult ( 0 , 100 , dbRptResult , "Result_Set" , true ) ;
return new ContentResult ( ) { Content = json } ;
}
}
}