/ Published in: C#
Expand |
Embed | Plain Text
using System; using System.Data; using System.Configuration; using System.Data.SqlClient; using System.Xml; using System.Collections; using System.Collections.Generic; /// <summary> /// Summary description for RawMaterialGateway /// </summary> public class RawMaterialGateway { private AppMessage appMsg = null; private DBConnector dbConnector = null; private SqlConnection sqlConnection = null; private SqlCommand sqlCommand = null; public RawMaterialGateway() { try { sqlConnection = dbConnector.Connection; } catch (XmlException xmlExObj) { throw xmlExObj; } catch (Exception exObj) { throw exObj; } } public List<RawMaterial> GetAllRawMaterial() { RawMaterial RawMaterialObj = null; try { string queryString = "SELECT * FROM t_RawMaterial"; sqlCommand.CommandText = queryString; sqlCommand.Connection = sqlConnection; sqlConnection.Open(); SqlDataReader RawMaterialData = sqlCommand.ExecuteReader(); while (RawMaterialData.Read()) { RawMaterialObj.Code = RawMaterialData[1].ToString(); RawMaterialObj.Name = RawMaterialData[0].ToString(); RawMaterialList.Add(RawMaterialObj); } return RawMaterialList; } catch (SqlException sqlExObj) { throw sqlExObj; } catch (XmlException xmlExObj) { throw xmlExObj; } catch (Exception exObj) { throw exObj; } finally { sqlConnection.Close(); } } public AppMessage AddRawMaterial(RawMaterialEntryView rmEntryObj, List<rawMaterialEntry> rawMaterialEntryList) { try { string queryString = "INSERT INTO t_StoreEntry( InvoiceNo, SupplierName, Date, StoreId ) VALUES ('" + rmEntryObj.InvoiceNo + "','" + rmEntryObj.SupplierName + "','" + rmEntryObj.Date + "','" + rmEntryObj.StoreId + "')"; //"INSERT INTO t_RawMaterialEntry(EntryNo, RawMaterialName, Quantity ) VALUES ('" + rmEntryObj.RawMaterialEntryNo + "','" + rmEntryObj.RawMaterialName + "','" + rmEntryObj.Quantity + "')"; sqlCommand.CommandText = queryString; sqlCommand.Connection = sqlConnection; sqlConnection.Open(); int affetedRows = sqlCommand.ExecuteNonQuery(); if (affetedRows > 0) { appMsg.Id = "0"; appMsg.Text = "RawMaterial has been saved"; } else { appMsg.Id = "1"; appMsg.Text = "RawMaterial is not saved."; } string rmEntryNoQuery = "SELECT ident_current('t_StoreEntry')"; sqlCommand.CommandText = rmEntryNoQuery; int rmEntryNo = ((int )sqlCommand.ExecuteScalar()) - 1; foreach (rawMaterialEntry rm in rawMaterialEntryList) { queryString = "INSERT INTO t_RawMaterialEntry(EntryNo, RawMaterialName, Quantity ) VALUES ('" + rmEntryNo + "','" + rm.RawMaterialName + "','" + rm.Quantity + "')"; sqlCommand.CommandText = queryString; affetedRows = sqlCommand.ExecuteNonQuery(); } return appMsg; } catch (SqlException sqlExObj) { throw sqlExObj; } catch (XmlException xmlExObj) { throw xmlExObj; } catch (Exception exObj) { throw exObj; } finally { sqlConnection.Close(); } /* try { string queryString = "INSERT INTO t_StoreEntry( EntryNo, InvoiceNo, SupplierName, Date, StoreId ) VALUES ('" + rmEntryObj.RawMaterialEntryNo + "','" + rmEntryObj.InvoiceNo + "','" + rmEntryObj.SupplierName + "','" + rmEntryObj.Date + "','" + rmEntryObj.StoreId+ "')"; sqlCommand.CommandText = queryString; sqlCommand.Connection = sqlConnection; sqlConnection.Open(); int affetedRows = sqlCommand.ExecuteNonQuery(); if (affetedRows > 0) { appMsg.Id = "0"; appMsg.Text = "RawMaterial has been saved"; } else { appMsg.Id = "1"; appMsg.Text = "RawMaterial is not saved."; } return appMsg; } catch (SqlException sqlExObj) { throw sqlExObj; } catch (XmlException xmlExObj) { throw xmlExObj; } catch (Exception exObj) { throw exObj; } finally { sqlConnection.Close(); }*/ } }
Comments
Subscribe to comments
You need to login to post a comment.

Why there is no any comment?!