I have data in form of list of collection as below code. With this article we can see how data directly update in collection, no required to write specific code for assign in variable and then pass that variable in business logic to update data.
With this list object always stay update as made changes in UI.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using IMS.DataAccess;
namespace IMS.BusinessLogic
{
public class Payment
{
public List GetPaymentList(int? InvoiceID)
{
List oPaymentList = new List();
DataSet dsPayment = new DataSet();
using (DataAccess.DatabaseHelper objDBHelper = new DataAccess.DatabaseHelper())
{
if (InvoiceID != null && InvoiceID > 0)
{
objDBHelper.AddParameter("PaymentID", InvoiceID);
}
dsPayment = objDBHelper.ExecuteDataSet("GetPaymentList", CommandType.StoredProcedure);
}
if (dsPayment.Tables.Count > 0 && dsPayment.Tables[0].Rows.Count > 0)
{
foreach (DataRow item in dsPayment.Tables[0].Rows)
{
PaymentInfo oPaymentInfo = new PaymentInfo();
oPaymentInfo.PaymentID = Int32.Parse(item["PaymentID"].ToString());
oPaymentInfo.PaymentDate = DateTime.Parse(item["PaymentDate"].ToString());
oPaymentInfo.TrasferCharges =
if (dsPayment.Tables.Count == 2 && dsPayment.Tables[1].Rows.Count > 0)
{
DataRow[] RowList = dsPayment.Tables[1].Select("PaymentID=" + oPaymentInfo.PaymentID);
List oPayDetailsList = new List();
oPaymentInfo.PaymentDetailList = oPayDetailsList;
foreach (DataRow itemRow in RowList)
{
PaymentDetailsInfo oPaymentInfoDetails = new PaymentDetailsInfo();
oPaymentInfoDetails.PaymentDetailsID = Int32.Parse(itemRow["PaymentDetailsID"].ToString());
oPaymentInfoDetails.PaymentID = Int32.Parse(itemRow["PaymentID"].ToString());
oPaymentInfoDetails.PaymentAmount = Decimal.Parse(itemRow["PayAmount"].ToString());
oPaymentInfoDetails.InvoiceID = Int32.Parse(itemRow["InvoiceID"].ToString());
oPaymentInfoDetails.DueAmount = Decimal.Parse(itemRow["PendingAmount"].ToString());
oPaymentInfoDetails.PaidAmount = Decimal.Parse(itemRow["PaidAmount"].ToString());
oPaymentInfoDetails.InvoiceNo = itemRow["InvoiceNo"].ToString();
if (! oPaymentInfo.InvoiceNos.Contains(oPaymentInfoDetails.InvoiceNo))
{
oPaymentInfo.InvoiceNos += "," + oPaymentInfoDetails.InvoiceNo;
}
oPaymentInfo.PaymentDetailList.Add(oPaymentInfoDetails);
}
oPaymentInfo.InvoiceNos = oPaymentInfo.InvoiceNos.Trim(",".ToCharArray());
}
oPaymentList.Add(oPaymentInfo);
}
}
return oPaymentList;
}
public class PaymentInfo
{
public int PaymentID { get; set; }
public DateTime PaymentDate { get; set; }
public decimal TotalPaymentAmount
{
get
{
return this.PaymentDetailList.Sum(P => P.PaymentAmount);
}
}
public string InvoiceNos { get; set; }
public int CurrencyID { get; set; }
public int CreatedID { get; set; }
public List PaymentDetailList { get; set; }
}
public class PaymentDetailsInfo
{
public int PaymentDetailsID { get; set; }
public int PaymentID { get; set; }
public int InvoiceID { get; set; }
public string InvoiceNo { get; set; }
public decimal PaymentAmount { get; set; }
public decimal InvoiceAmount { get; set; }
public decimal PaidAmount { get; set; }
public decimal DueAmount { get; set; }
}
}
This Data I am going to bind in my datagridview there I have added 5-7 fieds out of that one the field PaymentAmount text box with readonly=false property.
dgPaymentList.Visible = true;
Payment oPayment = new Payment();
List oPaymentList = oPayment.GetPaymentList(null);
dgPaymentList.AutoGenerateColumns = false;
dgPaymentList.RowHeadersVisible = false;
dgPaymentList.DataSource = oPaymentList;
Hence when I am doing any changes in that textbox that directly update my collection and one call update method which is in business class that directly update data by this collection entity.
Let me know if required any more information on this.
Image may be NSFW.
Clik here to view.
Clik here to view.
