123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440 |
- using Common;
- using DocManager.Forms;
- 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 FormPRJ : Form
- {
- string PRJ_TYPE = "PRJ_";//项目类型:售中(PRJ_)、售后(AfterSale_)
- public FormPRJ()
- {
- InitializeComponent();
- }
- public FormPRJ(string PRJ_TYPE)
- {
- InitializeComponent();
- this.PRJ_TYPE = PRJ_TYPE;
- this.lbl_title.Text = PRJ_TYPE.Substring(0, PRJ_TYPE.Length - 1) + " Manager";
- if (PRJ_TYPE == "AfterSale_")
- {
- checkBox_status.Checked = false;
- }
- else
- {
- checkBox_status.Checked = true;
- }
- Type dgvType = this.dgv_main.GetType();
- PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
- pi.SetValue(this.dgv_main, true, null);
- }
- public static string configpath = System.AppDomain.CurrentDomain.BaseDirectory + "PRJConfigFileModel.json";
- public static PRJConfigFileModel PRJConfigFileModel = new PRJConfigFileModel();
- private DataTable PRJ_DataTable = new DataTable();
- private void FormPRJ_Load(object sender, EventArgs e)
- {
-
- if (!File.Exists(configpath))
- {
- PRJConfigFileModel.DirPath = @"D:\D_项目资料";
- SerializeClassHelper.SerializeObject(configpath, PRJConfigFileModel);
- }
- else
- {
- PRJConfigFileModel = (PRJConfigFileModel)SerializeClassHelper.DeserializeObject<PRJConfigFileModel>(configpath);
- }
- btn_refresh_Click(sender,e);
- dgv_main.Columns["未税金额"].Visible = false;
- }
- private void btn_refresh_Click(object sender, EventArgs e)
- {
- try
- {
- dgv_main.Rows.Clear();
- DirectoryInfo dir = new DirectoryInfo(PRJConfigFileModel.DirPath);
- DirectoryInfo[] dirInfos = dir.GetDirectories();
- foreach (DirectoryInfo di in dirInfos)
- {
- // 处理一个文件夹
- if (!di.Name.StartsWith(PRJ_TYPE)) { continue; }
- string TYPE = di.Name.Substring(PRJ_TYPE.Length, di.Name.Length - PRJ_TYPE.Length);
- DirectoryInfo dir_PRJ = new DirectoryInfo(di.FullName);
- DirectoryInfo[] dir_PRJ_Infos = dir_PRJ.GetDirectories();
- foreach (DirectoryInfo di2 in dir_PRJ_Infos)
- {
- if (!di2.Name.StartsWith("PRJ")) { continue; }
- if (!di2.Name.Contains("_")) { continue; }
- string PRJ_CODE = di2.Name.Substring(0, di2.Name.IndexOf("_"));
- if (PRJ_CODE.Length != 14) { continue; }
- if (!di2.Name.Contains("(")) { continue; }
- string PRJ_NAME = di2.Name.Substring(15, di2.Name.LastIndexOf("(") - 15);
- 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;
- // 获取
- DotPRJMangerModel model = new DotPRJMangerModel();
- if (File.Exists(di2.FullName + "\\" + "DotPRJManger.json"))
- {
- model = (DotPRJMangerModel)SerializeClassHelper.DeserializeObject<DotPRJMangerModel>(di2.FullName + "\\" + "DotPRJManger.json");
- }
- // 获取PO
- // 获取报价信息
- //DirectoryInfo di3 = new DirectoryInfo(bj_dir);
- string poinfo= GetPOInfo(di2);
- // 获取订单金额
- string jiner = GetJinErInfo(di2);
- // 获取送货单信息
- string songhuoInfo = GetSongHuoInfo(di2);
- // 获取验收但信息
- string yanshouInfo = GetYanShouInfo(di2);
- object[] values = { id, di2.FullName, TYPE, PRJ_CODE, PRJ_NAME, PRJ_Contacts,model.PersonLiable, model.Status, poinfo, jiner,songhuoInfo , yanshouInfo };
- 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 GetPOInfo(DirectoryInfo di3)
- {
- List<string> bjInfo = new List<string>();
- FileInfo[] BJ = di3.GetFiles("PO_*.*");
- foreach (FileInfo f in BJ)
- {
- string[] arr = f.Name.Split('_');
- if (arr.Length < 2) { continue; }
- bjInfo.Add(arr[1].Split('.')[0]);
- }
- string bjstr = string.Join(",", bjInfo);
- return bjstr;
- }
- /// <summary>
- /// 获取金额
- /// </summary>
- /// <param name="di3">目录</param>
- /// <param name="type">比如:BJ_001*.*</param>
- /// <returns></returns>
- private string GetJinErInfo(DirectoryInfo di3)
- {
- List<string> bjInfo = new List<string>();
- FileInfo[] BJ = di3.GetFiles("PO_*.*");
- foreach (FileInfo f in BJ)
- {
- string[] arr = f.Name.Split('_');
- if (arr.Length < 3) { continue; }
- if(arr[2].StartsWith("$")|| arr[2].StartsWith("¥"))
- {
- bjInfo.Add(arr[2]);
- }
- }
- string bjstr = string.Join(",", bjInfo);
- return bjstr;
- }
- /// <summary>
- /// 获取送货信息
- /// </summary>
- /// <param name="di3"></param>
- /// <returns></returns>
- private string GetSongHuoInfo(DirectoryInfo di3)
- {
- List<string> bjInfo = new List<string>();
- FileInfo[] BJ = di3.GetFiles("送货单*.*");
- foreach (FileInfo f in BJ)
- {
- bjInfo.Add(f.Name);
- }
- string bjstr = string.Join(",", bjInfo);
- return bjstr;
- }
- /// <summary>
- /// 获取验收信息
- /// </summary>
- /// <param name="di3"></param>
- /// <returns></returns>
- private string GetYanShouInfo(DirectoryInfo di3)
- {
- List<string> ysInfo = new List<string>();
- FileInfo[] YS = di3.GetFiles("验收单*.*");
- foreach (FileInfo f in YS)
- {
- ysInfo.Add(f.Name);
- }
- string bjstr = string.Join(",", ysInfo);
- return bjstr;
- }
- 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]);
- }
- //状态,values[6]
- if (values[6] != null && !cb_prjstatus.Items.Contains(values[6]))
- {
- cb_prjstatus.Items.Add(values[6]);
- }
- }
- private void dgv_main_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
- {
- DataGridViewRow row = dgv_main.CurrentRow;
- string PRJ_NAME = row.Cells["项目名称"].Value.ToString();
- string PRJ_File_PATH= row.Cells["项目路径"].Value.ToString()+ "\\DotPRJManger.json";
- //MessageBox.Show(row.Cells["项目名称"].Value.ToString());
- new FormPRJDetail(PRJ_NAME, PRJ_File_PATH).ShowDialog();
-
- }
- 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 btn_query_Click(object sender, EventArgs e)
- {
- List<string> list = new List<string>();
- if (checkBox_status.Checked)
- {
- list.Add("项目状态<>'已完成'");
- }
- 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_prjstatus.Text != "")
- {
- list.Add("项目状态 like '%" + cb_prjstatus.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_prjstatus.Text = "";
- cb_prjid.Text = "";
- }
- private void btn_setting_Click(object sender, EventArgs e)
- {
- new FormPRJSetting().ShowDialog();
- }
- 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);
- }
- private void cb_jiner_CheckedChanged(object sender, EventArgs e)
- {
- if (cb_jiner.Checked)
- {
- dgv_main.Columns["未税金额"].Visible = true;
- }
- else
- {
- dgv_main.Columns["未税金额"].Visible = false;
- }
- }
- }
- }
|