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 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); } } }
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); // 刷新画面的父结点的信息 } } }
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); // 建立报警表 }
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_RunTimeValue_Tick(object sender, System.Timers.ElapsedEventArgs e) { string Table_Name = "runtimetable" + DateTime.Now.ToString("yyyyMMdd"); database_builder.Create_Table(Table_Name, runtime_create_sql_value_type); // 将所有的值插入进去 if (RunTime_Save_Table == null) { return; } if (AllValue_Table == null) { return; } if (RunTime_Save_Table.Rows.Count == 0) { return; } if (AllValue_Table.Rows.Count == 0) { return; } if (AllStation_Table == null) { return; } if (AllStation_Table.Rows.Count == 0) { return; } foreach (DataRow dr in RunTime_Save_Table.Rows) { string value_name = dr[0].ToString(); // 在变量表中找出值 DataRow[] valuerows = AllValue_Table.Select("Value_Name='" + value_name + "'"); DataRow valuerow = valuerows[0]; string value_type = valuerow[1].ToString(); int value_address = int.Parse(valuerow[3].ToString()); string return_value = ""; for (int i = 0; i < running_data.Station_Info_List.Count; i++) { Running_Data_Struct mystruct = (Running_Data_Struct)running_data.Station_Info_List[i]; if (mystruct.Get_Name() == valuerow[2].ToString()) { if (value_type == "Int") { int[] int_array = mystruct.Get_IntData(); return_value = int_array[value_address].ToString(); } if (value_type == "Bool") { bool[] bool_array = mystruct.Get_SwitchData(); return_value = bool_array[value_address].ToString(); } if (value_type == "String") { double[] double_array = mystruct.Get_DoubleData(); return_value = double_array[value_address].ToString(); } // 插入表中 string[] insert_cmd = new string[4]; insert_cmd[0] = DateTime.Now.ToString("yyyyMMddHHmmss") + DateTime.Now.Millisecond.ToString() + value_name; insert_cmd[1] = value_name; insert_cmd[2] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); insert_cmd[3] = return_value; database_builder.Insert(Table_Name, insert_cmd); // 插入到列表中 foreach (object mydatatable in MyChart.All_Used_Running_Table) { DataTable mydt = (DataTable)mydatatable; if (mydt.TableName == Table_Name) { DataRow newdr = mydt.NewRow(); newdr[0] = DateTime.Now.ToString("yyyyMMddHHmmss") + DateTime.Now.Millisecond.ToString() + value_name; newdr[1] = value_name; newdr[2] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); newdr[3] = return_value; mydt.Rows.Add(newdr); } } break; } } } }
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 { } }