using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Web; using System.Web.Mvc; using DSWeb.Areas.Import.Models.Comm; using DSWeb.Areas.CommMng.Models; using DSWeb.TruckMng.Helper; using DSWeb.TruckMng.Helper.Repository; using Microsoft.Practices.EnterpriseLibrary.Data; using HcUtility.Comm; using HcUtility.Core; using DSWeb.SoftMng.Filter; namespace DSWeb.Areas.Import.Controllers { /// /// 项目信息明细 /// public class PaymentController : Controller { // // GET: /Import/RptImportFeedetail/ public ActionResult Index() { return View(); } public ActionResult Edit() { return View(); } [SqlKeyWordsFilter(Type = "Action")]//sql 防注入过滤器 public ContentResult GetDataList(int start, int limit, string sort, string condition) { var dataList = GetDataList(condition,sort); var list = dataList.Skip(start).Take(limit); var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = list.ToList() }); return new ContentResult() { Content = json }; } [SqlKeyWordsFilter(Type = "Action")]//sql 防注入过滤器 private static List GetDataList(string strCondition, string sort) { var strSql = new StringBuilder(); strSql.Append(" select * from (select ip.FEENAME,ip.id,ip.gid ,c.NAME [companyname],M.HTH,ip.AMOUNT,ip.currency,m.op,M.buyer buyer,m.seller,m.port,m.company "); strSql.Append(" ,dbo.trimdate(ip.createtime) createtime,ip.remark,dbo.f_danhao(ip.gid,1) CR_DR "); strSql.Append(" ,cf.currency CF_currency,cf.settlement,(select top 1 PaymentGID from ch_fee where PaymentGID=ip.GID) as PaymentGID,isnull(ip.EXCHANGERATE,0) EXCHANGERATE "); strSql.Append(" ,isnull(ip.DHF,0)DHF,isnull(ip.SXF,0) SXF,isnull(ip.ReceiveAgio,0) ReceiveAgio,isnull(ip.TotalAmount,0) TotalAmount "); strSql.Append(" ,isnull((select sum(amount) amount from ch_fee where bsno=M.ContractNo "); strSql.Append(" and feetype=1 and (CUSTOMERNAME=ip.BUYER OR CUSTOMERNAME=ip.SELLER) and (feename=ip.feename or REMARK like '%'+ip.feename+'%' )),0) ReceiveAmount "); strSql.Append(" ,case ip.feename when '预付款' then dbo.trimdate(m.prepaydate) else dbo.trimdate(m.paydate) end paytime "); strSql.Append(" ,dbo.trimdate(CZDATE) CZDATE "); strSql.Append(" ,dbo.f_fee((select bsno from ch_fee where gid=ip.gid),ip.buyer,'RMB','购货差额') Amount_Did "); strSql.Append(" ,(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=10 and EnumValueID=M.port) as portRef "); strSql.Append(" from import_payment ip "); strSql.Append(" left join ch_fee cf on cf.gid=ip.gid "); strSql.Append(" left join import_main m on m.contractno=cf.BSNO "); strSql.Append(" left join [company] c on c.gid=m.company )t "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } return SetData(strSql); } private static List SetData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { var data = new Import_Paymentmb(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); //字段过滤器(判断是否存在该列) reader.GetSchemaTable().DefaultView.RowFilter = "ColumnName= 'FEENAME'"; if (reader.GetSchemaTable().DefaultView.Count > 0) data.FEENAME = Convert.ToString(reader["FEENAME"]); data.PaymentGID = Convert.ToString(reader["PaymentGID"]); data.HTH = Convert.ToString(reader["HTH"]); data.CURRENCY = Convert.ToString(reader["CURRENCY"]); data.AMOUNT = Convert.ToString(reader["AMOUNT"]); data.OP = Convert.ToString(reader["OP"]); data.BUYER = Convert.ToString(reader["BUYER"]); data.SELLER = Convert.ToString(reader["SELLER"]); data.REMARK = Convert.ToString(reader["REMARK"]); data.CREATETIME = Convert.ToString(reader["CREATETIME"]); data.PAYTIME = Convert.ToString(reader["PAYTIME"]); data.CR_DR = Convert.ToString(reader["CR_DR"]); data.CF_CURRENCY = Convert.ToString(reader["CF_CURRENCY"]); data.SETTLEMENT = Convert.ToString(reader["SETTLEMENT"]); data.EXCHANGERATE = Convert.ToDecimal(reader["EXCHANGERATE"]); data.DHF = Convert.ToDecimal(reader["DHF"]); data.SXF = Convert.ToDecimal(reader["SXF"]); data.ReceiveAmount = Convert.ToDecimal(reader["ReceiveAmount"]); data.ReceiveAgio = Convert.ToDecimal(reader["ReceiveAgio"]); data.TotalAmount = Convert.ToDecimal(reader["TotalAmount"]); data.id = Convert.ToDecimal(reader["id"]); data.COMPANYNAME = Convert.ToString(reader["COMPANYNAME"]); data.CZDATE = Convert.ToString(reader["CZDATE"]); data.AMOUNT_DID = Convert.ToString(reader["AMOUNT_DID"]); data.portRef = Convert.ToString(reader["portRef"]); #endregion headList.Add(data); } reader.Close(); } return headList; } public ContentResult Save(string PaymentBody, string PaymentDelBody) { var ProjectBodyList = JsonConvert.Deserialize>(PaymentBody); var ProjectDelBodyList = JsonConvert.Deserialize>(PaymentDelBody); var modb = new ModelObjectRepository(); DBResult result = modb.SaveComm( ModelObjectConvert.ToModelObjectList(ProjectBodyList), ModelObjectConvert.ToModelObjectList(ProjectDelBodyList) ); foreach (var item in ProjectBodyList) { var str = "UPDATE import_main SET "+(item.FEENAME == "预付款"? "prepaydate": "paydate") +"='" + item.PAYTIME + "' where contractno in(select BSNO from ch_fee where GID='" + item.GID + "')"; DSWeb.SoftMng.DBUtility.DbHelperSQL.ExecuteSql(str); } //刷新父窗口上的父节点 var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message, //Data = XXHDAL.GetData("M.ContractNo='" + head.ContractNo + "'") }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } } }