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 TEntityBase : Form { private int CurrID = 0; private TEntity CurrEntity = null; public delegate void closeForm(); public delegate void AddRow(TEntity id); public event closeForm eventcloseform = null; public event AddRow eventaddrow = null; private string CurrTableName = "TEntity"; public TEntityBase(TEntity id) { InitializeComponent(); InitTypeItem(); SetCurrID(id); } public void SetCurrID(TEntity id) { InitForm(id); } private void InitTypeItem() { StringBuilder sqlstr = new StringBuilder(100); string errorinfo = ""; sqlstr.AppendFormat("select a.subid ID,a.preid 主项ID,a.fname 名称,a.fnum clevel from constitem a where a.preid in(8,9)"); DataSet tempds = PubInfo.Select(sqlstr.ToString(), "constitem", ref errorinfo); if (tempds == null) { MessageBox.Show(errorinfo, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } List items = PubInfo.DataSetToItem(tempds); PubInfo.InitComboBox(editFTypeFName, items, 8); PubInfo.InitComboBox(editIfStart, items, 9); } private void InitForm(TEntity id) { CurrEntity = id; if (CurrEntity == null) { CurrEntity = new TEntity(); } //用实体的值去赋值界面控件显示的值 string errorinfo = ""; int result = DllPubInfo.PubInfo.InitFormControl(panel1, CurrEntity, null, ref errorinfo); if (result < 0) MessageBox.Show(errorinfo); } private void button1_Click(object sender, EventArgs e) { InitForm(null); } private TEntity CallIUBase(TEntity entity) { try { string errorinfo = ""; int result = PubInfo.UpdateRowFormControl(panel1, entity, ref errorinfo); if (result < 0) { MessageBox.Show("更新数据发生错误:" + errorinfo); return null; } Hashtable tempds = new Hashtable(); string str = JsonConvert.SerializeObject(entity); tempds.Add(nameof(TEntity), str); Hashtable reds = PubInfo.CallFunction("DllStatusShowBll.StatusShowBll", "IUTEntity", tempds); if (reds == null) return null; TEntity reentity = JsonConvert.DeserializeObject(reds[nameof(TEntity)].ToString()); return reentity; } catch (Exception e) { MessageBox.Show("操作发生错误,错误信息为:" + e.Message.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return 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; } TEntity result = CallIUBase(CurrEntity); if(result!=null) { MessageBox.Show("操作成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); InitForm(result); eventaddrow?.Invoke(result); } } 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) { CurrEntity = new TEntity(); editFCode.Text = ""; } private void btEmail_Click_1(object sender, EventArgs e) { TLcdQuery temp = new TLcdQuery(""); temp.eventSelRow += Temp_eventSelRow; temp.ShowDialog(); } private void Temp_eventSelRow(List rows, int seltype) { editTLcdFCode.Text = rows[0].FCode; editTLcdFCode.Tag = rows[0].ID; editTLcdFName.Text = rows[0].FName; } } }