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.
109 lines
4.3 KiB
C#
109 lines
4.3 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 JC_CountryService
|
|
{
|
|
#region 保存
|
|
public static int Save(JC_Country Model)
|
|
{
|
|
string tsql= @"
|
|
if @Id>0
|
|
begin
|
|
Update [JC_Country] set [Code]=@Code,[Name]=@Name,[CompanyId]=@CompanyId,EnglishName=@EnglishName where Id=@Id
|
|
end
|
|
else
|
|
begin
|
|
INSERT INTO [JC_Country]([Code],[Name],[CompanyId],EnglishName)values(@Code,@Name,@CompanyId,@EnglishName)
|
|
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,"@Code", DbType.String,Model.Code);
|
|
db.AddInParameter(cmd,"@Name", DbType.String,Model.Name);
|
|
db.AddInParameter(cmd, "@EnglishName", DbType.String, Model.EnglishName);
|
|
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_Country where Id=@Id
|
|
";
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
DbCommand cmd = db.GetSqlStringCommand(tsql);
|
|
db.AddInParameter(cmd,"@Id", DbType.Int32,Id);
|
|
db.ExecuteNonQuery(cmd);
|
|
}
|
|
#endregion
|
|
#region 分页查询
|
|
public static List<JC_Country> GetListJC_Country(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.Code,a.Name,a.CompanyId,a.EnglishName";
|
|
ser.Tables = @"JC_Country a";
|
|
ser.Filter = where.GetWhere(System.Data.CommandType.Text);
|
|
ser.PageIndex = PageIndex;
|
|
ser.PageSize = PageSize;
|
|
ser.Sort = Sort;
|
|
ser.KeyName = "Id";
|
|
string tsql=ser.GetText();
|
|
where.AddOutParameter("RowCount",System.Data.DbType.Int32);;
|
|
List<JC_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<JC_Country>();
|
|
return ListModel;
|
|
}
|
|
#endregion
|
|
#region 判断名称是否重复
|
|
public static bool CheckName(int Id, int CompanyID, string Name)
|
|
{
|
|
string tsql = @"select count(0) from JC_Country where Id<>@Id and CompanyID=@CompanyID and Name=@Name";
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
DbCommand cmd = db.GetSqlStringCommand(tsql);
|
|
db.AddInParameter(cmd, "@Id", DbType.Int32, Id);
|
|
db.AddInParameter(cmd, "@CompanyID", DbType.Int32, CompanyID);
|
|
db.AddInParameter(cmd, "@Name", DbType.String, Name);
|
|
int a = Convert.ToInt32(db.ExecuteScalar(cmd));
|
|
if (a == 0) return true;
|
|
return false;
|
|
}
|
|
#endregion
|
|
#region 判断代码是否重复
|
|
public static bool CheckCode(int Id, int CompanyID, string Code)
|
|
{
|
|
string tsql = @"select count(0) from JC_Country where Id<>@Id and CompanyID=@CompanyID and Code=@Code";
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
DbCommand cmd = db.GetSqlStringCommand(tsql);
|
|
db.AddInParameter(cmd, "@Id", DbType.Int32, Id);
|
|
db.AddInParameter(cmd, "@CompanyID", DbType.Int32, CompanyID);
|
|
db.AddInParameter(cmd, "@Code", DbType.String, Code);
|
|
int a = Convert.ToInt32(db.ExecuteScalar(cmd));
|
|
if (a == 0) return true;
|
|
return false;
|
|
}
|
|
#endregion
|
|
}
|
|
}
|
|
|