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 FrmproductMaterialOutWarehouse : FrmBaseForm { private Dictionary fieldDictionary = new Dictionary(); public FrmproductMaterialOutWarehouse() { InitializeComponent(); } private void FrmproductMaterialOutWarehouse_Load(object sender, EventArgs e) { InitFrom(xtraTabControl1,grdList,grdListView,new LayoutControlGroup[]{layoutControlGroup1},new productMaterialOutWarehouseInfo()); InitSearchDicData(); } /// /// 数据源初始化 /// /// private void Init() { txtdept.Properties.DataSource = GetDataTableUtils.SqlTable("部门"); repositoryItemTreeListtxtdept.DataSource= GetDataTableUtils.SqlTable("部门"); txtcreatorId.Properties.DataSource = GetDataTableUtils.SqlTable("用户"); repositoryItemtxtcreatorId.DataSource= GetDataTableUtils.SqlTable("用户"); } /// /// 搜索字段 /// /// private void InitSearchDicData() { fieldDictionary.Add("生产领料出库单号","code"); } public override void InitgrdListDataSource() { using (var con=new MESDB())/// { grdList.DataSource=con.productMaterialOutWarehouseInfo.ToList(); } Init(); } /// /// 字段为空校验 /// /// public override bool CheckInput() { if(string.IsNullOrEmpty(txtdept.EditValue.ToString())) { "领料单位不能为空".ShowWarning(); txtdept.Focus(); return false; } if(string.IsNullOrEmpty(txtouttime.EditValue.ToString())) { "出库日期不能为空".ShowWarning(); txtouttime.Focus(); return false; } if(string.IsNullOrEmpty(txtcreatorId.EditValue.ToString())) { "制单人不能为空".ShowWarning(); txtcreatorId.Focus(); return false; } return true; } /// /// 保存 /// /// public override bool SaveFunction() { try { productMaterialOutWarehouseInfo info= (productMaterialOutWarehouseInfo)this.ControlDataToModel(new productMaterialOutWarehouseInfo()); using (var db = new MESDB()) { db.productMaterialOutWarehouseInfo.AddOrUpdate(info); db.SaveChanges(); } } catch (Exception ex) { ex.Message.ShowError(); return false; } return true; } /// /// 删除 /// /// public override bool DelFunction() { try { productMaterialOutWarehouseInfo info = (productMaterialOutWarehouseInfo)this.ControlDataToModel(new productMaterialOutWarehouseInfo()); 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.productMaterialOutWarehouseInfo.SqlQuery("select * from productMaterialOutWarehouse").ToList(); } else { grdList.DataSource = db.productMaterialOutWarehouseInfo.SqlQuery($"select * from productMaterialOutWarehouse where {sql}").ToList(); } } } } } }