using System; using System.Collections.Generic; using System.Linq; using System.Text; using QMAPP.MD.Entity; using QMFrameWork.Data; using QMFrameWork.Log; using System.Data; using QMAPP.DAL; namespace QMAPP.MD.DAL { /// /// 模块名称:公司 /// 作 者:郭兆福 /// 编写日期:2017年05月05日 /// public class CorpDAL : BaseDAL { #region 获取信息 /// /// 获取信息 /// /// 信息 public Corp Get() { Corp model; try { StringBuilder sqlBuilder = new StringBuilder(); sqlBuilder.AppendLine(" SELECT TOP 1 R.PID "); sqlBuilder.AppendLine(" ,R.CORP_CODE "); sqlBuilder.AppendLine(" ,R.CORP_CODE AS CORP_CODE_OLD"); sqlBuilder.AppendLine(" ,R.CORP_NAME "); sqlBuilder.AppendLine(" ,R.CORP_SHORT "); sqlBuilder.AppendLine(" ,R.Siteid "); sqlBuilder.AppendLine(" ,R.Orgid "); sqlBuilder.AppendLine(" ,R.REMARK "); sqlBuilder.AppendLine(" ,R.CREATEUSER "); sqlBuilder.AppendLine(" ,R.CREATEDATE "); sqlBuilder.AppendLine(" ,R.UPDATEUSER "); sqlBuilder.AppendLine(" ,R.UPDATEDATE "); sqlBuilder.AppendLine(" FROM T_MD_CORP R "); List para = new List(); using (IDataSession session = AppDataFactory.CreateMainSession()) { // 对应多种数据库 string sqlChange = this.ChangeSqlByDB(sqlBuilder.ToString(), session); //获取信息 model = session.Get(sqlChange, para.ToArray()); } return null == model ? new Corp() : model; } catch (Exception ex) { RecordExceptionLog(ex, "公司信息数据层-获取信息" ); throw ex; } } #endregion #region 根据主键获取信息 /// /// 获取信息 /// /// 条件 /// 信息 public Corp Get(Corp model) { try { using (IDataSession session = AppDataFactory.CreateMainSession()) { //获取信息 model = session.Get(model); } return model; } catch (Exception ex) { RecordExceptionLog(ex, "公司信息数据层-获取信息"); throw ex; } } #endregion #region 插入信息 /// /// 插入信息(单表) /// /// 信息 /// 插入行数 public int Insert(Corp model) { int count = 0; try { using (IDataSession session = AppDataFactory.CreateMainSession()) { //插入基本信息 count = session.Insert(model); } return count; } catch (Exception ex) { throw ex; } } #endregion #region 更新信息 /// /// 更新信息 /// /// /// 更新行数 public int Update(Corp model) { int count = 0; try { using (IDataSession session = AppDataFactory.CreateMainSession()) { //更新基本信息 count = session.Update(model); } return count; } catch (Exception ex) { throw ex; } } #endregion #region 判断是否存在 /// /// 判断是否存在 /// /// true:已存在;false:不存在。 public bool ExistsCorp() { int count = 0; StringBuilder sqlBuilder = new StringBuilder(); try { List para = new List(); sqlBuilder.AppendLine("SELECT COUNT(*) FROM T_MD_CORP "); using (IDataSession session = AppDataFactory.CreateMainSession()) { count = Convert.ToInt32(session.ExecuteSqlScalar(sqlBuilder.ToString(), para.ToArray())); } return count == 0 ? false : true; } catch (Exception ex) { throw ex; } } #endregion #region 判断公司下边是否有工厂 /// /// 判断公司下边是否有工厂 /// /// 公司编码 /// true:使用 false:未使用 public bool IsCorpUsed(string corpCode) { int count = 0; StringBuilder sqlBuilder = new StringBuilder(); try { sqlBuilder.AppendLine("SELECT COUNT(*) FROM T_MD_FACTORY "); sqlBuilder.AppendLine(" WHERE CORP_CODE=@CORP_CODE AND FLGDEL = '0'"); using (IDataSession session = AppDataFactory.CreateMainSession()) { // 对应多种数据库 string sqlChange = this.ChangeSqlByDB(sqlBuilder.ToString(), session); count = Convert.ToInt32(session.ExecuteSqlScalar(sqlChange, new DataParameter { ParameterName = "CORP_CODE", Value = corpCode })); } return count == 0 ? false : true; } catch (Exception ex) { throw ex; } } #endregion } }