using System; using System.Text; using System.Data; using System.Data.Common; using System.Linq; using System.Data.SqlClient; using System.Collections.Generic; using NetLibrary; using NetLibrary.Data; using NetLibrary.ReportPrint; using TradeModel; namespace TradeData { public class JC_ExpressCodeService { #region 保存 public static int Save(JC_ExpressCode Model) { string tsql=@" if @Id>0 begin Update [JC_ExpressCode] set [ExpressId]=@ExpressId,[PostCode]=@PostCode,[IsUse]=@IsUse,[CompanyId]=@CompanyId where Id=@Id end else begin INSERT INTO [JC_ExpressCode]([ExpressId],[PostCode],[IsUse],[CompanyId])values(@ExpressId,@PostCode,@IsUse,@CompanyId) set @Id=SCOPE_IDENTITY() end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd,"@Id", DbType.Int32,Model.Id); db.AddInParameter(cmd,"@ExpressId", DbType.Int32,Model.ExpressId); db.AddInParameter(cmd,"@PostCode", DbType.String,Model.PostCode); db.AddInParameter(cmd,"@IsUse", DbType.Int32,Model.IsUse); db.AddInParameter(cmd,"@CompanyId", DbType.Int32,Model.CompanyId); int a=Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 删除 public static void Delete(int Id) { string tsql=@" delete from JC_ExpressCode where Id=@Id "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd,"@Id", DbType.Int32,Id); db.ExecuteNonQuery(cmd); } #endregion #region 返回Model public static JC_ExpressCode GetModel(int Id) { JC_ExpressCode model = null; string tsql="select * from JC_ExpressCode where Id=@Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd,"@Id", DbType.Int32,Id); DataTable tb=db.ExecuteDataTable(cmd); if (tb.Rows.Count>0)model=tb.Rows[0].ToModel(); return model; } #endregion #region 分页查询 public static List GetListJC_ExpressCode(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"Id=cast(a.Id as int),a.ExpressId,a.PostCode,a.IsUse,a.CompanyId,a.InDate,a.UpdateDate,ExpressName=b.Name,UseState=case when a.IsUse=1 then '已使用' else '未使用' end"; ser.Tables = @" JC_ExpressCode a inner join JC_Express b on a.ExpressId=b.ExpressId "; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "a.Id"; string tsql=ser.GetText(); where.AddOutParameter("RowCount",System.Data.DbType.Int32);; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb=db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel=tb.ToList(); return ListModel; } #endregion #region 导入运单号 public static void ImportExpressCode(int CompanyId, int ExpressId, List ListModel) { string tsql = @" if (select count(0) from JC_ExpressCode where CompanyId=@CompanyId and ExpressId=@ExpressId and PostCode=@PostCode)=0 begin insert JC_ExpressCode(CompanyId,ExpressId,PostCode,IsUse,InDate)values(@CompanyId,@ExpressId,@PostCode,0,getdate()) end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); foreach (string PostCode in ListModel) { cmd.Parameters.Clear(); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@ExpressId", DbType.Int32, ExpressId); db.AddInParameter(cmd, "@PostCode", DbType.String, PostCode); db.ExecuteNonQuery(cmd); } } #endregion #region 物流折扣 public List GetExpressOff(int CompanyId) { List list = null; string tsql = @" select ExpressPostID,Name,OffNum from JC_ExpressPost where CompanyId=@CompanyId and ExpressID in (select distinct b.Post from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.State=2 and a.CompanyId=@CompanyId )"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable dt = db.ExecuteDataTable(cmd); list = dt.ToList(); return list; } #endregion #region 修改物流折扣 public void UpdateExpressOff(int ExpressPostID,decimal OffNum) { string tsql = @" update JC_ExpressPost set OffNum=@OffNum where ExpressPostID=@ExpressPostID "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ExpressPostID", DbType.Int32, ExpressPostID); db.AddInParameter(cmd, "@OffNum", DbType.Decimal, OffNum); db.ExecuteNonQuery(cmd); } #endregion } }