You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
3.6 KiB
C#

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 API_CountryService
{
#region 保存
public static int Save(API_Country Model)
{
string tsql = @"
if @CountryID>0
begin
Update [API_Country] set [Name]=@Name,[EnglishName]=@EnglishName,[LoginUrl]=@LoginUrl,[PlatType]=@PlatType where CountryID=@CountryID
end
else
begin
INSERT INTO [API_Country]([Name],[EnglishName],[LoginUrl],[PlatType])values(@Name,@EnglishName,@LoginUrl,@PlatType)
set @CountryID=SCOPE_IDENTITY()
end
select @CountryID";
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand(tsql);
db.AddInParameter(cmd, "@CountryID", DbType.Int32, Model.CountryID);
db.AddInParameter(cmd, "@Name", DbType.String, Model.Name);
db.AddInParameter(cmd, "@EnglishName", DbType.String, Model.EnglishName);
db.AddInParameter(cmd, "@LoginUrl", DbType.String, Model.LoginUrl);
db.AddInParameter(cmd, "@PlatType", DbType.Int32, Model.PlatType);
int a = Convert.ToInt32(db.ExecuteScalar(cmd));
return a;
}
#endregion
#region 删除
public static void Delete(int CountryID)
{
string tsql = @"
delete from API_Country where CountryID=@CountryID
";
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand(tsql);
db.AddInParameter(cmd, "@CountryID", DbType.Int32, CountryID);
db.ExecuteNonQuery(cmd);
}
#endregion
#region 返回Model
public static API_Country GetModel(int CountryID)
{
API_Country model = null;
string tsql = "select * from API_Country where CountryID=@CountryID";
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand(tsql);
db.AddInParameter(cmd, "@CountryID", DbType.Int32, CountryID);
DataTable tb = db.ExecuteDataTable(cmd);
if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel<API_Country>();
return model;
}
#endregion
#region 分页查询
public List<API_Country> GetListAPI_Country(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount)
{
if (where == null) where = new RefParameterCollection();
QueryService ser = new QueryService();
ser.Fields = @"CountryID=cast(a.CountryID as int),a.Name,a.EnglishName,a.LoginUrl,a.PlatType";
ser.Tables = @"API_Country a";
ser.Filter = where.GetWhere(System.Data.CommandType.Text);
ser.PageIndex = PageIndex;
ser.PageSize = PageSize;
ser.Sort = Sort;
ser.KeyName = "CountryID";
string tsql = ser.GetText();
where.AddOutParameter("RowCount", System.Data.DbType.Int32); ;
List<API_Country> 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<API_Country>();
return ListModel;
}
#endregion
}
}