private void Fetch(SafeDataReader dr) { Database.LogInfo("OrderOrderDetail.FetchDR", GetHashCode()); try { _ProductID = dr.GetInt32("ProductID"); _UnitPrice = dr.GetDecimal("UnitPrice"); _Quantity = dr.GetInt16("Quantity"); _Discount = dr.GetFloat("Discount"); _Product_ProductName = dr.GetString("Product_ProductName"); _Product_SupplierID = (int?)dr.GetValue("Product_SupplierID"); _Product_CategoryID = (int?)dr.GetValue("Product_CategoryID"); _Product_QuantityPerUnit = dr.GetString("Product_QuantityPerUnit"); _Product_UnitPrice = (decimal?)dr.GetValue("Product_UnitPrice"); _Product_UnitsInStock = (Int16?)dr.GetValue("Product_UnitsInStock"); _Product_UnitsOnOrder = (Int16?)dr.GetValue("Product_UnitsOnOrder"); _Product_ReorderLevel = (Int16?)dr.GetValue("Product_ReorderLevel"); _Product_Discontinued = dr.GetBoolean("Product_Discontinued"); } catch (Exception ex) // FKItem Fetch { Database.LogException("OrderOrderDetail.FetchDR", ex); throw new DbCslaException("OrderOrderDetail.Fetch", ex); } MarkOld(); }
private void Fetch(SafeDataReader dr) { Database.LogInfo("ProductOrderDetail.FetchDR", GetHashCode()); try { _OrderID = dr.GetInt32("OrderID"); _UnitPrice = dr.GetDecimal("UnitPrice"); _Quantity = dr.GetInt16("Quantity"); _Discount = dr.GetFloat("Discount"); _Order_CustomerID = dr.GetString("Order_CustomerID"); _Order_EmployeeID = (int?)dr.GetValue("Order_EmployeeID"); _Order_OrderDate = dr.GetSmartDate("Order_OrderDate").Text; _Order_RequiredDate = dr.GetSmartDate("Order_RequiredDate").Text; _Order_ShippedDate = dr.GetSmartDate("Order_ShippedDate").Text; _Order_ShipVia = (int?)dr.GetValue("Order_ShipVia"); _Order_Freight = (decimal?)dr.GetValue("Order_Freight"); _Order_ShipName = dr.GetString("Order_ShipName"); _Order_ShipAddress = dr.GetString("Order_ShipAddress"); _Order_ShipCity = dr.GetString("Order_ShipCity"); _Order_ShipRegion = dr.GetString("Order_ShipRegion"); _Order_ShipPostalCode = dr.GetString("Order_ShipPostalCode"); _Order_ShipCountry = dr.GetString("Order_ShipCountry"); } catch (Exception ex) // FKItem Fetch { Database.LogException("ProductOrderDetail.FetchDR", ex); throw new DbCslaException("ProductOrderDetail.Fetch", ex); } MarkOld(); }
private void ReadData(SafeDataReader dr) { Database.LogInfo("OrderDetailInfo.ReadData", GetHashCode()); try { _OrderID = dr.GetInt32("OrderID"); _ProductID = dr.GetInt32("ProductID"); _UnitPrice = dr.GetDecimal("UnitPrice"); _Quantity = dr.GetInt16("Quantity"); _Discount = dr.GetFloat("Discount"); } catch (Exception ex) { Database.LogException("OrderDetailInfo.ReadData", ex); _ErrorMessage = ex.Message; throw new DbCslaException("OrderDetailInfo.ReadData", ex); } }
/// <summary> /// 獲得表信息 /// </summary> /// <param name="modelList">modelList</param> /// <param name="table">table</param> /// <param name="model">model</param> /// <param name="sdr">SafeDataReader sdr</param> public static void GetTable(IList modelList, QueryTable table, Object model, SelectSqlSection sql, int sum) { Type modelType = model.GetType(); //model的類型 Type tableType = table.GetType(); //table的類型 string proName = ""; //屬性名稱 using (SafeDataReader sdr = new SafeDataReader(sql.ToDataReader())) { while (sdr.Read()) { object modelObj = Activator.CreateInstance(modelType); //創建新對象 Type modelObjType = modelObj.GetType(); //獲得對象的類型 foreach (System.Reflection.PropertyInfo modelInfo in modelObjType.GetProperties()) //遍曆model的所有屬性 { proName = modelInfo.Name; if (proName.Equals("GridRowCount")) { modelInfo.SetValue(modelObj, sum, null); continue; } if (table.GetType().GetProperty(proName) == null) { continue; } Comfy.Data.QueryColumn queryColumn = (Comfy.Data.QueryColumn)table.GetType().GetProperty(proName).GetValue(table, null); //匹配類型 if (modelInfo.PropertyType.Equals(typeof(string))) { modelInfo.SetValue(modelObj, sdr.GetString(queryColumn), null); } else if (modelInfo.PropertyType.Equals(typeof(DateTime))) { modelInfo.SetValue(modelObj, sdr.GetDateTime(queryColumn), null); } else if (modelInfo.PropertyType.Equals(typeof(int))) { modelInfo.SetValue(modelObj, sdr.GetInt32(queryColumn), null); } else if (modelInfo.PropertyType.Equals(typeof(long))) { modelInfo.SetValue(modelObj, sdr.GetInt64(queryColumn), null); } else if (modelInfo.PropertyType.Equals(typeof(short))) { modelInfo.SetValue(modelObj, sdr.GetInt16(queryColumn), null); } else if (modelInfo.PropertyType.Equals(typeof(bool))) { modelInfo.SetValue(modelObj, sdr.GetBoolean(queryColumn), null); } else if (modelInfo.PropertyType.Equals(typeof(float))) { modelInfo.SetValue(modelObj, sdr.GetFloat(queryColumn), null); } else if (modelInfo.PropertyType.Equals(typeof(double))) { modelInfo.SetValue(modelObj, sdr.GetDouble(queryColumn), null); } else if (modelInfo.PropertyType.Equals(typeof(decimal))) { modelInfo.SetValue(modelObj, sdr.GetDecimal(queryColumn), null); } else { throw new Exception("沒有匹配中類型"); } } modelList.Add(modelObj); } } }