public List <SalesHead> getSalheadList() { List <SalesHead> salHeadList = new List <SalesHead>(); connection(); SqlCommand cmd = new SqlCommand("SELECT * FROM tbl_sal_head", con); cmd.CommandType = CommandType.Text; con.Open(); SqlDataReader rdr = cmd.ExecuteReader(); SalesHead salHead = default(SalesHead); while (rdr.Read()) { salHead = Activator.CreateInstance <SalesHead>(); foreach (PropertyInfo prop in salHead.GetType().GetProperties()) { if (!object.Equals(rdr[prop.Name], DBNull.Value)) { prop.SetValue(salHead, rdr[prop.Name], null); } } salHeadList.Add(salHead); } rdr.Close(); con.Close(); return(salHeadList); }
public SalesInvoice getSalInvoiceDetail(int?id, string type) { SalesInvoice salInvoice = new SalesInvoice(); if (id == null || type == null) { return(salInvoice); } List <SalesItem> salItemList = new List <SalesItem>(); connection(); string selectionQuery = "SELECT * FROM tbl_sal_head where docNum = '" + id + "' and docType = '" + type + "'"; string selectionQuery2 = "SELECT * FROM tbl_sal_item where docNum = '" + id + "' and docType = '" + type + "'"; SqlCommand cmd = new SqlCommand(selectionQuery, con); cmd.CommandType = CommandType.Text; con.Open(); SqlDataReader dr = cmd.ExecuteReader(); SalesHead salesHead = default(SalesHead); if (dr.Read()) { salesHead = Activator.CreateInstance <SalesHead>(); foreach (PropertyInfo prop in salesHead.GetType().GetProperties()) { if (!object.Equals(dr[prop.Name], DBNull.Value)) { prop.SetValue(salesHead, dr[prop.Name], null); } } salInvoice.salesHead = salesHead; dr.Close(); SqlCommand cmd2 = new SqlCommand(selectionQuery2, con); cmd2.CommandType = CommandType.Text; SqlDataReader rdr = cmd2.ExecuteReader(); SalesItem salesItem = default(SalesItem); while (rdr.Read()) { salesItem = Activator.CreateInstance <SalesItem>(); foreach (PropertyInfo prop in salesItem.GetType().GetProperties()) { if (!object.Equals(rdr[prop.Name], DBNull.Value)) { prop.SetValue(salesItem, rdr[prop.Name], null); } } salItemList.Add(salesItem); } salInvoice.salesItemList = salItemList; rdr.Close(); } con.Close(); return(salInvoice); }