/// <summary> /// 判断记录是否存在 /// </summary> /// <param name="sw">参见模型</param> /// <returns>true存在 false不存在</returns> public static bool isExists(DC_RESOURCE_NEW_SW sw) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("select 1 from DC_RESOURCE_NEW where 1=1"); if (string.IsNullOrEmpty(sw.DC_RESOURCE_NEW_ID) == false) { sb.AppendFormat(" where DC_RESOURCE_NEW_ID= '{0}'", ClsSql.EncodeSql(sw.DC_RESOURCE_NEW_ID)); } return(DataBaseClass.JudgeRecordExists(sb.ToString())); }
/// <summary> /// 统计当前用户下资源的记录数量 /// </summary> /// <param name="sw"></param> /// <returns></returns> public static string getNum(DC_RESOURCE_NEW_SW sw) { string total = ""; StringBuilder sb = new StringBuilder(); sb.AppendFormat(" from DC_RESOURCE_NEW a "); sb.AppendFormat("where 1 = 1 "); if (sw.ORGNOS.Substring(4, 11) == "00000000000")//获取所有市的 { sb.AppendFormat(" AND (SUBSTRING(ORGNOS,1,4) = '{0}' or ORGNOS is null or ORGNOS='')", ClsSql.EncodeSql(sw.ORGNOS.Substring(0, 4))); } else if (sw.ORGNOS.Substring(6, 9) == "000000000")//获取所有县的 { sb.AppendFormat(" AND (SUBSTRING(ORGNOS,1,6) = '{0}' or ORGNOS is null or ORGNOS='')", ClsSql.EncodeSql(sw.ORGNOS.Substring(0, 6))); } else { sb.AppendFormat(" AND (SUBSTRING(ORGNOS,1,9) = '{0}')", ClsSql.EncodeSql(sw.ORGNOS.Substring(0, 9))); } string sqlC = "select count(1) " + sb.ToString(); total = (DataBaseClass.ReturnSqlField(sqlC)).ToString(); return(total); }
/// <summary> /// 根据查询条件获取某一条用户信息记录,用于修改、删除、用户登录验证 /// </summary> /// <param name="sw">参见模型</param> /// <returns>参见模型</returns> public static DC_RESOURCE_NEW_Model getModel(DC_RESOURCE_NEW_SW sw) { var result = new List <DC_RESOURCE_NEW_Model>(); DataTable dt = BaseDT.DC_RESOURCE_NEW.getDT(sw);//列表 DataTable dtORG = BaseDT.T_SYS_ORG.getDT(new T_SYS_ORGSW { SYSFLAG = ConfigCls.getSystemFlag() }); //获取单位 DataTable dt27 = BaseDT.T_SYS_DICT.getDT(new T_SYS_DICTSW { DICTTYPEID = "27" }); //林龄类型 DataTable dt28 = BaseDT.T_SYS_DICT.getDT(new T_SYS_DICTSW { DICTTYPEID = "28" }); //数据中心资源类型 DataTable dt29 = BaseDT.T_SYS_DICT.getDT(new T_SYS_DICTSW { DICTTYPEID = "29" }); //数据中心资源起源类型 DataTable dt30 = BaseDT.T_SYS_DICT.getDT(new T_SYS_DICTSW { DICTTYPEID = "30" }); //数据中心资源可燃类型 DataTable dt31 = BaseDT.T_SYS_DICT.getDT(new T_SYS_DICTSW { DICTTYPEID = "31" }); //数据中心资源林木类型 DC_RESOURCE_NEW_Model m = new DC_RESOURCE_NEW_Model(); if (dt.Rows.Count > 0) { int i = 0; m.DC_RESOURCE_NEW_ID = dt.Rows[i]["DC_RESOURCE_NEW_ID"].ToString(); m.RESOURCETYPE = dt.Rows[i]["RESOURCETYPE"].ToString(); m.RESOURCETYPEName = BaseDT.T_SYS_DICT.getName(dt28, m.RESOURCETYPE); m.NUMBER = dt.Rows[i]["NUMBER"].ToString(); m.NAME = dt.Rows[i]["NAME"].ToString(); m.ORGNOS = dt.Rows[i]["ORGNOS"].ToString(); m.ORGNOSName = BaseDT.T_SYS_ORG.getNames(dtORG, m.ORGNOS); m.KINDTYPE = dt.Rows[i]["KINDTYPE"].ToString(); m.AGETYPE = dt.Rows[i]["AGETYPE"].ToString(); m.AGETYPEName = BaseDT.T_SYS_DICT.getName(dt27, m.AGETYPE); m.ORIGINTYPE = dt.Rows[i]["ORIGINTYPE"].ToString(); m.ORIGINTYPEName = BaseDT.T_SYS_DICT.getName(dt29, m.AGETYPE); m.AREA = dt.Rows[i]["AREA"].ToString(); m.BURNTYPE = dt.Rows[i]["BURNTYPE"].ToString(); m.BURNTYPEName = BaseDT.T_SYS_DICT.getName(dt30, m.BURNTYPE); m.TREETYPE = dt.Rows[i]["TREETYPE"].ToString(); m.TREETYPEName = BaseDT.T_SYS_DICT.getName(dt31, m.TREETYPE); m.ASPECT = dt.Rows[i]["ASPECT"].ToString(); m.ANGLE = dt.Rows[i]["ANGLE"].ToString(); m.MARK = dt.Rows[i]["MARK"].ToString(); m.JD = dt.Rows[i]["JD"].ToString(); m.WD = dt.Rows[i]["WD"].ToString(); m.POTHOOKLEADER = dt.Rows[i]["POTHOOKLEADER"].ToString(); m.POTHOOKLEADERJOB = dt.Rows[i]["POTHOOKLEADERJOB"].ToString(); m.POTHOOKLEADERTLEE = dt.Rows[i]["POTHOOKLEADERTLEE"].ToString(); m.DUTYPERSON = dt.Rows[i]["DUTYPERSON"].ToString(); m.DUTYPERSONTELL = dt.Rows[i]["DUTYPERSONTELL"].ToString(); m.JWDLIST = dt.Rows[i]["JWDLIST"].ToString(); } dt.Clear(); dt.Dispose(); dt27.Clear(); dt27.Dispose(); dt28.Clear(); dt28.Dispose(); dt29.Clear(); dt29.Dispose(); dt30.Clear(); dt30.Dispose(); dt31.Clear(); dt31.Dispose(); dtORG.Clear(); dtORG.Dispose(); return(m); }
/// <summary> /// 获取分页列表 /// </summary> /// <param name="sw"></param> /// <param name="total"></param> /// <returns></returns> public static DataTable getDT(DC_RESOURCE_NEW_SW sw, out int total) { StringBuilder sb = new StringBuilder(); sb.AppendFormat(" FROM DC_RESOURCE_NEW"); sb.AppendFormat(" WHERE 1=1"); if (string.IsNullOrEmpty(sw.DC_RESOURCE_NEW_ID) == false) { sb.AppendFormat(" AND DC_RESOURCE_NEW_ID = '{0}'", ClsSql.EncodeSql(sw.DC_RESOURCE_NEW_ID)); } if (string.IsNullOrEmpty(sw.RESOURCETYPE) == false) { sb.AppendFormat(" AND RESOURCETYPE = '{0}'", ClsSql.EncodeSql(sw.RESOURCETYPE)); } if (string.IsNullOrEmpty(sw.NUMBER) == false) { sb.AppendFormat(" AND NUMBER like '%{0}%'", ClsSql.EncodeSql(sw.NUMBER)); } if (string.IsNullOrEmpty(sw.NAME) == false) { sb.AppendFormat(" AND NAME like '%{0}%'", ClsSql.EncodeSql(sw.NAME)); } if (string.IsNullOrEmpty(sw.KINDTYPE) == false) { sb.AppendFormat(" AND KINDTYPE = '{0}'", ClsSql.EncodeSql(sw.KINDTYPE)); } if (string.IsNullOrEmpty(sw.AGETYPE) == false) { sb.AppendFormat(" AND AGETYPE = '{0}'", ClsSql.EncodeSql(sw.AGETYPE)); } if (string.IsNullOrEmpty(sw.ORIGINTYPE) == false) { sb.AppendFormat(" AND ORIGINTYPE = '{0}'", ClsSql.EncodeSql(sw.ORIGINTYPE)); } if (string.IsNullOrEmpty(sw.BURNTYPE) == false) { sb.AppendFormat(" AND BURNTYPE = '{0}'", ClsSql.EncodeSql(sw.BURNTYPE)); } if (string.IsNullOrEmpty(sw.TREETYPE) == false) { sb.AppendFormat(" AND TREETYPE = '{0}'", ClsSql.EncodeSql(sw.TREETYPE)); } if (!string.IsNullOrEmpty(sw.ORGNOS)) { if (sw.ORGNOS.Substring(4, 11) == "00000000000")//获取所有市的 { sb.AppendFormat(" AND (SUBSTRING(ORGNOS,1,4) = '{0}' or ORGNOS is null or ORGNOS='')", ClsSql.EncodeSql(sw.ORGNOS.Substring(0, 4))); } else if (sw.ORGNOS.Substring(4, 11) == "xxxxxxxxxxx")//单独市 { sb.AppendFormat(" AND (SUBSTRING(ORGNOS,1,15) = '{0}')", ClsSql.EncodeSql(sw.ORGNOS.Substring(0, 4) + "00000000000")); } else if (sw.ORGNOS.Substring(6, 9) == "xxxxxxxxx")//获取所有县的 { sb.AppendFormat(" AND (SUBSTRING(ORGNOS,1,6) = '{0}' or ORGNOS is null or ORGNOS='')", ClsSql.EncodeSql(sw.ORGNOS.Substring(0, 6))); } else if (sw.ORGNOS.Substring(9, 6) == "000000")//获取说有乡镇的 { sb.AppendFormat(" AND (SUBSTRING(ORGNOS,1,9) = '{0}'or ORGNOS is null or ORGNOS='')", ClsSql.EncodeSql(sw.ORGNOS.Substring(0, 9))); } else if (sw.ORGNOS.Substring(12, 3) == "000")//获取说有村的 { sb.AppendFormat(" AND (SUBSTRING(ORGNOS,1,12) = '{0}'or ORGNOS is null or ORGNOS='')", ClsSql.EncodeSql(sw.ORGNOS.Substring(0, 12))); } else { sb.AppendFormat(" AND ORGNOS = '{0}'", ClsSql.EncodeSql(sw.ORGNOS)); } } string sql = "SELECT DC_RESOURCE_NEW_ID, RESOURCETYPE, NUMBER, NAME, ORGNOS, KINDTYPE, AGETYPE, ORIGINTYPE, AREA, BURNTYPE, TREETYPE, ASPECT, ANGLE, MARK, JD, WD,POTHOOKLEADER,POTHOOKLEADERJOB,POTHOOKLEADERTLEE,DUTYPERSON,DUTYPERSONTELL,JWDLIST" + sb.ToString() + " order by ORGNOS "; string sqlC = "select count(1) " + sb.ToString(); total = int.Parse(DataBaseClass.ReturnSqlField(sqlC)); sw.curPage = PagerCls.getCurPage(new PagerSW { curPage = sw.curPage, pageSize = sw.pageSize, rowCount = total }); DataSet ds = DataBaseClass.FullDataSet(sql, (sw.curPage - 1) * sw.pageSize, sw.pageSize, "a"); return(ds.Tables[0]); }
/// <summary> /// 获取记录 /// </summary> /// <param name="sw"></param> /// <returns></returns> public static DataTable getDT(DC_RESOURCE_NEW_SW sw) { StringBuilder sb = new StringBuilder(); sb.AppendFormat(" FROM DC_RESOURCE_NEW"); sb.AppendFormat(" WHERE 1=1"); if (string.IsNullOrEmpty(sw.DC_RESOURCE_NEW_ID) == false) { sb.AppendFormat(" AND DC_RESOURCE_NEW_ID = '{0}'", ClsSql.EncodeSql(sw.DC_RESOURCE_NEW_ID)); } if (string.IsNullOrEmpty(sw.RESOURCETYPE) == false) { sb.AppendFormat(" AND RESOURCETYPE = '{0}'", ClsSql.EncodeSql(sw.RESOURCETYPE)); } if (string.IsNullOrEmpty(sw.NUMBER) == false) { sb.AppendFormat(" AND NUMBER like '%{0}%'", ClsSql.EncodeSql(sw.NUMBER)); } if (string.IsNullOrEmpty(sw.NAME) == false) { sb.AppendFormat(" AND NAME like '%{0}%'", ClsSql.EncodeSql(sw.NAME)); } if (string.IsNullOrEmpty(sw.KINDTYPE) == false) { sb.AppendFormat(" AND KINDTYPE = '{0}'", ClsSql.EncodeSql(sw.KINDTYPE)); } if (string.IsNullOrEmpty(sw.AGETYPE) == false) { sb.AppendFormat(" AND AGETYPE = '{0}'", ClsSql.EncodeSql(sw.AGETYPE)); } if (string.IsNullOrEmpty(sw.ORIGINTYPE) == false) { sb.AppendFormat(" AND ORIGINTYPE = '{0}'", ClsSql.EncodeSql(sw.ORIGINTYPE)); } if (string.IsNullOrEmpty(sw.BURNTYPE) == false) { sb.AppendFormat(" AND BURNTYPE = '{0}'", ClsSql.EncodeSql(sw.BURNTYPE)); } if (string.IsNullOrEmpty(sw.TREETYPE) == false) { sb.AppendFormat(" AND TREETYPE = '{0}'", ClsSql.EncodeSql(sw.TREETYPE)); } if (!string.IsNullOrEmpty(sw.ORGNOS)) { if (sw.ORGNOSXZ != "1") { if (sw.ORGNOS.Substring(4, 11) == "00000000000")//获取所有市的 { sb.AppendFormat(" AND (SUBSTRING(ORGNOS,1,4) = '{0}' or ORGNOS is null or ORGNOS='')", ClsSql.EncodeSql(sw.ORGNOS.Substring(0, 4))); } else if (sw.ORGNOS.Substring(6, 9) == "000000000")//获取所有县的 { sb.AppendFormat(" AND (SUBSTRING(ORGNOS,1,6) = '{0}' or ORGNOS is null or ORGNOS='')", ClsSql.EncodeSql(sw.ORGNOS.Substring(0, 6))); } else if (sw.ORGNOS.Substring(9, 6) == "000000")//获取说有乡镇的 { sb.AppendFormat(" AND (SUBSTRING(ORGNOS,1,9) = '{0}' or ORGNOS is null or ORGNOS='')", ClsSql.EncodeSql(sw.ORGNOS.Substring(0, 9))); } else if (sw.ORGNOS.Substring(12, 3) == "000")//获取说有村的 { sb.AppendFormat(" AND (SUBSTRING(ORGNOS,1,12) = '{0}' or ORGNOS is null or ORGNOS='')", ClsSql.EncodeSql(sw.ORGNOS.Substring(0, 12))); } else { sb.AppendFormat(" AND ORGNOS = '{0}'", ClsSql.EncodeSql(sw.ORGNOS)); } } else { sb.AppendFormat(" AND ORGNOS = '{0}'", ClsSql.EncodeSql(sw.ORGNOS)); } } string sql = "SELECT DC_RESOURCE_NEW_ID, RESOURCETYPE, NUMBER, NAME, ORGNOS, KINDTYPE, AGETYPE, ORIGINTYPE, AREA, BURNTYPE, TREETYPE, ASPECT, ANGLE, MARK, JD, WD,POTHOOKLEADER,POTHOOKLEADERJOB,POTHOOKLEADERTLEE,DUTYPERSON,DUTYPERSONTELL,JWDLIST" + sb.ToString() + " order by ORGNOS,DC_RESOURCE_NEW_ID desc"; DataSet ds = DataBaseClass.FullDataSet(sql); return(ds.Tables[0]); }