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 Frmbuyer : FrmBaseForm { private Dictionary fieldDictionary = new Dictionary(); public Frmbuyer() { InitializeComponent(); } private void Frmbuyer_Load(object sender, EventArgs e) { InitFrom(xtraTabControl1,grdList,grdListView,new LayoutControlGroup[]{layoutControlGroup1},new buyerInfo(),gridControl1,new []{ "txtbuyercode", "txttotalprice" }); InitSearchDicData(); repositoryItemTextEditrequisitioncode.KeyDown += RepositoryItemTextEditrequisitioncode_KeyDown; } private void RepositoryItemTextEditrequisitioncode_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { using (var db = new MESDB()) { // requisitiondetailInfo requisitiondetail=db.requisitiondetailInfo.Where(p=>p.re) } } } /// /// 数据源初始化 /// /// private void Init() { txtsupplierid.Properties.DataSource = GetDataTableUtils.SqlTable("物料"); repositoryItemtxtsupplierid.DataSource= GetDataTableUtils.SqlTable("物料"); txtcreatorId.Properties.DataSource = GetDataTableUtils.SqlTable("用户"); repositoryItemtxtcreatorId.DataSource= GetDataTableUtils.SqlTable("用户"); } /// /// 搜索字段 /// /// private void InitSearchDicData() { fieldDictionary.Add("id","id"); fieldDictionary.Add("采购单号","buyercode"); fieldDictionary.Add("采购日期","buyerdate"); fieldDictionary.Add("供应商","supplierid"); fieldDictionary.Add("供应商编码","suppliercode"); fieldDictionary.Add("完货日期","deliverdate"); fieldDictionary.Add("制单人","creatorId"); fieldDictionary.Add("金额","totalprice"); fieldDictionary.Add("备注","remark"); } public override void InitgrdListDataSource() { using (var con=new MESDB())/// { grdList.DataSource=con.buyerInfo.ToList(); } Init(); } /// /// 字段为空校验 /// /// public override bool CheckInput() { if(string.IsNullOrEmpty(txtbuyerdate.EditValue.ToString())) { "采购日期不能为空".ShowWarning(); txtbuyerdate.Focus(); return false; } if(string.IsNullOrEmpty(txtsupplierid.EditValue.ToString())) { "供应商不能为空".ShowWarning(); txtsupplierid.Focus(); return false; } if(string.IsNullOrEmpty(txtsuppliercode.EditValue.ToString())) { "供应商编码不能为空".ShowWarning(); txtsuppliercode.Focus(); return false; } if(string.IsNullOrEmpty(txtdeliverdate.EditValue.ToString())) { "完货日期不能为空".ShowWarning(); txtdeliverdate.Focus(); return false; } if(string.IsNullOrEmpty(txtcreatorId.EditValue.ToString())) { "制单人不能为空".ShowWarning(); txtcreatorId.Focus(); return false; } if(string.IsNullOrEmpty(txttotalprice.EditValue.ToString())) { "金额不能为空".ShowWarning(); txttotalprice.Focus(); return false; } return true; } /// /// 保存 /// /// public override bool SaveFunction() { try { buyerInfo info= (buyerInfo)this.ControlDataToModel(new buyerInfo()); using (var db = new MESDB()) { db.buyerInfo.AddOrUpdate(info); db.SaveChanges(); } } catch (Exception ex) { ex.Message.ShowError(); return false; } return true; } /// /// 删除 /// /// public override bool DelFunction() { try { buyerInfo info = (buyerInfo)this.ControlDataToModel(new buyerInfo()); 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.buyerInfo.SqlQuery("select * from buyer").ToList(); } else { grdList.DataSource = db.buyerInfo.SqlQuery($"select * from buyer where {sql}").ToList(); } } } } } }