public static string SearchFileByClassName(string dirPath, string className) { var searchResults = Directory.GetFiles(dirPath, "*", SearchOption.AllDirectories); foreach (var path in searchResults) { TableJson tableJson = ParseTableJson(path); if (tableJson.ClassName.Equals(className)) { return(path); } } return(null); }
void OnGUI() { GUILayout.Label("Base Settings", EditorStyles.boldLabel); rowShareUrl = EditorGUILayout.TextField("Rowshare url: ", rowShareUrl); if (GUILayout.Button("Import")) { Match match = Regex.Match(rowShareUrl, "[0-9a-z]{32}"); if (match == null || !match.Success) { Debug.Log("Table not found !"); return; } var tableId = match.Value; Debug.Log("Id: " + tableId); var url = rowShareApiUrl + tableId; Debug.Log("Download from : " + url); ServicePointManager.ServerCertificateValidationCallback = MyRemoteCertificateValidationCallback; WebClient client = new WebClient(); string JsonTable = client.DownloadString(url); Debug.Log("Download success"); Debug.Log("Deserialization"); TableJson table = JsonConvert.DeserializeObject <TableJson>(JsonTable); Debug.Log("Deserialization success of table : " + table.displayName); for (int i = 0; i < table.columns.Length; i++) { Debug.Log(table.columns[i].displayName); } } ; }
private Dictionary <string, string> GetOneRowTable(string subTableType) { var result = new Dictionary <string, string>(); try { if (GribleSettings.AppType == AppTypes.POSTGRESQL) { var ds = new DataSet(); var conn = GetConnection(); conn.Open(); var sql = ("SELECT t.keys, t.values FROM tables t " + "INNER JOIN tabletypes tt ON t.type = tt.id " + "INNER JOIN tables pt ON t.parentid=pt.id " + "INNER JOIN categories c ON pt.categoryid=c.id " + "INNER JOIN products p ON c.productid=p.id " + "INNER JOIN tabletypes ctt ON c.type = ctt.id " + "WHERE tt.name='" + subTableType + "' AND pt.name='" + _tableName + "' AND p.name='" + _productName + "' AND ctt.name='table'"); var da = new NpgsqlDataAdapter(sql, conn); ds.Reset(); da.Fill(ds); var dt = ds.Tables[0]; var strKeys = ""; var strValues = ""; foreach (DataRow row in dt.Rows) { strKeys = (string)row.ItemArray.GetValue(0); strValues = (string)row.ItemArray.GetValue(1); } conn.Close(); if (!"".Equals(strKeys) && !"".Equals(strValues)) { Key[] keys = JsonConvert.DeserializeObject <Key[]>(strKeys); string[][] values = JsonConvert.DeserializeObject <string[][]>(strValues); for (int j = 0; j < values[0].Length; j++) { result.Add(keys[j].Name, values[0][j]); } } else { throw new Exception(subTableType + "s in the table '" + _tableName + "' not found in product '" + _productName + "'."); } } else { string fileName = _tableName + "_" + subTableType.ToUpper() + ".json"; string filePath = IOHelper.SearchFile(_productPath + "\\" + "TestTables", fileName); if (filePath == null) { throw new Exception("File '" + fileName + "' not found in directory '" + _productPath + "\\" + "TestTables" + "'."); } TableJson tableJson = IOHelper.ParseTableJson(filePath); Key[] keys = tableJson.Keys; string[][] values = tableJson.Values; for (int j = 0; j < values[0].Length; j++) { result.Add(keys[j].Name, values[0][j]); } } } catch (Exception e) { GribleSettings.ErHandler.OnAdaptorFail(e); } return(result); }
private Dictionary <int, Dictionary <string, string> > GetValuesFromGrible(IEnumerable <int> iterationNumbers) { var result = new Dictionary <int, Dictionary <string, string> >(); try { if (GribleSettings.AppType == AppTypes.POSTGRESQL) { var conn = GetConnection(); conn.Open(); var ds = new DataSet(); string sql = "SELECT t.keys, t.values " + "FROM tables t " + "INNER JOIN tabletypes tt ON t.type = tt.id " + "INNER JOIN categories c ON t.categoryid=c.id " + "INNER JOIN products p ON c.productid=p.id " + "INNER JOIN tabletypes ctt ON c.type = ctt.id " + "WHERE tt.name='storage' AND t.classname='" + _tableName + "' AND p.name='" + _productName + "'"; var da = new NpgsqlDataAdapter(sql, conn); ds.Reset(); da.Fill(ds); var dt = ds.Tables[0]; var strKeys = ""; var strValues = ""; foreach (DataRow row in dt.Rows) { strKeys = (string)row.ItemArray.GetValue(0); strValues = (string)row.ItemArray.GetValue(1); } conn.Close(); if (!"".Equals(strKeys) && !"".Equals(strValues)) { Key[] keys = JsonConvert.DeserializeObject <Key[]>(strKeys); string[][] values = JsonConvert.DeserializeObject <string[][]>(strValues); int[] iterNumbers = (int[])iterationNumbers; for (int i = 0; i < iterNumbers.Length; i++) { var row = new Dictionary <string, string>(); for (int j = 0; j < values[0].Length; j++) { row.Add(keys[j].Name, values[iterNumbers[i] - 1][j]); } result.Add(iterNumbers[i], row); } } else { throw new Exception("Storage with name '" + _tableName + "' not found in product '" + _productName + "'."); } } else { string className = _tableName; string sectionDir = "DataStorages"; string filePath = IOHelper.SearchFileByClassName(_productPath + "\\" + sectionDir, className); if (filePath == null) { throw new Exception("File with class name '" + className + "' not found in directory '" + _productPath + "\\" + sectionDir + "'."); } TableJson tableJson = IOHelper.ParseTableJson(filePath); Key[] keys = tableJson.Keys; string[][] values = tableJson.Values; int[] iterNumbers = (int[])iterationNumbers; for (int i = 0; i < iterNumbers.Length; i++) { var row = new Dictionary <string, string>(); for (int j = 0; j < values[0].Length; j++) { row.Add(keys[j].Name, values[iterNumbers[i] - 1][j]); } result.Add(iterNumbers[i], row); } } } catch (Exception e) { GribleSettings.ErHandler.OnAdaptorFail(e); } return(result); }
private string GetJson(TableJson tableJson) { return(SerilizeService <TableJson> .CreateSerilizer(Serilize_Type.Json).Serilize(tableJson)); }
public string LoadNewlist(HttpContext context) { var fbsj = "00"; var gzgw = context.Request["work"]; var ssldbm = context.Request["place"]; var page = context.Request["page"]; string url = string.Format(@"http://fjlylm.com/vizpxx.asp?ssldbm={0}&gzgw={1}&fbsj={2}&page={3}", ssldbm, gzgw, fbsj, page); string content = CommonUtility.HttpUtility.Get(url, System.Text.Encoding.Default); int iTableStart = content.IndexOf("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"95%\" class=\"pix9\">", 0); if (iTableStart < 1) { return(""); } int iTableEnd = content.IndexOf("</table>", iTableStart); if (iTableEnd < 1) { return(""); } string strWeb = content.Substring(iTableStart, iTableEnd - iTableStart); #region Tr列表 //生成HtmlDocument HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(strWeb); List <MyLink> myLinkList = new List <MyLink>(); foreach (HtmlNode trNode in doc.DocumentNode.SelectNodes("//tr")) { if (!trNode.InnerHtml.Contains("font")) { var mylink = new MyLink(); foreach (HtmlNode tdNode in trNode.ChildNodes) { HtmlAttribute width = tdNode.Attributes["width"]; if (width == null) { continue; } HtmlNode node; switch (width.Value) { case "40%": node = tdNode.ChildNodes.FindFirst("a"); mylink.Url = node.OuterHtml.Replace("zwxq.asp", "detail.html"); break; case "35%": node = tdNode.ChildNodes.FindFirst("p"); mylink.Work = node.InnerHtml.Trim(); break; case "10%": node = tdNode.ChildNodes.FindFirst("p"); mylink.Num = node.InnerHtml.Trim(); break; case "12%": node = tdNode.ChildNodes.FindFirst("p"); mylink.Time = node.InnerHtml.Trim(); break; default: break; } } myLinkList.Add(mylink); } } #endregion if (myLinkList.Count > 0) { var tableJson = new TableJson() { myLinkList = myLinkList }; //分页 int iPageStart = content.IndexOf("<p align='center' vAlign='bottom'>", 0); if (iPageStart < 1) { return(GetJson(tableJson)); } int iPageEnd = content.IndexOf("转到:", iPageStart); if (iPageEnd < 1) { return(GetJson(tableJson)); } string pageContent = content.Substring(iPageStart, iPageEnd + 3 - iPageStart); HtmlDocument pageDoc = new HtmlDocument(); pageDoc.LoadHtml(pageContent); MyPage mypage = new MyPage(); var ANodeList = pageDoc.DocumentNode.SelectNodes("//a"); if (ANodeList == null) { return(GetJson(tableJson)); } foreach (HtmlNode aNode in ANodeList) { if (aNode.ChildNodes.FindFirst("font").InnerHtml == "上一页") { mypage.Previous = GetPageParam(aNode.Attributes["href"].Value); } else { mypage.Next = GetPageParam(aNode.Attributes["href"].Value); } } iPageStart = pageContent.IndexOf("] ", "] ".Length); iPageEnd = pageContent.IndexOf("转到:", iPageStart); mypage.Desc = pageContent.Substring(iPageStart, iPageEnd - iPageStart).Replace("]", ""); tableJson.mypage = mypage; return(GetJson(tableJson)); } return(""); }
public TableJson LoadEntities(string queryPage, int currentPageIndex, List <WhereParam> whereList) { string cmdWhere = ""; List <OracleParameter> parameters = new List <OracleParameter>(); whereList.ForEach(p => { cmdWhere += string.Format(p.Where, p.ParameterName); parameters.Add(new OracleParameter() { ParameterName = p.ParameterName, Value = p.Value }); }); string sqlSelect = @"select count(*) from LYJYGD.ZP03 w inner join LYJYGD.ZP01 c on w.ZPA001=C.ZPA001 where w.ZPC006=1 and w.ZPC010=0 {0} "; string commandText = string.Format(sqlSelect, cmdWhere); int count = 0; try { count = int.Parse( OracleHelper.ExecuteScalar(OracleHelper.ConnectionString, CommandType.Text, commandText, parameters).ToString() ); } catch (Exception ex) { return(null); } int pageSize = 10; sqlSelect = @" select * from (select a.*, rownum rn from (select w.ZPC001, w.ZPA001, w.ZPA002, w.ZPB003, w.ZPC002, w.ZPC004 from LYJYGD.ZP03 w inner join LYJYGD.ZP01 c on w.ZPA001 = C.ZPA001 where w.ZPC006 = 1 and w.ZPC010 = 0 {0} order by w.ZPC004 desc, w.ZPA002) a) where rn >{1} and rn <{2} "; commandText = string.Format(sqlSelect, cmdWhere, (currentPageIndex - 1) * pageSize, currentPageIndex * pageSize + 1); var reader = OracleHelper.ExecuteReader(OracleHelper.ConnectionString, CommandType.Text, commandText, parameters); StringBuilder sb = new StringBuilder(); List <MyLink> myLinkList = new List <MyLink>(); while (reader.Read()) { try { MyLink mylink = new MyLink(); //target=\"_blank\" mylink.Url = string.Format("<a href=\"detail.html?id={0}\">{1}</a>", reader["ZPC001"].ToString(), reader["ZPA002"]); mylink.Work = reader["ZPB003"].ToString(); mylink.Company = reader["ZPA002"].ToString(); mylink.Num = reader["ZPC002"].ToString(); mylink.Time = ((DateTime)reader["ZPC004"]).ToString("yyyy-MM-dd"); myLinkList.Add(mylink); } catch (Exception ex) { return(null); } } MyPage page = new MyPage(); int pageTotals = (int)(count / pageSize) + 1; if (currentPageIndex - 1 > 0) { page.Previous = string.Format("{0},'{1}'", queryPage, currentPageIndex - 1); } if (currentPageIndex + 1 <= pageTotals) { page.Next = string.Format("{0},'{1}'", queryPage, currentPageIndex + 1); } page.SelPage = pageTotals.ToString(); page.Desc = string.Format(" 页次:<strong><font color=\"red\">{0}</font>/{1}</strong>页" + " 共<b>{2}</b>条信息<b>{3}</b>条信息/页 </div>", currentPageIndex, page.SelPage, count, pageSize ); TableJson tableJson = new TableJson(); tableJson.myLinkList = myLinkList; tableJson.mypage = page; return(tableJson); }