/** * 根据type类型,往history文件中写入数据 **/ public static bool WriteToHistory(string type, HIS_Model hIS_Model) { List <HIS_Model> hIS_Models = new List <HIS_Model>(); hIS_Models = QueryHistoryByType(type); bool flag = false; /* type 转大写*/ string H_type = type.ToUpper(); string filePath = "../Data/" + H_type + "/HISTORY.txt"; FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite); StreamWriter wr = new StreamWriter(fs, Encoding.UTF8); //先写入新的一条记录放在开头 wr.WriteLine(hIS_Model.Model_no); //写入之前的99条记录,超过100条的记录会被覆盖 int i = 1; foreach (HIS_Model item in hIS_Models) { wr.WriteLine(item.Model_no); i++; if (i >= 99) { break; } } wr.Close(); fs.Close(); return(true); }
private void edit_Click(object sender, RoutedEventArgs e) { //获取datagrid选中行,并获取其model_no DEV_I_Model dEV_I_Model = new DEV_I_Model(); dEV_I_Model = (DEV_I_Model)device_information_datagrid.SelectedItem; String model_no = dEV_I_Model.Model_no; //往history添加记录 HIS_Model hIS_Model = new HIS_Model(); hIS_Model.Model_no = model_no; Dao.DEV_DAO.WriteToHistory("hpo", hIS_Model); //页面跳转,传递model_no参数 HPO_Pump_Injector_Edit_ hPO_Pump_Injector_Edit_Page = new HPO_Pump_Injector_Edit_(model_no); this.NavigationService.Navigate(hPO_Pump_Injector_Edit_Page); }
private void confirm_Click(object sender, RoutedEventArgs e) { //获取datagrid选中行,并获取其model_no DEV_I_Model dEV_I_Model = new DEV_I_Model(); dEV_I_Model = (DEV_I_Model)device_information_datagrid.SelectedItem; String model_no = dEV_I_Model.Model_no; //往history添加记录 HIS_Model hIS_Model = new HIS_Model(); hIS_Model.Model_no = model_no; Dao.DEV_DAO.WriteToHistory("hpo", hIS_Model); //页面跳转,传递model_no参数 HPO_Pump_Injector_Test hPO_Pump_Injector_Test_page = new HPO_Pump_Injector_Test(model_no); this.NavigationService.Navigate(hPO_Pump_Injector_Test_page); //NavigationService.GetNavigationService(this).Navigate(new Uri("Pages/Common_Rail_Injector_Test.xaml", UriKind.Relative)); }
/** * 根据type获取该类型的Histoyry集合,取出的是txt文件中的所有数据 **/ public static List <HIS_Model> QueryHistoryByType(string type) { List <HIS_Model> hIS_Models = new List <HIS_Model>(); /* type 转大写*/ string H_type = type.ToUpper(); string filePath = "../Data/" + H_type + "/HISTORY.txt"; FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite); StreamReader rd = new StreamReader(fs, Encoding.UTF8); string readLine; while ((readLine = rd.ReadLine()) != null) { HIS_Model temp = new HIS_Model(); temp.Model_no = readLine; hIS_Models.Add(temp); } rd.Close(); fs.Close(); return(hIS_Models); }