Posted By

moneema on 07/19/09


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

umang_nine


Test


 / Published in: C#
 

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Data.SqlClient;
  5. using System.Xml;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8.  
  9. /// <summary>
  10. /// Summary description for RawMaterialGateway
  11. /// </summary>
  12. public class RawMaterialGateway
  13. {
  14. private AppMessage appMsg = null;
  15. private DBConnector dbConnector = null;
  16. private SqlConnection sqlConnection = null;
  17. private SqlCommand sqlCommand = null;
  18.  
  19. public RawMaterialGateway()
  20. {
  21. try
  22. {
  23. dbConnector = new DBConnector();
  24. sqlConnection = new SqlConnection();
  25. sqlConnection = dbConnector.Connection;
  26. appMsg = new AppMessage();
  27. sqlCommand = new SqlCommand();
  28. }
  29. catch (XmlException xmlExObj)
  30. {
  31. throw xmlExObj;
  32. }
  33. catch (Exception exObj)
  34. {
  35. throw exObj;
  36. }
  37. }
  38.  
  39.  
  40.  
  41. public List<RawMaterial> GetAllRawMaterial()
  42. {
  43. List<RawMaterial> RawMaterialList = new List<RawMaterial>();
  44. RawMaterial RawMaterialObj = null;
  45. try
  46. {
  47. string queryString = "SELECT * FROM t_RawMaterial";
  48. sqlCommand.CommandText = queryString;
  49. sqlCommand.Connection = sqlConnection;
  50. sqlConnection.Open();
  51. SqlDataReader RawMaterialData = sqlCommand.ExecuteReader();
  52. while (RawMaterialData.Read())
  53. {
  54. RawMaterialObj = new RawMaterial();
  55. RawMaterialObj.Code = RawMaterialData[1].ToString();
  56. RawMaterialObj.Name = RawMaterialData[0].ToString();
  57. RawMaterialList.Add(RawMaterialObj);
  58. }
  59. return RawMaterialList;
  60. }
  61. catch (SqlException sqlExObj)
  62. {
  63. throw sqlExObj;
  64. }
  65. catch (XmlException xmlExObj)
  66. {
  67. throw xmlExObj;
  68. }
  69. catch (Exception exObj)
  70. {
  71. throw exObj;
  72. }
  73. finally
  74. {
  75. sqlConnection.Close();
  76. }
  77. }
  78.  
  79. public AppMessage AddRawMaterial(RawMaterialEntryView rmEntryObj, List<rawMaterialEntry> rawMaterialEntryList)
  80. {
  81. try
  82. {
  83. string queryString = "INSERT INTO t_StoreEntry( InvoiceNo, SupplierName, Date, StoreId ) VALUES ('" + rmEntryObj.InvoiceNo + "','" + rmEntryObj.SupplierName + "','" + rmEntryObj.Date + "','" + rmEntryObj.StoreId + "')";
  84. //"INSERT INTO t_RawMaterialEntry(EntryNo, RawMaterialName, Quantity ) VALUES ('" + rmEntryObj.RawMaterialEntryNo + "','" + rmEntryObj.RawMaterialName + "','" + rmEntryObj.Quantity + "')";
  85. sqlCommand.CommandText = queryString;
  86. sqlCommand.Connection = sqlConnection;
  87. sqlConnection.Open();
  88. int affetedRows = sqlCommand.ExecuteNonQuery();
  89. if (affetedRows > 0)
  90. {
  91. appMsg.Id = "0";
  92. appMsg.Text = "RawMaterial has been saved";
  93. }
  94. else
  95. {
  96. appMsg.Id = "1";
  97. appMsg.Text = "RawMaterial is not saved.";
  98. }
  99.  
  100. string rmEntryNoQuery = "SELECT ident_current('t_StoreEntry')";
  101. sqlCommand.CommandText = rmEntryNoQuery;
  102. int rmEntryNo = ((int )sqlCommand.ExecuteScalar()) - 1;
  103. foreach (rawMaterialEntry rm in rawMaterialEntryList)
  104. {
  105. queryString = "INSERT INTO t_RawMaterialEntry(EntryNo, RawMaterialName, Quantity ) VALUES ('" + rmEntryNo + "','" + rm.RawMaterialName + "','" + rm.Quantity + "')";
  106. sqlCommand.CommandText = queryString;
  107. affetedRows = sqlCommand.ExecuteNonQuery();
  108. }
  109. return appMsg;
  110. }
  111. catch (SqlException sqlExObj)
  112. {
  113. throw sqlExObj;
  114. }
  115. catch (XmlException xmlExObj)
  116. {
  117. throw xmlExObj;
  118. }
  119. catch (Exception exObj)
  120. {
  121. throw exObj;
  122. }
  123. finally
  124. {
  125. sqlConnection.Close();
  126. }
  127.  
  128. /* try
  129.   {
  130.   string queryString = "INSERT INTO t_StoreEntry( EntryNo, InvoiceNo, SupplierName, Date, StoreId ) VALUES ('" + rmEntryObj.RawMaterialEntryNo + "','" + rmEntryObj.InvoiceNo + "','" + rmEntryObj.SupplierName + "','" + rmEntryObj.Date + "','" + rmEntryObj.StoreId+ "')";
  131.   sqlCommand.CommandText = queryString;
  132.   sqlCommand.Connection = sqlConnection;
  133.   sqlConnection.Open();
  134.   int affetedRows = sqlCommand.ExecuteNonQuery();
  135.   if (affetedRows > 0)
  136.   {
  137.   appMsg.Id = "0";
  138.   appMsg.Text = "RawMaterial has been saved";
  139.   }
  140.   else
  141.   {
  142.   appMsg.Id = "1";
  143.   appMsg.Text = "RawMaterial is not saved.";
  144.   }
  145.   return appMsg;
  146.   }
  147.   catch (SqlException sqlExObj)
  148.   {
  149.   throw sqlExObj;
  150.   }
  151.   catch (XmlException xmlExObj)
  152.   {
  153.   throw xmlExObj;
  154.   }
  155.   catch (Exception exObj)
  156.   {
  157.   throw exObj;
  158.   }
  159.   finally
  160.   {
  161.   sqlConnection.Close();
  162.   }*/
  163. }
  164. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: misserwell on September 8, 2009

Why there is no any comment?!

You need to login to post a comment.