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.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace DllXqManager { public partial class LayoutMstBase : Form { private LayoutMst CurrEntity = null; private List CurrDs = null; public delegate void closeForm(); public event closeForm eventcloseform = null; //public event AddRow eventaddrow = null; //public delegate void AddRow(int id); public LayoutMstBase(LayoutMst id) { InitializeComponent(); SetCurrID(id); } public void SetCurrID(LayoutMst id) { InitForm(id); } private void InitForm(LayoutMst id) { CurrEntity = id; if (CurrEntity == null) { CurrEntity = new LayoutMst(); } //用实体的值去赋值界面控件显示的值 string errorinfo = ""; int result = DllPubInfo.PubInfo.InitFormControl(panel1, CurrEntity, null, ref errorinfo); if (result < 0) MessageBox.Show(errorinfo); Filldgvmain(" and a.preid="+CurrEntity.ID); } private void Filldgvmain(string condition) { try { Cursor = Cursors.WaitCursor; string errorinfo = ""; CurrDs = PubInfo.SelectForCondition(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(dgvmain); foreach (DataGridViewColumn dgvc in dgvmain.Columns) dgvc.ReadOnly = true; dgvmain.Columns["选择"].ReadOnly = false; dgvmain.Columns[nameof(LayoutDetail.LocX)].ReadOnly = false; dgvmain.Columns[nameof(LayoutDetail.LocY)].ReadOnly = false; dgvmain.Columns[nameof(LayoutDetail.Remark)].ReadOnly = false; dgvmain.Columns[nameof(LayoutDetail.SizeH)].ReadOnly = false; dgvmain.Columns[nameof(LayoutDetail.SizeW)].ReadOnly = false; dgvmain.Columns[nameof(LayoutDetail.FontSize)].ReadOnly = false; dgvmain.Columns[nameof(LayoutDetail.LocX)].DefaultCellStyle.BackColor = PubInfo.CurrEditColor; dgvmain.Columns[nameof(LayoutDetail.LocY)].DefaultCellStyle.BackColor = PubInfo.CurrEditColor; dgvmain.Columns[nameof(LayoutDetail.SizeH)].DefaultCellStyle.BackColor = PubInfo.CurrEditColor; dgvmain.Columns[nameof(LayoutDetail.SizeW)].DefaultCellStyle.BackColor = PubInfo.CurrEditColor; dgvmain.Columns[nameof(LayoutDetail.FontSize)].DefaultCellStyle.BackColor = PubInfo.CurrEditColor; dgvmain.Columns[nameof(LayoutDetail.Remark)].DefaultCellStyle.BackColor = PubInfo.CurrEditColor; //dgvmain.Columns[nameof(BaseEntity.IsSelected)].Visible = false; //dgvColDetail.Rows[0].Visible = false; } private void button1_Click(object sender, EventArgs e) { InitForm(null); } private void button2_Click(object sender, EventArgs e) { //if(edit代码.Text.Trim()=="") //{ // MessageBox.Show("代码不能为空,请填写!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); // edit代码.Focus(); // return; //} if (editFName.Text.Trim() == "") { MessageBox.Show("名称不能为空,请填写!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); editFName.Focus(); return; } string errorinfo = ""; int result = PubInfo.UpdateRowFormControl(panel1, CurrEntity, ref errorinfo); if (result < 0) { MessageBox.Show("更新数据发生错误:" + errorinfo); return; } List changes = EntityHelper.GetEntityChange(CurrDs); LayoutMst resultentity = CallFunction.CallIULayoutMst(CurrEntity, changes); if(resultentity != null) { MessageBox.Show("操作成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); InitForm(resultentity); } } private void mmabase_FormClosing(object sender, FormClosingEventArgs e) { eventcloseform?.Invoke(); } public void Selmma(DataRow row) { //if(row==null) //{ // edit机型代码.Text = ""; // return; //} //edit机型代码.Text = row["代码"].ToString(); } private void btEmail_Click(object sender, EventArgs e) { //mmaquery temp = new mmaquery(); //temp.eventselrow += Selmma; //temp.ShowDialog(); } private void button3_Click(object sender, EventArgs e) { //if (CurrDs == null) //{ // InitForm(0); // return; //} CurrEntity = new LayoutMst(); editFCode.Text = ""; foreach (var item in CurrDs) item.EntityStatusID = 1; } private void button4_Click(object sender, EventArgs e) { TEntityQuery temp = new TEntityQuery(CurrDs); temp.eventSelRow += Temp_eventSelRow; temp.ShowDialog(); } private LayoutDetail AddDetail(TEntity row) { LayoutDetail addrow = new LayoutDetail(); CurrDs.Add(addrow); int? minid = CurrDs.Where(t=>t.ID<0).Min(t => (int?)t.ID); int id = minid == null ? -1 : minid.Value - 1; addrow.ID = id; addrow.EntityID = row.ID; addrow.FCode = row.FCode; addrow.FName = row.FName; addrow.IPAddress= row.FIP; addrow.LocX= 0; addrow.LocY = 0; addrow.SizeW = 0.1; addrow.SizeH= 0.1; addrow.FontSize = 9; addrow.FColor = ""; return addrow; } private void Temp_eventSelRow(List rows, int seltype) { double x = 0; double y = 0; foreach(var temprow in rows) { List templist = CurrDs.Where(t => t.EntityID == temprow.ID).ToList(); if (templist.Count > 0) continue; x += 0.01; y += 0.01; LayoutDetail addrow = AddDetail(temprow); addrow.LocX = x; addrow.LocY = y; } Binddgvmain(); } private void button5_Click(object sender, EventArgs e) { LayoutMstBaseFor temp = new LayoutMstBaseFor(CurrEntity); temp.ShowDialog(); } 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 toolStripMenuItem2_Click(object sender, EventArgs e) { List rows = CurrDs.Where(t => t.IsSelected == 1).ToList(); PubInfo.DelSelRow(rows, CurrDs); Binddgvmain(); } private void cms_Opening(object sender, CancelEventArgs e) { dgvmain.EndEdit(); editFCode.Focus(); } } }