/// <summary> /// 保存查询条件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btSave_Click(object sender, EventArgs e) { var model = GetParameterModel(); if (model == null) { return; } var modelByte = ByteConvertHelper.T2Bytes <ParameterModel>(model); //设置保存文件的格式 saveFileDialog1.Filter = "二进制文件(*.dat)|*.dat"; saveFileDialog1.InitialDirectory = bastDataPath; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { //使用“另存为”对话框中输入的文件名实例化FileStream对象 FileStream myStream = new FileStream(saveFileDialog1.FileName, FileMode.OpenOrCreate, FileAccess.ReadWrite); //使用FileStream对象实例化BinaryWriter二进制写入流对象 BinaryWriter myWriter = new BinaryWriter(myStream); //以二进制方式向创建的文件中写入内容 myWriter.Write(modelByte); //关闭当前二进制写入流 myWriter.Close(); //关闭当前文件流 myStream.Close(); } MessageBox.Show("保存成功."); InitializePage(); }
/// <summary> /// 加载参数 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btLoding_Click(object sender, EventArgs e) { var filePath = bastDataPath + "\\" + this.cbQueryList.Text; var fileByte = FileHelper.FileToBytes(filePath); var model = ByteConvertHelper.Bytes2T <ParameterModel>(fileByte); var a = new SelectModel { Value = model.postType.GetHashCode(), Title = model.postType.GetFieldDisplay() }; var b = new SelectModel { Value = model.postType.GetHashCode(), Title = model.postType.GetFieldDisplay() }; if (model != null) { this.tbDataBody.Text = model.postBody; this.tbUrl.Text = model.postUrl.AbsoluteUri; var postTypeList = postType.ToList(); this.cbPostType.SelectedIndex = postTypeList.IndexOf(postTypeList.Where(item => item.Value == model.postType.GetHashCode()).FirstOrDefault()); var langTypeList = langType.ToList(); this.cbLangType.SelectedIndex = langTypeList.IndexOf(langTypeList.Where(item => item.Value == model.langType.GetHashCode()).FirstOrDefault()); this.dgvFiles.Rows.Clear(); foreach (var item in model.fileList) { var dgvIndex = this.dgvFiles.Rows.Add(); this.dgvFiles.Rows[dgvIndex].Cells[0].Value = item; } } }
/// <summary> /// 加载历史查询数 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btLoding_Click(object sender, EventArgs e) { //var filePath = bastDataPath + "\\" + this.cbQueryList.Text; var fileModel = this.cbQueryList.SelectedItem.ToOfType <FilesTree>(); if (fileModel.IsFolder) { MessageBox.Show("请不要选择目录."); return; } var fileByte = FileHelper.FileToBytes(fileModel.AbsolutePath); var model = ByteConvertHelper.Bytes2T <ParameterModel>(fileByte); var a = new SelectModel { Value = model.postType.GetHashCode(), Title = model.postType.GetFieldDisplay() }; var b = new SelectModel { Value = model.postType.GetHashCode(), Title = model.postType.GetFieldDisplay() }; if (model != null) { this.tbDataBody.Text = model.postBody; this.tbUrl.Text = model.postUrl.AbsoluteUri; var postTypeList = postType.ToList(); this.cbPostType.SelectedIndex = postTypeList.IndexOf(postTypeList.Where(item => item.Value == model.postType.GetHashCode()).FirstOrDefault()); var langTypeList = langType.ToList(); this.cbLangType.SelectedIndex = langTypeList.IndexOf(langTypeList.Where(item => item.Value == model.langType.GetHashCode()).FirstOrDefault()); this.dgvFiles.Rows.Clear(); foreach (var item in model.fileList) { var dgvIndex = this.dgvFiles.Rows.Add(); this.dgvFiles.Rows[dgvIndex].Cells[0].Value = item; } this.cbIsBinary.Checked = model.IsBinary; this.dgvParameter.Rows.Clear(); if (model.HeadersDic != null) { foreach (var item in model.HeadersDic) { var dgvIndex = this.dgvParameter.Rows.Add(); this.dgvParameter.Rows[dgvIndex].Cells[0].Value = item.Key; this.dgvParameter.Rows[dgvIndex].Cells[1].Value = item.Value; } } } }