public void ExportCunDangAnDai(XZDM xzdm, string saveDir) { Dictionary <string, XMLObject> ClazzDic = XMLRead.XmlToObjects_get <XZDM>(); var doc = WordRead.Read(JTSYQCustom.CunDangAnDaiTemplete); WordWrite.ReplaceText(doc, ClazzDic, xzdm); WordWrite.SaveToFile(doc, saveDir + "//00档案袋.doc"); }
/// <summary> /// 生成集体土地所有权证 /// </summary> public void CreateJTTDSYQZ_doc(string excelPath, string saveDir) { if (Utils.CheckFileExists(excelPath) && Utils.CheckDirExists(saveDir)) { List <MyAction> actions = new List <MyAction>(); IList <JTTDSYQZ> jtsyqzs = JTTDSYQZCustom.GetJTTDSYQZS(excelPath); Dictionary <string, XMLObject> xmlObjectDic = XMLRead.XmlToObjects_get <JTTDSYQZ> (); foreach (JTTDSYQZ jtsyqz in jtsyqzs) { Action action = new Action(() => { string th = jtsyqz.TuHao; if (th != null) { string[] array = th.Split('、'); if (array.Length > 2) { jtsyqz.TuHao = array[0] + "、" + array[1]; string th1 = ""; for (int a = 2; a < array.Length; a++) { if (a % 2 == 0) { th1 = th1 + "" + array[a]; } else { th1 = th1 + "、" + array[a]; } } jtsyqz.TH1 = th1; } } XWPFDocument docx = WordRead.Read(JTTDSYQZCustom.DocxTemplete); WordWrite.ReplaceText(docx, xmlObjectDic, jtsyqz); WordWrite.SaveToFile(docx, saveDir + "\\" + jtsyqz.DH + "_" + jtsyqz.DZ.Replace("中江县", "") + ".docx"); }); MyAction myAction = new MyAction(action, jtsyqz.DH + "_" + jtsyqz.DZ.Replace("中江县", "") + ".docx"); actions.Add(myAction); //break; } SingleTaskForm task = new SingleTaskForm(actions, "生成中江档案封面 "); } }
public static IList <T> ReadAllData <T>(string tableName, string mdbPath, string xmlPath = null) { Dictionary <string, XMLObject> xmlObjectDic; if (Utils.IsStrNull(xmlPath)) { xmlObjectDic = XMLRead.XmlToObjects_get <T>(); } else { xmlObjectDic = XMLRead.XmlToObjects(xmlPath); } Type type = typeof(T); string fullName = type.AssemblyQualifiedName; object[] array = new object[1]; IList <T> list = new List <T>(); string str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + mdbPath; OleDbConnection oleDbConnection = new OleDbConnection(str + ";OLE DB Services=-4"); oleDbConnection.Open(); OleDbCommand oleDbCommand = oleDbConnection.CreateCommand(); oleDbCommand.CommandText = "select * from " + tableName; Dictionary <int, string> dictionary = new Dictionary <int, string>(); OleDbDataReader oleDbDataReader = oleDbCommand.ExecuteReader(); int fieldCount = oleDbDataReader.FieldCount; for (int i = 0; i < fieldCount; i++) { dictionary.Add(i, oleDbDataReader.GetName(i)); } Dictionary <string, Clazz> clazzDic = ReflectUtils.MethodToFunction <T>(); Clazz clazz; string title; XMLObject xmlObject; IList <XMLObject> defualts = new List <XMLObject>(); foreach (XMLObject xml in xmlObjectDic.Values) { if (!Utils.IsStrNull(xml.Deafult)) { defualts.Add(xml); } } while (oleDbDataReader.Read()) { object obj = Activator.CreateInstance(type); for (int j = 0; j < fieldCount; j++) { title = oleDbDataReader.GetName(j); if (xmlObjectDic.TryGetValue(title, out xmlObject)) { clazz = clazzDic[xmlObject.Key]; array[0] = Utils.GetValueTrueType(oleDbDataReader[j], clazz.getParamterType().Name); if (array[0] == null) { continue; } else { clazz.SetMethodInfo.Invoke(obj, array); } } } foreach (XMLObject x in defualts) { clazz = clazzDic[x.Column]; array[0] = Utils.GetValueTrueType(x.Deafult, clazz.getParamterType().Name); if (array[0] == null) { continue; } else { clazz.SetMethodInfo.Invoke(obj, array); } } list.Add((T)((object)obj)); } oleDbDataReader.Close(); oleDbConnection.Close(); return(list); }