123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433 |
- using DllPubInfo;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using Cksoft.Unity;
- using DllEapEntity;
- using System.Collections;
- using Newtonsoft.Json;
- using DllHsms;
- namespace DllXqManager
- {
- public partial class MachineQuery : Form
- {
- private IList<Machine02> CurrDs = null;
- private string CurrTableName = nameof(Machine02);
- private int IsSel = 0;//1为选择模式
- private Form CurrForm = null;
- private string CurrCondition = "";
- private int CurrType = 1;
- public delegate void SelRow(List<Machine02> rows);
- public event SelRow eventSelRow = null;
- public delegate void CloseForm();
- public event CloseForm eventCloseForm = null;
- private List<LayoutDetail> AlreadySelDs = null;
- public MachineQuery(List<LayoutDetail> sels)
- {
- InitializeComponent();
- InitTypeItem();
- AlreadySelDs = sels;
- }
- //public Machine02Query(int statusid)
- //{
- // InitializeComponent();
- // InitTypeItem();
- // PubInfo.FillComBoBox(edit状态, 0);
- // Filldgvmain(GetCondition());
- // this.IsSel = 1;
- //}
- //public Machine02Query(string condition)
- //{
- // InitializeComponent();
- // CurrCondition = condition;
- // SetForm(2);
- // InitTypeItem();
- // //PubInfo.FillComBoBox(edit状态, 0);
- // Filldgvmain(GetCondition());
- // this.IsSel = 1;
- //}
- private void SetForm(int ftype)
- {
- CurrType = ftype;
- if (ftype == 2)
- {
- button3.Visible = true;
- button4.Visible = false;
- }
- }
- private void InitTypeItem()
- {
- //string sqlstr = $"select * from constitem where preid=8";
- //string errorinfo = "";
- //IList<Constitem> items = PubInfo.Select<Constitem>(sqlstr,nameof(Constitem), ref errorinfo);
- //PubInfo.InitComboBox(edit状态, items, 8);
- //PubInfo.FillComBoBox(edit状态, 0);
- //dateTimePicker2.Value = DateTime.Now;
- //dateTimePicker1.Value = DateTime.Now.AddDays(-3);
- }
- private string GetCondition()
- {
- string sqlstr ="";
- string colname = EntityAttribute.GetPropertyCondition<Machine02>(nameof(Machine02.MModeCode));
- if (edit机型代码.Text.Trim() != ""&&!string.IsNullOrEmpty(colname))
- {
- sqlstr += string.Format($" and {colname} like '%{edit机型代码.Text.Trim()}%'");
- }
- colname = EntityAttribute.GetPropertyCondition<Machine02>(nameof(Machine02.MModeName));
- if (edit机型名称.Text.Trim() != "" && !string.IsNullOrEmpty(colname))
- {
- sqlstr += string.Format($" and {colname} like '%{edit机型名称.Text.Trim()}%'");
- }
- colname = EntityAttribute.GetPropertyCondition<Machine02>(nameof(Machine02.FCode));
- if (edit机台代码.Text.Trim() != "" && !string.IsNullOrEmpty(colname))
- {
- sqlstr += string.Format($" and {colname} like '%{edit机台代码.Text.Trim()}%'");
- }
- colname = EntityAttribute.GetPropertyCondition<Machine02>(nameof(Machine02.FName));
- if (edit机台名称.Text.Trim() != "" && !string.IsNullOrEmpty(colname))
- {
- sqlstr += string.Format($" and {colname} like '%{edit机台名称.Text.Trim()}%'");
- }
- colname = EntityAttribute.GetPropertyCondition<Machine02>(nameof(Machine02.SupplierFCode));
- if (edit厂商代码.Text.Trim() != "" && !string.IsNullOrEmpty(colname))
- {
- sqlstr += string.Format($" and {colname} like '%{edit厂商代码.Text.Trim()}%'");
- }
- colname = EntityAttribute.GetPropertyCondition<Machine02>(nameof(Machine02.FactoryName));
- if (edit厂区名称.Text.Trim() != "" && !string.IsNullOrEmpty(colname))
- {
- sqlstr += string.Format($" and {colname} like '%{edit厂区名称.Text.Trim()}%'");
- }
- colname = EntityAttribute.GetPropertyCondition<Machine02>(nameof(Machine02.StatusID));
- if (radioButton2.Checked)
- {
- sqlstr += string.Format($" and {colname} >1");
- }
- if (radioButton3.Checked)
- {
- sqlstr += string.Format($" and {colname} <=1");
- }
- if (CurrCondition != "")
- sqlstr += CurrCondition;
- return sqlstr;
- }
- private void Filldgvmain(string condition)
- {
- try
- {
- Cursor = Cursors.WaitCursor;
- string errorinfo = "";
- CurrDs = PubInfo.SelectForCondition<Machine02>(condition, ref errorinfo);
- if (CurrDs == null)
- {
- MessageBox.Show(errorinfo);
- return;
- }
- Binddgvmain();
- }
- catch (Exception ex)
- {
- MessageBox.Show("操作发生错误,错误信息为:" + ex.Message.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- finally
- {
- Cursor = Cursors.Default;
- }
- }
- private BindingSource currbs = null;
- public void Binddgvmain()
- {
- currbs = new BindingSource();
- List<Machine02> cols = new List<Machine02>();// CurrDs.Where(t => t.EntityStatusID >= 0).ToList();
- List<LayoutDetail> templist = new List<LayoutDetail>();
- foreach(var item in CurrDs)
- {
- item.IsSelected = 0;//清空所有选择
- templist = AlreadySelDs.Where(t => t.EntityTypeID == EntityType.Machine&& t.EntityID == item.ID).ToList();
- if (templist.Count > 0)
- continue;
- cols.Add(item);
- }
- currbs.DataSource = cols;
- bindingNavigator2.BindingSource = currbs;
- dgvmain.DataSource = currbs;
- PubInfo.InitDataGridView<Machine02>(dgvmain);
- //Type type = typeof(Machine02);
- //PropertyInfo[] props = type.GetProperties();
- //foreach (PropertyInfo prop in props)
- //{
- // if (dgvmain.Columns.Contains(prop.Name))
- // {
- // dgvmain.Columns[prop.Name].Visible = false;
- // }
- //}
- //dgvmain.Columns[prop.Name].Visible = true;
- //dgvmain.Columns[nameof(BaseEntity.IsSelected)].Visible = false;
- //dgvColDetail.Rows[0].Visible = false;
- }
- private void button1_Click(object sender, EventArgs e)
- {
- Filldgvmain(GetCondition());
- }
- private void button4_Click(object sender, EventArgs e)
- {
- ShowDetailForm(new Machine02());
- }
- private void JobbookingQueryFor_Load(object sender, EventArgs e)
- {
- this.Location = new Point(this.Owner.Right-this.Width, 0);
- Filldgvmain(GetCondition());
- }
- private void ShowDetailForm(Machine02 entity)
- {
- //if(CurrForm==null)
- //{
- // CurrForm = new Machine02Base(entity);
- // (CurrForm as Machine02Base).eventChangeDs += Machine02Query_eventChangeDs;
- // (CurrForm as Machine02Base).eventCloseForm += Machine02Query_eventCloseForm;
- // CurrForm.Owner = this;
- // CurrForm.Show();
- //}
- //else
- //{
- // (CurrForm as Machine02Base).InitForm(entity);
- //}
- }
- private void MachineQuery_eventCloseForm()
- {
- //throw new NotImplementedException();
- CurrForm = null;
- }
- private void MachineQuery_eventChangeDs(Machine02 entity)
- {
- //throw new NotImplementedException();
- var temp = CurrDs.Where(t => t.ID == entity.ID).ToList();
- if(temp.Count>0)
- {
- EntityHelper.CopyPropertyValue<Machine02>(entity, temp[0]);
- }
- else
- {
- CurrDs.Add(entity);
- }
- Binddgvmain();
- }
- private void dgvmain_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
- {
- //if (dgvmain.CurrentRow == null)
- // return;
- //Machine02 job = dgvmain.CurrentRow.DataBoundItem as Machine02;
- //ShowDetailForm(job);
- }
- private void button3_Click(object sender, EventArgs e)
- {
- //Machine02Base temp = new Machine02Base();
- //CurrDs.Add(temp);
- dgvmain.EndEdit();
- edit机型代码.Focus();
- List<Machine02> rows = CurrDs.Where(t => t.IsSelected == 1).ToList();
- if (rows.Count <= 0)
- {
- MessageBox.Show("您没有选择数据,请选择!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- eventSelRow?.Invoke(rows);
- this.Close();
- }
- private void 全选ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- foreach (DataGridViewRow dgvr in dgvmain.Rows)
- {
- dgvr.Cells[nameof(BaseEntity.IsSelected)].Value = 1;
- }
- }
- private void 反全选ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- foreach (DataGridViewRow dgvr in dgvmain.Rows)
- {
- dgvr.Cells[nameof(BaseEntity.IsSelected)].Value = 0;
- }
- }
- private void dgvmain_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
- {
- if (e.RowIndex < 0)
- return;
- DataGridView dgv = sender as DataGridView;
- dgv.CurrentCell = dgv.Rows[e.RowIndex].Cells[e.ColumnIndex];
- if (e.Button != MouseButtons.Right)
- {
- if(dgv.Columns[e.ColumnIndex].Name== "IsSelected")
- {
- //if((dgv.Columns[e.ColumnIndex] as DataGridViewCheckBoxColumn).v)
- //Machine02 mac = dgv.Rows[e.RowIndex].DataBoundItem as Machine02;
- ////if(mac.IsSelected)
- //mac.IsSelected = mac.IsSelected == 0 ? 1 : 0;
- //dgv.Refresh();
- }
- else
- {
- dgvmain.EndEdit();
- edit机型代码.Focus();
- List<Machine02> macs = CurrDs.Where(t => t.IsSelected == 1).ToList();// new List<Machine02>();
- if(macs.Count<=0)
- {
- macs = new List<Machine02>();
- macs.Add(dgvmain.CurrentRow.DataBoundItem as Machine02);
- }
- List<LayoutDetail> details = new List<LayoutDetail>();
- foreach(var item in macs)
- {
- details.Add(AddDetailFor(item));
- }
- dgvmain.DoDragDrop(details, DragDropEffects.Move);
- }
- return;
- }
- if (e.RowIndex < 0 || e.ColumnIndex < 0)
- {
- return;
- }
- System.Drawing.Point pointglobal = System.Windows.Forms.Control.MousePosition;
- cms.Show(pointglobal);
- }
- private LayoutDetail AddDetailFor(Machine02 row)
- {
- LayoutDetail addrow = new LayoutDetail();
- addrow.ID = 0;
- addrow.EntityTypeID = EntityType.Machine;
- addrow.EntityID = row.ID;
- addrow.FCode = row.FCode;
- addrow.FName = row.FName;
- addrow.IPAddress = row.IPAddress;
- addrow.FontSize = 9;
- addrow.FColor = "";
- return addrow;
- }
- private LayoutDetail AddDetailFor(int entitytype)
- {
- LayoutDetail addrow = new LayoutDetail();
- addrow.ID = 0;
- addrow.EntityTypeID = entitytype;
- addrow.EntityID = 0;
- switch(entitytype)
- {
- case EntityType.Label:
- addrow.FCode = "Label";
- addrow.FName = "标签";
- break;
- case EntityType.Porwer:
- addrow.FCode = "Power";
- addrow.FName = "动力棒";
- break;
- }
-
- addrow.IPAddress = "";
- addrow.FontSize = 9;
- addrow.FColor = "";
- return addrow;
- }
- private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- List<Machine02> rows = CurrDs.Where(t => t.IsSelected == 1).ToList();// CurrDs.Tables[0].Select("选择=1");
- if (rows.Count <= 0)
- {
- MessageBox.Show("您没有选择数据,请选择!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (MessageBox.Show("您确定要执行此操作吗?", "询问", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk) == DialogResult.Cancel)
- return;
-
- List<Machine02> tempdt = new List<Machine02>();
- foreach (var temprow in rows)
- {
- tempdt.Add(temprow);
- }
- int result = CallDelMachine(tempdt);
- if (result > 0)
- {
- MessageBox.Show("操作成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- foreach (var ttrow in rows)
- {
- CurrDs.Remove(ttrow);
- }
- Binddgvmain();
- }
- }
- private int CallDelMachine(List<Machine02> entitys)
- {
- try
- {
- Hashtable tempds = new Hashtable();
- string str = JsonConvert.SerializeObject(entitys);
- tempds.Add(nameof(Machine02), str);
- Hashtable reds = PubInfo.CallFunction("DllEapBll.EapBll", "DelMachine02", tempds);
- if (reds == null)
- return -1;
- int count = int.Parse(reds["result"].ToString());
- return 1;
- }
- catch (Exception e)
- {
- MessageBox.Show(e.Message);
- return -1;
- }
- }
- private void dgvmain_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
- {
- if (dgvmain.Columns[e.ColumnIndex].Name == "IsSelected")
- return;
- PubInfo.DataGridViewSort<Machine02>(sender, e);
- }
- private void dgvmain_MouseDown(object sender, MouseEventArgs e)
- {
- //if (e.Button == MouseButtons.Left)
- //{
- // //if (dgvSelRole.SelectedCells.Count <= 0)
- // // return;
- // //Control tempcontrol = dgvmain.GetChildAtPoint(new Point(e.X, e.Y));
- // List<Machine02> macs = new List<Machine02>();
- // macs.Add(dgvmain.CurrentRow.DataBoundItem as Machine02);
- // dgvmain.DoDragDrop(macs, DragDropEffects.Move);
- //}
- }
- private void MachineQuery_FormClosing(object sender, FormClosingEventArgs e)
- {
- eventCloseForm?.Invoke();
- }
- private void label5_MouseDown(object sender, MouseEventArgs e)
- {
- List<LayoutDetail> details = new List<LayoutDetail>();
- details.Add(AddDetailFor(EntityType.Label));
- label5.DoDragDrop(details, DragDropEffects.Move);
- }
- private void label6_MouseDown(object sender, MouseEventArgs e)
- {
- List<LayoutDetail> details = new List<LayoutDetail>();
- details.Add(AddDetailFor(EntityType.Porwer));
- label6.DoDragDrop(details, DragDropEffects.Move);
- }
- }
- }
|