/// <summary> /// 获取列表 /// </summary> /// <param name="sw"></param> /// <returns></returns> public static IEnumerable <T_SYS_ORG_CWH_Model> getModelList(T_SYS_ORG_CWH_SW sw) { var result = new List <T_SYS_ORG_CWH_Model>(); DataTable dt = BaseDT.T_SYS_ORG_CWH.getDT(sw);//列表 DataTable dtORG = BaseDT.T_SYS_ORG.getDT(new T_SYS_ORGSW { SYSFLAG = ConfigCls.getSystemFlag() }); //获取单位 for (int i = 0; i < dt.Rows.Count; i++) { T_SYS_ORG_CWH_Model m = new T_SYS_ORG_CWH_Model(); m.CWHID = dt.Rows[i]["CWHID"].ToString(); m.BYORGNO = dt.Rows[i]["BYORGNO"].ToString(); m.CWHNAME = dt.Rows[i]["CWHNAME"].ToString(); m.ORDERBY = dt.Rows[i]["ORDERBY"].ToString(); m.ORGName = BaseDT.T_SYS_ORG.getName(dtORG, m.BYORGNO); result.Add(m); } dt.Clear(); dt.Dispose(); dtORG.Clear(); dtORG.Dispose(); return(result); }
/// <summary> /// 获取记录 /// </summary> /// <param name="sw"></param> /// <returns></returns> public static DataTable getDT(T_SYS_ORG_CWH_SW sw) { StringBuilder sb = new StringBuilder(); sb.AppendFormat(" FROM T_SYS_ORG_CWH"); sb.AppendFormat(" WHERE 1=1"); if (string.IsNullOrEmpty(sw.CWHID) == false) { sb.AppendFormat(" AND CWHID = '{0}'", ClsSql.EncodeSql(sw.CWHID)); } if (string.IsNullOrEmpty(sw.ORGNO) == false) { sb.AppendFormat(" AND BYORGNO = '{0}'", ClsSql.EncodeSql(sw.ORGNO)); } if (string.IsNullOrEmpty(sw.CWHNAME) == false) { sb.AppendFormat(" AND (CWHNAME like '%{0}%')", ClsSql.EncodeSql(sw.CWHNAME)); } if (!string.IsNullOrEmpty(sw.BYORGNO)) { if (sw.BYORGNO.Substring(4, 11) == "00000000000")//获取所有市的 { sb.AppendFormat(" AND (SUBSTRING(BYORGNO,1,4) = '{0}' or BYORGNO is null or BYORGNO='')", ClsSql.EncodeSql(sw.BYORGNO.Substring(0, 4))); } else if (sw.BYORGNO.Substring(6, 9) == "000000000")//获取所有县的 { sb.AppendFormat(" AND (SUBSTRING(BYORGNO,1,6) = '{0}' or BYORGNO is null or BYORGNO='')", ClsSql.EncodeSql(sw.BYORGNO.Substring(0, 6))); } else if (sw.BYORGNO.Substring(9, 6) == "000000")//获取所有乡镇的 { sb.AppendFormat(" AND (SUBSTRING(BYORGNO,1,9) = '{0}' or BYORGNO is null or BYORGNO='')", ClsSql.EncodeSql(sw.BYORGNO.Substring(0, 9))); } else { sb.AppendFormat(" AND BYORGNO = '{0}'", ClsSql.EncodeSql(sw.BYORGNO)); } } string sql = "SELECT CWHID, BYORGNO, CWHNAME+'村委会' as CWHNAME, ORDERBY" + sb.ToString() + " order by BYORGNO,ORDERBY"; DataSet ds = DataBaseClass.FullDataSet(sql); return(ds.Tables[0]); }
/// <summary> /// 判断记录是否存在 /// </summary> /// <param name="sw">参见模型</param> /// <returns>true存在 false不存在</returns> public static bool isExists(T_SYS_ORG_CWH_SW sw) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("select 1 from T_SYS_ORG_CWH where 1=1"); sb.AppendFormat(" where 1= 1", ClsSql.EncodeSql(sw.CWHID)); if (string.IsNullOrEmpty(sw.CWHID) == false) { sb.AppendFormat(" AND CWHID= '{0}'", ClsSql.EncodeSql(sw.CWHID)); } if (string.IsNullOrEmpty(sw.BYORGNO) == false) { sb.AppendFormat(" AND BYORGNO= '{0}'", ClsSql.EncodeSql(sw.BYORGNO)); } if (string.IsNullOrEmpty(sw.CWHNAME) == false) { sb.AppendFormat(" AND CWHNAME= '{0}'", ClsSql.EncodeSql(sw.CWHNAME)); } return(DataBaseClass.JudgeRecordExists(sb.ToString())); }
/// <summary> /// 获取组织机构json字符串 /// </summary> /// <param name="sw"></param> /// <returns></returns> public static string getVillageJsonStr(T_SYS_ORG_CWH_SW sw) { DataTable dt = BaseDT.T_SYS_ORG_CWH.getVillageDT(sw);//列表 char[] specialChars = new char[] { ',' }; string JSONstring = "["; for (int i = 0; i < dt.Rows.Count; i++) { string orgNo = dt.Rows[i]["ORGNO"].ToString(); string UNITNAME = dt.Rows[i]["UNITNAME"].ToString(); JSONstring += "{"; JSONstring += "\"id\":\"" + UNITNAME + "\","; JSONstring += "\"text\":\"" + UNITNAME + "\""; JSONstring += "},"; } JSONstring = JSONstring.TrimEnd(specialChars); JSONstring += "]"; return(JSONstring.ToString()); }
/// <summary> /// 获取记录 /// </summary> /// <param name="sw"></param> /// <returns></returns> public static DataTable getVillagecComDT(T_SYS_ORG_CWH_SW sw) { StringBuilder sb = new StringBuilder(); sb.Append(" Left Join T_SYS_ORG_LINK b on convert(varchar, a.CWHID)=b.BYORGNO "); sb.AppendFormat(" WHERE 1=1"); if (string.IsNullOrEmpty(sw.CWHID) == false) { sb.AppendFormat(" AND a.CWHID = '{0}'", ClsSql.EncodeSql(sw.CWHID)); } if (string.IsNullOrEmpty(sw.ORGNO) == false) { sb.AppendFormat(" AND a.BYORGNO = '{0}'", ClsSql.EncodeSql(sw.ORGNO)); } if (string.IsNullOrEmpty(sw.CWHNAME) == false) { sb.AppendFormat(" AND (a.CWHNAME like '%{0}%')", ClsSql.EncodeSql(sw.CWHNAME)); } if (!string.IsNullOrEmpty(sw.BYORGNO)) { if (sw.BYORGNO.Substring(4, 11) == "00000000000")//获取所有市的 { sb.AppendFormat(" AND (SUBSTRING(a.BYORGNO,1,4) = '{0}' or a.BYORGNO is null or a.BYORGNO='')", ClsSql.EncodeSql(sw.BYORGNO.Substring(0, 4))); } else if (sw.BYORGNO.Substring(6, 9) == "000000000")//获取所有县的 { sb.AppendFormat(" AND (SUBSTRING(a.BYORGNO,1,6) = '{0}' or a.BYORGNO is null or a.BYORGNO='')", ClsSql.EncodeSql(sw.BYORGNO.Substring(0, 6))); } else if (sw.BYORGNO.Substring(9, 6) == "000000")//获取所有乡镇的 { sb.AppendFormat(" AND (SUBSTRING(a.BYORGNO,1,9) = '{0}' or a.BYORGNO is null or a.BYORGNO='')", ClsSql.EncodeSql(sw.BYORGNO.Substring(0, 9))); } else { sb.AppendFormat(" AND a.BYORGNO = '{0}'", ClsSql.EncodeSql(sw.BYORGNO)); } } if (!string.IsNullOrEmpty(sw.GetContyORGNOByCity))//市获取所有县 { sb.AppendFormat(" AND (SUBSTRING(a.BYORGNO,1,4)='{0}' and SUBSTRING(a.BYORGNO,5,2)<>'00' and SUBSTRING(a.BYORGNO,7,9) = '000000000')", ClsSql.EncodeSql(sw.GetContyORGNOByCity.Substring(0, 4))); } if (!string.IsNullOrEmpty(sw.GetXZOrgNOByConty)) { sb.AppendFormat(" AND (SUBSTRING(a.BYORGNO,1,6)='{0}' and SUBSTRING(a.BYORGNO,7,9) != '000000000')", ClsSql.EncodeSql(sw.GetXZOrgNOByConty.Substring(0, 6))); } if (string.IsNullOrEmpty(sw.OnlyGetShiXian) == false) { sb.AppendFormat(" AND (SUBSTRING(a.BYORGNO,1,4)='{0}' and SUBSTRING(a.BYORGNO,7,9) = '000000000')", ClsSql.EncodeSql(sw.TopORGNO.Substring(0, 4))); } if (string.IsNullOrEmpty(sw.ORGLINKTYPE) == false) { sb.AppendFormat(" AND b.ORGLINKTYPE = '{0}'", ClsSql.EncodeSql(sw.ORGLINKTYPE)); } if (string.IsNullOrEmpty(sw.UNITNAME) == false) { sb.AppendFormat(" AND b.UNITNAME = '{0}'", ClsSql.EncodeSql(sw.UNITNAME)); } string sql = "SELECT b.UNITNAME,a.CWHID, a.BYORGNO, a.CWHNAME+'村委会' as CWHNAME, a.ORDERBY ,b.ORGLINK_ID,b.ORGLINKTYPE,b.NAME,b.USERJOB,b.PHONE,b.BYORGNO as ORGNO from T_SYS_ORG_CWH a" + sb.ToString() + " order by a.BYORGNO,a.ORDERBY"; DataSet ds = DataBaseClass.FullDataSet(sql); return(ds.Tables[0]); }