|
- using MaiMuAOI.SysCtrl;
- using Microsoft.Office.Interop.Excel;
- using Models;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
-
- namespace MaiMuAOI.SysUI.ProcessStep
- {
- public partial class StepListFrm : Form
- {
- private Service.StepService service = new Service.StepService();
- public StepListFrm()
- {
- InitializeComponent();
- UIStyle.SetUIStyle(this);
- this.uiTitel1.FatherForm = this;
- #region dataGridView设置
- dataGridView1.AutoGenerateColumns = false;//自动创建列
- dataGridView1.AllowUserToAddRows = dataGridView1.AllowUserToDeleteRows = false;//用户添加删除行
- dataGridView1.AllowUserToResizeRows = true;//用户调整行大小
- //dataGridView1.AllowUserToResizeColumns = false;//用户调整列大小
- //显示行号与列宽度自动调整
- dataGridView1.RowHeadersVisible = true;
- dataGridView1.RowHeadersWidth = 50;
- dataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders;//数据量过百绑定太变
- dataGridView1.RowPostPaint += (sender, e) =>//序号列头
- {
- SysMgr.showRowNum_onDataGrid_RowPostPaint(this.dataGridView1, sender, e);
- };
- dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
- #endregion
- this.tbSearch.Top = toolStrip1.Top + 15;
- }
- private void InitDataView(int selIndex = -1)
- {
- var list = service.GetListNav(0);
- tsslCount.Text = $"共 {list.Count} 条记录";
- int liIndex = 0;
- if (selIndex > 0) liIndex = selIndex;
- else if (this.dataGridView1.CurrentRow != null)
- liIndex = this.dataGridView1.CurrentRow.Index;
- dataGridView1.DataSource = new BindingSource(list, null);
- if (dataGridView1.Rows.Count > liIndex)
- dataGridView1.CurrentCell = dataGridView1[2, liIndex];
- }
- private void StepListFrm_Load(object sender, EventArgs e)
- {
- this.Cursor = Cursors.WaitCursor;
- InitDataView();
- this.Cursor = Cursors.Default;
- }
-
- private void tsbtnAdd_Click(object sender, EventArgs e)
- {
- StepSelectFrm stepSelectFrm = new StepSelectFrm();
- stepSelectFrm.ShowDialog();
- if (stepSelectFrm.ProcessSelect == 200)
- {
- //老流程
- StepInfoFrm frm = new StepInfoFrm();
- frm.ShowDialog();
- }
- else if (stepSelectFrm.ProcessSelect == 100)
- {
- //新流程
- StepProcessFrm frm = new StepProcessFrm();
- frm.ShowDialog();
- }
- InitDataView();
- }
-
- private void tsbtnDel_Click(object sender, EventArgs e)
- {
- try
- {
- if (this.dataGridView1.CurrentRow == null)
- return;
-
- var list = ((BindingSource)dataGridView1.DataSource).DataSource as List<Step>;
- int liIndex = this.dataGridView1.CurrentRow.Index;//获取当前选中行的索引
- if (service.InUse(list[liIndex].Id))
- throw new Exception("此流程已有产品在使用中,不可删除!");
- if (MessageBox.Show($"确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- if (!service.DelNav(list[liIndex]))
- throw new Exception("删除失败!");
-
- SysMgr.Instance.WriteSysEditLog("流程删除", JsonConvert.SerializeObject(list[liIndex]));
-
- MessageBox.Show("删除成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- this.dataGridView1.Rows.RemoveAt(liIndex);
- if (this.dataGridView1.Rows.Count == 0)
- InitDataView();
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- private void tsbtnClone_Click(object sender, EventArgs e)
- {
- if (this.dataGridView1.CurrentRow == null)
- {
- MessageBox.Show("请选择要克隆的流程!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
-
- var list = ((BindingSource)dataGridView1.DataSource).DataSource as List<Step>;
- int liIndex = this.dataGridView1.CurrentRow.Index;//获取当前选中行的索引
-
- Step newStep = new Step()
- {
- Code = list[liIndex].Code + $"_{DateTime.Now.ToString("yyyyMMddHHmmss")}clone",
- Name = $"{list[liIndex].Name} (克隆)",
- StartTimeIndex = list[liIndex].StartTimeIndex,
- ModifyUserCode = SysMgr.Instance.UserMgr.LoginUser.Code,
- CreateUserCode = SysMgr.Instance.UserMgr.LoginUser.Code,
- ProcessList = new List<StepProcess>(),
- ProcessType = list[liIndex].ProcessType,
- };
- foreach (var item in list[liIndex].ProcessList)
- {
- StepProcess sp;
- string spPrarms = "";
- if (item.ProcessCode == "Size")
- {
- if (item.ProcessParams.IndexOf("MapPath") > 0)
- {
- JObject jo = JObject.Parse(item.ProcessParams);//解析成json
- jo["MapPath"] = "";//修改需要的字段
- jo["GetPointList"] = null;
- spPrarms = Convert.ToString(jo);
- }
- else
- spPrarms = item.ProcessParams;
- }
- else
- spPrarms = item.ProcessParams;
-
- sp = new StepProcess()
- {
- Order = item.Order,
- ProcessCode = item.ProcessCode,
- ProcessName = item.ProcessName,
- ProcessParams = spPrarms,
- ModifyUserCode = SysMgr.Instance.UserMgr.LoginUser.Code,
- CreateUserCode = SysMgr.Instance.UserMgr.LoginUser.Code
- };
-
- newStep.ProcessList.Add(sp);
- }
-
- try
- {
- bool result = service.InsertNav(newStep);
- if (result)
- {
- SysMgr.Instance.WriteSysEditLog("流程克隆", JsonConvert.SerializeObject(newStep));
-
- MessageBox.Show("克隆成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- InitDataView(dataGridView1.Rows.Count);
- }
- else
- throw new Exception("克隆失败!");
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- private void tsbtnClose_Click(object sender, EventArgs e)
- {
- this.Close();
- }
-
- private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
- {
- var list = ((BindingSource)dataGridView1.DataSource).DataSource as List<Step>;
- int liIndex = this.dataGridView1.CurrentRow.Index;//获取当前选中行的索引
- //新老流程判断
- if (list[liIndex].ProcessType == "快速流程")
- {
- StepProcessFrm frm = new StepProcessFrm(list[liIndex]);
- frm.ShowDialog(this);
- }
- else
- {
- StepInfoFrm frm = new StepInfoFrm(list[liIndex]);
- frm.ShowDialog(this);
- }
- InitDataView();
- }
-
- private void tbSearch_TextChanged(object sender, EventArgs e)
- {
- if (tbSearch.Text != "")
- {
- int count = 0;
- foreach (DataGridViewRow row in dataGridView1.Rows)
- {
- for (int i = 0; i < row.Cells.Count; i++)
- {
- if (row.Cells[i].Value != null && row.Cells[i].Value.ToString().Contains(tbSearch.Text))
- {
- count = count + 1;
- }
- }
- if (count == 0)
- {
- CurrencyManager cm = (CurrencyManager)BindingContext[dataGridView1.DataSource];
-
- cm.SuspendBinding(); //挂起数据绑定
- row.Visible = false;
- cm.ResumeBinding(); //恢复数据绑定
- }
- count = 0;
- }
- }
- else
- {
- for (int i = 0; i < dataGridView1.Rows.Count; i++)
- {
- dataGridView1.Rows[i].Visible = true;
- }
- }
- }
- }
- }
|