using System; using System.Data; using System.Collections.Generic; using System.Text; using Microsoft.Practices.EnterpriseLibrary.Data; using DSWeb.Areas.CommMng.Models; using HcUtility.Comm; using DSWeb.Areas.CommMng.DAL; using DSWeb.MvcShipping.Helper; using DSWeb.MvcShipping.Models.MsStevedores; using System.Transactions; using System.Data.SqlClient; using DSWeb.DataAccess; using DSWeb.Areas.MvcShipping.Models.MsCustomReport; using DSWeb.MvcShipping.Models.WMSNew; namespace DSWeb.Areas.MvcShipping.DAL.MsOpCtnFeeModelDAL { public class MsCustomReportDAL { public static List GetDataList ( string condition, int start, int limit, out int total, string sort = null ) { StringBuilder sql = new StringBuilder(); sql.Append("select * FROM sys_report where isCustom = 1 "); if (condition!="") { sql.Append(" and "+ condition); } if (!string.IsNullOrEmpty(sort)) { var so = JsonConvert.Deserialize>(sort); string orderbyStr = " order by "; foreach (var s in so) { orderbyStr += s.property + " " + s.direction + ","; } orderbyStr = orderbyStr.Substring(0, orderbyStr.Length - 1); sql.Append(orderbyStr); } else { sql.Append(" order by rptname "); } int totalCount; StringBuilder sb = PagerHelper.PageSQL(sql.ToString(), start, limit, out totalCount); total = totalCount; var list = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, sb.ToString())) { while (reader.Read()) { MsCustomReportModel rpt = new MsCustomReportModel(); rpt.GID = reader["GID"].ToString(); rpt.RPTNAME = reader["RPTNAME"].ToString(); rpt.RPTNOTE = reader["RPTNOTE"].ToString(); list.Add(rpt); } } return list; } public static bool Save ( MsCustomReportModel fm, out string msg, out string MGID ) { //保存主表 string GID = fm.GID; bool rst = false; Database db = DatabaseFactory.CreateDatabase(); if (GID==""||GID=="*") { //新增 GID = Guid.NewGuid().ToString(); StringBuilder sb = new StringBuilder(); sb.Append("insert into sys_report (GID,RPTNAME,RPTCONTENT,RPTPROP,ISDEFAULT,REPORT,COMPANYID,isCustom,RPTNOTE) "); sb.Append("values('" + GID + "','" + fm.RPTNAME + "','" + fm.RPTCONTENT + "','" + fm.RPTPROP + "','" + fm.ISDEFAULT + "','" + fm.REPORT + "','" + fm.COMPANYID + "'," + fm.isCustom + ",'" + fm.RPTNOTE + "')"); int exeRst = db.ExecuteNonQuery(CommandType.Text, sb.ToString()); rst = exeRst > 0; } else { //修改 StringBuilder sb = new StringBuilder(); sb.Append("update sys_report set "); sb.Append("RPTNAME = '" + fm.RPTNAME + "',"); sb.Append("RPTNOTE = '" + fm.RPTNOTE + "'"); sb.Append(" where GID = '"+fm.GID+"'"); rst = db.ExecuteNonQuery(CommandType.Text,sb.ToString()) > 0; } MGID = GID; msg = rst?"操作成功":"操作失败"; return rst; } public static bool Delete ( MsCustomReportModel fm, out string msg, out string MGID ) { //保存主表 string GID = fm.GID.Replace("{","").Replace("}",""); bool rst = false; string sql = "delete from sys_report where gid = '" + GID + "'"; Database db = DatabaseFactory.CreateDatabase(); rst= db.ExecuteNonQuery(CommandType.Text, sql)>0; MGID = GID; msg = rst ? "操作成功" : "操作失败"; return rst; } } }