FormPreSale.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Diagnostics;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Reflection;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13. namespace DocManager
  14. {
  15. public partial class FormPreSale : Form
  16. {
  17. public FormPreSale()
  18. {
  19. InitializeComponent();
  20. Type dgvType = this.dgv_main.GetType();
  21. PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
  22. pi.SetValue(this.dgv_main, true, null);
  23. }
  24. private void FormPreSale_Load(object sender, EventArgs e)
  25. {
  26. btn_refresh_Click(sender,e);
  27. }
  28. private DataTable PRJ_DataTable = new DataTable();
  29. private void btn_refresh_Click(object sender, EventArgs e)
  30. {
  31. try
  32. {
  33. dgv_main.Rows.Clear();
  34. DirectoryInfo dir = new DirectoryInfo(FormPRJ.PRJConfigFileModel.DirPath);
  35. DirectoryInfo[] dirInfos = dir.GetDirectories();
  36. foreach (DirectoryInfo di in dirInfos)
  37. {
  38. // 处理一个文件夹
  39. if (!di.Name.StartsWith("PreSale_")) { continue; }
  40. string TYPE = di.Name.Substring(8, di.Name.Length - 8);
  41. DirectoryInfo dir_PRJ = new DirectoryInfo(di.FullName);
  42. DirectoryInfo[] dir_PRJ_Infos = dir_PRJ.GetDirectories();
  43. foreach (DirectoryInfo di2 in dir_PRJ_Infos)
  44. {
  45. if (!di2.Name.Contains("_")) { continue; }
  46. string PRJ_CODE = di2.Name.Substring(0, di2.Name.IndexOf("_"));
  47. if (PRJ_CODE.Length != 4) { continue; }
  48. // PRJ Code 针对售前项目,必须是一个4位的数字
  49. int tmp = 0;
  50. if (!int.TryParse(PRJ_CODE, out tmp))
  51. {
  52. continue;
  53. }
  54. if (!di2.Name.Contains("(")) { continue; }
  55. string PRJ_NAME = di2.Name.Substring(5, di2.Name.LastIndexOf("(") - 5);
  56. if (!di2.Name.Contains(")")) { continue; }
  57. string PRJ_Contacts = di2.Name.Substring(di2.Name.LastIndexOf("(") + 1, di2.Name.LastIndexOf(")") - di2.Name.LastIndexOf("(") - 1);
  58. int id = dgv_main.Rows.Count + 1;
  59. // 获取报价信息
  60. string bj_dir = di2.FullName + "\\1002 报价&方案";
  61. if (!Directory.Exists(bj_dir)) { Directory.CreateDirectory(bj_dir); }
  62. DirectoryInfo di3 = new DirectoryInfo(bj_dir);
  63. List<string> list = new List<string>();
  64. // 第N次报价
  65. string BJ001=GetBJInfo(di3,"BJ_001_*.*");
  66. string BJ002 = GetBJInfo(di3, "BJ_002_*.*");
  67. string BJ003 = GetBJInfo(di3, "BJ_003_*.*");
  68. string BJ004 = GetBJInfo(di3, "BJ_004_*.*");
  69. string BJ005 = GetBJInfo(di3, "BJ_005_*.*");
  70. string BJ006 = GetBJInfo(di3, "BJ_006_*.*");
  71. string BJ007 = GetBJInfo(di3, "BJ_007_*.*");
  72. list.AddRange(new string[] { BJ001, BJ002, BJ003, BJ004, BJ005, BJ006, BJ007 });
  73. // 当前报价
  74. string currentJiaGe = "";
  75. foreach(string str in list)
  76. {
  77. if (str == "") { continue; } else { currentJiaGe = str; }
  78. }
  79. object[] values = { id, di2.FullName, TYPE, PRJ_CODE, PRJ_NAME, PRJ_Contacts,
  80. currentJiaGe,BJ001,BJ002,BJ003,BJ004,BJ005,BJ006,BJ007};
  81. dgv_main.Rows.Add(values);
  82. AddComboxItems(values);
  83. }
  84. }
  85. // 修改datagridview的类型
  86. for (int count = 0; count < dgv_main.Columns.Count; count++)
  87. {
  88. if (dgv_main.Columns[count].Name.ToString() == "ID")
  89. {
  90. dgv_main.Columns[count].ValueType = typeof(int);
  91. continue;
  92. }
  93. dgv_main.Columns[count].ValueType = typeof(string);
  94. }
  95. PRJ_DataTable = new DataTable();
  96. //把DataGridView控件数据,转成DataTable
  97. for (int count = 0; count < dgv_main.Columns.Count; count++)
  98. {
  99. Type t = dgv_main.Columns[count].ValueType;
  100. DataColumn dc = new DataColumn(dgv_main.Columns[count].Name.ToString(), t);
  101. PRJ_DataTable.Columns.Add(dc);
  102. }
  103. for (int count = 0; count < dgv_main.Rows.Count; count++)
  104. {
  105. DataRow dr = PRJ_DataTable.NewRow();
  106. for (int countsub = 0; countsub < dgv_main.Columns.Count; countsub++)
  107. {
  108. dr[countsub] = Convert.ToString(dgv_main.Rows[count].Cells[countsub].Value);
  109. }
  110. PRJ_DataTable.Rows.Add(dr);
  111. }
  112. }
  113. catch (Exception ex)
  114. {
  115. MessageBox.Show(ex.Message);
  116. }
  117. tsl_querycout.Text = dgv_main.Rows.Count + " 条";
  118. }
  119. /// <summary>
  120. /// 获取报价信息
  121. /// </summary>
  122. /// <param name="di3">目录</param>
  123. /// <param name="type">比如:BJ_001*.*</param>
  124. /// <returns></returns>
  125. private string GetBJInfo(DirectoryInfo di3,string type)
  126. {
  127. List<string> bjInfo = new List<string>();
  128. FileInfo[] BJ = di3.GetFiles(type);
  129. foreach (FileInfo f in BJ)
  130. {
  131. string[] arr = f.Name.Split('_');
  132. if (arr.Length < 4) { continue; }
  133. bjInfo.Add(arr[2]);
  134. }
  135. string bjstr = string.Join(",", bjInfo);
  136. return bjstr;
  137. }
  138. private void btn_query_Click(object sender, EventArgs e)
  139. {
  140. List<string> list = new List<string>();
  141. if (cb_type.Text != "")
  142. {
  143. list.Add("类型 like '%" + cb_type.Text + "%'");
  144. }
  145. if (cb_contacts.Text != "")
  146. {
  147. list.Add("项目联系人 like '%" + cb_contacts.Text + "%'");
  148. }
  149. if (cb_prjname.Text != "")
  150. {
  151. list.Add("项目名称 like '%" + cb_prjname.Text + "%'");
  152. }
  153. if (cb_prjid.Text != "")
  154. {
  155. list.Add("ID in(" + cb_prjid.Text + ")");
  156. }
  157. string querystr = string.Join(" and ", list);
  158. try
  159. {
  160. dgv_main.Rows.Clear();
  161. DataRow[] drArr = PRJ_DataTable.Select(querystr, "id");
  162. DataTable dtNew = PRJ_DataTable.Clone();
  163. for (int i = 0; i < drArr.Length; i++) { dtNew.ImportRow(drArr[i]); }
  164. for (int count = 0; count < dtNew.Rows.Count; count++)
  165. {
  166. object[] values = new object[dtNew.Columns.Count];
  167. for (int countsub = 0; countsub < dtNew.Columns.Count; countsub++)
  168. {
  169. values[countsub] = Convert.ToString(dtNew.Rows[count][countsub].ToString());
  170. }
  171. dgv_main.Rows.Add(values);
  172. }
  173. }
  174. catch (Exception ex) { MessageBox.Show(ex.Message + " 查询字符串:" + querystr); }
  175. tsl_querycout.Text = dgv_main.Rows.Count + " 条";
  176. }
  177. private void btn_clear_Click(object sender, EventArgs e)
  178. {
  179. cb_type.Text = "";
  180. cb_contacts.Text = "";
  181. cb_prjname.Text = "";
  182. cb_prjid.Text = "";
  183. }
  184. private void AddComboxItems(object[] values)
  185. {
  186. // id,values[0]
  187. // 项目路径,values[1]
  188. // 项目类型,values[2]
  189. if (values[2] != null && !cb_type.Items.Contains(values[2]))
  190. {
  191. cb_type.Items.Add(values[2]);
  192. }
  193. //项目编号,values[3]
  194. //项目名称,values[4]
  195. if (values[4] != null && !cb_prjname.Items.Contains(values[4]))
  196. {
  197. cb_prjname.Items.Add(values[4]);
  198. }
  199. //项目联系人,values[5]
  200. if (values[5] != null && !cb_contacts.Items.Contains(values[5]))
  201. {
  202. cb_contacts.Items.Add(values[5]);
  203. }
  204. }
  205. private void cb_search_KeyUp(object sender, KeyEventArgs e)
  206. {
  207. if (e.KeyCode == Keys.Enter)
  208. {
  209. try
  210. {
  211. dgv_main.Rows.Clear();
  212. DataRow[] drArr = PRJ_DataTable.Select(cb_search.Text, cb_px.Text);
  213. DataTable dtNew = PRJ_DataTable.Clone();
  214. for (int i = 0; i < drArr.Length; i++) { dtNew.ImportRow(drArr[i]); }
  215. for (int count = 0; count < dtNew.Rows.Count; count++)
  216. {
  217. object[] values = new object[dtNew.Columns.Count];
  218. for (int countsub = 0; countsub < dtNew.Columns.Count; countsub++)
  219. {
  220. values[countsub] = Convert.ToString(dtNew.Rows[count][countsub].ToString());
  221. }
  222. dgv_main.Rows.Add(values);
  223. }
  224. }
  225. catch (Exception ex) { MessageBox.Show(ex.Message); }
  226. tsl_querycout.Text = dgv_main.Rows.Count + " 条";
  227. }
  228. }
  229. private void 打开所在文件夹ToolStripMenuItem_Click(object sender, EventArgs e)
  230. {
  231. int a = dgv_main.CurrentRow.Index;
  232. string dirpath = dgv_main.Rows[a].Cells["项目路径"].Value.ToString();
  233. Process.Start(dirpath);
  234. }
  235. }
  236. }