WinFormTools/WinformGeneralDeveloperFrame/Form/Frmbuyer.cs

239 lines
8.0 KiB
C#
Raw Normal View History

2021-06-01 17:31:40 +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
{
2021-06-05 17:08:16 +08:00
public partial class Frmbuyer : FrmBaseForm
2021-06-01 17:31:40 +08:00
{
private Dictionary<string, string> fieldDictionary = new Dictionary<string, string>();
2021-06-05 17:08:16 +08:00
public Frmbuyer()
2021-06-01 17:31:40 +08:00
{
InitializeComponent();
}
2021-06-05 17:08:16 +08:00
private void Frmbuyer_Load(object sender, EventArgs e)
2021-06-01 17:31:40 +08:00
{
2021-06-05 17:08:16 +08:00
InitFrom(xtraTabControl1,grdList,grdListView,new LayoutControlGroup[]{layoutControlGroup1},new buyerInfo(),gridControl1,new []{ "txtbuyercode", "txttotalprice" });
2021-06-01 17:31:40 +08:00
InitSearchDicData();
2021-06-05 17:08:16 +08:00
repositoryItemTextEditrequisitioncode.KeyDown += RepositoryItemTextEditrequisitioncode_KeyDown;
2021-06-08 08:31:02 +08:00
txtsupplierid.EditValueChanged += Txtsupplierid_EditValueChanged;
2021-06-05 17:08:16 +08:00
}
2021-06-01 17:31:40 +08:00
2021-06-08 08:31:02 +08:00
private void Txtsupplierid_EditValueChanged(object sender, EventArgs e)
{
using (var db=new MESDB())
{
supplierInfo supplier = db.supplierInfo.Find(txtsupplierid.EditValue);
txtsuppliercode.Text = supplier.suppliercode;
}
}
2021-06-05 17:08:16 +08:00
private void RepositoryItemTextEditrequisitioncode_KeyDown(object sender, KeyEventArgs e)
{
2021-06-08 08:31:02 +08:00
if (e.KeyCode == Keys.Tab)
2021-06-05 17:08:16 +08:00
{
using (var db = new MESDB())
{
2021-06-08 08:31:02 +08:00
string code = gridView1.EditingValue.ToString();
if (!string.IsNullOrEmpty(code))
{
requisitiondetailInfo requisitiondetail = db.requisitiondetailInfo
.Where(p => p.requisitiondetailcode.Equals(code)).FirstOrDefault();
if (requisitiondetail == null)
{
"单号不存在".ShowWarning();
}
else
{
gridView1.GetFocusedDataRow()["materialid"] = requisitiondetail.materialid;
gridView1.GetFocusedDataRow()["materialcode"] = requisitiondetail.materialcode;
gridView1.GetFocusedDataRow()["materialspec"] = requisitiondetail.materialspec;
gridView1.GetFocusedDataRow()["materialunit"] = requisitiondetail.materialunit;
gridView1.GetFocusedDataRow()["buyernumber"] = requisitiondetail.requisitionnumber;
gridView1.GetFocusedDataRow()["unitprice"] = requisitiondetail.unitprice;
gridView1.GetFocusedDataRow()["money"] = requisitiondetail.money;
gridView1.GetFocusedDataRow()["warehouse"] = requisitiondetail.warehouse;
}
}
2021-06-05 17:08:16 +08:00
}
}
}
2021-06-01 17:31:40 +08:00
2021-06-05 17:08:16 +08:00
/// <summary>
/// 数据源初始化
/// </summary>
/// <returns></returns>
private void Init()
{
2021-06-08 08:31:02 +08:00
txtsupplierid.Properties.DataSource = GetDataTableUtils.SqlTable("供应商");
repositoryItemtxtsupplierid.DataSource= GetDataTableUtils.SqlTable("物料");
txtcreatorId.Properties.DataSource = GetDataTableUtils.SqlTable("用户");
repositoryItemtxtcreatorId.DataSource= GetDataTableUtils.SqlTable("用户");
repositoryItemLookUpEditmaterialid.DataSource = GetDataTableUtils.SqlTable("物料");
repositoryItemLookUpEditmaterialunit.DataSource = GetDataTableUtils.SqlTable("计量单位");
repositoryItemLookUpEditwarehouse.DataSource = GetDataTableUtils.SqlTable("仓库");
}
2021-06-01 17:31:40 +08:00
/// <summary>
/// 搜索字段
/// </summary>
/// <returns></returns>
private void InitSearchDicData()
{
2021-06-05 17:08:16 +08:00
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");
2021-06-01 17:31:40 +08:00
fieldDictionary.Add("备注","remark");
}
public override void InitgrdListDataSource()
{
using (var con=new MESDB())///
{
2021-06-05 17:08:16 +08:00
grdList.DataSource=con.buyerInfo.ToList();
2021-06-01 17:31:40 +08:00
}
Init();
}
/// <summary>
/// 字段为空校验
/// </summary>
/// <returns></returns>
public override bool CheckInput()
{
2021-06-08 08:31:02 +08:00
if(string.IsNullOrEmpty(txtbuyerdate.ToString()))
2021-06-01 17:31:40 +08:00
{
2021-06-05 17:08:16 +08:00
"采购日期不能为空".ShowWarning();
txtbuyerdate.Focus();
2021-06-01 17:31:40 +08:00
return false;
}
2021-06-05 17:08:16 +08:00
if(string.IsNullOrEmpty(txtsupplierid.EditValue.ToString()))
2021-06-01 17:31:40 +08:00
{
2021-06-05 17:08:16 +08:00
"供应商不能为空".ShowWarning();
txtsupplierid.Focus();
2021-06-01 17:31:40 +08:00
return false;
}
2021-06-05 17:08:16 +08:00
if(string.IsNullOrEmpty(txtsuppliercode.EditValue.ToString()))
2021-06-01 17:31:40 +08:00
{
2021-06-05 17:08:16 +08:00
"供应商编码不能为空".ShowWarning();
txtsuppliercode.Focus();
2021-06-01 17:31:40 +08:00
return false;
}
2021-06-05 17:08:16 +08:00
if(string.IsNullOrEmpty(txtdeliverdate.EditValue.ToString()))
2021-06-01 17:31:40 +08:00
{
2021-06-05 17:08:16 +08:00
"完货日期不能为空".ShowWarning();
txtdeliverdate.Focus();
2021-06-01 17:31:40 +08:00
return false;
}
2021-06-05 17:08:16 +08:00
if(string.IsNullOrEmpty(txtcreatorId.EditValue.ToString()))
2021-06-01 17:31:40 +08:00
{
2021-06-05 17:08:16 +08:00
"制单人不能为空".ShowWarning();
txtcreatorId.Focus();
2021-06-01 17:31:40 +08:00
return false;
}
2021-06-05 17:08:16 +08:00
if(string.IsNullOrEmpty(txttotalprice.EditValue.ToString()))
2021-06-01 17:31:40 +08:00
{
2021-06-05 17:08:16 +08:00
"金额不能为空".ShowWarning();
txttotalprice.Focus();
2021-06-01 17:31:40 +08:00
return false;
}
return true;
}
2021-06-08 08:31:02 +08:00
public override void AddFunction()
{
gridControl1.DataSource = new List<buyerdetailInfo>().ToDataTable();
}
2021-06-01 17:31:40 +08:00
/// <summary>
/// 保存
/// </summary>
/// <returns></returns>
public override bool SaveFunction()
{
try
{
2021-06-05 17:08:16 +08:00
buyerInfo info= (buyerInfo)this.ControlDataToModel(new buyerInfo());
2021-06-01 17:31:40 +08:00
using (var db = new MESDB())
{
2021-06-05 17:08:16 +08:00
db.buyerInfo.AddOrUpdate(info);
2021-06-01 17:31:40 +08:00
db.SaveChanges();
}
}
catch (Exception ex)
{
ex.Message.ShowError();
return false;
}
return true;
}
/// <summary>
/// 删除
/// </summary>
/// <returns></returns>
public override bool DelFunction()
{
try
{
2021-06-05 17:08:16 +08:00
buyerInfo info = (buyerInfo)this.ControlDataToModel(new buyerInfo());
2021-06-01 17:31:40 +08:00
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))
{
2021-06-05 17:08:16 +08:00
grdList.DataSource = db.buyerInfo.SqlQuery("select * from buyer").ToList();
2021-06-01 17:31:40 +08:00
}
else
{
2021-06-05 17:08:16 +08:00
grdList.DataSource = db.buyerInfo.SqlQuery($"select * from buyer where {sql}").ToList();
2021-06-01 17:31:40 +08:00
}
}
}
}
2021-06-08 08:31:02 +08:00
private void toolStripMenuItemAdd_Click(object sender, EventArgs e)
{
gridView1.AddNewRow();
}
private void toolStripMenuItemDel_Click(object sender, EventArgs e)
{
gridView1.DeleteRow(gridView1.FocusedRowHandle);
}
}
2021-06-01 17:31:40 +08:00
}