public static void InitConstValues(System.Collections.Hashtable data) { if (data == null) { data = new System.Collections.Hashtable(); } if (!data.ContainsKey("TODAY")) { data.Add("TODAY", System.DateTime.Now); } if (!data.ContainsKey("YEAR")) { data.Add("YEAR", System.DateTime.Now.Year); } if (!data.ContainsKey("MONTH")) { data.Add("MONTH", System.DateTime.Now.Month); } if (!data.ContainsKey("DAY")) { data.Add("DAY", System.DateTime.Now.Day); } foreach (System.Collections.DictionaryEntry dictionaryEntry in data) { if (dictionaryEntry.Value is DataTable) { BaseInit.InitDataTableNUM(dictionaryEntry.Value as DataTable); } } }
public bool PrintToFile(string sourceFile, string saveAsFile, System.Collections.Hashtable data) { System.IO.FileInfo fileInfo = new System.IO.FileInfo(sourceFile); IGHPrinterDefine obj = this.GetObj(fileInfo.Extension.ToLower()); bool result; if (obj != null) { this.CheckDir(saveAsFile); try { BaseInit.InitConstValues(data); if (obj.LoadSourceFile(sourceFile) && obj.LoadData(data)) { result = obj.BuildFile(saveAsFile); return(result); } } catch (System.Exception ex) { throw ex; } finally { obj.Dispose(); } } result = false; return(result); }
private string GetSourceString(string rowString, object source, string regString, decimal constCount) { rowString = this.SetAutoRowHeight(rowString); rowString = this.SetTableBoder(rowString); string result; if (source != null) { decimal num = -1m; Match match = Regex.Match(rowString, "ROWCOUNT_\\d+"); if (match != null && !string.IsNullOrEmpty(match.Value)) { num = System.Convert.ToDecimal(match.Value.Replace("ROWCOUNT_", "")); rowString = rowString.Replace("|" + match.Value, ""); } match = Regex.Match(rowString, "CONST_\\d+"); if (match != null && !string.IsNullOrEmpty(match.Value)) { rowString = rowString.Replace("|" + match.Value, ""); } DataTable dataTable = source as DataTable; if (dataTable == null) { dataTable = new DataTable(); dataTable.Columns.Add("NULLROW"); } if (num > 0m) { if (dataTable.Rows.Count < num) { int count = dataTable.Rows.Count; bool flag = false; int num2 = 0; while (num2 < num - count) { DataRow dataRow = dataTable.NewRow(); if (!flag) { dataRow[0] = "以下空白"; flag = true; } dataTable.Rows.Add(dataRow); num2++; } } } if (dataTable.Rows.Count > 0) { System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(); if (constCount == 0m) { foreach (DataRow row in dataTable.Rows) { stringBuilder.Append(this.ReplaceValuesString(rowString, BaseInit.GetHashtable(row), regString)); } } else { this.ConstTdString = this.GetConstTdString(rowString); rowString = rowString.Replace("|END", ""); stringBuilder.Append(this.ReplaceValuesString(rowString, BaseInit.GetHashtable(dataTable.Rows[0]), regString)); } result = stringBuilder.ToString(); return(result); } } result = ""; return(result); }