2023-05-23 16:13:17 +08:00
/// <summary>
///Data Implemention Object
///BASIC CRUD CLASS FOR TABLE t_PublicNews
///By wm
2023-09-04 22:41:19 +08:00
///on 08/04/2023
2023-05-23 16:13:17 +08:00
/// </summary>
using System ;
using DeiNiu.Utils ;
using System.Data.SqlClient ;
using DeiNiu.Data.BaseObject ;
using System.Data ;
namespace DeiNiu.wms.Data.Model
{
#region PublicNews_base_Imp
[Serializable] class PublicNews_base_Imp : BaseModel_Imp {
2023-09-04 22:41:19 +08:00
2023-05-23 16:13:17 +08:00
protected override void datarowToModel ( DataRow dr , BaseModel obj )
{
if ( dr ! = null )
{
PublicNews_base tmpObj = ( PublicNews_base ) obj ;
if ( dr . Table . Columns . Contains ( "id" ) & & ! ( dr [ "id" ] is DBNull ) )
{
tmpObj . ID = Convert . ToInt32 ( dr [ "id" ] . ToString ( ) ) ; ;
}
if ( dr . Table . Columns . Contains ( "news_title" ) & & ! ( dr [ "news_title" ] is DBNull ) )
{
tmpObj . _news_title = dr [ "news_title" ] . ToString ( ) ;
2023-09-04 22:41:19 +08:00
tmpObj . _Onews_title = dr [ "news_title" ] . ToString ( ) ;
2023-05-23 16:13:17 +08:00
}
if ( dr . Table . Columns . Contains ( "news_content" ) & & ! ( dr [ "news_content" ] is DBNull ) )
{
tmpObj . _news_content = dr [ "news_content" ] . ToString ( ) ;
2023-09-04 22:41:19 +08:00
tmpObj . _Onews_content = dr [ "news_content" ] . ToString ( ) ;
2023-05-23 16:13:17 +08:00
}
if ( dr . Table . Columns . Contains ( "news_alert" ) & & ! ( dr [ "news_alert" ] is DBNull ) )
{
tmpObj . _news_alert = Convert . ToBoolean ( dr [ "news_alert" ] . ToString ( ) ) ; ;
2023-09-04 22:41:19 +08:00
tmpObj . _Onews_alert = Convert . ToBoolean ( dr [ "news_alert" ] . ToString ( ) ) ; ;
2023-05-23 16:13:17 +08:00
}
if ( dr . Table . Columns . Contains ( "news_authority" ) & & ! ( dr [ "news_authority" ] is DBNull ) )
{
tmpObj . _news_authority = Convert . ToInt32 ( dr [ "news_authority" ] . ToString ( ) ) ; ;
2023-09-04 22:41:19 +08:00
tmpObj . _Onews_authority = Convert . ToInt32 ( dr [ "news_authority" ] . ToString ( ) ) ; ;
2023-05-23 16:13:17 +08:00
}
if ( dr . Table . Columns . Contains ( "news_startdate" ) & & ! ( dr [ "news_startdate" ] is DBNull ) )
{
tmpObj . _news_startdate = dr [ "news_startdate" ] . ToString ( ) ;
2023-09-04 22:41:19 +08:00
tmpObj . _Onews_startdate = dr [ "news_startdate" ] . ToString ( ) ;
2023-05-23 16:13:17 +08:00
}
if ( dr . Table . Columns . Contains ( "news_endDate" ) & & ! ( dr [ "news_endDate" ] is DBNull ) )
{
tmpObj . _news_endDate = dr [ "news_endDate" ] . ToString ( ) ;
2023-09-04 22:41:19 +08:00
tmpObj . _Onews_endDate = dr [ "news_endDate" ] . ToString ( ) ;
2023-05-23 16:13:17 +08:00
}
if ( dr . Table . Columns . Contains ( "dr" ) & & ! ( dr [ "dr" ] is DBNull ) )
{
tmpObj . _dr = Convert . ToBoolean ( dr [ "dr" ] . ToString ( ) ) ; ;
}
if ( dr . Table . Columns . Contains ( "create_time" ) & & ! ( dr [ "create_time" ] is DBNull ) )
{
tmpObj . _create_time = dr [ "create_time" ] . ToString ( ) ;
}
if ( dr . Table . Columns . Contains ( "lastmodified" ) & & ! ( dr [ "lastmodified" ] is DBNull ) )
{
tmpObj . _lastmodified = dr [ "lastmodified" ] . ToString ( ) ;
}
}
}
protected override void CmdPrepare ( SqlCommand oraCmd ) {
PublicNews_base tmpObj = ( PublicNews_base ) modelObj ;
switch ( this . _op_flag ) {
case ( int ) op_flag . add :
2023-09-04 22:41:19 +08:00
_strSql = "INSERT INTO dbo.T_PUBLICNEWS({0}) VALUES({1} )" ;
_strSql = String . Format ( _strSql , getFields ( tmpObj ) , getValues ( tmpObj ) ) ;
2023-05-23 16:13:17 +08:00
break ;
case ( int ) op_flag . update :
2023-09-04 22:41:19 +08:00
// _strSql = "UPDATE dbo.T_PUBLICNEWS SET NEWS_TITLE = @NEWS_TITLE,NEWS_CONTENT = @NEWS_CONTENT,NEWS_ALERT = @NEWS_ALERT,NEWS_AUTHORITY = @NEWS_AUTHORITY,NEWS_STARTDATE = @NEWS_STARTDATE,NEWS_ENDDATE = @NEWS_ENDDATE,LASTMODIFIED = getdate() WHERE ID = @ID";
_strSql = "UPDATE dbo.T_PUBLICNEWS {0} WHERE ID = @ID" ;
_strSql = String . Format ( _strSql , getChangedFields ( tmpObj ) ) ;
2023-05-23 16:13:17 +08:00
break ;
case ( int ) op_flag . delete :
// _strSql = "UPDATE dbo.T_PUBLICNEWS SET DR =0 WHERE ID = @ID";
_strSql = "delete from dbo.T_PUBLICNEWS WHERE ID = @ID" ;
break ;
case ( int ) op_flag . getObj :
_strSql = "SELECT * FROM dbo.T_PUBLICNEWS WHERE ID = @ID" ;
break ;
case ( int ) op_flag . queryAll :
_strSql = "SELECT * FROM dbo.T_PUBLICNEWS WHERE DR =1 " ;
2023-09-04 22:41:19 +08:00
// if (this.rownumEnd >0 )
2023-05-23 16:13:17 +08:00
{
2023-09-04 22:41:19 +08:00
// _strSql = "SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY ID DESC) as sortNo FROM dbo.T_PUBLICNEWS WHERE DR =1 )AS SORTEDTB WHERE DR =1 AND sortNo BETWEEN @START AND @END";
2023-05-23 16:13:17 +08:00
}
2023-09-04 22:41:19 +08:00
// _strSql += ";SELECT COUNT(*) FROM T_PUBLICNEWS WHERE DR =1";
2023-05-23 16:13:17 +08:00
break ;
case ( int ) op_flag . queryActived :
_strSql = "SELECT * FROM dbo.T_PUBLICNEWS WHERE DR =1" ;
_strSql + = ";SELECT COUNT(*) FROM T_PUBLICNEWS WHERE DR =1" ;
break ;
case ( int ) op_flag . getPk :
_strSql = "SELECT MAX(ID) FROM dbo.T_PUBLICNEWS WHERE DR =1" ;
break ;
case ( int ) op_flag . getCount :
_strSql = "SELECT COUNT(*) FROM T_PUBLICNEWS WHERE DR =1" ;
break ;
}
oraCmd . CommandText = _strSql ;
fillParameters ( oraCmd , tmpObj ) ;
}
2023-09-04 22:41:19 +08:00
private string getFields ( PublicNews_base tmpObj )
{
String colums = "" ;
colums + = tmpObj . _news_title = = null ? "" : "NEWS_TITLE" + "," ;
colums + = tmpObj . _news_content = = null ? "" : "NEWS_CONTENT" + "," ;
colums + = tmpObj . _news_alert = = null ? "" : "NEWS_ALERT" + "," ;
colums + = tmpObj . _news_authority = = null ? "" : "NEWS_AUTHORITY" + "," ;
colums + = tmpObj . _news_startdate = = null ? "" : "NEWS_STARTDATE" + "," ;
colums + = tmpObj . _news_endDate = = null ? "" : "NEWS_ENDDATE" + "," ;
return colums . Substring ( 0 , colums . Length - 1 ) ;
}
2023-05-23 16:13:17 +08:00
2023-09-04 22:41:19 +08:00
private string getValues ( PublicNews_base tmpObj )
{
String values = "" ;
values + = tmpObj . _news_title = = null ? "" : "@NEWS_TITLE" + "," ;
values + = tmpObj . _news_content = = null ? "" : "@NEWS_CONTENT" + "," ;
values + = tmpObj . _news_alert = = null ? "" : "@NEWS_ALERT" + "," ;
values + = tmpObj . _news_authority = = null ? "" : "@NEWS_AUTHORITY" + "," ;
values + = tmpObj . _news_startdate = = null ? "" : "@NEWS_STARTDATE" + "," ;
values + = tmpObj . _news_endDate = = null ? "" : "@NEWS_ENDDATE" + "," ;
return values . Substring ( 0 , values . Length - 1 ) ;
}
private string getChangedFields ( PublicNews_base tmpObj )
{
string updateFields = " set " ;
if ( tmpObj . _news_title ! = null & & tmpObj . _news_title ! = tmpObj . _Onews_title )
{
updateFields + = "NEWS_TITLE = @NEWS_TITLE," ;
}
if ( tmpObj . _news_content ! = null & & tmpObj . _news_content ! = tmpObj . _Onews_content )
{
updateFields + = "NEWS_CONTENT = @NEWS_CONTENT," ;
}
if ( tmpObj . _news_alert ! = null & & tmpObj . _news_alert ! = tmpObj . _Onews_alert )
{
updateFields + = "NEWS_ALERT = @NEWS_ALERT," ;
}
if ( tmpObj . _news_authority ! = null & & tmpObj . _news_authority ! = tmpObj . _Onews_authority )
{
updateFields + = "NEWS_AUTHORITY = @NEWS_AUTHORITY," ;
}
if ( tmpObj . _news_startdate ! = null & & tmpObj . _news_startdate ! = tmpObj . _Onews_startdate )
{
updateFields + = "NEWS_STARTDATE = @NEWS_STARTDATE," ;
}
if ( tmpObj . _news_endDate ! = null & & tmpObj . _news_endDate ! = tmpObj . _Onews_endDate )
{
updateFields + = "NEWS_ENDDATE = @NEWS_ENDDATE," ;
}
updateFields + = "LASTMODIFIED = getdate()" ;
return updateFields ;
}
2023-05-23 16:13:17 +08:00
private void fillParameters ( SqlCommand oraCmd , PublicNews_base tmpObj ) {
switch ( this . _op_flag ) {
case ( int ) op_flag . getObj :
case ( int ) op_flag . delete :
oraCmd . Parameters . AddWithValue ( "@ID" , tmpObj . ID ) ;
return ;
case ( int ) op_flag . getPk :
oraCmd . Parameters . AddWithValue ( "@ID" , tmpObj . ID ) ;
return ;
case ( int ) op_flag . queryAll :
if ( this . rownumEnd > 0 )
{
oraCmd . Parameters . AddWithValue ( "@START" , this . _rownumStart ) ;
oraCmd . Parameters . AddWithValue ( "@END" , this . _rownumEnd ) ;
}
return ;
case 0 :
case ( int ) op_flag . queryActived :
return ;
case ( int ) op_flag . update :
2023-09-04 22:41:19 +08:00
oraCmd . Parameters . AddWithValue ( "@ID" , tmpObj . ID ) ;
oraCmd . Parameters . AddWithValue ( "@NEWS_TITLE" , VerifyDbnull ( tmpObj . _news_title ) ) ;
oraCmd . Parameters . AddWithValue ( "@NEWS_CONTENT" , VerifyDbnull ( tmpObj . _news_content ) ) ;
oraCmd . Parameters . AddWithValue ( "@NEWS_ALERT" , VerifyDbnull ( tmpObj . _news_alert ) ) ;
oraCmd . Parameters . AddWithValue ( "@NEWS_AUTHORITY" , VerifyDbnull ( tmpObj . _news_authority ) ) ;
oraCmd . Parameters . AddWithValue ( "@NEWS_STARTDATE" , VerifyDbnull ( tmpObj . _news_startdate ) ) ;
oraCmd . Parameters . AddWithValue ( "@NEWS_ENDDATE" , VerifyDbnull ( tmpObj . _news_endDate ) ) ;
// oraCmd.Parameters.AddWithValue("@LASTMODIFIED", "getdate()") ;
return ;
case ( int ) op_flag . add :
if ( tmpObj . _news_title ! = null )
oraCmd . Parameters . AddWithValue ( "@NEWS_TITLE" , VerifyDbnull ( tmpObj . _news_title ) ) ;
if ( tmpObj . _news_content ! = null )
oraCmd . Parameters . AddWithValue ( "@NEWS_CONTENT" , VerifyDbnull ( tmpObj . _news_content ) ) ;
if ( tmpObj . _news_alert ! = null )
oraCmd . Parameters . AddWithValue ( "@NEWS_ALERT" , VerifyDbnull ( tmpObj . _news_alert ) ) ;
if ( tmpObj . _news_authority ! = null )
oraCmd . Parameters . AddWithValue ( "@NEWS_AUTHORITY" , VerifyDbnull ( tmpObj . _news_authority ) ) ;
if ( tmpObj . _news_startdate ! = null )
oraCmd . Parameters . AddWithValue ( "@NEWS_STARTDATE" , VerifyDbnull ( tmpObj . _news_startdate ) ) ;
if ( tmpObj . _news_endDate ! = null )
oraCmd . Parameters . AddWithValue ( "@NEWS_ENDDATE" , VerifyDbnull ( tmpObj . _news_endDate ) ) ;
return ;
2023-05-23 16:13:17 +08:00
}
2023-09-04 22:41:19 +08:00
2023-05-23 16:13:17 +08:00
}
protected override enumDbInstance instance
{
get
{
2023-09-04 22:41:19 +08:00
2023-05-23 16:13:17 +08:00
return enumDbInstance . platForm ;
}
}
}
#endregion
}