/// <summary> /// 构造函数 /// </summary> public Base() { this.m_state = objstate.Newed; this.m_state_manager = null; this.m_ismodified = false; this.m_reload = false; this.m_manager = null; }
/// <summary> /// 根据给定的ID加载sheet,以及与其相关的所有后代对象, /// 如果不存在,则返回null /// 并采用给定的StateManager对对象的状态进行管理 /// </summary> /// <param name="sheetid"></param> /// <returns></returns> public Prj_Sheet Load_Sheet(int sheetid, StateManager sm) { Hashtable table = new Hashtable(); Prj_Sheet result; IList<Cld_FCBlock> blocks; IList<Cld_Signal> signals; IList<Cld_Constant> consts; IList<Cld_Graphic> graphics; IList<Cld_FCInput> inputs; IList<Cld_FCOutput> outputs; IList<Cld_FCParameter> parameters; using (ITransaction transaction = this.session.BeginTransaction()) { try { result = (Prj_Sheet)this.session.Get(typeof(Prj_Sheet), sheetid); //如果没有找到对应的Prj_Sheet,返回null if (result == null) { return null; } result.State = objstate.Loaded; result.State_Manager = sm; sm.Loaded_List.Add(result); blocks = this.session.CreateQuery("from Cld_FCBlock as b where b.Prj_Sheet_ID = " + sheetid).List<Cld_FCBlock>(); signals = this.session.CreateQuery("from Cld_Signal as s where s.Prj_Sheet_ID = " + sheetid).List<Cld_Signal>(); consts = this.session.CreateQuery("from Cld_Constant as c where c.Prj_Sheet_ID = " + sheetid).List<Cld_Constant>(); graphics = this.session.CreateQuery("from Cld_Graphic as g where g.Prj_Sheet_ID = " + sheetid).List<Cld_Graphic>(); inputs = this.session.CreateQuery("from Cld_FCInput as i where i.Prj_Sheet_ID = " + sheetid).List<Cld_FCInput>(); outputs = this.session.CreateQuery("from Cld_FCOutput as o where o.Prj_Sheet_ID = " + sheetid).List<Cld_FCOutput>(); parameters = this.session.CreateQuery("from Cld_FCParameter as p where p.Prj_Sheet_ID = " + sheetid).List<Cld_FCParameter>(); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw e; } } //List to Hahstable foreach (Cld_FCBlock b in blocks) { b.State = objstate.Loaded; b.State_Manager = sm; table[b.ID] = b; b.Cld_FCInput_List = new MyList(b); b.Cld_FCOutput_List = new MyList(b); b.Cld_FCParameter_List = new MyList(b); } //关联input result.Cld_FCInput_List = new MyList(result); foreach (Cld_FCInput input in inputs) { input.State = objstate.Loaded; input.State_Manager = sm; sm.Loaded_List.Add(input); //关联到Block if (table.ContainsKey(input.Cld_FCBlock_ID)) { Cld_FCBlock block = (Cld_FCBlock)table[input.Cld_FCBlock_ID]; block.Cld_FCInput_List.Add(input); input.Cld_FCBlock = block; } else { continue; } //关联到sheet result.Cld_FCInput_List.Add(input); input.Prj_Sheet = result; } //关联output result.Cld_FCOutput_List = new MyList(result); foreach (Cld_FCOutput output in outputs) { output.State = objstate.Loaded; output.State_Manager = sm; sm.Loaded_List.Add(output); //关联到Block if (table.ContainsKey(output.Cld_FCBlock_ID)) { Cld_FCBlock block = (Cld_FCBlock)table[output.Cld_FCBlock_ID]; block.Cld_FCOutput_List.Add(output); output.Cld_FCBlock = block; } else { continue; } //关联到sheet result.Cld_FCOutput_List.Add(output); output.Prj_Sheet = result; } //关联parameter result.Cld_FCParameter_List = new MyList(result); foreach (Cld_FCParameter p in parameters) { p.State = objstate.Loaded; p.State_Manager = sm; sm.Loaded_List.Add(p); //关联到Block if (table.ContainsKey(p.Cld_FCBlock_ID)) { Cld_FCBlock block = (Cld_FCBlock)table[p.Cld_FCBlock_ID]; block.Cld_FCParameter_List.Add(p); p.Cld_FCBlock = block; } else { continue; } //关联到sheet result.Cld_FCParameter_List.Add(p); p.Prj_Sheet = result; } //关联signal result.Cld_Signal_List = new MyList(result); foreach (Cld_Signal signal in signals) { signal.State = objstate.Loaded; signal.State_Manager = sm; sm.Loaded_List.Add(signal); result.Cld_Signal_List.Add(signal); signal.Prj_Sheet = result; } //关联constant result.Cld_Constant_List = new MyList(result); foreach (Cld_Constant c in consts) { c.State = objstate.Loaded; c.State_Manager = sm; sm.Loaded_List.Add(c); result.Cld_Constant_List.Add(c); c.Prj_Sheet = result; } //关联graphic result.Cld_Graphic_List = new MyList(result); foreach (Cld_Graphic g in graphics) { g.State = objstate.Loaded; g.State_Manager = sm; sm.Loaded_List.Add(g); result.Cld_Graphic_List.Add(g); g.Prj_Sheet = result; } //关联block result.Cld_FCBlock_List = new MyList(result); foreach (Cld_FCBlock b in blocks) { b.State = objstate.Loaded; b.State_Manager = sm; sm.Loaded_List.Add(b); result.Cld_FCBlock_List.Add(b); b.Prj_Sheet = result; } Console.WriteLine("Load Prj_Sheet OK!"); return result; }
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()); }
/// <summary> /// 根据给定的ID加载sheet,以及与其相关的所有后代对象, /// 如果不存在,则返回null /// 并采用给定的StateManager对对象的状态进行管理 /// </summary> /// <param name="sheetid"></param> /// <returns></returns> public Prj_Sheet Load_Sheet(int sheetid, StateManager sm) { Hashtable table = new Hashtable(); Prj_Sheet result; IList <Cld_FCBlock> blocks; IList <Cld_Signal> signals; IList <Cld_Constant> consts; IList <Cld_Graphic> graphics; IList <Cld_FCInput> inputs; IList <Cld_FCOutput> outputs; IList <Cld_FCParameter> parameters; using (ITransaction transaction = this.session.BeginTransaction()) { try { result = (Prj_Sheet)this.session.Get(typeof(Prj_Sheet), sheetid); //如果没有找到对应的Prj_Sheet,返回null if (result == null) { return(null); } result.State = objstate.Loaded; result.State_Manager = sm; sm.Loaded_List.Add(result); blocks = this.session.CreateQuery("from Cld_FCBlock as b where b.Prj_Sheet_ID = " + sheetid).List <Cld_FCBlock>(); signals = this.session.CreateQuery("from Cld_Signal as s where s.Prj_Sheet_ID = " + sheetid).List <Cld_Signal>(); consts = this.session.CreateQuery("from Cld_Constant as c where c.Prj_Sheet_ID = " + sheetid).List <Cld_Constant>(); graphics = this.session.CreateQuery("from Cld_Graphic as g where g.Prj_Sheet_ID = " + sheetid).List <Cld_Graphic>(); inputs = this.session.CreateQuery("from Cld_FCInput as i where i.Prj_Sheet_ID = " + sheetid).List <Cld_FCInput>(); outputs = this.session.CreateQuery("from Cld_FCOutput as o where o.Prj_Sheet_ID = " + sheetid).List <Cld_FCOutput>(); parameters = this.session.CreateQuery("from Cld_FCParameter as p where p.Prj_Sheet_ID = " + sheetid).List <Cld_FCParameter>(); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw e; } } //List to Hahstable foreach (Cld_FCBlock b in blocks) { b.State = objstate.Loaded; b.State_Manager = sm; table[b.ID] = b; b.Cld_FCInput_List = new MyList(b); b.Cld_FCOutput_List = new MyList(b); b.Cld_FCParameter_List = new MyList(b); } //关联input result.Cld_FCInput_List = new MyList(result); foreach (Cld_FCInput input in inputs) { input.State = objstate.Loaded; input.State_Manager = sm; sm.Loaded_List.Add(input); //关联到Block if (table.ContainsKey(input.Cld_FCBlock_ID)) { Cld_FCBlock block = (Cld_FCBlock)table[input.Cld_FCBlock_ID]; block.Cld_FCInput_List.Add(input); input.Cld_FCBlock = block; } else { continue; } //关联到sheet result.Cld_FCInput_List.Add(input); input.Prj_Sheet = result; } //关联output result.Cld_FCOutput_List = new MyList(result); foreach (Cld_FCOutput output in outputs) { output.State = objstate.Loaded; output.State_Manager = sm; sm.Loaded_List.Add(output); //关联到Block if (table.ContainsKey(output.Cld_FCBlock_ID)) { Cld_FCBlock block = (Cld_FCBlock)table[output.Cld_FCBlock_ID]; block.Cld_FCOutput_List.Add(output); output.Cld_FCBlock = block; } else { continue; } //关联到sheet result.Cld_FCOutput_List.Add(output); output.Prj_Sheet = result; } //关联parameter result.Cld_FCParameter_List = new MyList(result); foreach (Cld_FCParameter p in parameters) { p.State = objstate.Loaded; p.State_Manager = sm; sm.Loaded_List.Add(p); //关联到Block if (table.ContainsKey(p.Cld_FCBlock_ID)) { Cld_FCBlock block = (Cld_FCBlock)table[p.Cld_FCBlock_ID]; block.Cld_FCParameter_List.Add(p); p.Cld_FCBlock = block; } else { continue; } //关联到sheet result.Cld_FCParameter_List.Add(p); p.Prj_Sheet = result; } //关联signal result.Cld_Signal_List = new MyList(result); foreach (Cld_Signal signal in signals) { signal.State = objstate.Loaded; signal.State_Manager = sm; sm.Loaded_List.Add(signal); result.Cld_Signal_List.Add(signal); signal.Prj_Sheet = result; } //关联constant result.Cld_Constant_List = new MyList(result); foreach (Cld_Constant c in consts) { c.State = objstate.Loaded; c.State_Manager = sm; sm.Loaded_List.Add(c); result.Cld_Constant_List.Add(c); c.Prj_Sheet = result; } //关联graphic result.Cld_Graphic_List = new MyList(result); foreach (Cld_Graphic g in graphics) { g.State = objstate.Loaded; g.State_Manager = sm; sm.Loaded_List.Add(g); result.Cld_Graphic_List.Add(g); g.Prj_Sheet = result; } //关联block result.Cld_FCBlock_List = new MyList(result); foreach (Cld_FCBlock b in blocks) { b.State = objstate.Loaded; b.State_Manager = sm; sm.Loaded_List.Add(b); result.Cld_FCBlock_List.Add(b); b.Prj_Sheet = result; } Console.WriteLine("Load Prj_Sheet OK!"); return(result); }