/** * 将Common_Rail_Injector_Test数据初始化到界面上 * */ //public void fillData(Model.Common_Rail_Injector_Test common_Rail_Injector_Test) //{ // last_time_TextBox.Text = common_Rail_Injector_Test.Duration.ToString(); // pressure_TextBox.Text = common_Rail_Injector_Test.Rail_pressure.ToString(); // oil_p_hor_TextBox.Text = common_Rail_Injector_Test.Fuel_p_hor.ToString(); // oil_p_ver_TextBox.Text = common_Rail_Injector_Test.Fuel_p_ver.ToString(); // oil_h_hor_TextBox.Text = common_Rail_Injector_Test.Fuel_h_hor.ToString(); // oil_h_ver_TextBox.Text = common_Rail_Injector_Test.Fuel_h_hor.ToString(); // test_time_TextBox.Text = common_Rail_Injector_Test.Test_time.ToString(); // if (null == common_Rail_Injector_Test.Curve|| common_Rail_Injector_Test.Curve.Length ==0) // { // curve_TextBox.Text = null; // } // else // { // curve_TextBox.Text = common_Rail_Injector_Test.Curve.ToString(); // } // magn_TextBox.Text = common_Rail_Injector_Test.Magnification.ToString(); // period_TextBox.Text = common_Rail_Injector_Test.Period.ToString(); // voltage_TextBox.Text = common_Rail_Injector_Test.Voltage.ToString(); // //读取数据后设置不可读 // setEditable(false); //} /** * 将Common_Rail_Injector_Test数据初始化到界面上 * */ public void fillData(CRI_Model cRI_Model) { last_time_TextBox.Text = cRI_Model.Pulse_width; pressure_TextBox.Text = cRI_Model.Rail_pressure.ToString(); oil_p_hor_TextBox.Text = cRI_Model.Oil_p_standard; oil_p_ver_TextBox.Text = cRI_Model.Oil_p_deviation; oil_h_hor_TextBox.Text = cRI_Model.Oil_h_standard; oil_h_ver_TextBox.Text = cRI_Model.Oil_h_pressure; //脉宽和时间的区分? test_time_TextBox.Text = cRI_Model.Control_last_time; if (null == cRI_Model.Curve || cRI_Model.Curve.Length == 0) { curve_TextBox.Text = null; } else { CURVE = cRI_Model.Curve.ToString(); curve_TextBox.Text = cRI_Model.Curve.ToString(); } magn_TextBox.Text = cRI_Model.Manufacturer; period_TextBox.Text = "未设定"; voltage_TextBox.Text = cRI_Model.Voltage; //读取数据后设置不可读 setEditable(false); }
/** * 更新选择的step_name的数据信息 * */ //private void step_change_Click(object sender, RoutedEventArgs e) //{ // //获取选择的listbox的step_name // string step_name = ((ListBoxItem)step_ListBox.SelectedItem).Content.ToString(); // Model.Common_Rail_Injector_Test common_Rail_Injector_Test = new Model.Common_Rail_Injector_Test(); // common_Rail_Injector_Test = Get_data_from_page(); // //根据model_no和step_name更新数据 // bool flag = OilP.Service.Common_Rail_Injector_Test_Service.UpdateData(common_Rail_Injector_Test); // if (flag) // { // string message = "测试步骤更新成功"; // MessageBoxResult dr = MessageBox.Show(message, "提示", MessageBoxButton.OKCancel, MessageBoxImage.Information); // //if (dr == MessageBoxResult.OK) // //{ // // //重新加载ListBox // // step_ListBox.Items.Clear(); // // Init_step_ListBox(MODEL_NO); // //} // } // else // { // string message = "测试步骤更新失败"; // MessageBoxResult dr = MessageBox.Show(message, "提示", MessageBoxButton.OKCancel, MessageBoxImage.Information); // //if (dr == MessageBoxResult.OK) // //{ // // //重新加载ListBox // // step_ListBox.Items.Clear(); // // Init_step_ListBox(MODEL_NO); // //} // } //} private void step_change_Click(object sender, RoutedEventArgs e) { //获取选择的listbox的step_name string step_name = ((ListBoxItem)step_ListBox.SelectedItem).Content.ToString(); CRI_Model cRI_Model = new CRI_Model(); cRI_Model = Get_data_from_page(); //根据model_no和step_name更新数据 bool flag = OilP.Service.Common_Rail_Injector_Test_Service.UpdateData(cRI_Model); if (flag) { string message = "测试步骤更新成功"; MessageBoxResult dr = MessageBox.Show(message, "提示", MessageBoxButton.OKCancel, MessageBoxImage.Information); //if (dr == MessageBoxResult.OK) //{ // //重新加载ListBox // step_ListBox.Items.Clear(); // Init_step_ListBox(MODEL_NO); //} } else { string message = "测试步骤更新失败"; MessageBoxResult dr = MessageBox.Show(message, "提示", MessageBoxButton.OKCancel, MessageBoxImage.Information); //if (dr == MessageBoxResult.OK) //{ // //重新加载ListBox // step_ListBox.Items.Clear(); // Init_step_ListBox(MODEL_NO); //} } }
/** * 添加数据 * */ //public static string AddData(Common_Rail_Injector_Test data,string model_no) //{ // //判断是否是已经存在的测试步骤,根据step_name // List<Common_Rail_Injector_Test> common_Rail_Injector_Tests = new List<Common_Rail_Injector_Test>(); // common_Rail_Injector_Tests = OilP.Dao.Common_Rail_Injector_Test_DAO.QueryByModelNo(model_no); // for (int i = 0; i < common_Rail_Injector_Tests.Count; i++) // { // if (common_Rail_Injector_Tests[i].Step_name.ToLower().ToString().Equals(data.Step_name.ToLower().ToString())) // { // return "测试步骤添加失败:已经存在该测试步骤!"; // } // } // bool flag = false; // flag = OilP.Dao.Common_Rail_Injector_Test_DAO.AddData(data); // if (flag) // { // return "测试步骤添加成功"; // } // else // { // return "测试步骤添加失败"; // } //} /** * 添加数据 * */ public static string AddData(CRI_Model data, string model_no) { //判断是否是已经存在的测试步骤,根据step_name List <CRI_Model> cRI_Models = new List <CRI_Model>(); cRI_Models = OilP.Dao.CRI_DAO.QueryByModelNo(model_no); for (int i = 0; i < cRI_Models.Count; i++) { if (cRI_Models[i].Step_name.ToLower().ToString().Equals(data.Step_name.ToLower().ToString())) { return("测试步骤添加失败:已经存在该测试步骤!"); } } bool flag = false; flag = OilP.Dao.CRI_DAO.AddData(data, model_no); if (flag) { return("测试步骤添加成功"); } else { return("测试步骤添加失败"); } }
/** * 根据model_no和step_name更新选中的数据 * */ //public static bool UpdateData(Common_Rail_Injector_Test common_Rail_Injector_Test) //{ // bool flag = false; // flag = OilP.Dao.Common_Rail_Injector_Test_DAO.UpdateData(common_Rail_Injector_Test); // return flag; //} /** * 根据model_no和step_name更新选中的数据 * */ public static bool UpdateData(CRI_Model cRI_Model) { bool flag = false; flag = OilP.Dao.CRI_DAO.UpdateData(cRI_Model); return(flag); }
/** * get all data from table **/ //public static List<Common_Rail_Injector_Test> QueryForAll() //{ // List<Common_Rail_Injector_Test> common_Rail_Injector_Tests = new List<Common_Rail_Injector_Test>(); // common_Rail_Injector_Tests = OilP.Dao.Common_Rail_Injector_Test_DAO.QueryForAll(); // return common_Rail_Injector_Tests; //} /** * 通过model_no和step_name查询所单条数据 **/ //public static Common_Rail_Injector_Test QueryByModelNoAndStepName(string model_no ,string step_name) //{ // Common_Rail_Injector_Test common_Rail_Injector_Test = new Common_Rail_Injector_Test(); // common_Rail_Injector_Test = OilP.Dao.Common_Rail_Injector_Test_DAO.QueryByModelNoAndStepName(model_no,step_name); // return common_Rail_Injector_Test; //} /** * 通过model_no和step_name查询所单条数据 **/ public static CRI_Model QueryByModelNoAndStepName(string model_no, string step_name) { CRI_Model cRI_Model = new CRI_Model(); cRI_Model = OilP.Dao.CRI_DAO.QueryByModelNoAndStepName(model_no, step_name); return(cRI_Model); }
public static CRI_Model StringToCRIModel(int length, string[] readline) { CRI_Model cRI_Model = new CRI_Model(); cRI_Model.Model_no = readline[0]; cRI_Model.Manufacturer = readline[1]; cRI_Model.Curve = readline[2]; cRI_Model.Step_name = readline[3]; cRI_Model.Round_speed = readline[4]; cRI_Model.Oil_p_standard = readline[5]; cRI_Model.Oil_p_deviation = readline[6]; cRI_Model.Oil_h_standard = readline[7]; cRI_Model.Oil_h_deviation = readline[8]; cRI_Model.Pulse_width = readline[9]; cRI_Model.Rail_pressure = readline[10]; cRI_Model.Oil_j_pressure = readline[11]; cRI_Model.Oil_h_pressure = readline[12]; cRI_Model.Punmp_pressure = readline[13]; cRI_Model.Control_last_time = readline[14]; cRI_Model.Voltage = readline[15]; cRI_Model.Oil_tank_T = readline[16]; cRI_Model.Oil_j_T = readline[17]; cRI_Model.Oil_h_T = readline[18]; return(cRI_Model); }
/** * 根据model_no和step_name查找详细数据 * */ //public void setData(string model_no,string step_name) //{ // Model.Common_Rail_Injector_Test common_Rail_Injector_Test = new Model.Common_Rail_Injector_Test(); // common_Rail_Injector_Test = OilP.Service.Common_Rail_Injector_Test_Service.QueryByModelNoAndStepName(model_no, step_name); // //在页面上填入step_name和model_no的数据 // step_name_TextBox.Text = step_name; // fillData(common_Rail_Injector_Test); //} /** * 根据model_no和step_name查找详细数据 * */ public void setData(string model_no, string step_name) { CRI_Model cRI_Model = new CRI_Model(); cRI_Model = OilP.Service.Common_Rail_Injector_Test_Service.QueryByModelNoAndStepName(model_no, step_name); //在页面上填入step_name和model_no的数据 step_name_TextBox.Text = step_name; fillData(cRI_Model); }
/** * 通过反射将实体类转化成string字符串 * */ public static string GetEntityToString(CRI_Model t) { System.Text.StringBuilder sb = new StringBuilder(); Type type = t.GetType(); System.Reflection.PropertyInfo[] propertyInfos = type.GetProperties(); for (int i = 0; i < propertyInfos.Length; i++) { //带变量名的字符串 //sb.Append(propertyInfos[i].Name + ":" + propertyInfos[i].GetValue(t, null) + ","); //不带变量名的字符串 sb.Append(propertyInfos[i].GetValue(t, null) + ","); } return(sb.ToString().TrimEnd(new char[] { ',' })); }
/** * 新增测试步骤 * */ //private void step_add_Click(object sender, RoutedEventArgs e) //{ // //获取当前页面上的数据 // Model.Common_Rail_Injector_Test common_Rail_Injector_Test = new Model.Common_Rail_Injector_Test(); // common_Rail_Injector_Test = Get_data_from_page(); // string message = OilP.Service.Common_Rail_Injector_Test_Service.AddData(common_Rail_Injector_Test, MODEL_NO); // MessageBoxResult dr = MessageBox.Show(message, "提示", MessageBoxButton.OKCancel, MessageBoxImage.Information); // if (dr == MessageBoxResult.OK) // { // //重新加载ListBox // step_ListBox.Items.Clear(); // Init_step_ListBox(MODEL_NO); // } /** * 新增测试步骤 * */ private void step_add_Click(object sender, RoutedEventArgs e) { //获取当前页面上的数据 CRI_Model cRI_Model = new CRI_Model(); cRI_Model = Get_data_from_page(); string message = OilP.Service.Common_Rail_Injector_Test_Service.AddData(cRI_Model, MODEL_NO); MessageBoxResult dr = MessageBox.Show(message, "提示", MessageBoxButton.OKCancel, MessageBoxImage.Information); if (dr == MessageBoxResult.OK) { //重新加载ListBox step_ListBox.Items.Clear(); Init_step_ListBox(MODEL_NO); } }
/** * 根据model_no和step_name获取数据 * */ public static CRI_Model QueryByModelNoAndStepName(string model_no, string step_name) { CRI_Model cRI_Model = new CRI_Model(); List <CRI_Model> cRI_Models = new List <CRI_Model>(); cRI_Models = QueryByModelNo(model_no); //遍历取出step_name为传入值的数据 foreach (CRI_Model item in cRI_Models) { if (step_name.Equals(item.Step_name)) { return(item); } } return(new CRI_Model()); }
/** * 根据model_no和step_name更新选中的数据 * */ public static bool UpdateData(CRI_Model cRI_Model) { //读取当前model_no的文件内容保存在list中 List <CRI_Model> cRI_Models = new List <CRI_Model>(); cRI_Models = QueryByModelNo(cRI_Model.Model_no); //将该测试步骤的数据更新进list for (int i = 0; i < cRI_Models.Count; i++) { if (cRI_Model.Step_name.Equals(cRI_Models[i].Step_name)) { cRI_Models[i] = cRI_Model; } } WriteListToTxt(cRI_Model.Model_no, cRI_Models); return(true); }
/** * 新增测试步骤 **/ public static bool AddData(CRI_Model data, string model_no) { bool flag = false; string filePath = "../Data/CRI/" + model_no + ".txt"; FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite); StreamWriter wr = new StreamWriter(fs, Encoding.UTF8); //写入末尾 string data_string = GetEntityToString(data); wr.BaseStream.Seek(0, SeekOrigin.End); wr.WriteLine(data_string); wr.Close(); fs.Close(); return(true); }
/** * 获取页面上需要新增的测试步骤数据 * */ // public Model.Common_Rail_Injector_Test Get_data_from_page() //{ // Model.Common_Rail_Injector_Test common_Rail_Injector_Test = new Model.Common_Rail_Injector_Test(); // common_Rail_Injector_Test.Model_no = model_no_TextBox.Text.ToString(); // common_Rail_Injector_Test.Step_name = step_name_TextBox.Text.ToString(); // common_Rail_Injector_Test.Duration = double.Parse(last_time_TextBox.Text.ToString()) ; // common_Rail_Injector_Test.Rail_pressure = double.Parse(pressure_TextBox.Text.ToString()); // common_Rail_Injector_Test.Fuel_p_hor = double.Parse(oil_p_hor_TextBox.Text.ToString()); // common_Rail_Injector_Test.Fuel_p_ver = double.Parse(oil_p_ver_TextBox.Text.ToString()); // common_Rail_Injector_Test.Fuel_h_hor = double.Parse(oil_h_hor_TextBox.Text.ToString()); // common_Rail_Injector_Test.Fuel_h_ver = double.Parse(oil_h_ver_TextBox.Text.ToString()); // common_Rail_Injector_Test.Test_time = int.Parse(test_time_TextBox.Text.ToString()); // common_Rail_Injector_Test.Curve = curve_TextBox.Text.ToString(); // common_Rail_Injector_Test.Magnification = double.Parse(magn_TextBox.Text.ToString()); // common_Rail_Injector_Test.Period = int.Parse(period_TextBox.Text.ToString()); // common_Rail_Injector_Test.Voltage = int.Parse(voltage_TextBox.Text.ToString()); // return common_Rail_Injector_Test; //} /** * 获取页面上需要新增的测试步骤数据 * */ public CRI_Model Get_data_from_page() { CRI_Model cRI_Model = new CRI_Model(); cRI_Model.Model_no = model_no_TextBox.Text.ToString(); cRI_Model.Step_name = step_name_TextBox.Text.ToString(); cRI_Model.Control_last_time = last_time_TextBox.Text.ToString(); cRI_Model.Rail_pressure = pressure_TextBox.Text.ToString(); cRI_Model.Oil_p_standard = oil_p_hor_TextBox.Text.ToString(); cRI_Model.Oil_p_deviation = oil_p_ver_TextBox.Text.ToString(); cRI_Model.Oil_h_standard = oil_h_hor_TextBox.Text.ToString(); cRI_Model.Oil_h_deviation = oil_h_ver_TextBox.Text.ToString(); //三个时间的疑问 // cRI_Model.Test_time =test_time_TextBox.Text.ToString(); cRI_Model.Curve = curve_TextBox.Text.ToString(); cRI_Model.Magnification = magn_TextBox.Text.ToString(); cRI_Model.Period = period_TextBox.Text.ToString(); cRI_Model.Voltage = voltage_TextBox.Text.ToString(); return(cRI_Model); }
/** * 根据model_no获取数据集合 **/ public static List <CRI_Model> QueryByModelNo(string model_no) { List <CRI_Model> cRI_Models = new List <CRI_Model>(); string filePath = "../Data/CRI/" + model_no + ".txt"; FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite); StreamReader rd = new StreamReader(fs, Encoding.UTF8); string readLine; while ((readLine = rd.ReadLine()) != null) { string[] data = readLine.Split(','); int length = data.Length; CRI_Model cRI_Model = new CRI_Model(); cRI_Model = StringToCRIModel(length, data); cRI_Models.Add(cRI_Model); } rd.Close(); fs.Close(); return(cRI_Models); }
/** * 向页面填充数据 * */ //public void fillData(Model.Common_Rail_Injector_Test common_Rail_Injector_Test) //{ // pulse_width_textBox.Text = common_Rail_Injector_Test.Duration.ToString(); // hor_rail_pressure_textBox.Text = common_Rail_Injector_Test.Rail_pressure.ToString(); // hor_fuel_P_textBox.Text = common_Rail_Injector_Test.Fuel_p_hor.ToString(); // ver_fuel_P_textBox.Text = common_Rail_Injector_Test.Fuel_p_ver.ToString(); // hor_fuel_h_textBox.Text = common_Rail_Injector_Test.Fuel_h_hor.ToString(); // ver_fuel_h_textBox.Text = common_Rail_Injector_Test.Fuel_h_ver.ToString(); // test_time_textBox.Text = common_Rail_Injector_Test.Test_time.ToString(); // voltage_textBox.Text = common_Rail_Injector_Test.Voltage.ToString(); //} /** * 向页面填充数据 * */ public void fillData(CRI_Model cRI_Model) { //脉宽 pulse_width_textBox.Text = cRI_Model.Pulse_width; //共轨压力 TextBox_rail_pressure.Text = cRI_Model.Rail_pressure; //进油压力 TextBox_oil_j_pressure.Text = cRI_Model.Oil_j_pressure; //回油压力 TextBox_oil_h_pressure.Text = cRI_Model.Oil_h_pressure; //喷油标准 TextBox_oil_p_standard.Text = cRI_Model.Oil_p_standard; //喷油偏差 TextBox_oil_p_deviation.Text = cRI_Model.Oil_p_deviation; //回油标准 TextBox_oil_h_standrad.Text = cRI_Model.Oil_h_standard; //回油偏差 TextBox_oil_h_deviation.Text = cRI_Model.Oil_h_deviation; //控制持续时间 TextBox_control_last_time.Text = cRI_Model.Control_last_time; //电压 voltage_textBox.Text = cRI_Model.Voltage; }