123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
-
- using Cksoft.Unity;
- using DllEapEntity;
- using DllPubInfo;
- using Newtonsoft.Json;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Diagnostics;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Windows.Forms;
- namespace DllXqManager
- {
- public partial class MacStatusQuery : Form
- {
- private List<MacStatus> CurrDs = null;
- public delegate void SelRow(List<MacStatus> rows,int seltype);
- public event SelRow eventSelRow = null;
- private int CurrType = 1;//1为维护机台,2为选择机台
- private int CurrSelType = 1;//选择模式,1为启动模式,2为标准模式
- private string CurrCondition = "";
- public MacStatusQuery()
- {
- InitializeComponent();
- }
- public MacStatusQuery(string condition)
- {
- InitializeComponent();
- CurrSelType = 1;
- CurrCondition = condition;
- SetForm(2);
- }
-
- private void SetForm(int ftype)
- {
- CurrType = ftype;
- if (ftype == 2)
- {
- button3.Visible = true;
- button4.Visible = false;
- }
- }
- private string GetCondition()
- {
- StringBuilder sqlstr = new StringBuilder(100);
- if(edit代码.Text.Trim()!="")
- {
- sqlstr.AppendFormat(" and a.fcode like '%{0}%'", edit代码.Text.Trim());
- }
- if (edit名称.Text.Trim() != "")
- {
- sqlstr.AppendFormat(" and a.fname like '%{0}%'", edit名称.Text.Trim());
- }
- sqlstr.AppendFormat(CurrCondition);
- return sqlstr.ToString();
- }
- private void Filldgvmain(string condition)
- {
- try
- {
- Cursor = Cursors.WaitCursor;
- string errorinfo = "";
- CurrDs = PubInfo.SelectForCondition<MacStatus>(condition, ref errorinfo).ToList();
- if (CurrDs == null)
- {
- MessageBox.Show(errorinfo);
- return;
- }
- Binddgvmain();
- foreach (DataGridViewColumn dgvc in dgvmain.Columns)
- {
- dgvc.ReadOnly = true;
- }
- dgvmain.Columns["选择"].ReadOnly = false;
- if (CurrType == 1)
- {
- //dgvmain.Columns[nameof(OrderMst.MacFCode)].Visible = false;
- //dgvmain.Columns[nameof(OrderMst.MacFName)].Visible = false;
- //dgvmain.Columns["机台指令类别"].Visible = false;
- //dgvmain.Columns["机台指令类别ID"].Visible = false;
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show("操作发生错误,错误信息为:" + ex.Message.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- finally
- {
- Cursor = Cursors.Default;
- }
- //dgvmain.Columns["选择"].ReadOnly = false;
- }
- private BindingSource currbs = null;
- private void Binddgvmain()
- {
- currbs = new BindingSource();
- var cols = CurrDs.Where(t => t.EntityStatusID >= 0).ToList();
- currbs.DataSource = cols;
- bindingNavigator2.BindingSource = currbs;
- dgvmain.DataSource = currbs;
- PubInfo.InitDataGridView<MacStatus>(dgvmain);
- //dgvmain.Columns[nameof(BaseEntity.IsSelected)].Visible = false;
- //dgvColDetail.Rows[0].Visible = false;
- }
- private void button1_Click(object sender, EventArgs e)
- {
- Filldgvmain(GetCondition());
- }
- private Form CurrForm = null;
- public void CloseCurrForm()
- {
- CurrForm =null;
- }
-
- private void ShowBase(MacStatus id)
- {
- if (CurrForm != null)
- {
- (CurrForm as MacStatusBase).SetCurrID(id);
- }
- else
- {
- CurrForm = new MacStatusBase(id);
- (CurrForm as MacStatusBase).eventaddrow += AddRow;
- (CurrForm as MacStatusBase).eventcloseform += CloseCurrForm;
- CurrForm.Owner = this;
- CurrForm.Show();
- }
- //MacStatusBase temp = new MacStatusBase(id);
- //temp.ShowDialog();
- }
- private void AddRow(MacStatus id)
- {
- //throw new NotImplementedException();
- List<MacStatus> templist = CurrDs.Where(t => t.ID == id.ID).ToList();
- if(templist.Count>0)
- {
- EntityHelper.CopyPropertyValue<MacStatus>(id, templist[0]);
- }
- else
- {
- CurrDs.Add(id);
- }
- Binddgvmain();
- }
- private void ShowBaseFor(MacStatus id)
- {
- //if(CurrForm != null)
- //{
- // (CurrForm as TLcdBase).SetCurrID(id);
- //}
- //else
- //{
- // CurrForm = new TLcdBase(id);
- // (CurrForm as TLcdBase).eventaddrow += AddRow;
- // (CurrForm as TLcdBase).eventcloseform += CloseCurrForm;
- // CurrForm.Owner = this;
- // CurrForm.Show();
- //}
- //MacStatusBaseFor temp = new MacStatusBaseFor(id);
- //temp.Show();
- }
- private void button4_Click(object sender, EventArgs e)
- {
- ShowBase(null);
- }
- private void mmaquery_Load(object sender, EventArgs e)
- {
- Filldgvmain(GetCondition());
- }
- private void dgvmain_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
- {
- if (dgvmain.CurrentRow == null)
- return;
- ShowBaseFor(dgvmain.CurrentRow.DataBoundItem as MacStatus);
- }
- private void dgvmain_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
- {
-
- if (e.Button == MouseButtons.Right)
- {
- if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
- {
- dgvmain.CurrentCell = dgvmain.Rows[e.RowIndex].Cells[e.ColumnIndex];
- System.Drawing.Point pointglobal = System.Windows.Forms.Control.MousePosition;
- cms.Show(pointglobal);
- }
- }
- }
- private void toolStripMenuItem3_Click(object sender, EventArgs e)
- {
- foreach(var temprow in CurrDs)
- {
- temprow.IsSelected = 1;
- }
- dgvmain.Refresh();
- }
- private void toolStripMenuItem4_Click(object sender, EventArgs e)
- {
- foreach (var temprow in CurrDs)
- {
- temprow.IsSelected = 0;
- }
- dgvmain.Refresh();
- }
- private void button2_Click(object sender, EventArgs e)
- {
- }
- private void button3_Click(object sender, EventArgs e)
- {
- dgvmain.EndEdit();
- edit代码.Focus();
- List<MacStatus> rows = CurrDs.Where(t => t.IsSelected == 1).ToList();//.Tables[0].Select("选择=1");
- if(rows.Count<=0)
- {
- MessageBox.Show("您没有选择数据,请选择!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- eventSelRow?.Invoke(rows,CurrSelType);
- this.Close();
- }
- private MacStatus DelMacStatus(List<MacStatus> entitys)
- {
- try
- {
- Hashtable tempds = new Hashtable();
- string str = JsonConvert.SerializeObject(entitys);
- tempds.Add(nameof(MacStatus), str);
- Hashtable reds = PubInfo.CallFunction("DllStatusShowBll.StatusShowBll", "DelMacStatus", tempds);
- if (reds == null)
- return null;
- MacStatus reentity = JsonConvert.DeserializeObject<MacStatus>(reds[nameof(MacStatus)].ToString());
- return reentity;
- }
- catch (Exception e)
- {
- MessageBox.Show("操作发生错误,错误信息为:" + e.Message.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return null;
- }
- }
- private void toolStripMenuItem2_Click(object sender, EventArgs e)
- {
- List<MacStatus> rows = CurrDs.Where(t => t.IsSelected == 1).ToList();//.Tables[CurrTableName].Select("选择=1");
- if (rows.Count <= 0)
- {
- MessageBox.Show("您没有选择数据,请选择。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (MessageBox.Show("您确定要执行此操作吗?", "询问", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk) == DialogResult.Cancel)
- return;
- MacStatus result = DelMacStatus(rows);
- if (result != null)
- {
- MessageBox.Show("操作成功。");
- foreach (var temprow in rows)
- CurrDs.Remove(temprow);
- Binddgvmain();
- }
- }
-
- private void mcaquery_FormClosed(object sender, FormClosedEventArgs e)
- {
-
- }
-
- private void cms_Opening(object sender, CancelEventArgs e)
- {
- dgvmain.EndEdit();
- edit代码.Focus();
- }
- private void 编辑位置ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- if (dgvmain.CurrentRow == null)
- return;
- MacStatus mst = dgvmain.CurrentRow.DataBoundItem as MacStatus;
- //MacStatusBase temp = new MacStatusBase(mst);
- //temp.Show();
- }
- }
- }
|