/// <summary> /// 文件的选择,Controlladdr的显示 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { OpenFileDialog open_file_dialog = new OpenFileDialog(); if (open_file_dialog.ShowDialog() == DialogResult.OK) { this.file_path = open_file_dialog.FileName; this.toolStripStatusLabel1.Text = "Current File is:" + this.file_path; this.strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data Source=" + this.file_path; this.myConn = new OleDbConnection(this.strConn); this.meta_modules = new Meta_ModuleS(this.myConn); this.meta_symbols = new Meta_SymbolS(this.meta_modules); string sqlStr = "SELECT DISTINCT ControllerAddress FROM Prj_Document"; OleDbDataAdapter da = new OleDbDataAdapter(sqlStr, myConn); DataSet ds = new DataSet(); da.Fill(ds); this.dataGridView_ControlAddr.DataSource = ds.Tables[0].DefaultView; foreach (DataRow row in ds.Tables[0].Rows) { controlladdr_list.Add(row[0].ToString()); } } }
/// <summary> /// 构造函数,根据给定的Meta_ModuleS,构造Meta_symbols /// </summary> /// <param name="meta_modules">给定的Meta_Modules</param> public Meta_SymbolS(Meta_ModuleS meta_modules) { // 数据成员的初始化 meta_symbols = new Hashtable(); //对每一个Meta_Module构造相应的Meta_Symbol foreach (Meta_Module meta_module in meta_modules.meta_modules.Values) { #region 特殊模块图标的构造 if (meta_module.FunctionName.Equals("XPgDO")) { List<Meta_SymbolMaster> temp = Create_XPgDO(17.5, "XPgDO", "XPgDO", "60", meta_module); foreach (Meta_SymbolMaster meta_sym_master in temp) { meta_symbols[meta_sym_master.SymbolID] = meta_sym_master; } continue; } else if (meta_module.FunctionName.Equals("XPgAO")) { List<Meta_SymbolMaster> temp = Create_XPgAO("XPgAO", 15, "te", meta_module); foreach (Meta_SymbolMaster meta_sym_master in temp) { meta_symbols[meta_sym_master.SymbolID] = meta_sym_master; } continue; } else if (meta_module.FunctionName.Equals("XPgDI")) { List<Meta_SymbolMaster> temp = Create_XPgDI("XPgDI", 17.5, "w", "w", meta_module); foreach (Meta_SymbolMaster meta_sym_master in temp) { meta_symbols[meta_sym_master.SymbolID] = meta_sym_master; } continue; } else if (meta_module.FunctionName.Equals("XPgAI")) { List<Meta_SymbolMaster> temp = Create_XPgAI("XPgAI", 15, "w", "w", meta_module); foreach (Meta_SymbolMaster meta_sym_master in temp) { meta_symbols[meta_sym_master.SymbolID] = meta_sym_master; } continue; } else if (meta_module.FunctionName.Equals("XPI")) { List<Meta_SymbolMaster> temp = Create_XPI("XPI", 75, 15, "null", meta_module); foreach (Meta_SymbolMaster meta_sym_master in temp) { meta_symbols[meta_sym_master.SymbolID] = meta_sym_master; } continue; } else if (meta_module.FunctionName.Equals("XDO")) { List<Meta_SymbolMaster> temp = Create_XDO("XDO", 75, 15, "null", meta_module); foreach (Meta_SymbolMaster meta_sym_master in temp) { meta_symbols[meta_sym_master.SymbolID] = meta_sym_master; } continue; } else if (meta_module.FunctionName.Equals("XAI")) { List<Meta_SymbolMaster> temp = Create_XAI("XAI", 75, 15, "null", meta_module); foreach (Meta_SymbolMaster meta_sym_master in temp) { meta_symbols[meta_sym_master.SymbolID] = meta_sym_master; } continue; } else if (meta_module.FunctionName.Equals("XAO")) { List<Meta_SymbolMaster> temp = Create_XAO("XAO", 75, 15, "null", meta_module); foreach (Meta_SymbolMaster meta_sym_master in temp) { meta_symbols[meta_sym_master.SymbolID] = meta_sym_master; } continue; } else if (meta_module.FunctionName.Equals("XDI")) { List<Meta_SymbolMaster> temp = Create_XDI("XDI", 75, 15, "null", meta_module); foreach (Meta_SymbolMaster meta_sym_master in temp) { meta_symbols[meta_sym_master.SymbolID] = meta_sym_master; } continue; } else if (meta_module.FunctionName.Equals("XAI")) { List<Meta_SymbolMaster> temp = Create_XAI("XAI", 75, 15, "null", meta_module); foreach (Meta_SymbolMaster meta_sym_master in temp) { meta_symbols[meta_sym_master.SymbolID] = meta_sym_master; } continue; } else if (meta_module.FunctionName.Equals("XNetDO")) { List<Meta_SymbolMaster> temp = Create_XNetDOI("XNetDO", 75, 15, "null", true, meta_module); foreach (Meta_SymbolMaster meta_sym_master in temp) { meta_symbols[meta_sym_master.SymbolID] = meta_sym_master; } continue; } else if (meta_module.FunctionName.Equals("XNetDI")) { List<Meta_SymbolMaster> temp = Create_XNetDOI("XNetDI", 75, 15, "null", false, meta_module); foreach (Meta_SymbolMaster meta_sym_master in temp) { meta_symbols[meta_sym_master.SymbolID] = meta_sym_master; } continue; } else if (meta_module.FunctionName.Equals("XNetAO")) { List<Meta_SymbolMaster> temp = Create_XNetAOI("XNetAO", 75, 15, "null", true, meta_module); foreach (Meta_SymbolMaster meta_sym_master in temp) { meta_symbols[meta_sym_master.SymbolID] = meta_sym_master; } continue; } else if (meta_module.FunctionName.Equals("XNetAI")) { List<Meta_SymbolMaster> temp = Create_XNetAOI("XNetAI", 75, 15, "null", false, meta_module); foreach (Meta_SymbolMaster meta_sym_master in temp) { meta_symbols[meta_sym_master.SymbolID] = meta_sym_master; } continue; } #endregion //一般模块图标的构造 //构造Master的整体 Meta_SymbolMaster meta_symbolmaster = new Meta_SymbolMaster(); meta_symbolmaster.SymbolID = meta_module.FunctionName; string symbolid = meta_module.FunctionName; meta_symbolmaster.SymbolName = meta_module.FunctionName; meta_symbolmaster.SymbolType = "FunctionCode"; meta_symbolmaster.OringinPoint = "0.00_0.00"; meta_symbolmaster.ReadOnly = false; meta_symbolmaster.FunctionName = meta_module.FunctionName; string functionname = meta_symbolmaster.FunctionName; meta_symbolmaster.Code = 0; List<int> width_height = GetWidthHeight(meta_module); //模块中输入引脚的个数 int module_input_count = Int32.Parse(meta_module.InputCount); //模块中输出引脚的个数 int module_output_count = Int32.Parse(meta_module.OutputCount); //记录模块图标的高度和宽度,以方便后边的使用 meta_symbolmaster.Height = width_height[1]; meta_symbolmaster.Width = width_height[0]; meta_symbols[meta_symbolmaster.SymbolID] = meta_symbolmaster; //构造Details部分 //对Input_Pin按Index的大小进行排序,其实可以采用实现比较接口的办法来实现 List<Meta_Module_Pin> in_mmp_temp = new List<Meta_Module_Pin>(); Hashtable index_2_Pin = new Hashtable(); foreach (Meta_Module_Pin mmp in meta_module.Input_Pin.Values) { index_2_Pin[Int32.Parse(mmp.PinIndex)] = mmp; } List<int> pin_index_list = new List<int>(); foreach (int pinindex in index_2_Pin.Keys) { pin_index_list.Add(pinindex); } pin_index_list.Sort(); foreach (int i in pin_index_list) { in_mmp_temp.Add((Meta_Module_Pin)index_2_Pin[i]); } //排序结束 //对Out_Pin按Index的大小进行排序,其实可以采用实现比较接口的办法来实现 List<Meta_Module_Pin> out_mmp_temp = new List<Meta_Module_Pin>(); index_2_Pin = new Hashtable(); foreach (Meta_Module_Pin mmp in meta_module.Out_Pin.Values) { index_2_Pin[Int32.Parse(mmp.PinIndex)] = mmp; } pin_index_list = new List<int>(); foreach (int pinindex in index_2_Pin.Keys) { pin_index_list.Add(pinindex); } pin_index_list.Sort(); foreach (int i in pin_index_list) { out_mmp_temp.Add((Meta_Module_Pin)index_2_Pin[i]); } //排序结束 #region 输入引脚的插入 List<double> Pin_y_pos = Get_Pin_Y_Pos(width_height[1], module_input_count); int index = 1; foreach (Meta_Module_Pin inputpin in in_mmp_temp) { //输入引脚 Meta_SymbolDetail meta_symboldetail = new Meta_SymbolDetail(); Point point_temp = new Point();//存储Pin的相对位置 meta_symboldetail.SymbolID = meta_symbolmaster.SymbolID; meta_symboldetail.ElementType = "Pin"; meta_symboldetail.ElementData = Get_Pin_Data(width_height[0], 5, true, index, ref point_temp, inputpin.PinName, Pin_y_pos); meta_symboldetail.DynamicType = 1; meta_symbolmaster.Details.Add(meta_symboldetail); index++; //增加Pin的相对位置 meta_symbolmaster.Pin_Relative_Pos[inputpin] = point_temp; //增加引脚数据值的显示 meta_symboldetail = new Meta_SymbolDetail(); meta_symboldetail.SymbolID = meta_symbolmaster.SymbolID; meta_symboldetail.ElementType = "Text"; string PinName = ""; string text_pos = ""; PinName = inputpin.PinName; text_pos = (point_temp.x + 16) + "_" + (point_temp.y - 2); meta_symboldetail.ElementData = "TextDispFun(AbbPinValueDisplayRule," + PinName + ".Value$$w||右下||" + text_pos + "||0||\"Courier New\"||8||255_255_255"; meta_symboldetail.DynamicType = 1; meta_symbolmaster.Details.Add(meta_symboldetail); } #endregion #region 输出引脚的插入 Pin_y_pos = Get_Pin_Y_Pos(width_height[1], module_output_count); index = 1; foreach (Meta_Module_Pin outputpin in out_mmp_temp) { //输出引脚 Meta_SymbolDetail meta_symboldetail = new Meta_SymbolDetail(); Point point_temp = new Point(); meta_symboldetail.SymbolID = meta_symbolmaster.SymbolID; meta_symboldetail.ElementType = "Pin"; meta_symboldetail.ElementData = Get_Pin_Data(width_height[0], 5, false, index, ref point_temp, outputpin.PinName, Pin_y_pos); meta_symboldetail.DynamicType = 1; meta_symbolmaster.Details.Add(meta_symboldetail); index++; //增加Pin的相对位置 meta_symbolmaster.Pin_Relative_Pos[outputpin] = point_temp; //增加引脚数据值的显示 meta_symboldetail = new Meta_SymbolDetail(); meta_symboldetail.SymbolID = meta_symbolmaster.SymbolID; meta_symboldetail.ElementType = "Text"; string PinName = ""; string text_pos = ""; PinName = outputpin.PinName; text_pos = (point_temp.x - 13) + "_" + (point_temp.y - 2); meta_symboldetail.ElementData = "TextDispFun(AbbPinValueDisplayRule," + PinName + ".Value$$w||左下||" + text_pos + "||0||\"\"Courier New\"\"||8||255_255_255"; meta_symboldetail.DynamicType = 1; meta_symbolmaster.Details.Add(meta_symboldetail); } #endregion {//DocShape Meta_SymbolDetail meta_symboldetail = new Meta_SymbolDetail(); meta_symboldetail.SymbolID = meta_symbolmaster.SymbolID; meta_symboldetail.ElementType = "DocShape"; meta_symboldetail.ElementData = "BODY_" + meta_symbolmaster.SymbolID + "||0_0||0"; meta_symboldetail.DynamicType = 0; meta_symbolmaster.Details.Add(meta_symboldetail); } {//动态文字的添加 //功能名字 Meta_SymbolDetail meta_symboldetail = new Meta_SymbolDetail(); meta_symboldetail.SymbolID = meta_symbolmaster.SymbolID; meta_symboldetail.ElementType = "Text";//TextDispFun(OwtBlankRule,BlockMe.FUNC_NAME)$$ ||左下||62.37_203.61||0||"Courier New"||12||255_255_255 //meta_symboldetail.ElementData = Get_Text_Data(meta_symbolmaster.FunctionName, width_height[0], width_height[1]); meta_symboldetail.ElementData = "TextDispFun(XinhuaBlankRule,BlockMe.FUNC_NAME)$$ ||正中||" + (0.5 * meta_symbolmaster.Width) + "_" + (0.2 * meta_symbolmaster.Height) + "||0||\"Courier New\"||8||255_255_255"; meta_symboldetail.DynamicType = 1; meta_symbolmaster.Details.Add(meta_symboldetail); //alg_name meta_symboldetail = new Meta_SymbolDetail(); meta_symboldetail.SymbolID = meta_symbolmaster.SymbolID; meta_symboldetail.ElementType = "Text";//TextDispFun(OwtBlankRule,BlockMe.ALG_NAME)$$ ||左下||62.37_188.61||0||"Courier New"||12||255_255_255 meta_symboldetail.ElementData = "TextDispFun(XinhuaBlockNameAndOrderRule,BlockMe.ALG_NAME,BlockMe.Order)$$ ||正中||" + (0.5 * meta_symbolmaster.Width) + "_" + (0.8 * meta_symbolmaster.Height) + "||0||\"Courier New\"||7||255_255_255"; meta_symboldetail.DynamicType = 2; meta_symbolmaster.Details.Add(meta_symboldetail); } Meta_SymbolMaster master_symbol = meta_symbolmaster; //body部分(里边的内容都为静态) { #region 构造Body部分 meta_symbolmaster = new Meta_SymbolMaster(); meta_symbolmaster.SymbolID = "BODY_" + symbolid; meta_symbolmaster.SymbolName = "BODY_" + symbolid; meta_symbolmaster.SymbolType = "DocumentShape"; meta_symbolmaster.OringinPoint = "0.00_0.00"; meta_symbolmaster.ReadOnly = false; meta_symbolmaster.FunctionName = functionname; meta_symbolmaster.Code = 0; meta_symbolmaster.Height = width_height[1];//模块的高度 meta_symbolmaster.Width = width_height[0];//模块的宽度 meta_symbols["BODY" + symbolid] = meta_symbolmaster; //构造Body的Detail部分 { Meta_SymbolDetail meta_symboldetail; //输入Pin Name的显示 foreach (Meta_Module_Pin inpin in in_mmp_temp) { meta_symboldetail = new Meta_SymbolDetail(); meta_symboldetail.SymbolID = meta_symbolmaster.SymbolID; meta_symboldetail.ElementType = "Text"; Point body_pin = (Point)master_symbol.Pin_Relative_Pos[inpin]; meta_symboldetail.ElementData = inpin.PinName + "||左下||" + 0 + "_" + (body_pin.y + 4) + "||0||MONOTEXT||6||255_255_255"; meta_symboldetail.DynamicType = 0; meta_symbolmaster.Details.Add(meta_symboldetail); } //输出Pin Name的显示 foreach (Meta_Module_Pin outpin in out_mmp_temp) { meta_symboldetail = new Meta_SymbolDetail(); meta_symboldetail.SymbolID = meta_symbolmaster.SymbolID; meta_symboldetail.ElementType = "Text"; Point body_pin = (Point)master_symbol.Pin_Relative_Pos[outpin]; meta_symboldetail.ElementData = outpin.PinName + "||右下||" + (master_symbol.Width) + "_" + (body_pin.y + 4) + "||0||MONOTEXT||6||255_255_255"; meta_symboldetail.DynamicType = 0; meta_symbolmaster.Details.Add(meta_symboldetail); } //Line for (int i = 0; i < 4; i++) { //four lines meta_symboldetail = new Meta_SymbolDetail(); meta_symboldetail.SymbolID = meta_symbolmaster.SymbolID; meta_symboldetail.ElementType = "Line"; meta_symboldetail.ElementData = Get_Line_Data(width_height[0], width_height[1], i); meta_symboldetail.DynamicType = 0; meta_symbolmaster.Details.Add(meta_symboldetail); } } #endregion } } }
/// <summary> /// 将Meta_FCMaster和Meta_FCDetail表中的内容转换到Meta_SymbolMaster和Meta_SymbolDetail表中 /// </summary> /// <param name="conn">数据库连接:OleDbConnection</param> static public void Meta_Module_2_Meta_Symbol(OleDbConnection conn) { Meta_ModuleS meta_modules = new Meta_ModuleS(conn);//读取Meta_Module信息 Meta_SymbolS meta_symbols = new Meta_SymbolS(meta_modules);//转换为描述Meta_Symbol信息 meta_symbols.InsertIntoTable(conn);//插入到Meta_SymbolMaster和meta_symboldetail中 }
/// <summary> /// 构造函数,从数据库中读取包含给定ControllerAddr,DocumentName,SheetName的Cld_Module的集合 /// </summary> /// <param name="conn">到数据库的连接</param> /// <param name="ControllerAddr">Controller Address</param> /// <param name="DocumentName">Document Name</param> /// <param name="SheetName">Sheet Name</param> /// <param name="metamodules">Meta_Modules</param> public Cld_ModuleS(OleDbConnection conn, string ControllerAddr, string DocumentName, string SheetName, Meta_ModuleS metamodules) { //进行必要的初始化 cld_modules = new Hashtable(); signals = new Signals(); cld_signals = new Cld_SignalS(); meta_modules = metamodules; this.ControllerAddr = ControllerAddr; this.DocumentName = DocumentName; this.SheetName = SheetName; //建立数据库连接 if (conn.State == ConnectionState.Closed) { try { conn.Open(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } //数据库操作字符串 string sql_string = "SELECT * FROM Cld_FCMaster WHERE ControllerAddress='" + ControllerAddr + "' AND DocumentName='" + DocumentName + "' AND SheetName='" + SheetName + "'"; OleDbDataAdapter Cld_FCMaster_Adapter = new OleDbDataAdapter(sql_string, conn); DataSet myDataSet = new DataSet(); Cld_FCMaster_Adapter.Fill(myDataSet, "Cld_FCMaster"); //处理CLD FCMaster表的每一行 for (int i = 0; i < myDataSet.Tables["Cld_FCMaster"].Rows.Count; i++) { Cld_Module cld_module_temp = new Cld_Module(); //处理相应的Cld_FCMaster表 cld_module_temp.ObjectID = myDataSet.Tables["Cld_FCMaster"].Rows[i]["ObjectID"].ToString(); cld_module_temp.ControllerAddress = myDataSet.Tables["Cld_FCMaster"].Rows[i]["ControllerAddress"].ToString(); cld_module_temp.DocumentName = myDataSet.Tables["Cld_FCMaster"].Rows[i]["DocumentName"].ToString(); cld_module_temp.SheetName = myDataSet.Tables["Cld_FCMaster"].Rows[i]["SheetName"].ToString(); cld_module_temp.AlgName = myDataSet.Tables["Cld_FCMaster"].Rows[i]["AlgName"].ToString(); cld_module_temp.AlgOrder = myDataSet.Tables["Cld_FCMaster"].Rows[i]["AlgOrder"].ToString(); cld_module_temp.FunctionName = myDataSet.Tables["Cld_FCMaster"].Rows[i]["FunctionName"].ToString(); cld_module_temp.X_Y = myDataSet.Tables["Cld_FCMaster"].Rows[i]["X_Y"].ToString(); cld_module_temp.SymbolName = myDataSet.Tables["Cld_FCMaster"].Rows[i]["SymbolName"].ToString(); cld_module_temp.DESCRP = myDataSet.Tables["Cld_FCMaster"].Rows[i]["DESCRP"].ToString(); cld_module_temp.PERIOD = myDataSet.Tables["Cld_FCMaster"].Rows[i]["PERIOD"].ToString(); cld_module_temp.PHASE = myDataSet.Tables["Cld_FCMaster"].Rows[i]["PHASE"].ToString(); cld_module_temp.LOOPID = myDataSet.Tables["Cld_FCMaster"].Rows[i]["LOOPID"].ToString(); //处理相应的Cld_FCDetail表 sql_string = "SELECT * FROM Cld_FCDetail WHERE ObjectID='" + cld_module_temp.ObjectID + "'"; OleDbDataAdapter Cld_FCDetail_Adapter = new OleDbDataAdapter(sql_string, conn); Cld_FCDetail_Adapter.Fill(myDataSet, "Cld_FCDetail"); for (int m = 0; m < myDataSet.Tables["Cld_FCDetail"].Rows.Count; m++) { Cld_Module_Pin cld_module_pin_temp = new Cld_Module_Pin(); //对Cld_Module_Pin对象进行数据的填充 cld_module_pin_temp.ObjectID = myDataSet.Tables["Cld_FCDetail"].Rows[m]["ObjectID"].ToString(); cld_module_pin_temp.PinName = myDataSet.Tables["Cld_FCDetail"].Rows[m]["PinName"].ToString(); cld_module_pin_temp.PinValue = myDataSet.Tables["Cld_FCDetail"].Rows[m]["PinValue"].ToString(); cld_module_pin_temp.NetworkID = myDataSet.Tables["Cld_FCDetail"].Rows[m]["NetworkID"].ToString(); cld_module_pin_temp.IsHistory = (bool)(myDataSet.Tables["Cld_FCDetail"].Rows[m]["IsHistory"]); cld_module_pin_temp.Point = myDataSet.Tables["Cld_FCDetail"].Rows[m]["Point"].ToString(); cld_module_temp.Pins[cld_module_pin_temp.PinName] = cld_module_pin_temp; if (metamodules.Pin_Type(cld_module_temp.FunctionName, cld_module_pin_temp.PinName).Equals("Input")) { cld_module_pin_temp.PinType = "Input"; cld_module_temp.PinType[cld_module_pin_temp.PinName] = "Input"; cld_module_temp.Input_Pin[cld_module_pin_temp.PinName] = cld_module_pin_temp; } else if (metamodules.Pin_Type(cld_module_temp.FunctionName, cld_module_pin_temp.PinName).Equals("Output")) { cld_module_pin_temp.PinType = "Output"; cld_module_temp.PinType[cld_module_pin_temp.PinName] = "Output"; cld_module_temp.Out_Pin[cld_module_pin_temp.PinName] = cld_module_pin_temp; } else if (metamodules.Pin_Type(cld_module_temp.FunctionName, cld_module_pin_temp.PinName).Equals("Constant")) { cld_module_temp.PinType[cld_module_pin_temp.PinName] = "Constant"; cld_module_pin_temp.PinType = "Constant"; //cld_module_temp.Constant_Pin.Add(cld_module_pin_temp); cld_module_temp.Constant_Pin[cld_module_pin_temp.PinName] = cld_module_pin_temp; } else if (metamodules.Pin_Type(cld_module_temp.FunctionName, cld_module_pin_temp.PinName).Equals("Internal")) { cld_module_pin_temp.PinType = "Internal"; cld_module_temp.PinType[cld_module_pin_temp.PinName] = "Internal"; //cld_module_temp.Internal_Pin.Add(cld_module_pin_temp); cld_module_temp.Internal_Pin[cld_module_pin_temp.PinName] = cld_module_pin_temp; } else { //没有这种类型的引脚,因该是数据库有问题 cld_module_temp.PinType[cld_module_pin_temp.PinName] = ""; cld_module_pin_temp.PinType = ""; } } myDataSet.Tables["Cld_FCDetail"].Clear(); cld_modules[cld_module_temp.ObjectID] = cld_module_temp; } //读取数据完毕 myDataSet.Dispose(); Cld_FCMaster_Adapter.Dispose(); conn.Close(); }