using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using WinformGeneralDeveloperFrame; using WinformGeneralDeveloperFrame.Commons; using DevExpress.XtraLayout; using MES.Entity; using System.Data.Entity.Migrations; using System.Data.Entity; namespace MES.Form { public partial class Frmworkorder : FrmBaseForm { private Dictionary fieldDictionary = new Dictionary(); public Frmworkorder() { InitializeComponent(); } private void Frmworkorder_Load(object sender, EventArgs e) { InitFrom(xtraTabControl1,grdList,grdListView,new LayoutControlGroup[]{layoutControlGroup1},new workorderInfo()); InitSearchDicData(); } /// /// 数据源初始化 /// /// private void Init() { txtworkordertype.Properties.DataSource = GetDataTableUtils.SqlTable("部门"); repositoryItemtxtworkordertype.DataSource= GetDataTableUtils.SqlTable("部门"); txtproductdept.Properties.DataSource = GetDataTableUtils.SqlTable("部门"); repositoryItemtxtproductdept.DataSource= GetDataTableUtils.SqlTable("部门"); txtproductid.Properties.DataSource = GetDataTableUtils.SqlTable("产品"); repositoryItemtxtproductid.DataSource= GetDataTableUtils.SqlTable("产品"); txtunit.Properties.DataSource = GetDataTableUtils.SqlTable("计量单位"); repositoryItemtxtunit.DataSource= GetDataTableUtils.SqlTable("计量单位"); txtwarehouse.Properties.DataSource = GetDataTableUtils.SqlTable("仓库"); repositoryItemtxtwarehouse.DataSource= GetDataTableUtils.SqlTable("仓库"); txtcreatorId.Properties.DataSource = GetDataTableUtils.SqlTable("用户"); repositoryItemtxtcreatorId.DataSource= GetDataTableUtils.SqlTable("用户"); } /// /// 搜索字段 /// /// private void InitSearchDicData() { fieldDictionary.Add("id","id"); fieldDictionary.Add("工单号","wordordercode"); fieldDictionary.Add("销售单号","salecode"); fieldDictionary.Add("销售明细单号","saledetailcode"); fieldDictionary.Add("工单类型","workordertype"); fieldDictionary.Add("生产日期","productdate"); fieldDictionary.Add("生产单位","productdept"); fieldDictionary.Add("产品编号","productcode"); fieldDictionary.Add("产品名称","productid"); fieldDictionary.Add("规格型号","spec"); fieldDictionary.Add("生产数量","productnumber"); fieldDictionary.Add("计量单位","unit"); fieldDictionary.Add("完工日期","finishdate"); fieldDictionary.Add("交货日期","deliverdate"); fieldDictionary.Add("仓库","warehouse"); fieldDictionary.Add("制单人","creatorId"); fieldDictionary.Add("制单日期","createTime"); fieldDictionary.Add("备注","remark"); } public override void InitgrdListDataSource() { using (var con=new MESDB())/// { grdList.DataSource=con.workorderInfo.ToList(); } Init(); } /// /// 字段为空校验 /// /// public override bool CheckInput() { if(string.IsNullOrEmpty(txtwordordercode.EditValue.ToString())) { "工单号不能为空".ShowWarning(); txtwordordercode.Focus(); return false; } if(string.IsNullOrEmpty(txtsalecode.EditValue.ToString())) { "销售单号不能为空".ShowWarning(); txtsalecode.Focus(); return false; } if(string.IsNullOrEmpty(txtsaledetailcode.EditValue.ToString())) { "销售明细单号不能为空".ShowWarning(); txtsaledetailcode.Focus(); return false; } if(string.IsNullOrEmpty(txtworkordertype.EditValue.ToString())) { "工单类型不能为空".ShowWarning(); txtworkordertype.Focus(); return false; } if(string.IsNullOrEmpty(txtproductdate.EditValue.ToString())) { "生产日期不能为空".ShowWarning(); txtproductdate.Focus(); return false; } if(string.IsNullOrEmpty(txtproductdept.EditValue.ToString())) { "生产单位不能为空".ShowWarning(); txtproductdept.Focus(); return false; } if(string.IsNullOrEmpty(txtproductcode.EditValue.ToString())) { "产品编号不能为空".ShowWarning(); txtproductcode.Focus(); return false; } if(string.IsNullOrEmpty(txtproductid.EditValue.ToString())) { "产品名称不能为空".ShowWarning(); txtproductid.Focus(); return false; } if(string.IsNullOrEmpty(txtspec.EditValue.ToString())) { "规格型号不能为空".ShowWarning(); txtspec.Focus(); return false; } if(string.IsNullOrEmpty(txtproductnumber.EditValue.ToString())) { "生产数量不能为空".ShowWarning(); txtproductnumber.Focus(); return false; } if(string.IsNullOrEmpty(txtunit.EditValue.ToString())) { "计量单位不能为空".ShowWarning(); txtunit.Focus(); return false; } if(string.IsNullOrEmpty(txtfinishdate.EditValue.ToString())) { "完工日期不能为空".ShowWarning(); txtfinishdate.Focus(); return false; } if(string.IsNullOrEmpty(txtdeliverdate.EditValue.ToString())) { "交货日期不能为空".ShowWarning(); txtdeliverdate.Focus(); return false; } if(string.IsNullOrEmpty(txtwarehouse.EditValue.ToString())) { "仓库不能为空".ShowWarning(); txtwarehouse.Focus(); return false; } if(string.IsNullOrEmpty(txtcreatorId.EditValue.ToString())) { "制单人不能为空".ShowWarning(); txtcreatorId.Focus(); return false; } if(string.IsNullOrEmpty(txtcreateTime.EditValue.ToString())) { "制单日期不能为空".ShowWarning(); txtcreateTime.Focus(); return false; } return true; } /// /// 保存 /// /// public override bool SaveFunction() { try { workorderInfo info= (workorderInfo)this.ControlDataToModel(new workorderInfo()); using (var db = new MESDB()) { db.workorderInfo.AddOrUpdate(info); db.SaveChanges(); } } catch (Exception ex) { ex.Message.ShowError(); return false; } return true; } /// /// 删除 /// /// public override bool DelFunction() { try { workorderInfo info = (workorderInfo)this.ControlDataToModel(new workorderInfo()); using (var db = new MESDB()) { db.Entry(info).State=EntityState.Deleted; db.SaveChanges(); } } catch (Exception ex) { ex.Message.ShowError(); return false; } return true; } /// /// 搜索 /// /// public override void SearchFunction() { FrmSearch frm = new FrmSearch(fieldDictionary); if (frm.ShowDialog()==DialogResult.OK) { string sql = frm.sql; using (var db = new MESDB()) { if (string.IsNullOrEmpty(sql)) { grdList.DataSource = db.workorderInfo.SqlQuery("select * from workorder").ToList(); } else { grdList.DataSource = db.workorderInfo.SqlQuery($"select * from workorder where {sql}").ToList(); } } } } } }