static void Main() { SessionManager sessionmanager = new SessionManager("hibernate_config.xml"); ISession session = sessionmanager.GetSession(); // 相关操作的接口 PrjManager manager = new PrjManager(session); //add your code bellow Prj_Sheet sheet = manager.SheetCRUD.GetPrj_Sheet_By_ID(202); Cld_FCBlock temp = sheet.New_Cld_FCBlock(); temp.AlgName = "weifdajflkjdlkajfkldjlkajfkdjkaljfkdjajfldjalfjlkajfldjlak"; manager.persistence_save(temp); //释放相关资源 manager.Close(); Console.WriteLine("\nPress Enter to Exit !"); Console.ReadKey(); //以下为GUI运行 //Application.EnableVisualStyles(); //Application.SetCompatibleTextRenderingDefault(false); //Application.Run(new Form1()); }
private static void load_commit_test(PrjManager manager) { Prj_Sheet sheet = manager.SheetCRUD.Load_Sheet(2316); Prj_Sheet backup = ObjectCopier.Clone(sheet); Cld_FCBlock block = sheet.New_Cld_FCBlock(); block.AlgName = "added"; block.Sequence = 12; Cld_FCInput inpt = block.New_FCInput(); inpt.Description = "added desc"; inpt.PinName = "for test"; Cld_FCOutput output = block.New_FCOutput(); output.PinName = "for test output"; SheetDiffer diff = manager.SheetCRUD.CompareSheet(backup, sheet); manager.SheetCRUD.Commit_Sheet(diff); }
/// <summary> /// 生成Block之间的连线关系,Signal的集合,并存储数据 /// </summary> /// <param name="sheet"></param> /// <returns></returns> public IDictionary <string, Cld_Signal> GenerateSignalLines(Prj_Sheet sheet) { // 测点名与起始引脚的对应关系 IDictionary <string, Cld_FCOutput> pointNameToStartPin = new Dictionary <string, Cld_FCOutput>(); // IDictionary <string, Cld_Signal> pointNameToSignal = new Dictionary <string, Cld_Signal>(); // 匹配PointName格式为"%-%-%-%"的项 Regex regPointName = new Regex(@"^(\d+)((-(\d+)){3})$"); foreach (Cld_FCBlock block in sheet.Cld_FCBlock_List) { foreach (Cld_FCOutput output in sheet.Cld_FCOutput_List) { // 将当前页面所有 Output 与点名的对应关系存储在 pointNameToStartPin 字典中 // 在该字典中,通过 PointName 就可以找到对应的 Output if (!pointNameToStartPin.ContainsKey(output.PointName)) { pointNameToStartPin.Add(output.PointName, output); } } } foreach (Cld_FCBlock block in sheet.Cld_FCBlock_List) { foreach (Cld_FCInput input in block.Cld_FCInput_List) { if (input.PointName == null || !regPointName.IsMatch(input.PointName) || !input.Visible || !pointNameToStartPin.ContainsKey(input.PointName)) { // 该管脚未连接,或不显示信号线,或连接的Pin不在当前Sheet中,继续扫描下一个 Input。 continue; } Cld_FCOutput startPin = pointNameToStartPin[input.PointName] as Cld_FCOutput; string signalData; if (startPin.Point != null || input.Point != null) { signalData = GenerateSignalData(startPin, input); } else { throw new Exception("管脚坐标未计算!"); } Cld_Signal signalTemp; if (pointNameToSignal.ContainsKey(input.PointName)) { signalTemp = pointNameToSignal[input.PointName]; signalTemp.Data += signalData; pointNameToSignal[input.PointName] = signalTemp; //manager.Update(signal_temp); } else { signalTemp = new Cld_Signal(); signalTemp.Prj_Controller = sheet.Prj_Controller; signalTemp.Prj_Document = sheet.Prj_Document; signalTemp.Prj_Sheet = sheet; signalTemp.Name = startPin.PointName; signalTemp.Data = signalData; signalTemp.SignalType = get_pin_dataType(startPin.Cld_FCBlock.FunctionName, startPin.PinName); pointNameToSignal.Add(input.PointName, signalTemp); //this.manager.Save(signal_temp); } } } //this.manager.Flush(); return(pointNameToSignal); }
/// <summary> /// Prj_Sheet To Xml /// </summary> /// <param name="sheet"></param> public static void Generate_Sheet_Xml(Prj_Sheet sheet, BllManager bll) { //因为此方法采用反射来获取类中的所有共有属性进行输出,因此这里屏蔽对象中的某些不需要输出的属性 List <string> myclass = new List <string>(); myclass.Add("Prj_Project"); myclass.Add("Prj_Network"); myclass.Add("Prj_Unit"); myclass.Add("Prj_Controller"); myclass.Add("Prj_Document"); myclass.Add("Prj_Sheet"); myclass.Add("Cld_FCBlock"); myclass.Add("Cld_Signal"); myclass.Add("Cld_Constant"); myclass.Add("Cld_Graphic"); myclass.Add("X"); myclass.Add("Y"); myclass.Add("PinIndex"); try { // 创建XmlTextWriter类的实例对象 XmlTextWriter textWriter = new XmlTextWriter(sheet.ID.ToString() + ".xml", null); textWriter.Formatting = Formatting.Indented; // 开始写过程,调用WriteStartDocument方法 textWriter.WriteStartDocument(); // 写入说明 textWriter.WriteComment("First Comment XmlTextWriter Sample Example"); textWriter.WriteComment("w3sky.xml in root dir"); Type sheet_type = typeof(Prj_Sheet); Type fcblock_type = typeof(Cld_FCBlock); Type fcconst_type = typeof(Cld_Constant); Type fcgraphic_type = typeof(Cld_Graphic); Type fcsignal_type = typeof(Cld_Signal); Type fcinput_type = typeof(Cld_FCInput); Type fcoutput_type = typeof(Cld_FCOutput); Type fcpara_type = typeof(Cld_FCParameter); //创建sheet结点 textWriter.WriteStartElement("sheet"); foreach (PropertyInfo pi in sheet_type.GetProperties()) { object value_object = pi.GetValue(sheet, null); string value_string = ""; if (pi.PropertyType.Name.Equals("IList") || myclass.Contains(pi.PropertyType.Name)) { continue; } if (value_object != null) { value_string = value_object.ToString(); } textWriter.WriteAttributeString(pi.Name, value_string); } //fcblock foreach (Cld_FCBlock fcblock in sheet.Cld_FCBlock_List) { textWriter.WriteStartElement("element"); textWriter.WriteAttributeString("type", "Cld_FCBlock"); bll.generate_Rec_symbol(fcblock, TDK.Core.Logic.BLL.BllManager.rela_pos.UPLEFT); foreach (PropertyInfo pi in fcblock_type.GetProperties()) { object value_object = pi.GetValue(fcblock, null); string value_string = ""; if (pi.PropertyType.Name.Equals("IList") || myclass.Contains(pi.PropertyType.Name)) { continue; } if (value_object != null) { value_string = value_object.ToString(); } textWriter.WriteAttributeString(pi.Name, value_string); } foreach (Cld_FCInput input in fcblock.Cld_FCInput_List) { textWriter.WriteStartElement("element"); textWriter.WriteAttributeString("type", "Cld_FCInput"); foreach (PropertyInfo pi in fcinput_type.GetProperties()) { object value_object = pi.GetValue(input, null); string value_string = ""; if (pi.PropertyType.Name.Equals("IList") || myclass.Contains(pi.PropertyType.Name)) { continue; } if (value_object != null) { value_string = value_object.ToString(); } textWriter.WriteAttributeString(pi.Name, value_string); } textWriter.WriteEndElement(); } //foreach (Cld_FCOutput output in fcblock.Cld_FCOutput_List) //{ // textWriter.WriteStartElement("element"); // textWriter.WriteAttributeString("type", "FCOutput"); // foreach (PropertyInfo pi in fcoutput_type.GetProperties()) // { // object value_object = pi.GetValue(output, null); // string value_string = ""; // if (pi.PropertyType.Name.Equals("IList") || myclass.Contains(pi.PropertyType.Name)) // { // continue; // } // if (value_object != null) // { // value_string = value_object.ToString(); // } // textWriter.WriteAttributeString(pi.Name, value_string); // } // textWriter.WriteEndElement(); //} //foreach (Cld_FCParameter para in fcblock.Cld_FCParameter_List) //{ // textWriter.WriteStartElement("element"); // textWriter.WriteAttributeString("type", "Cld_FCParameter"); // foreach (PropertyInfo pi in fcpara_type.GetProperties()) // { // object value_object = pi.GetValue(para, null); // string value_string = ""; // if (pi.PropertyType.Name.Equals("IList") || myclass.Contains(pi.PropertyType.Name)) // { // continue; // } // if (value_object != null) // { // value_string = value_object.ToString(); // } // textWriter.WriteAttributeString(pi.Name, value_string); // } // textWriter.WriteEndElement(); //} textWriter.WriteEndElement(); } ////const //foreach (Cld_Constant cldconst in sheet.Cld_Constant_List) //{ // textWriter.WriteStartElement("element"); // textWriter.WriteAttributeString("type", "Cld_Constant"); // foreach (PropertyInfo pi in fcconst_type.GetProperties()) // { // object value_object = pi.GetValue(cldconst, null); // string value_string = ""; // if (pi.PropertyType.Name.Equals("IList") || myclass.Contains(pi.PropertyType.Name)) // { // continue; // } // if (value_object == null) // { // value_string = value_object.ToString(); // } // textWriter.WriteAttributeString(pi.Name, value_string); // } // textWriter.WriteEndElement(); //} ////graphic //foreach (Cld_Graphic graphic in sheet.Cld_Graphic_List) //{ // textWriter.WriteStartElement("element"); // textWriter.WriteAttributeString("type", "Cld_Graphic"); // foreach (PropertyInfo pi in fcgraphic_type.GetProperties()) // { // object value_object = pi.GetValue(graphic, null); // string value_string = ""; // if (pi.PropertyType.Name.Equals("IList") || myclass.Contains(pi.PropertyType.Name)) // { // continue; // } // if (value_object == null) // { // value_string = value_object.ToString(); // } // textWriter.WriteAttributeString(pi.Name, value_string); // } // textWriter.WriteEndElement(); //} ////signal //foreach (Cld_Signal signal in sheet.Cld_Signal_List) //{ // textWriter.WriteStartElement("element"); // textWriter.WriteAttributeString("type", "Cld_Signal"); // foreach (PropertyInfo pi in fcsignal_type.GetProperties()) // { // object value_object = pi.GetValue(signal, null); // string value_string = ""; // if (pi.PropertyType.Name.Equals("IList") || myclass.Contains(pi.PropertyType.Name)) // { // continue; // } // if (value_object == null) // { // value_string = value_object.ToString(); // } // textWriter.WriteAttributeString(pi.Name, value_string); // } // textWriter.WriteEndElement(); //} textWriter.WriteEndElement(); // 关闭textWriter textWriter.Close(); } catch (System.Exception e) { Console.WriteLine(e.ToString()); } }
static void Main() { SessionManager sessionmanager = new SessionManager("hibernate_config.xml"); ISession session = sessionmanager.GetSession(); // 相关操作的接口 PrjManager manager = new PrjManager(session); //add your code bellow TDK.Core.Logic.URdoLib.URdoManager man = new TDK.Core.Logic.URdoLib.URdoManager(); StateManager sm = new StateManager(); for (int i = 169; i <= 179; i++) { Prj_Sheet sheet = manager.SheetCRUD.Load_Sheet(i, sm); Cld_FCBlock weiyuanke = sheet.New_Cld_FCBlock(); weiyuanke.FunctionName = "fortest"; manager.Save(weiyuanke); Cld_FCInput input = weiyuanke.New_FCInput(); Console.WriteLine(sheet.State); sheet.SheetName = "weiyuantafkjaljfl"; Console.WriteLine(sheet.State); Cld_FCBlock b = sheet.Cld_FCBlock_List[0] as Cld_FCBlock; Console.WriteLine(b.State); sheet.Cld_FCBlock_List.RemoveAt(0); Console.WriteLine(b.State); sheet.Cld_FCBlock_List.Add(b); Console.WriteLine(b.State); Cld_FCBlock temp = sheet.New_Cld_FCBlock(); Console.WriteLine(temp.State); sheet.Cld_FCBlock_List.Add(temp); Console.WriteLine(temp.State); } //GraphicsDocument.GenerateProjects(bll); // 产生xml文件的代码 //Prj_Sheet sheet = bll.manager.SheetCRUD.Load_Sheet(170); //Generate_Sheet_Xml(sheet, bll); //释放相关资源 //bll.Close(); Console.WriteLine("\nPress Enter to Exit !"); Console.ReadKey(); //以下为GUI运行 //Application.EnableVisualStyles(); //Application.SetCompatibleTextRenderingDefault(false); //Application.Run(new Form1()); }