/// <summary> /// 根据id生成扩展js文件字符串; /// </summary> private static string BuildExtJs(string fileId) { var s = string.Empty; DbHelper.Open(); var dt = new DataTable(); try { dt = DbHelper.GetDataTable(string.Format("select jsplugin from p_form_m where code='{0}'", fileId)); } catch (Exception ex) { throw new Exception(ex.Message); } finally { DbHelper.Close(); } //id号无对应扩展js内容 if (dt.Rows.Count <= 0 || string.IsNullOrEmpty(dt.Rows[0]["jsplugin"].ToString())) { return(string.Empty); } var bformBytes = (Byte[])dt.Rows[0]["jsplugin"]; //id号对应扩展js内容为空 if (bformBytes.Length < 1) { return(string.Empty); } /********************************************** * "LZW15"开头的流数据是经过压缩的,需解压后再转码; * 非"LZW15"开头的数据直接转码即可; **********************************************/ var headBytes = new byte[5]; Array.Copy(bformBytes, 0, headBytes, 0, 5); var headStr = Encoding.GetEncoding("gb2312").GetString(headBytes); if (headStr == "LZW15") { var sourceBytes = new byte[bformBytes.Length - 5]; Array.Copy(bformBytes, 5, sourceBytes, 0, bformBytes.Length - 5); var deCompressByte = new LzwZip(Encoding.GetEncoding("gb2312")).Decompress(sourceBytes); s = Encoding.Default.GetString(deCompressByte); } else { s = Encoding.Default.GetString(bformBytes); } return(s); }
/// <summary> /// 根据id生成ini文件; /// </summary> private static string BuildFile(string fileId, ref string ucode) { var s = string.Empty; // 根据传入的id值取出ini文件的内容; DbHelper.Open(); var dt = new DataTable(); try { dt = DbHelper.GetDataTable(string.Format("select * from p_form_m where code='{0}'", fileId)); } catch (Exception ex) { throw new Exception(ex.Message); } finally { DbHelper.Close(); } if (dt.Rows.Count <= 0) { throw new Exception("id号无对应数据;"); } ucode = dt.Rows[0]["ucode"].ToString(); var bformBytes = (Byte[])dt.Rows[0]["bform"]; /********************************************** * "LZW15"开头的流数据是经过压缩的,需解压后再转码; * 非"LZW15"开头的数据直接转码即可; **********************************************/ var headBytes = new byte[5]; Array.Copy(bformBytes, 0, headBytes, 0, 5); var headStr = Encoding.GetEncoding("gb2312").GetString(headBytes); if (headStr == "LZW15") { var sourceBytes = new byte[bformBytes.Length - 5]; Array.Copy(bformBytes, 5, sourceBytes, 0, bformBytes.Length - 5); var deCompressByte = new LzwZip(Encoding.GetEncoding("gb2312")).Decompress(sourceBytes); s = Encoding.Default.GetString(deCompressByte); } else { s = Encoding.Default.GetString(bformBytes); } var path = AppDomain.CurrentDomain.BaseDirectory + "pform\\"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } // 在ini文件中加入pform信息'id'和'表描述'; var pformInfo = new StringBuilder(); pformInfo.Append("[pformInfo]\r\n"); pformInfo.Append("fileid=" + fileId + "\r\n"); pformInfo.Append("description=" + dt.Rows[0]["title"].ToString() + "\r\n"); // 将bform数据写入ini文件,路径为主程序下pform文件夹中; var filename = path + fileId + ".ini"; using (var sw = new StreamWriter(filename, false, Encoding.GetEncoding("gb2312"))) { sw.Write(pformInfo.ToString() + s); } return(filename); }