[英]C# Winform Datagrid CRUD
i use 3-Tiers Application.我使用 3 层应用程序。 I have created Data acces layer and Business Layer.
我已经创建了数据访问层和业务层。 How can i bind this with my Datagrid on View layer?
如何将它与视图层上的 Datagrid 绑定?
public partial class Magasinier : Form
{
Magasinier_BL oMag_BL = new Magasinier_BL();
public Magasinier()
{
InitializeComponent();
GetDataOrdre();
}
public void GetDataOrdre()
{
dataGridView_Mag.DataSource = oMag_BL.Get_All_Magasinier_BL();
dataGridView_Mag.DataMember = "MagTable";
}
}
private void Del_Mag(object sender, DataGridViewRowCancelEventArgs e)
{
if (!e.Row.IsNewRow)
{
DialogResult res = MessageBox.Show("Etes-vous sûr de vouloir supprimer cette ligne ?", "confirmation suppression",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (res == DialogResult.No)
{
e.Cancel = true;
}
else
{
oMag_BL.DelMag_BL(e.Row.Cells["CODE_MAG"].Value.ToString());
}
}
}
i have done the Read and Delete, but not Create and Update.我已经完成了读取和删除,但没有完成创建和更新。
How can i cable these Create and Update to my businnes layer, by the way, how can i retrive NEW row value or CHANGE row value.我如何将这些创建和更新连接到我的业务层,顺便说一下,我如何检索新行值或更改行值。
these what i did in ASP.NET: Create这些我在 ASP.NET 中所做的:创建
protected void Insrting_Obj_ClientMag(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
{
Pers_Magasinier oPersMag = new Pers_Magasinier();
oPersMag.NoClient = Id;
oPersMag.CodeMag = e.NewValues["CODE_MAG"].ToString();
oPersMag.NomUsr = e.NewValues["NOM"].ToString();
oPersMag.PrenomUsr = e.NewValues["PRENOM"].ToString();
oPersMag.MemoMag = e.NewValues["MEMO"].ToString();
oMag_BL.InstUpdtMag_BL(oPersMag, true);
//To Stop processing Gridview
ASPxGridView_Mag.CancelEdit();
e.Cancel = true;
//Rebind donne
GetDataMags();
}
and Update:和更新:
protected void Updting_Obj_ClientMag(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
{
Pers_Magasinier oPersMag = new Pers_Magasinier();
oPersMag.NoClient = Id;
oPersMag.CodeMag = e.NewValues["CODE_MAG"].ToString();
oPersMag.NomUsr = e.NewValues["NOM"].ToString();
oPersMag.PrenomUsr = e.NewValues["PRENOM"].ToString();
oPersMag.MemoMag = e.NewValues["MEMO"].ToString();
oMag_BL.InstUpdtMag_BL(oPersMag, false);
ASPxGridView_Mag.CancelEdit();
e.Cancel = true;
GetDataMags();
}
Now how can i do that in WinForm?现在我如何在 WinForm 中做到这一点?
Thanks you in advance提前谢谢你
Update: To get Create/Update working, you usually use Grid RowEditTemplate control (which basically is another WinForm which allows you to do extra validation and create/update existing values).更新:为了让创建/更新工作,您通常使用 Grid RowEditTemplate 控件(它基本上是另一个 WinForm,它允许您进行额外的验证和创建/更新现有值)。 Infragistics got good one.
基础设施取得了不错的成绩。
you might need to fix your tags, because you are talking about ASP and not WinForms.您可能需要修复您的标签,因为您在谈论 ASP 而不是 WinForms。
I am using Telerik's Grid with ASP MVC 2 atm.我将 Telerik 的 Grid 与 ASP MVC 2 atm 一起使用。 Helps a lot with serializing your data into the ViewModel and you work with ViewModel in your Controllers (dont have to mess around with Request.Params most of the time).
有助于将数据序列化到 ViewModel 中,并且您可以在控制器中使用 ViewModel(大多数时候不必乱用 Request.Params)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.