public void LoadAllDatabase(List <MaterialStorages> listMaterialstorage) { DatabaseConnection(); sqlConnection.Open(); sqlCommand.CommandText = "EXEC dbo.ProcMaterialStoragesSelect"; SqlDataReader sqlDataReader = sqlCommand.ExecuteReader(); while (sqlDataReader.Read()) { var materialStorage = new MaterialStorages(); for (int i = 0; i < sqlDataReader.FieldCount; i++) { var colName = sqlDataReader.GetName(i); var value = sqlDataReader.GetValue(i); var property = materialStorage.GetType().GetProperty(colName); if (property != null) { property.SetValue(materialStorage, value); } } listMaterialstorage.Add(materialStorage); } sqlConnection.Close(); }
public void InsertMaterialStorages(MaterialStorages materialStorages) { materialStorages.MaterialstorageId = listMaterialStorages.Count() + 1; materialStorages.MaterialDelivery = DateTime.Today.ToString("d"); listMaterialStorages.Add(materialStorages); //SQL INSERT database.InsertMaterialStorages(materialStorages); }
public void UpdateMaterialStorages(MaterialStorages materialStorages) { var xMaterialStorage = listMaterialStorages.Where(e => e.MaterialstorageId == materialStorages.MaterialstorageId).FirstOrDefault(); listMaterialStorages.Remove(xMaterialStorage); materialStorages.MaterialstorageCode = xMaterialStorage.MaterialstorageCode; materialStorages.MaterialsinorderCode = xMaterialStorage.MaterialsinorderCode; materialStorages.MaterialCode = xMaterialStorage.MaterialCode; materialStorages.MaterialDimension = xMaterialStorage.MaterialDimension; materialStorages.MaterialDelivery = xMaterialStorage.MaterialDelivery; listMaterialStorages.Add(materialStorages); //SQL UPDATE database.UpdateMaterialsinorder(materialStorages); }
public void UpdateMaterialsinorder(MaterialStorages materialStorage) { DatabaseConnection(); sqlConnection.Open(); sqlCommand.CommandText = "EXEC ProcMaterialStoragesUpdate @id, @codes, @codei, @code, @dimension, @quantity, @delivery, @note"; sqlCommand.Parameters.AddWithValue("@id", materialStorage.MaterialstorageId); sqlCommand.Parameters.AddWithValue("@codes", materialStorage.MaterialstorageCode); sqlCommand.Parameters.AddWithValue("@codei", materialStorage.MaterialsinorderCode); sqlCommand.Parameters.AddWithValue("@code", materialStorage.MaterialCode); sqlCommand.Parameters.AddWithValue("@dimension", materialStorage.MaterialDimension); sqlCommand.Parameters.AddWithValue("@quantity", materialStorage.MaterialQuantity); sqlCommand.Parameters.AddWithValue("@delivery", materialStorage.MaterialDelivery); sqlCommand.Parameters.AddWithValue("@note", materialStorage.MaterialstorageNote); sqlCommand.ExecuteNonQuery(); sqlConnection.Close(); }
public int Put([FromBody] MaterialStorages materialStorages) { materialstorageBL.UpdateMaterialStorages(materialStorages); return(1); }
public int Post([FromBody] MaterialStorages materialStorages) { materialstorageBL.getData(); materialstorageBL.InsertMaterialStorages(materialStorages); return(1); }