WinFormTools/WinformGeneralDeveloperFrame/Form/FrmbuyerInWarehouse.cs

157 lines
4.5 KiB
C#
Raw Normal View History

2021-07-03 17:28:43 +08:00
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 FrmbuyerInWarehouse : FrmBaseForm
{
private Dictionary<string, string> fieldDictionary = new Dictionary<string, string>();
public FrmbuyerInWarehouse()
{
InitializeComponent();
}
private void FrmbuyerInWarehouse_Load(object sender, EventArgs e)
{
InitFrom(xtraTabControl1,grdList,grdListView,new LayoutControlGroup[]{layoutControlGroup1},new buyerInWarehouseInfo());
InitSearchDicData();
}
/// <summary>
/// 数据源初始化
/// </summary>
/// <returns></returns>
private void Init()
{
txtcreatorId.Properties.DataSource = GetDataTableUtils.SqlTable("用户");
repositoryItemtxtcreatorId.DataSource= GetDataTableUtils.SqlTable("用户");
txtsupplierid.Properties.DataSource = GetDataTableUtils.SqlTable("供应商");
repositoryItemtxtsupplierid.DataSource= GetDataTableUtils.SqlTable("供应商");
}
/// <summary>
/// 搜索字段
/// </summary>
/// <returns></returns>
private void InitSearchDicData()
{
fieldDictionary.Add("入库单号","code");
}
public override void InitgrdListDataSource()
{
using (var con=new MESDB())///
{
grdList.DataSource=con.buyerInWarehouseInfo.ToList();
}
Init();
}
/// <summary>
/// 字段为空校验
/// </summary>
/// <returns></returns>
public override bool CheckInput()
{
if(string.IsNullOrEmpty(txtcreatorId.EditValue.ToString()))
{
"制单人不能为空".ShowWarning();
txtcreatorId.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(txtintime.EditValue.ToString()))
{
"入库日期不能为空".ShowWarning();
txtintime.Focus();
return false;
}
return true;
}
/// <summary>
/// 保存
/// </summary>
/// <returns></returns>
public override bool SaveFunction()
{
try
{
buyerInWarehouseInfo info= (buyerInWarehouseInfo)this.ControlDataToModel(new buyerInWarehouseInfo());
using (var db = new MESDB())
{
db.buyerInWarehouseInfo.AddOrUpdate(info);
db.SaveChanges();
}
}
catch (Exception ex)
{
ex.Message.ShowError();
return false;
}
return true;
}
/// <summary>
/// 删除
/// </summary>
/// <returns></returns>
public override bool DelFunction()
{
try
{
buyerInWarehouseInfo info = (buyerInWarehouseInfo)this.ControlDataToModel(new buyerInWarehouseInfo());
using (var db = new MESDB())
{
db.Entry(info).State=EntityState.Deleted;
db.SaveChanges();
}
}
catch (Exception ex)
{
ex.Message.ShowError();
return false;
}
return true;
}
/// <summary>
/// 搜索
/// </summary>
/// <returns></returns>
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.buyerInWarehouseInfo.SqlQuery("select * from buyerInWarehouse").ToList();
}
else
{
grdList.DataSource = db.buyerInWarehouseInfo.SqlQuery($"select * from buyerInWarehouse where {sql}").ToList();
}
}
}
}
}
}