FormPRJ.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. using Common;
  2. using DocManager.Forms;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Diagnostics;
  8. using System.Drawing;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Reflection;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Windows.Forms;
  15. namespace DocManager
  16. {
  17. public partial class FormPRJ : Form
  18. {
  19. string PRJ_TYPE = "PRJ_";//项目类型:售中(PRJ_)、售后(AfterSale_)
  20. public FormPRJ()
  21. {
  22. InitializeComponent();
  23. }
  24. public FormPRJ(string PRJ_TYPE)
  25. {
  26. InitializeComponent();
  27. this.PRJ_TYPE = PRJ_TYPE;
  28. this.lbl_title.Text = PRJ_TYPE.Substring(0, PRJ_TYPE.Length - 1) + " Manager";
  29. if (PRJ_TYPE == "AfterSale_")
  30. {
  31. checkBox_status.Checked = false;
  32. }
  33. else
  34. {
  35. checkBox_status.Checked = true;
  36. }
  37. Type dgvType = this.dgv_main.GetType();
  38. PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
  39. pi.SetValue(this.dgv_main, true, null);
  40. }
  41. public static string configpath = System.AppDomain.CurrentDomain.BaseDirectory + "PRJConfigFileModel.json";
  42. public static PRJConfigFileModel PRJConfigFileModel = new PRJConfigFileModel();
  43. private DataTable PRJ_DataTable = new DataTable();
  44. private void FormPRJ_Load(object sender, EventArgs e)
  45. {
  46. if (!File.Exists(configpath))
  47. {
  48. PRJConfigFileModel.DirPath = @"D:\D_项目资料";
  49. SerializeClassHelper.SerializeObject(configpath, PRJConfigFileModel);
  50. }
  51. else
  52. {
  53. PRJConfigFileModel = (PRJConfigFileModel)SerializeClassHelper.DeserializeObject<PRJConfigFileModel>(configpath);
  54. }
  55. btn_refresh_Click(sender,e);
  56. dgv_main.Columns["未税金额"].Visible = false;
  57. }
  58. private void btn_refresh_Click(object sender, EventArgs e)
  59. {
  60. try
  61. {
  62. dgv_main.Rows.Clear();
  63. DirectoryInfo dir = new DirectoryInfo(PRJConfigFileModel.DirPath);
  64. DirectoryInfo[] dirInfos = dir.GetDirectories();
  65. foreach (DirectoryInfo di in dirInfos)
  66. {
  67. // 处理一个文件夹
  68. if (!di.Name.StartsWith(PRJ_TYPE)) { continue; }
  69. string TYPE = di.Name.Substring(PRJ_TYPE.Length, di.Name.Length - PRJ_TYPE.Length);
  70. DirectoryInfo dir_PRJ = new DirectoryInfo(di.FullName);
  71. DirectoryInfo[] dir_PRJ_Infos = dir_PRJ.GetDirectories();
  72. foreach (DirectoryInfo di2 in dir_PRJ_Infos)
  73. {
  74. if (!di2.Name.StartsWith("PRJ")) { continue; }
  75. if (!di2.Name.Contains("_")) { continue; }
  76. string PRJ_CODE = di2.Name.Substring(0, di2.Name.IndexOf("_"));
  77. if (PRJ_CODE.Length != 14) { continue; }
  78. if (!di2.Name.Contains("(")) { continue; }
  79. string PRJ_NAME = di2.Name.Substring(15, di2.Name.LastIndexOf("(") - 15);
  80. if (!di2.Name.Contains(")")) { continue; }
  81. string PRJ_Contacts = di2.Name.Substring(di2.Name.LastIndexOf("(") + 1, di2.Name.LastIndexOf(")") - di2.Name.LastIndexOf("(") - 1);
  82. int id = dgv_main.Rows.Count + 1;
  83. // 获取
  84. DotPRJMangerModel model = new DotPRJMangerModel();
  85. if (File.Exists(di2.FullName + "\\" + "DotPRJManger.json"))
  86. {
  87. model = (DotPRJMangerModel)SerializeClassHelper.DeserializeObject<DotPRJMangerModel>(di2.FullName + "\\" + "DotPRJManger.json");
  88. }
  89. // 获取PO
  90. // 获取报价信息
  91. //DirectoryInfo di3 = new DirectoryInfo(bj_dir);
  92. string poinfo= GetPOInfo(di2);
  93. // 获取订单金额
  94. string jiner = GetJinErInfo(di2);
  95. // 获取送货单信息
  96. string songhuoInfo = GetSongHuoInfo(di2);
  97. // 获取验收但信息
  98. string yanshouInfo = GetYanShouInfo(di2);
  99. object[] values = { id, di2.FullName, TYPE, PRJ_CODE, PRJ_NAME, PRJ_Contacts,model.PersonLiable, model.Status, poinfo, jiner,songhuoInfo , yanshouInfo };
  100. dgv_main.Rows.Add(values);
  101. AddComboxItems(values);
  102. }
  103. }
  104. // 修改datagridview的类型
  105. for (int count = 0; count < dgv_main.Columns.Count; count++)
  106. {
  107. if (dgv_main.Columns[count].Name.ToString() == "ID")
  108. {
  109. dgv_main.Columns[count].ValueType = typeof(int);
  110. continue;
  111. }
  112. dgv_main.Columns[count].ValueType = typeof(string);
  113. }
  114. PRJ_DataTable = new DataTable();
  115. //把DataGridView控件数据,转成DataTable
  116. for (int count = 0; count < dgv_main.Columns.Count; count++)
  117. {
  118. Type t = dgv_main.Columns[count].ValueType;
  119. DataColumn dc = new DataColumn(dgv_main.Columns[count].Name.ToString(), t);
  120. PRJ_DataTable.Columns.Add(dc);
  121. }
  122. for (int count = 0; count < dgv_main.Rows.Count; count++)
  123. {
  124. DataRow dr = PRJ_DataTable.NewRow();
  125. for (int countsub = 0; countsub < dgv_main.Columns.Count; countsub++)
  126. {
  127. dr[countsub] = Convert.ToString(dgv_main.Rows[count].Cells[countsub].Value);
  128. }
  129. PRJ_DataTable.Rows.Add(dr);
  130. }
  131. }catch(Exception ex)
  132. {
  133. MessageBox.Show(ex.Message);
  134. }
  135. tsl_querycout.Text = dgv_main.Rows.Count + " 条";
  136. }
  137. /// <summary>
  138. /// 获取报价信息
  139. /// </summary>
  140. /// <param name="di3">目录</param>
  141. /// <param name="type">比如:BJ_001*.*</param>
  142. /// <returns></returns>
  143. private string GetPOInfo(DirectoryInfo di3)
  144. {
  145. List<string> bjInfo = new List<string>();
  146. FileInfo[] BJ = di3.GetFiles("PO_*.*");
  147. foreach (FileInfo f in BJ)
  148. {
  149. string[] arr = f.Name.Split('_');
  150. if (arr.Length < 2) { continue; }
  151. bjInfo.Add(arr[1].Split('.')[0]);
  152. }
  153. string bjstr = string.Join(",", bjInfo);
  154. return bjstr;
  155. }
  156. /// <summary>
  157. /// 获取金额
  158. /// </summary>
  159. /// <param name="di3">目录</param>
  160. /// <param name="type">比如:BJ_001*.*</param>
  161. /// <returns></returns>
  162. private string GetJinErInfo(DirectoryInfo di3)
  163. {
  164. List<string> bjInfo = new List<string>();
  165. FileInfo[] BJ = di3.GetFiles("PO_*.*");
  166. foreach (FileInfo f in BJ)
  167. {
  168. string[] arr = f.Name.Split('_');
  169. if (arr.Length < 3) { continue; }
  170. if(arr[2].StartsWith("$")|| arr[2].StartsWith("¥"))
  171. {
  172. bjInfo.Add(arr[2]);
  173. }
  174. }
  175. string bjstr = string.Join(",", bjInfo);
  176. return bjstr;
  177. }
  178. /// <summary>
  179. /// 获取送货信息
  180. /// </summary>
  181. /// <param name="di3"></param>
  182. /// <returns></returns>
  183. private string GetSongHuoInfo(DirectoryInfo di3)
  184. {
  185. List<string> bjInfo = new List<string>();
  186. FileInfo[] BJ = di3.GetFiles("送货单*.*");
  187. foreach (FileInfo f in BJ)
  188. {
  189. bjInfo.Add(f.Name);
  190. }
  191. string bjstr = string.Join(",", bjInfo);
  192. return bjstr;
  193. }
  194. /// <summary>
  195. /// 获取验收信息
  196. /// </summary>
  197. /// <param name="di3"></param>
  198. /// <returns></returns>
  199. private string GetYanShouInfo(DirectoryInfo di3)
  200. {
  201. List<string> ysInfo = new List<string>();
  202. FileInfo[] YS = di3.GetFiles("验收单*.*");
  203. foreach (FileInfo f in YS)
  204. {
  205. ysInfo.Add(f.Name);
  206. }
  207. string bjstr = string.Join(",", ysInfo);
  208. return bjstr;
  209. }
  210. private void AddComboxItems(object[] values)
  211. {
  212. // id,values[0]
  213. // 项目路径,values[1]
  214. // 项目类型,values[2]
  215. if (values[2]!=null&&!cb_type.Items.Contains(values[2]))
  216. {
  217. cb_type.Items.Add(values[2]);
  218. }
  219. //项目编号,values[3]
  220. //项目名称,values[4]
  221. if (values[4] != null && !cb_prjname.Items.Contains(values[4]))
  222. {
  223. cb_prjname.Items.Add(values[4]);
  224. }
  225. //项目联系人,values[5]
  226. if (values[5] != null && !cb_contacts.Items.Contains(values[5]))
  227. {
  228. cb_contacts.Items.Add(values[5]);
  229. }
  230. //状态,values[6]
  231. if (values[6] != null && !cb_prjstatus.Items.Contains(values[6]))
  232. {
  233. cb_prjstatus.Items.Add(values[6]);
  234. }
  235. }
  236. private void dgv_main_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  237. {
  238. DataGridViewRow row = dgv_main.CurrentRow;
  239. string PRJ_NAME = row.Cells["项目名称"].Value.ToString();
  240. string PRJ_File_PATH= row.Cells["项目路径"].Value.ToString()+ "\\DotPRJManger.json";
  241. //MessageBox.Show(row.Cells["项目名称"].Value.ToString());
  242. new FormPRJDetail(PRJ_NAME, PRJ_File_PATH).ShowDialog();
  243. }
  244. private void cb_search_KeyUp(object sender, KeyEventArgs e)
  245. {
  246. if (e.KeyCode == Keys.Enter)
  247. {
  248. try
  249. {
  250. dgv_main.Rows.Clear();
  251. DataRow[] drArr = PRJ_DataTable.Select(cb_search.Text, cb_px.Text);
  252. DataTable dtNew = PRJ_DataTable.Clone();
  253. for (int i = 0; i < drArr.Length; i++) { dtNew.ImportRow(drArr[i]); }
  254. for (int count = 0; count < dtNew.Rows.Count; count++)
  255. {
  256. object[] values=new object[dtNew.Columns.Count];
  257. for (int countsub = 0; countsub < dtNew.Columns.Count; countsub++)
  258. {
  259. values[countsub] = Convert.ToString(dtNew.Rows[count][countsub].ToString());
  260. }
  261. dgv_main.Rows.Add(values);
  262. }
  263. }
  264. catch (Exception ex) { MessageBox.Show(ex.Message); }
  265. tsl_querycout.Text = dgv_main.Rows.Count + " 条";
  266. }
  267. }
  268. private void btn_query_Click(object sender, EventArgs e)
  269. {
  270. List<string> list = new List<string>();
  271. if (checkBox_status.Checked)
  272. {
  273. list.Add("项目状态<>'已完成'");
  274. }
  275. if (cb_type.Text != "")
  276. {
  277. list.Add("类型 like '%" +cb_type.Text+"%'");
  278. }
  279. if (cb_contacts.Text != "")
  280. {
  281. list.Add("项目联系人 like '%" + cb_contacts.Text + "%'");
  282. }
  283. if (cb_prjname.Text != "")
  284. {
  285. list.Add("项目名称 like '%" + cb_prjname.Text + "%'");
  286. }
  287. if (cb_prjstatus.Text != "")
  288. {
  289. list.Add("项目状态 like '%" + cb_prjstatus.Text + "%'");
  290. }
  291. if (cb_prjid.Text != "")
  292. {
  293. list.Add("ID in("+cb_prjid.Text+")");
  294. }
  295. string querystr = string.Join(" and ",list);
  296. try
  297. {
  298. dgv_main.Rows.Clear();
  299. DataRow[] drArr = PRJ_DataTable.Select(querystr, "id");
  300. DataTable dtNew = PRJ_DataTable.Clone();
  301. for (int i = 0; i < drArr.Length; i++) { dtNew.ImportRow(drArr[i]); }
  302. for (int count = 0; count < dtNew.Rows.Count; count++)
  303. {
  304. object[] values = new object[dtNew.Columns.Count];
  305. for (int countsub = 0; countsub < dtNew.Columns.Count; countsub++)
  306. {
  307. values[countsub] = Convert.ToString(dtNew.Rows[count][countsub].ToString());
  308. }
  309. dgv_main.Rows.Add(values);
  310. }
  311. }
  312. catch (Exception ex) { MessageBox.Show(ex.Message+" 查询字符串:"+querystr); }
  313. tsl_querycout.Text = dgv_main.Rows.Count + " 条";
  314. }
  315. private void btn_clear_Click(object sender, EventArgs e)
  316. {
  317. cb_type.Text = "";
  318. cb_contacts.Text = "";
  319. cb_prjname.Text = "";
  320. cb_prjstatus.Text = "";
  321. cb_prjid.Text = "";
  322. }
  323. private void btn_setting_Click(object sender, EventArgs e)
  324. {
  325. new FormPRJSetting().ShowDialog();
  326. }
  327. private void 打开所在文件夹ToolStripMenuItem_Click(object sender, EventArgs e)
  328. {
  329. int a= dgv_main.CurrentRow.Index;
  330. string dirpath = dgv_main.Rows[a].Cells["项目路径"].Value.ToString();
  331. Process.Start(dirpath);
  332. }
  333. private void cb_jiner_CheckedChanged(object sender, EventArgs e)
  334. {
  335. if (cb_jiner.Checked)
  336. {
  337. dgv_main.Columns["未税金额"].Visible = true;
  338. }
  339. else
  340. {
  341. dgv_main.Columns["未税金额"].Visible = false;
  342. }
  343. }
  344. }
  345. }