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 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 rows); public event SelRow eventSelRow = null; public delegate void CloseForm(); public event CloseForm eventCloseForm = null; private List AlreadySelDs = null; public MachineQuery(List 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 items = PubInfo.Select(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(nameof(Machine02.MModeCode)); if (edit机型代码.Text.Trim() != ""&&!string.IsNullOrEmpty(colname)) { sqlstr += string.Format($" and {colname} like '%{edit机型代码.Text.Trim()}%'"); } colname = EntityAttribute.GetPropertyCondition(nameof(Machine02.MModeName)); if (edit机型名称.Text.Trim() != "" && !string.IsNullOrEmpty(colname)) { sqlstr += string.Format($" and {colname} like '%{edit机型名称.Text.Trim()}%'"); } colname = EntityAttribute.GetPropertyCondition(nameof(Machine02.FCode)); if (edit机台代码.Text.Trim() != "" && !string.IsNullOrEmpty(colname)) { sqlstr += string.Format($" and {colname} like '%{edit机台代码.Text.Trim()}%'"); } colname = EntityAttribute.GetPropertyCondition(nameof(Machine02.FName)); if (edit机台名称.Text.Trim() != "" && !string.IsNullOrEmpty(colname)) { sqlstr += string.Format($" and {colname} like '%{edit机台名称.Text.Trim()}%'"); } colname = EntityAttribute.GetPropertyCondition(nameof(Machine02.SupplierFCode)); if (edit厂商代码.Text.Trim() != "" && !string.IsNullOrEmpty(colname)) { sqlstr += string.Format($" and {colname} like '%{edit厂商代码.Text.Trim()}%'"); } colname = EntityAttribute.GetPropertyCondition(nameof(Machine02.FactoryName)); if (edit厂区名称.Text.Trim() != "" && !string.IsNullOrEmpty(colname)) { sqlstr += string.Format($" and {colname} like '%{edit厂区名称.Text.Trim()}%'"); } colname = EntityAttribute.GetPropertyCondition(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(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 cols = new List();// CurrDs.Where(t => t.EntityStatusID >= 0).ToList(); List templist = new List(); 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(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(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 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 macs = CurrDs.Where(t => t.IsSelected == 1).ToList();// new List(); if(macs.Count<=0) { macs = new List(); macs.Add(dgvmain.CurrentRow.DataBoundItem as Machine02); } List details = new List(); 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 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 tempdt = new List(); 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 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(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 macs = new List(); // 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 details = new List(); details.Add(AddDetailFor(EntityType.Label)); label5.DoDragDrop(details, DragDropEffects.Move); } private void label6_MouseDown(object sender, MouseEventArgs e) { List details = new List(); details.Add(AddDetailFor(EntityType.Porwer)); label6.DoDragDrop(details, DragDropEffects.Move); } } }