ldj/Model/base/BaseModel.cs

232 lines
6.0 KiB
C#
Raw Normal View History

2023-05-23 16:13:17 +08:00
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Configuration;
using DeiNiu.Utils;
namespace DeiNiu.Data.BaseObject
{
[Serializable]
public abstract class BaseModel :BaseOperModel
{
internal int custOperFlag = 0;
public BaseModel()
{
getImp();
}
public BaseModel(DataRow dr)
{
getModel(dr);
}
public BaseModel(System.Data.SqlClient.SqlConnection _Conn)
{
getImp();
model_imp._Conn = _Conn;
}
public BaseModel(int operid,string connStr)
{
getImp();
model_imp.operid = operid;
model_imp.connString = connStr;
}
protected BaseModel_Imp model_imp;
public int Add()
{
// _operater = _operater >0 ?_operater : DeiNiu.Utils.LoginInfo.UserId;
return model_imp.Add(this);
}
public int Update()
{
// _operater = DeiNiu.Utils. LoginInfo.UserId > 0 ? DeiNiu.Utils. LoginInfo.UserId : _operater;
_lastmodified = getDateTime();
return model_imp.Update(this);
}
public int UpdateNoCompare()
{
// _operater = DeiNiu.Utils. LoginInfo.UserId > 0 ? DeiNiu.Utils. LoginInfo.UserId : _operater;
_lastmodified = getDateTime();
return model_imp.UpdateNoCompare(this);
}
public int Delete()
{
return model_imp.Delete(this);
}
public int rownumStart
{
get { return model_imp.rownumStart; }
set { model_imp.rownumStart = value; }
}
public int rownumEnd
{
get { return model_imp.rownumEnd; }
set { model_imp.rownumEnd = value; }
}
public int QueryCount()
{
string tmp = model_imp.QueryCount().Tables[0].Rows[0][0].ToString();
return tmp != string.Empty
? Convert.ToInt32(tmp)
: 0;
}
public DataSet QueryActived()
{
return model_imp.QueryActived();
}
public DataSet Query(BaseModel exampleObj)
{
return model_imp.Query(exampleObj);
}
public DataSet Query()
{
return model_imp.Query();
}
protected DataSet CustQuery(int custOperFlag)
{
this.custOperFlag = custOperFlag;
return model_imp.CustQuery(this);
}
protected int queryCount(int custOperFlag)
{
this.custOperFlag = custOperFlag;
DataTable dt = model_imp.CustQuery(this).Tables[0];
if (dt.Rows.Count ==1)
{
if (dt.Columns.Count > 0)
{
return Convert.ToInt16( dt.Rows[0][0].ToString());
}
}
return 0;
}
protected int CustOper(int custOperFlag)
{
this.custOperFlag = custOperFlag;
return model_imp.CustOper(this);
}
// public int colone()
// {
// }
public void getModel(DataRow dr)
{
try
{
model_imp.getModel(this, dr);
}
catch (Exception er )
{
throw er;
}
}
public void getModel()
{
custOperFlag = 0; //2010.1.3
model_imp.getModel(this);
}
public void getModel(int custOperFlag)
{
this.custOperFlag = custOperFlag;
model_imp.getModel(this);
}
/*private void getImp()
{
Type tp = GetType();
String impClassName = getImpClassName(tp.FullName);
// impClassName = "DeiNiu.wms.Data.Model.Department_Imp";
Type tpImp = tp.Assembly.GetType(impClassName);
model_imp = (BaseModel_Imp)System.Activator.CreateInstance(tpImp);
}
*/
protected virtual void getImp()
{
}
private String getImpClassName(String ClassName)
{
return ClassName + "_Imp";
}
public DataSet Query(string condition)
{
cmdParameters[0] = condition;
return CustQuery(99);
}
public int getNextSeq(enumCreateOrderType orderType)
{
return model_imp.getSequence("seq" + Utils.Util.getPrefix(orderType) );
}
/// <summary>
/// <20><>ȡ<EFBFBD><C8A1><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
/// </summary>
/// <returns></returns>
public string getDateTime()
{
return model_imp.getDateTime();
}
protected string getCondition(string querystr, int start, int end)
{
if (end > start && start > 0)
{
this.rownumStart = start;
this.rownumEnd = end;
}
// DataSet ds = string.IsNullOrEmpty(querystr) ? _obj.Query() : _obj.Query(querystr);
if (string.IsNullOrEmpty(querystr))
{
return "";
}
return getCondition( querystr);
}
protected string getCondition(string querystr)
{
string condition = "";
// querystr = filtRiskChar(querystr);
string[] parameters = querystr.Split(";".ToCharArray());
foreach (string value in parameters)
{
if (string.IsNullOrEmpty(value))
{
continue;
}
string[] par = value.Split("#".ToCharArray());
condition += par.Length == 0 ? "" : " and ";
foreach (string p in par)
{
condition += p;
}
}
return condition;
}
}
}