public static void Parse_All_Data_Grid(SQL_Connect_Builder builder) { DataTable dt = builder.Select_Table("AllDataGrid"); foreach (DataRow dr in dt.Rows) { string name = dr[0].ToString(); string table_type = dr[1].ToString(); if (table_type == "OrderTable") { // 这个地方数量不对 CreateSqlValueType[] create_sql_value_type = new CreateSqlValueType[1 + (dr.ItemArray.Length - 2) / 2]; create_sql_value_type[0] = new CreateSqlValueType("integer", "MyOrder", true); for (int i = 0; i < (dr.ItemArray.Length - 12) / 2; i++) { if (dr[12 + i * 2].ToString() == "" || dr[12 + i * 2 + 1].ToString() == "") { break; } create_sql_value_type[1 + i] = new CreateSqlValueType(dr[12 + i * 2 + 1].ToString(), dr[12 + i * 2].ToString()); } builder.Create_Table(name, create_sql_value_type); } } }
public MapConfig() { InitializeComponent(); Show_Pic_List(); Show_Voice(); this.DoubleBuffered = true; create_map[0] = new CreateSqlValueType("datetime", "createtime", true); create_map[1] = new CreateSqlValueType("int", "startX"); create_map[2] = new CreateSqlValueType("int", "startY"); create_map[3] = new CreateSqlValueType("int", "endX"); create_map[4] = new CreateSqlValueType("int", "endY"); create_map[5] = new CreateSqlValueType("int", "start_value"); create_map[6] = new CreateSqlValueType("int", "end_value"); create_map[7] = new CreateSqlValueType("nvarchar(50)", "kind"); create_map[8] = new CreateSqlValueType("nvarchar(50)", "voice"); pictureBox1.Parent = panel2; //pictureBox2.Parent = panel2; pictureBox1.BackColor = Color.Transparent; comboBox_warningtype.Items.Add("行人"); comboBox_warningtype.Items.Add("攀爬"); //pictureBox2.BackColor = Color.Transparent; }
private void 新建ToolStripMenuItem_Click(object sender, EventArgs e) { // 出现新增窗体页面 MainSubView.AddView view = new MainSubView.AddView(); DialogResult result = view.ShowDialog(); if (result == DialogResult.OK) { string[] insert_cmd = new string[1]; insert_cmd[0] = MainSubView.AddView.View_Name; bool success = Main_DataBase_Builder.Insert("AllView", insert_cmd); TreeNode viewnode = FindTreeNodeWithName("画面", treeview1); /// 创建一个这个界面的表 /// if (success == true) { CreateSqlValueType[] create_cmd = new CreateSqlValueType[2]; create_cmd[0] = new CreateSqlValueType("nvarchar(50)", "member", true, true); create_cmd[1] = new CreateSqlValueType("nvarchar(50)", "type"); Main_DataBase_Builder.Create_Table(MainSubView.AddView.View_Name, create_cmd); } if (viewnode != null) { Reflush_TreeView_ViewNode(viewnode); // 刷新画面的父结点的信息 } } }
private void timer1_Tick(object sender, EventArgs e) { CreateSqlValueType[] create_warningtable = new CreateSqlValueType[3]; string table_name = "warning" + DateTime.Now.ToString("yyyyMMdd"); create_warningtable[0] = new CreateSqlValueType("datetime", "createtime", true); create_warningtable[1] = new CreateSqlValueType("nvarchar(50)", "type"); create_warningtable[2] = new CreateSqlValueType("nvarchar(50)", "location"); Login.builder.Create_Table(table_name, create_warningtable); }
public static SQL_Connect_Builder builder = new SQL_Connect_Builder(".", "realphotonics", 0, 100); // 数据库的连接 public Login() { InitializeComponent(); // 建立用户表 CreateSqlValueType[] create_usertable_value = new CreateSqlValueType[3]; create_usertable_value[0] = new CreateSqlValueType("nvarchar(50)", "userID", true); create_usertable_value[1] = new CreateSqlValueType("nvarchar(50)", "password"); create_usertable_value[2] = new CreateSqlValueType("nvarchar(50)", "passion"); builder.Create_Table("usertable", create_usertable_value); // 建立报警表 }
private void Create_Device_Database() { // 创建串口通讯数据库 CreateSqlValueType[] create_cmd = new CreateSqlValueType[7]; create_cmd[0] = new CreateSqlValueType("nvarchar(50)", "com_name", true); create_cmd[1] = new CreateSqlValueType("nvarchar(50)", "com_num"); create_cmd[2] = new CreateSqlValueType("nvarchar(50)", "botelv"); create_cmd[3] = new CreateSqlValueType("nvarchar(50)", "shujuwei"); create_cmd[4] = new CreateSqlValueType("nvarchar(50)", "tingzhiwei"); create_cmd[5] = new CreateSqlValueType("nvarchar(50)", "jiaoyanwei"); create_cmd[6] = new CreateSqlValueType("nvarchar(50)", "chejian"); MainView.builder.Create_Table("com_config", create_cmd); }
public Form1() { InitializeComponent(); CreateSqlValueType[] create_cmd = new CreateSqlValueType[2]; create_cmd[0] = new CreateSqlValueType("nvarchar(50)", "mykey", true); create_cmd[1] = new CreateSqlValueType("nvarchar(50)", "num"); builder.Create_Table("tiaonum", create_cmd); string[] inser_cmd = new string[2]; inser_cmd[0] = "mynum"; inser_cmd[1] = "0"; builder.Insert("tiaonum", inser_cmd); }
public CamConfig() { InitializeComponent(); // 建立摄像头设定列表 CreateSqlValueType[] cam_config_table = new CreateSqlValueType[7]; cam_config_table[0] = new CreateSqlValueType("nvarchar(50)", "camID", true); cam_config_table[1] = new CreateSqlValueType("nvarchar(50)", "camIP"); cam_config_table[2] = new CreateSqlValueType("nvarchar(50)", "camPort"); cam_config_table[3] = new CreateSqlValueType("nvarchar(50)", "username"); cam_config_table[4] = new CreateSqlValueType("nvarchar(50)", "password"); cam_config_table[5] = new CreateSqlValueType("nvarchar(50)", "minvalue"); cam_config_table[6] = new CreateSqlValueType("nvarchar(50)", "maxvalue"); Login.builder.Create_Table("camconfig", cam_config_table); Read_Cam_Info(); }
CreateSqlValueType[] runtime_create_sql_value_type = new CreateSqlValueType[4]; // 保存实时数据的表结构 public MainWindow() { InitializeComponent(); // 解析主界面 // 解析所有的Grid this.Left = 0; this.Top = 0; this.Width = ViewCaoZuo.width; this.Height = ViewCaoZuo.height; this.Name = "MainWindow"; DataTable dt = database_builder.Select_Table("Station_Info"); running_data = new Running_Data(dt); // 解析所有表 DataPrase.Parse_All_Table_Struct(database_builder); DataPrase.Parse_All_Data_Grid(database_builder); WPFDataStruct.WindowParsing.ParseWindow(this, database_builder, MainGrid); WPFDataStruct.WindowParsing.Read_All_SubWindow(database_builder, AllSubWindow, running_data); Add_Event(); // 读取所有的窗体 Read_All_Value(); Read_All_RunTime_Table(); Read_All_Station(); // 初始化建立实时历史数据库的命令 runtime_create_sql_value_type[0] = new CreateSqlValueType("nvarchar(50)", "TimeAndName", true); runtime_create_sql_value_type[1] = new CreateSqlValueType("nvarchar(50)", "Value_Name"); runtime_create_sql_value_type[2] = new CreateSqlValueType("DateTime", "Time"); runtime_create_sql_value_type[3] = new CreateSqlValueType("nvarchar(50)", "Value"); // 初始化时钟 savetimer.Interval = 10000; savetimer.Elapsed += new System.Timers.ElapsedEventHandler(Save_RunTimeValue_Tick); savetimer.Enabled = true; //解析所有的保存数据 }
public static void Parse_All_Table_Struct(SQL_Connect_Builder builder) { DataTable dt = builder.Select_Table("TableStruct"); if (dt != null) { if (dt.Rows.Count > 0) { int colcount = dt.Columns.Count; foreach (DataRow dr in dt.Rows) { int value_count = 0; for (int i = 0; i < colcount; i++) { if (dr[i].ToString() != "") { value_count++; } else { break; } } int table_col_count = (value_count - 1) / 2; CreateSqlValueType[] createsqlvaluetype = new CreateSqlValueType[table_col_count]; for (int j = 0; j < table_col_count; j++) { if (j == 0) { createsqlvaluetype[j] = new CreateSqlValueType(dr[2 + j * 2].ToString(), dr[1 + j * 2].ToString(), true); } else { createsqlvaluetype[j] = new CreateSqlValueType(dr[2 + j * 2].ToString(), dr[1 + j * 2].ToString()); } } builder.Create_Table(dr[0].ToString(), createsqlvaluetype); } } } }
private void Save_Info() { // 温度信息保存 CreateSqlValueType[] createsaveinfo = new CreateSqlValueType[5]; createsaveinfo[0] = new CreateSqlValueType("nvarchar(50)", "ID", true); createsaveinfo[1] = new CreateSqlValueType("int", "machine_num"); createsaveinfo[2] = new CreateSqlValueType("nvarchar(50)", "value_name"); createsaveinfo[3] = new CreateSqlValueType("datetime", "value_time"); createsaveinfo[4] = new CreateSqlValueType("nvarchar(50)", "value"); MainView.builder.Create_Table("save_info", createsaveinfo); string where_cmd = "value_name='机缸温度'"; DataTable dt = MainView.builder.Select_Table("Value_Config", where_cmd); int wendu_address = 0; try { wendu_address = int.Parse(dt.Rows[0][2].ToString()); } catch { return; } for (int i = 1; i < 100; i++) { string[] insert_cmd = new string[5]; insert_cmd[0] = DateTime.Now.ToString("yyyyMMddHHmmss") + i.ToString(); insert_cmd[1] = i.ToString(); insert_cmd[2] = "机缸温度"; insert_cmd[3] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); insert_cmd[4] = Device_Data.chejian3_com1_DT[i, wendu_address].ToString(); MainView.builder.Insert("save_info", insert_cmd); } }
private void Init_Database() { // 建立画面列表 CreateSqlValueType[] create_allview = new CreateSqlValueType[1]; create_allview[0] = new CreateSqlValueType("nvarchar(50)", "viewname", true, false); Main_DataBase_Builder.Create_Table("AllView", create_allview); // 建立标签列表 #region CreateSqlValueType[] create_allLabel = new CreateSqlValueType[10]; create_allLabel[0] = new CreateSqlValueType("nvarchar(50)", "labelname", true, false); create_allLabel[1] = new CreateSqlValueType("nvarchar(50)", "txt"); create_allLabel[2] = new CreateSqlValueType("nvarchar(50)", "labelLeft"); create_allLabel[3] = new CreateSqlValueType("nvarchar(50)", "labelTop"); create_allLabel[4] = new CreateSqlValueType("nvarchar(50)", "Width"); create_allLabel[5] = new CreateSqlValueType("nvarchar(50)", "Height"); create_allLabel[6] = new CreateSqlValueType("nvarchar(50)", "BackGroundColor"); create_allLabel[7] = new CreateSqlValueType("nvarchar(50)", "Font"); create_allLabel[8] = new CreateSqlValueType("nvarchar(50)", "FontSize"); create_allLabel[9] = new CreateSqlValueType("nvarchar(50)", "FontColor"); Main_DataBase_Builder.Create_Table("Alllabel", create_allLabel); #endregion // 建立数据列表 #region CreateSqlValueType[] create_data = new CreateSqlValueType[7]; create_data[0] = new CreateSqlValueType("nvarchar(50)", "dataname", true, false); create_data[1] = new CreateSqlValueType("nvarchar(50)", "datatype"); create_data[2] = new CreateSqlValueType("nvarchar(50)", "datascope"); create_data[3] = new CreateSqlValueType("nvarchar(50)", "Value"); create_data[4] = new CreateSqlValueType("nvarchar(50)", "DataSource"); create_data[5] = new CreateSqlValueType("nvarchar(50)", "Machine_num"); create_data[6] = new CreateSqlValueType("nvarchar(50)", "Address"); Main_DataBase_Builder.Create_Table("AllData", create_data); #endregion // 建立数据标签列表 #region CreateSqlValueType[] create_valueLabel = new CreateSqlValueType[14]; create_valueLabel[0] = new CreateSqlValueType("nvarchar(50)", "labelname", true, false); create_valueLabel[1] = new CreateSqlValueType("nvarchar(50)", "txt"); create_valueLabel[2] = new CreateSqlValueType("nvarchar(50)", "labelLeft"); create_valueLabel[3] = new CreateSqlValueType("nvarchar(50)", "labelTop"); create_valueLabel[4] = new CreateSqlValueType("nvarchar(50)", "Width"); create_valueLabel[5] = new CreateSqlValueType("nvarchar(50)", "Height"); create_valueLabel[6] = new CreateSqlValueType("nvarchar(50)", "BackGroundColor"); create_valueLabel[7] = new CreateSqlValueType("nvarchar(50)", "Font"); create_valueLabel[8] = new CreateSqlValueType("nvarchar(50)", "FontSize"); create_valueLabel[9] = new CreateSqlValueType("nvarchar(50)", "FontColor"); create_valueLabel[10] = new CreateSqlValueType("nvarchar(50)", "DateType"); create_valueLabel[11] = new CreateSqlValueType("nvarchar(50)", "Machine_Num"); create_valueLabel[12] = new CreateSqlValueType("nvarchar(50)", "offsite"); create_valueLabel[13] = new CreateSqlValueType("nvarchar(50)", "ValueAddress"); Main_DataBase_Builder.Create_Table("AllValuelabel", create_valueLabel); #endregion // 建立按钮的标签列表 #region CreateSqlValueType[] create_valueButton = new CreateSqlValueType[10]; create_valueButton[0] = new CreateSqlValueType("nvarchar(50)", "buttonname", true, false); create_valueButton[1] = new CreateSqlValueType("nvarchar(50)", "txt"); create_valueButton[2] = new CreateSqlValueType("nvarchar(50)", "buttonLeft"); create_valueButton[3] = new CreateSqlValueType("nvarchar(50)", "buttonTop"); create_valueButton[4] = new CreateSqlValueType("nvarchar(50)", "Width"); create_valueButton[5] = new CreateSqlValueType("nvarchar(50)", "Height"); create_valueButton[6] = new CreateSqlValueType("nvarchar(50)", "BackGroundColor"); create_valueButton[7] = new CreateSqlValueType("nvarchar(50)", "Font"); create_valueButton[8] = new CreateSqlValueType("nvarchar(50)", "FontSize"); create_valueButton[9] = new CreateSqlValueType("nvarchar(50)", "FontColor"); Main_DataBase_Builder.Create_Table("AllButton", create_valueButton); #endregion // 建立指标类的列表 #region CreateSqlValueType[] create_ligth = new CreateSqlValueType[15]; create_ligth[0] = new CreateSqlValueType("nvarchar(50)", "lightname", true, false); create_ligth[1] = new CreateSqlValueType("nvarchar(50)", "lightLight"); create_ligth[2] = new CreateSqlValueType("nvarchar(50)", "lightTop"); create_ligth[3] = new CreateSqlValueType("nvarchar(50)", "Width"); create_ligth[4] = new CreateSqlValueType("nvarchar(50)", "Height"); create_ligth[5] = new CreateSqlValueType("nvarchar(50)", "State0Color"); create_ligth[6] = new CreateSqlValueType("nvarchar(50)", "State1Color"); create_ligth[7] = new CreateSqlValueType("nvarchar(50)", "condition0"); create_ligth[8] = new CreateSqlValueType("nvarchar(50)", "condition1"); create_ligth[9] = new CreateSqlValueType("nvarchar(50)", "Value00"); create_ligth[10] = new CreateSqlValueType("nvarchar(50)", "Value01"); create_ligth[11] = new CreateSqlValueType("nvarchar(50)", "Value10"); create_ligth[12] = new CreateSqlValueType("nvarchar(50)", "Value11"); create_ligth[13] = new CreateSqlValueType("nvarchar(50)", "Value0"); create_ligth[14] = new CreateSqlValueType("nvarchar(50)", "Value1"); Main_DataBase_Builder.Create_Table("Alllights", create_ligth); #endregion }
private void 属性ToolStripMenuItem_Click(object sender, EventArgs e) { if (MainView.Is_Edit == false) { return; } ButtonConfig.ButtonName = MyName; ButtonConfig.ButtontTxt = button1.Text; ButtonConfig.ButtonLeft = this.Left.ToString(); ButtonConfig.ButtonTop = this.Top.ToString(); ButtonConfig.ButtonWidth = this.Width.ToString(); ButtonConfig.ButtonHeight = this.Height.ToString(); ButtonConfig.BackColor = button1.BackColor.Name; ButtonConfig.Font = ""; ButtonConfig.FontSize = button1.Font.Size.ToString(); ButtonConfig.FontColor = button1.ForeColor.Name; ButtonConfig view = new ButtonConfig(); DialogResult result = view.ShowDialog(); if (result == DialogResult.OK) { try { UpName = ButtonConfig.ButtonName; ViewName = MainView.Selected_View_Name; button1.Text = ButtonConfig.ButtontTxt; this.Left = int.Parse(ButtonConfig.ButtonLeft); this.Top = int.Parse(ButtonConfig.ButtonTop); this.Width = int.Parse(ButtonConfig.ButtonWidth); this.Height = int.Parse(ButtonConfig.ButtonHeight); button1.BackColor = Color.FromName(ButtonConfig.BackColor); button1.Font = new Font(Font.FontFamily, float.Parse(ButtonConfig.FontSize), FontStyle.Regular); button1.ForeColor = Color.FromName(ButtonConfig.FontColor); } catch { MessageBox.Show("属性数据有误!"); return; } // 插入或更新 if (MyName == "") { // 插入数据库 string[] insert_cmd = new string[10]; insert_cmd[0] = UpName; insert_cmd[1] = ButtonConfig.ButtontTxt; insert_cmd[2] = ButtonConfig.ButtonLeft; insert_cmd[3] = ButtonConfig.ButtonTop; insert_cmd[4] = ButtonConfig.ButtonWidth; insert_cmd[5] = ButtonConfig.ButtonHeight; insert_cmd[6] = ButtonConfig.BackColor; insert_cmd[7] = ""; insert_cmd[8] = ButtonConfig.FontSize; insert_cmd[9] = ButtonConfig.FontColor; bool success = MainView.Main_DataBase_Builder.Insert("AllButton", insert_cmd); if (success == true) { string[] sub_insert_cmd = new string[2]; sub_insert_cmd[0] = UpName; sub_insert_cmd[1] = "Button"; MainView.Main_DataBase_Builder.Insert(ViewName, sub_insert_cmd); MyName = UpName; } // 创建与铵钮相关的功能表格 CreateSqlValueType[] button_funciton_table = new CreateSqlValueType[12]; button_funciton_table[0] = new CreateSqlValueType("nvarchar(50)", "functionkey", true, false); button_funciton_table[1] = new CreateSqlValueType("nvarchar(50)", "myfunction"); button_funciton_table[2] = new CreateSqlValueType("nvarchar(50)", "Value1"); button_funciton_table[3] = new CreateSqlValueType("nvarchar(50)", "Value2"); button_funciton_table[4] = new CreateSqlValueType("nvarchar(50)", "Value3"); button_funciton_table[5] = new CreateSqlValueType("nvarchar(50)", "Value4"); button_funciton_table[6] = new CreateSqlValueType("nvarchar(50)", "Value5"); button_funciton_table[7] = new CreateSqlValueType("nvarchar(50)", "Value6"); button_funciton_table[8] = new CreateSqlValueType("nvarchar(50)", "Value7"); button_funciton_table[9] = new CreateSqlValueType("nvarchar(50)", "Value8"); button_funciton_table[10] = new CreateSqlValueType("nvarchar(50)", "Value9"); button_funciton_table[11] = new CreateSqlValueType("nvarchar(50)", "Value10"); MainView.Main_DataBase_Builder.Create_Table(UpName, button_funciton_table); } if (MyName != "") { // 更新数据库 string[] update_cmd = new string[10]; update_cmd[0] = "buttonname='" + UpName + "'"; update_cmd[1] = "txt='" + ButtonConfig.ButtontTxt + "'"; update_cmd[2] = "buttonLeft='" + ButtonConfig.ButtonLeft + "'"; update_cmd[3] = "buttonTop='" + ButtonConfig.ButtonTop + "'"; update_cmd[4] = "Width='" + ButtonConfig.ButtonWidth + "'"; update_cmd[5] = "Height='" + ButtonConfig.ButtonHeight + "'"; update_cmd[6] = "BackGroundColor='" + ButtonConfig.BackColor + "'"; update_cmd[7] = "Font=''"; update_cmd[8] = "FontSize='" + ButtonConfig.FontSize + "'"; update_cmd[9] = "FontColor='" + ButtonConfig.FontColor + "'"; string where_cmd = "buttonname='" + MyName + "'"; bool success = MainView.Main_DataBase_Builder.Updata("AllButton", where_cmd, update_cmd); if (success == true) { string[] sub_update_cmd = new string[2]; sub_update_cmd[0] = "member='" + UpName + "'"; sub_update_cmd[1] = "type='Button'"; string sub_where_cmd = "member='" + MyName + "'"; MainView.Main_DataBase_Builder.Updata(ViewName, sub_where_cmd, sub_update_cmd); // 更新表名 MainView.Main_DataBase_Builder.Updata_Table_Name(MyName, UpName); MyName = UpName; } } } }
private void init_database() { // 初始化数据库 // 建立固定列表 // 设备情况列表 // 设备ID,设备名称,设备车间,设备种类,设备通讯端口,设备地址,通讯协议 CreateSqlValueType[] create1 = new CreateSqlValueType[7]; create1[0] = new CreateSqlValueType("nvarchar(50)", "ID", true); create1[1] = new CreateSqlValueType("nvarchar(50)", "Name"); create1[2] = new CreateSqlValueType("nvarchar(50)", "workshop"); create1[3] = new CreateSqlValueType("nvarchar(50)", "DeivceType"); create1[4] = new CreateSqlValueType("nvarchar(50)", "Com"); create1[5] = new CreateSqlValueType("nvarchar(50)", "Address"); create1[6] = new CreateSqlValueType("nvarchar(50)", "Protocol"); builder.Create_Table("Device_Info", create1); // builder.Create_Database(); // 创建实时数据库 CreateSqlValueType[] create_real_data = new CreateSqlValueType[4]; create_real_data[0] = new CreateSqlValueType("nvarchar(50)", "value_ID", true); create_real_data[1] = new CreateSqlValueType("nvarchar(50)", "device_name"); create_real_data[2] = new CreateSqlValueType("nvarchar(50)", "value_name"); create_real_data[3] = new CreateSqlValueType("nvarchar(50)", "value"); builder.Create_Table("Real_Value_Table", create_real_data); // 数据存放地址 所有的设备都相同 CreateSqlValueType[] data_address = new CreateSqlValueType[4]; data_address[0] = new CreateSqlValueType("nvarchar(50)", "value_name", true); data_address[1] = new CreateSqlValueType("nvarchar(50)", "value_type"); data_address[2] = new CreateSqlValueType("nvarchar(50)", "value_address"); builder.Create_Table("Value_Config", data_address); //============== 所有的MyLabel 地址存放初始化 ==============// foreach (MyLabel.value_name name in Enum.GetValues(typeof(MyLabel.value_name))) { string[] insert_cmd = new string[3]; insert_cmd[0] = name.ToString(); insert_cmd[1] = ""; insert_cmd[2] = ""; builder.Insert("Value_Config", insert_cmd); } //============== 所有的MyLabeltimne 地址存放初始化 ==============// foreach (MyLabel_time.value_name name in Enum.GetValues(typeof(MyLabel_time.value_name))) { string[] insert_cmd = new string[3]; insert_cmd[0] = name.ToString(); insert_cmd[1] = ""; insert_cmd[2] = ""; builder.Insert("Value_Config", insert_cmd); } //============== 所有的MyLabeltimne 地址存放初始化 ==============// foreach (MyLabel_Red_Yellow.value_name name in Enum.GetValues(typeof(MyLabel_Red_Yellow.value_name))) { string[] insert_cmd = new string[3]; insert_cmd[0] = name.ToString(); insert_cmd[1] = ""; insert_cmd[2] = ""; builder.Insert("Value_Config", insert_cmd); } //试验 Device_Data.chejian1_com1_DT[11, 10] = 3705; Device_Data.chejian1_com1_R[12, 15] = true; Device_Data.chejian1_com1_R[10, 20] = true; // 工艺管理有关数据库 // 工艺名称与参数名称之间的关系 CreateSqlValueType[] create_gongyi = new CreateSqlValueType[12]; create_gongyi[0] = new CreateSqlValueType("nvarchar(50)", "Gongyi_Name", true); create_gongyi[1] = new CreateSqlValueType("nvarchar(50)", "value1_name"); create_gongyi[2] = new CreateSqlValueType("nvarchar(50)", "value2_name"); create_gongyi[3] = new CreateSqlValueType("nvarchar(50)", "value3_name"); create_gongyi[4] = new CreateSqlValueType("nvarchar(50)", "value4_name"); create_gongyi[5] = new CreateSqlValueType("nvarchar(50)", "value5_name"); create_gongyi[6] = new CreateSqlValueType("nvarchar(50)", "value6_name"); create_gongyi[7] = new CreateSqlValueType("nvarchar(50)", "value7_name"); create_gongyi[8] = new CreateSqlValueType("nvarchar(50)", "value8_name"); create_gongyi[9] = new CreateSqlValueType("nvarchar(50)", "value9_name"); create_gongyi[10] = new CreateSqlValueType("nvarchar(50)", "value10_name"); create_gongyi[11] = new CreateSqlValueType("nvarchar(255)", "beizhu"); builder.Create_Table("Craft_Name_Table", create_gongyi); //============================================================================= // 工艺代码表 CreateSqlValueType[] create_craft_code = new CreateSqlValueType[2]; create_craft_code[0] = new CreateSqlValueType("nvarchar(50)", "Craft_Name", true); create_craft_code[1] = new CreateSqlValueType("nvarchar(50)", "Craft_Code"); builder.Create_Table("Craft_Name_Code", create_craft_code); //=============================================================================== // 生产排产 CreateSqlValueType[] shenchanpaichan_crate_sql_type = new CreateSqlValueType[3]; shenchanpaichan_crate_sql_type[0] = new CreateSqlValueType("nvarchar(50)", "ID", true); shenchanpaichan_crate_sql_type[1] = new CreateSqlValueType("nvarchar(50)", "state"); shenchanpaichan_crate_sql_type[2] = new CreateSqlValueType("nvarchar(50)", "工艺名"); builder.Create_Table("Shengchanpaichan", shenchanpaichan_crate_sql_type); //=============================================================================== // 启动日期 CreateSqlValueType[] qidongriqi = new CreateSqlValueType[2]; qidongriqi[0] = new CreateSqlValueType("int", "machine_num"); qidongriqi[1] = new CreateSqlValueType("datetime", "start_time"); builder.Create_Table("start_time", qidongriqi); for (int i = 1; i <= 100; i++) { string[] insert_cmd = new string[2]; insert_cmd[0] = i.ToString(); insert_cmd[1] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); builder.Insert("start_time", insert_cmd); } // 临时工艺表 CreateSqlValueType[] linshi_craft = new CreateSqlValueType[3]; linshi_craft[0] = new CreateSqlValueType("int", "machine_num"); linshi_craft[1] = new CreateSqlValueType("nvarchar(50)", "craft_table"); builder.Create_Table("linshi_craft", linshi_craft); for (int i = 1; i <= 100; i++) { string[] insert_cmd = new string[2]; insert_cmd[0] = i.ToString(); insert_cmd[1] = ""; builder.Insert("linshi_craft", insert_cmd); } // 执行的工单号 // 机号 工单号 CreateSqlValueType[] gongdan_exe = new CreateSqlValueType[2]; gongdan_exe[0] = new CreateSqlValueType("int", "machine_num"); gongdan_exe[1] = new CreateSqlValueType("nvarchar(50)", "gongdanhao"); builder.Create_Table("gongdan", gongdan_exe); for (int i = 1; i <= 100; i++) { string[] insert_cmd = new string[2]; insert_cmd[0] = i.ToString(); insert_cmd[1] = ""; builder.Insert("gongdan", insert_cmd); } // // 操作记录表 // 操作记录ID="机号+时间" 机号 time="时间" 工单号="" 变量="" 动作=""; // **单独开发工艺运行情况记录** CreateSqlValueType[] caozuo_create = new CreateSqlValueType[6]; caozuo_create[0] = new CreateSqlValueType("nvarchar(50)", "ID", true); caozuo_create[1] = new CreateSqlValueType("int", "machine_num"); caozuo_create[2] = new CreateSqlValueType("datetime", "mytime"); caozuo_create[3] = new CreateSqlValueType("nvarchar(50)", "gongdanhao"); caozuo_create[4] = new CreateSqlValueType("nvarchar(50)", "bianliang"); caozuo_create[5] = new CreateSqlValueType("nvarchar(50)", "dongzuo"); builder.Create_Table("caozuo_save", caozuo_create); // // 跳段记录 // 记录 ID="机号+时间" 机号 时间 工单 跳段 跳段内容 CreateSqlValueType[] tiaoduan_save = new CreateSqlValueType[6]; tiaoduan_save[0] = new CreateSqlValueType("nvarchar(50)", "ID", true); tiaoduan_save[1] = new CreateSqlValueType("int", "machine_num"); tiaoduan_save[2] = new CreateSqlValueType("datetime", "mytime"); tiaoduan_save[3] = new CreateSqlValueType("nvarchar(50)", "gongdan"); tiaoduan_save[4] = new CreateSqlValueType("nvarchar(50)", "tiaoduan"); tiaoduan_save[5] = new CreateSqlValueType("nvarchar(max)", "tiaoduanneirong"); builder.Create_Table("tiaoduan_save", tiaoduan_save); }
private void Thread_Tick() { try { if (gengxin_is == false) { Console.Write("false"); } if (gengxin_is == false) { gengxin_is = true; } else { return; } Console.WriteLine("开始读取"); ArrayList[] yingbian = null; ArrayList[] wendu = null; try { yingbian = new ArrayList[line_count]; wendu = new ArrayList[line_count]; for (int i = 0; i < line_count; i++) { yingbian[i] = new ArrayList(); wendu[i] = new ArrayList(); } } catch { } DateTime newtime = new DateTime(); DirectoryInfo[] dirs = FileCaozuo.Read_All_FilesDirect(path); ArrayList allpoints = Point_ini.ReadSections(); // 地图上所有的点 bool is_exit = false; // 是否在柱子上 timelist.Clear(); foreach (DirectoryInfo dir in dirs) { try { string nowtime_string = dir.Name; string nowtime_sub_string = nowtime_string.Substring(4, nowtime_string.Length - 4); string year = nowtime_sub_string.Substring(0, 4); string month = nowtime_sub_string.Substring(4, 2); string day = nowtime_sub_string.Substring(6, 2); string hour = nowtime_sub_string.Substring(8, 2); string min = nowtime_sub_string.Substring(10, 2); DateTime nowtime = DateTime.Parse(year + "-" + month + "-" + day + " " + hour + ":" + min + ":00"); if (nowtime > newtime) { newtime = nowtime; } } catch { } } newpath = "D:\\bgdata\\" + "data" + newtime.ToString("yyyyMMddHHmm") + "\\"; ArrayList filelist = FileCaozuo.Read_All_Files(newpath, "*.txt"); // 时间列表 foreach (string name in filelist) { // 每个文件的的名称 string filename = string_caozuo.Get_Dian_String(name, 1); string mydate = string_caozuo.Get_HengGang_String(filename, 1); string mytime = string_caozuo.Get_HengGang_String(filename, 2); string year = string_caozuo.Get_Xiahuaxian_String(mydate, 1); string month = string_caozuo.Get_Xiahuaxian_String(mydate, 2); string day = string_caozuo.Get_Xiahuaxian_String(mydate, 3); string hour = string_caozuo.Get_Xiahuaxian_String(mytime, 1); string min = string_caozuo.Get_Xiahuaxian_String(mytime, 2); string sec = string_caozuo.Get_Xiahuaxian_String(mytime, 3); DateTime nowtime = DateTime.Parse(year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec); timelist.Add(nowtime); } DateTime maxtime = new DateTime(); DateTime mintime = DateTime.Now; // 找出最近的时候 foreach (DateTime time in timelist) { if (time >= maxtime) { maxtime = time; } if (time < mintime) { mintime = time; } //<<<<<<< HEAD // //lock (timer1) // //{ // // timer1.Stop(); // // timer1.Start(); // //} // // mainthread = Thread.CurrentThread; // //ThreadPool.SetMaxThreads(1000, 1000); // //ThreadPool.SetMinThreads(100, 100); // //ThreadPool.QueueUserWorkItem(new WaitCallback(Insert_Cmd),time); // CreateSqlValueType[] create = new CreateSqlValueType[2]; // create[0] = new CreateSqlValueType("float", "position", true); // //create[1] = new CreateSqlValueType("datetime", "mytime"); // create[1] = new CreateSqlValueType("nvarchar(50)", "value"); // bool result = MainWindow.data_builder.Create_Table("data" + time.ToString("yyyyMMddHHmmss"), create); // if (result == false) continue; // Insert_Cmd(time); //======= Insert_Cmd(time); //lock (timer1) //{ // timer1.Stop(); // timer1.Start(); //} //mainthread = Thread.CurrentThread; ////ThreadPool.SetMaxThreads(1000, 1000); ////ThreadPool.SetMinThreads(100, 100); //ThreadPool.QueueUserWorkItem(new WaitCallback(Insert_Cmd),time); } updatetime = maxtime; //更新时间 // 最新的文件就是maxtime的文件 string nowfilename = maxtime.ToString("yyyy_MM_dd-HH_mm_ss") + ".txt"; string oldfilename = mintime.ToString("yyyy_MM_dd-HH_mm_ss") + ".txt"; try { if (is_shebei == true) { // 建立数据库图表 CreateSqlValueType[] create_type = new CreateSqlValueType[7]; create_type[0] = new CreateSqlValueType("nvarchar(50)", "id", true); create_type[1] = new CreateSqlValueType("datetime", "create_time"); create_type[2] = new CreateSqlValueType("int", "position"); create_type[3] = new CreateSqlValueType("int", "positionX"); create_type[4] = new CreateSqlValueType("int", "positionY"); create_type[5] = new CreateSqlValueType("float", "yingbian"); create_type[6] = new CreateSqlValueType("float", "weiyi"); data_builder.Create_Table("Data" + DateTime.Now.ToString("yyyy_MM_dd"), create_type); } } catch { } // 读取些文件信息 // 最新值 string[] all_line = FileCaozuo.Read_All_Line(newpath + nowfilename); // double position = 0; double value = 0; // 标准值 string[] all_line_old = FileCaozuo.Read_All_Line("D:\\bgdata\\标准.txt"); double value_old = 0; //Real_Data_List.Clear(); // string myfilename = time.ToString("yyyy_MM_dd-HH_mm_ss") + ".txt"; for (int i = 0; i < all_line.Length; i++) { try { lock (timer1) { timer1.Stop(); timer1.Start(); } string str_new = all_line[i]; string str_old = all_line_old[i]; position = double.Parse(string_caozuo.Get_Table_String(str_new, 1)); value = double.Parse(string_caozuo.Get_Table_String(str_new, 2)); value_old = double.Parse(string_caozuo.Get_Table_String(str_old, 2)); DataList.Data_Struct datasrtuct = new DataList.Data_Struct(); datasrtuct.位置 = position; datasrtuct.位置X = 0; datasrtuct.位置Y = 0; datasrtuct.应变量 = double.Parse(Math.Abs(value - value_old).ToString("#0.0000")); datasrtuct.位移量 = double.Parse(Jisuan_Weiyi(Math.Abs(value - value_old)).ToString("#0.0000")); try { // 保存数据 if (is_shebei == true) { string[] insert_data = new string[7]; insert_data[0] = datasrtuct.位置.ToString() + str_new; } } catch { } // 应变量应减去相应的温度变化 try { for (int j = 0; j < line_count; j++) { try { if (position >= yingbian_start[j] && position <= yingbian_end[j]) { yingbian[j].Add(datasrtuct); DataList.Data_Struct yingbian_struct = (DataList.Data_Struct)yingbian[j][yingbian[j].IndexOf(datasrtuct)]; DataList.Data_Struct wendu_struct = (DataList.Data_Struct)wendu[j][yingbian[j].IndexOf(datasrtuct)]; yingbian_struct.应变量 = Math.Abs(yingbian_struct.应变量 - wendu_struct.应变量); yingbian_struct.位移量 = Math.Abs(yingbian_struct.位移量 - wendu_struct.位移量); } } catch { } try { if (position >= wendu_start[j] && position <= wendu_end[j]) { wendu[j].Add(datasrtuct); } } catch { } } } catch { } // 将值放入数据队列中 if (Real_Data_List.Count < all_line.Length) { Real_Data_List.Add(datasrtuct); Dizhi_Index.Add(position); } else { Real_Data_List[i] = datasrtuct; Dizhi_Index[i] = position; } } catch { } //int a = 0; } gengxin_is = false; } catch { } }
private void Insert_Cmd(DateTime mytime) { DateTime time = mytime; string filename = time.ToString("yyyy_MM_dd-HH_mm_ss") + ".txt"; all_file_num = timelist.IndexOf(time, 0); ArrayList inser_array = new ArrayList(); // 建立数据库 //<<<<<<< HEAD string[] allline = File.ReadAllLines(newpath + filename, Encoding.Default); for (int i = 0; i < allline.Length; i++) { //lock (timer1) //{ // timer1.Stop(); // timer1.Start(); //} string line = allline[i]; string tablename = string_caozuo.Get_Table_String(line, 1); string myvalue = string_caozuo.Get_Table_String(line, 2); //if (first == true) //{ // CreateSqlValueType[] create = new CreateSqlValueType[3]; // create[0] = new CreateSqlValueType("nvarchar(50)", "id", true); // create[1] = new CreateSqlValueType("datetime", "mytime"); // create[2] = new CreateSqlValueType("nvarchar(50)", "value"); // MainWindow.data_builder.Create_Table("position" + string_caozuo.Get_Dian_String(tablename, 1) + string_caozuo.Get_Dian_String(tablename, 2), create); //} string[] insert_cmd = new string[2]; insert_cmd[0] = tablename; //insert_cmd[1] = time.ToString("yyyy-MM-dd HH:mm:ss"); insert_cmd[1] = myvalue; CreateSqlValueType[] create = new CreateSqlValueType[2]; create[0] = new CreateSqlValueType("float", "positon", true); create[1] = new CreateSqlValueType("float", "value"); //create[2] = new CreateSqlValueType("nvarchar(50)", "value"); MainWindow.data_builder.Create_Table("data" + time.ToString("yyyyMMddHHmmss"), create); //string[] allline = File.ReadAllLines(newpath + filename, Encoding.Default); //ArrayList inser_list = new ArrayList(); //for (int i = 0; i < allline.Length; i++) //{ // //lock (timer1) // //{ // // timer1.Stop(); // // timer1.Start(); // //} // string line = allline[i]; // string tablename = string_caozuo.Get_Table_String(line, 1); // string myvalue = string_caozuo.Get_Table_String(line, 2); // ////if (first == true) // ////{ // //// //CreateSqlValueType[] create = new CreateSqlValueType[3]; // //// //create[0] = new CreateSqlValueType("nvarchar(50)", "id", true); // //// //create[1] = new CreateSqlValueType("datetime", "mytime"); // //// //create[2] = new CreateSqlValueType("nvarchar(50)", "value"); // //// //MainWindow.data_builder.Create_Table("position" + string_caozuo.Get_Dian_String(tablename, 1) + string_caozuo.Get_Dian_String(tablename, 2), create); // ////} // string[] insert_cmd = new string[2]; // insert_cmd[0] = tablename; // insert_cmd[1] = myvalue; // inser_list.Add(insert_cmd); // //insert_struct mystruct = new insert_struct(); // //mystruct.insert_object = insert_cmd; // //mystruct.insertcmd = "position" + string_caozuo.Get_Dian_String(tablename, 1) + string_caozuo.Get_Dian_String(tablename, 2); // //mystruct.table_name = tablename; //>>>>>>> 5238b9f6468378890bb9d93c3da65cd0380fb016 // //insert_struct mystruct = new insert_struct(); // //mystruct.insert_object = insert_cmd; // //mystruct.insertcmd = "position" + string_caozuo.Get_Dian_String(tablename, 1) + string_caozuo.Get_Dian_String(tablename, 2); // //mystruct.table_name = tablename; // inser_array.Add(insert_cmd); // //insert_struct mystruct = new insert_struct(); // //mystruct.insert_object = insert_cmd; // //mystruct.insertcmd = "position" + string_caozuo.Get_Dian_String(tablename, 1) + string_caozuo.Get_Dian_String(tablename, 2); // //mystruct.table_name = tablename; // inser_array.Add(insert_cmd); //if (result == false) // break; copyed_num = i; } MainWindow.data_builder.Insert_Array("data" + time.ToString("yyyyMMddHHmmss"), inser_array); //======= // // //lock (timer1) // // //{ // // // timer1.Stop(); // // // timer1.Start(); // // //} // // //if (result == false) // // // break; // // copyed_num = i; // //} // bool result = MainWindow.data_builder.Insert_Data_From_Txt("data" + time.ToString("yyyyMMddHHmmss"), newpath + filename); //>>>>>>> 5238b9f6468378890bb9d93c3da65cd0380fb016 }
private void thread() { if (isupdate == false) { isupdate = true; } else { return; } ArrayList list = FileCaozuo.Read_All_Files("D://data//", "*.txt"); int count = 0; try { string where_cmd = "mykey='mynum'"; DataTable dt = builder.Select_Table("tiaonum", where_cmd); count = int.Parse(dt.Rows[0][1].ToString()); } catch { } for (int i = count; i < list.Count; i++) { CreateSqlValueType[] create_cmd = new CreateSqlValueType[2]; create_cmd[0] = new CreateSqlValueType("float", "pos", true); create_cmd[1] = new CreateSqlValueType("float", "value"); string name = (string)list[i]; string filename = string_caozuo.Get_Dian_String(name, 1); builder.Create_Table("data" + string_caozuo.Get_HengGang_String(filename, 1) + string_caozuo.Get_HengGang_String(filename, 2), create_cmd); wenjian = i; wenjianzong = list.Count; string mywhere_cmd = "mykey='mynum'"; string[] update_cmd = new string[1]; update_cmd[0] = "num='" + i.ToString() + "'"; builder.Updata("tiaonum", mywhere_cmd, update_cmd); // 读取全部数据 string[] jizhun_list = FileCaozuo.Read_All_Line("D:\\data\\" + name); for (int j = 0; j < jizhun_list.Length; j++) { try { shuju = j; shujuzong = jizhun_list.Length; string pos = string_caozuo.Get_Table_String(jizhun_list[j], 1); string value = string_caozuo.Get_Table_String(jizhun_list[j], 2); string[] insert_cmd = new string[2]; insert_cmd[0] = pos; insert_cmd[1] = value; bool result = builder.Insert("data" + string_caozuo.Get_HengGang_String(filename, 1) + string_caozuo.Get_HengGang_String(filename, 2), insert_cmd); } catch { } } } isupdate = false; }