123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Diagnostics;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace DocManager
- {
- public partial class FormPreSale : Form
- {
- public FormPreSale()
- {
- InitializeComponent();
- Type dgvType = this.dgv_main.GetType();
- PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
- pi.SetValue(this.dgv_main, true, null);
- }
- private void FormPreSale_Load(object sender, EventArgs e)
- {
- btn_refresh_Click(sender,e);
- }
- private DataTable PRJ_DataTable = new DataTable();
- private void btn_refresh_Click(object sender, EventArgs e)
- {
- try
- {
- dgv_main.Rows.Clear();
- DirectoryInfo dir = new DirectoryInfo(FormPRJ.PRJConfigFileModel.DirPath);
- DirectoryInfo[] dirInfos = dir.GetDirectories();
- foreach (DirectoryInfo di in dirInfos)
- {
- // 处理一个文件夹
- if (!di.Name.StartsWith("PreSale_")) { continue; }
- string TYPE = di.Name.Substring(8, di.Name.Length - 8);
- DirectoryInfo dir_PRJ = new DirectoryInfo(di.FullName);
- DirectoryInfo[] dir_PRJ_Infos = dir_PRJ.GetDirectories();
- foreach (DirectoryInfo di2 in dir_PRJ_Infos)
- {
-
- if (!di2.Name.Contains("_")) { continue; }
- string PRJ_CODE = di2.Name.Substring(0, di2.Name.IndexOf("_"));
- if (PRJ_CODE.Length != 4) { continue; }
- // PRJ Code 针对售前项目,必须是一个4位的数字
- int tmp = 0;
- if (!int.TryParse(PRJ_CODE, out tmp))
- {
- continue;
- }
- if (!di2.Name.Contains("(")) { continue; }
- string PRJ_NAME = di2.Name.Substring(5, di2.Name.LastIndexOf("(") - 5);
- if (!di2.Name.Contains(")")) { continue; }
- string PRJ_Contacts = di2.Name.Substring(di2.Name.LastIndexOf("(") + 1, di2.Name.LastIndexOf(")") - di2.Name.LastIndexOf("(") - 1);
- int id = dgv_main.Rows.Count + 1;
- // 获取报价信息
- string bj_dir = di2.FullName + "\\1002 报价&方案";
- if (!Directory.Exists(bj_dir)) { Directory.CreateDirectory(bj_dir); }
- DirectoryInfo di3 = new DirectoryInfo(bj_dir);
- List<string> list = new List<string>();
- // 第N次报价
- string BJ001=GetBJInfo(di3,"BJ_001_*.*");
- string BJ002 = GetBJInfo(di3, "BJ_002_*.*");
- string BJ003 = GetBJInfo(di3, "BJ_003_*.*");
- string BJ004 = GetBJInfo(di3, "BJ_004_*.*");
- string BJ005 = GetBJInfo(di3, "BJ_005_*.*");
- string BJ006 = GetBJInfo(di3, "BJ_006_*.*");
- string BJ007 = GetBJInfo(di3, "BJ_007_*.*");
- list.AddRange(new string[] { BJ001, BJ002, BJ003, BJ004, BJ005, BJ006, BJ007 });
- // 当前报价
- string currentJiaGe = "";
- foreach(string str in list)
- {
- if (str == "") { continue; } else { currentJiaGe = str; }
- }
- object[] values = { id, di2.FullName, TYPE, PRJ_CODE, PRJ_NAME, PRJ_Contacts,
- currentJiaGe,BJ001,BJ002,BJ003,BJ004,BJ005,BJ006,BJ007};
- dgv_main.Rows.Add(values);
- AddComboxItems(values);
- }
- }
- // 修改datagridview的类型
- for (int count = 0; count < dgv_main.Columns.Count; count++)
- {
- if (dgv_main.Columns[count].Name.ToString() == "ID")
- {
- dgv_main.Columns[count].ValueType = typeof(int);
- continue;
- }
- dgv_main.Columns[count].ValueType = typeof(string);
- }
- PRJ_DataTable = new DataTable();
- //把DataGridView控件数据,转成DataTable
- for (int count = 0; count < dgv_main.Columns.Count; count++)
- {
- Type t = dgv_main.Columns[count].ValueType;
- DataColumn dc = new DataColumn(dgv_main.Columns[count].Name.ToString(), t);
- PRJ_DataTable.Columns.Add(dc);
- }
- for (int count = 0; count < dgv_main.Rows.Count; count++)
- {
- DataRow dr = PRJ_DataTable.NewRow();
- for (int countsub = 0; countsub < dgv_main.Columns.Count; countsub++)
- {
- dr[countsub] = Convert.ToString(dgv_main.Rows[count].Cells[countsub].Value);
- }
- PRJ_DataTable.Rows.Add(dr);
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- tsl_querycout.Text = dgv_main.Rows.Count + " 条";
- }
- /// <summary>
- /// 获取报价信息
- /// </summary>
- /// <param name="di3">目录</param>
- /// <param name="type">比如:BJ_001*.*</param>
- /// <returns></returns>
- private string GetBJInfo(DirectoryInfo di3,string type)
- {
- List<string> bjInfo = new List<string>();
- FileInfo[] BJ = di3.GetFiles(type);
- foreach (FileInfo f in BJ)
- {
- string[] arr = f.Name.Split('_');
- if (arr.Length < 4) { continue; }
- bjInfo.Add(arr[2]);
- }
- string bjstr = string.Join(",", bjInfo);
- return bjstr;
- }
- private void btn_query_Click(object sender, EventArgs e)
- {
- List<string> list = new List<string>();
- if (cb_type.Text != "")
- {
- list.Add("类型 like '%" + cb_type.Text + "%'");
- }
- if (cb_contacts.Text != "")
- {
- list.Add("项目联系人 like '%" + cb_contacts.Text + "%'");
- }
- if (cb_prjname.Text != "")
- {
- list.Add("项目名称 like '%" + cb_prjname.Text + "%'");
- }
-
- if (cb_prjid.Text != "")
- {
- list.Add("ID in(" + cb_prjid.Text + ")");
- }
- string querystr = string.Join(" and ", list);
- try
- {
- dgv_main.Rows.Clear();
- DataRow[] drArr = PRJ_DataTable.Select(querystr, "id");
- DataTable dtNew = PRJ_DataTable.Clone();
- for (int i = 0; i < drArr.Length; i++) { dtNew.ImportRow(drArr[i]); }
- for (int count = 0; count < dtNew.Rows.Count; count++)
- {
- object[] values = new object[dtNew.Columns.Count];
- for (int countsub = 0; countsub < dtNew.Columns.Count; countsub++)
- {
- values[countsub] = Convert.ToString(dtNew.Rows[count][countsub].ToString());
- }
- dgv_main.Rows.Add(values);
- }
- }
- catch (Exception ex) { MessageBox.Show(ex.Message + " 查询字符串:" + querystr); }
- tsl_querycout.Text = dgv_main.Rows.Count + " 条";
- }
- private void btn_clear_Click(object sender, EventArgs e)
- {
- cb_type.Text = "";
- cb_contacts.Text = "";
- cb_prjname.Text = "";
- cb_prjid.Text = "";
- }
- private void AddComboxItems(object[] values)
- {
- // id,values[0]
- // 项目路径,values[1]
- // 项目类型,values[2]
- if (values[2] != null && !cb_type.Items.Contains(values[2]))
- {
- cb_type.Items.Add(values[2]);
- }
- //项目编号,values[3]
- //项目名称,values[4]
- if (values[4] != null && !cb_prjname.Items.Contains(values[4]))
- {
- cb_prjname.Items.Add(values[4]);
- }
- //项目联系人,values[5]
- if (values[5] != null && !cb_contacts.Items.Contains(values[5]))
- {
- cb_contacts.Items.Add(values[5]);
- }
- }
- private void cb_search_KeyUp(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- try
- {
- dgv_main.Rows.Clear();
- DataRow[] drArr = PRJ_DataTable.Select(cb_search.Text, cb_px.Text);
- DataTable dtNew = PRJ_DataTable.Clone();
- for (int i = 0; i < drArr.Length; i++) { dtNew.ImportRow(drArr[i]); }
- for (int count = 0; count < dtNew.Rows.Count; count++)
- {
- object[] values = new object[dtNew.Columns.Count];
- for (int countsub = 0; countsub < dtNew.Columns.Count; countsub++)
- {
- values[countsub] = Convert.ToString(dtNew.Rows[count][countsub].ToString());
- }
- dgv_main.Rows.Add(values);
- }
- }
- catch (Exception ex) { MessageBox.Show(ex.Message); }
- tsl_querycout.Text = dgv_main.Rows.Count + " 条";
- }
- }
- private void 打开所在文件夹ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- int a = dgv_main.CurrentRow.Index;
- string dirpath = dgv_main.Rows[a].Cells["项目路径"].Value.ToString();
- Process.Start(dirpath);
- }
- }
- }
|