public int insertSrvcSrvItem(billingItem tmpSrvcBItm, int billID, int Serv_Id) { int result = 0; try { using (SqlConnection con = new SqlConnection(conString)) { if (con.State == ConnectionState.Closed) { con.Open(); } SqlCommand cmd = new SqlCommand("InsertBillItm_Srvc", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@bill_Id", billID); cmd.Parameters.AddWithValue("@Serv_Id", Serv_Id); cmd.Parameters.AddWithValue("@quantity", tmpSrvcBItm.Quantiy); cmd.Parameters.AddWithValue("@itm_total", tmpSrvcBItm.Total); result = (int)cmd.ExecuteScalar(); if (con.State == ConnectionState.Open) { con.Close(); } } } catch (Exception e) { result = 0; logger.Error("\n DAL Error in BillingDataAccess.insertProdSrvItem: " + e.ToString()); //Console.WriteLine("DAL Error in BillingDataAccess.insertProdSrvItem: " + e.ToString()); } return(result); }
public List <billingItem> getBillingItemData(int bill_Id) { Console.WriteLine("Bill ID is: " + bill_Id); List <billingItem> billingLst = new List <billingItem>(); try { using (SqlConnection con = new SqlConnection(conString)) { if (con.State == ConnectionState.Closed) { con.Open(); } SqlCommand cmd = new SqlCommand("GetBillItemsWithData", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@bill_Id", bill_Id); using (SqlDataReader rdr = cmd.ExecuteReader()) { if (rdr.HasRows) { while (rdr.Read()) { billingItem tmpBillItm = new billingItem(); tmpBillItm.BillItemId = (int)rdr["bill_item_Id"]; tmpBillItm._type = (String)rdr["itmtype"]; tmpBillItm.Quantiy = (int)rdr["quantity"]; tmpBillItm.Total = Convert.ToDecimal(rdr["itm_total"]); if (tmpBillItm._type.Equals("Product")) { products tmpPrd = new products(); tmpPrd.ProductID = (int)rdr["prod_ID"]; tmpPrd.ProductCode = (String)rdr["prod_Code"]; tmpPrd.ProductName = (String)rdr["prod_Name"]; tmpPrd.ProductPrice = Convert.ToDecimal(rdr["prod_Price"]); tmpBillItm.Product = tmpPrd; } else if (tmpBillItm._type.Equals("Service")) { serviceProducts tmpSrvcPrd = new serviceProducts(); tmpSrvcPrd.Service_ID = (int)rdr["Serv_Id"]; Console.WriteLine("Service name id is: " + tmpSrvcPrd.Service_ID); tmpSrvcPrd.Service_Name = (String)rdr["serv_Name"]; tmpSrvcPrd.Service_Price = Convert.ToDecimal(rdr["serv_Price"]); tmpBillItm.Service = tmpSrvcPrd; } billingLst.Add(tmpBillItm); } } } if (con.State == ConnectionState.Open) { con.Close(); } } } catch (Exception e) { logger.Error("DAL Error in BillingDataAccess.getBillingItemData: " + e.ToString()); //Console.WriteLine("DAL Error in BillingDataAccess.getBillingItemData: " + e.ToString()); } return(billingLst); }