/////////////////////////////////////////////////////////// // Bool.cs // Implementation of Class PartInventoryAdjustmentDetailedReportData // CSLA type: Read-only object // Created on: 30-Dec-2005 // Object design: John // Coded: 30-Dec-2005 /////////////////////////////////////////////////////////// using System; using System.Data; using CSLA.Data; using GZTW.Data; using CSLA; using System.Threading; using CSLA.Security; using System.IO; using System.Reflection; using System.Collections.Generic; namespace GZTW.AyaNova.BLL { /// /// List of detailed adjustment items objects used in detailed report /// [Serializable] public class PartInventoryAdjustmentDetailedReportData : ReadOnlyBase { #region Attributes private ReportDataSet ds; #endregion #region Constructor /// /// Private constructor to prevent direct instantiation /// private PartInventoryAdjustmentDetailedReportData() { } #endregion #region Static methods /// /// Returns the report key which is a property of /// reports used to link all reports that can be used /// with a particular data source. /// public static string ReportKey { get { return "PartInventoryAdjustmentDetailed"; } } /// /// Get list based on filter and sort criteria /// /// Use AyaNova UI to easily build xmlCriteria and Ctrl-Alt-g keyboard command to display it for use in your code /// ReportDataSet public static ReportDataSet GetItems(string xmlCriteria) { return ((PartInventoryAdjustmentDetailedReportData)DataPortal.Fetch(new Criteria(xmlCriteria, null, -1))).ds; } /// /// Takes a single ID and returns a "list" of one object /// /// ID of PartInventoryAdjustment object /// ReportDataSet public static ReportDataSet GetItem(Guid PartInventoryAdjustmentID) { List l = new List(); l.Add(PartInventoryAdjustmentID); return ((PartInventoryAdjustmentDetailedReportData)DataPortal.Fetch(new Criteria("", l, -1))).ds; } /// /// Internal method used by list factory /// internal static ReportDataSet Get(string Filter, int MaxRecords, List IDList) { return ((PartInventoryAdjustmentDetailedReportData)DataPortal.Fetch(new Criteria(Filter, IDList, MaxRecords))).ds; } /// /// Get list by items indicated in IDList /// /// Generic list of Guid's /// list of objects public static ReportDataSet GetListFromIDList(List IDList) { //case 556 //Handle empty list if (IDList.Count == 0) return new PartInventoryAdjustmentDetailedReportData().ds; return ((PartInventoryAdjustmentDetailedReportData)DataPortal.Fetch(new Criteria("", IDList, -1))).ds; } #endregion #region Initialize data set private void InitDS() { ds=new ReportDataSet(); System.IO.Stream s=Assembly.GetExecutingAssembly().GetManifestResourceStream("GZTW.AyaNova.BLL.PartInventoryAdjustmentDetailedSchema.xsd"); ds.ReadXmlSchema(s); ds.ShowOnlyStartingWith="PartInventoryAdjustment"; } #endregion initalize data set #region DAL DATA ACCESS /// /// protected override void DataPortal_Fetch(object Criteria) { InitDS(); Criteria crit = (Criteria)Criteria; SafeDataReader dr = null; try { #region Cached objects //Users UserPickList users=UserPickList.GetList(false); #endregion cached objects DBCommandWrapper cm = null; #region Query string q = //************************************************************ "SELECT ~MAXRECS~ aPartInventoryAdjustment.aID, aPartInventoryAdjustment.aCreator, " + "aPartInventoryAdjustment.aDateAdjusted, " + "aPartInventoryAdjustment.AADJUSTMENTNUMBER, " + "aPartInventoryAdjustment.aReasonForAdjustment " + "FROM aPartInventoryAdjustment " ; //*********************************************************************************************************** ; if (crit.MaxRecords > 0) q = q.Replace("~MAXRECS~", "TOP " + crit.MaxRecords.ToString()); else q = q.Replace("~MAXRECS~", ""); if (crit.IDList != null) { //Case 556 System.Text.StringBuilder sbIN = new System.Text.StringBuilder(); sbIN.Append(" WHERE (aPartInventoryAdjustment.aID in ("); foreach (Guid gItem in crit.IDList) { sbIN.Append("'"); sbIN.Append("{"); sbIN.Append(gItem.ToString().ToUpperInvariant()); sbIN.Append("}"); sbIN.Append("',"); } sbIN.Length = sbIN.Length - 1; sbIN.Append(")) "); cm = DBUtil.DB.GetSqlStringCommandWrapper(q + sbIN.ToString() + " " + AyaBizUtils.GetGridSortOrderColumns(crit.CriteriaXML)); } else { //string strCrit=AyaBizUtils.GetGridColumnCriteria(crit.CriteriaXML,false); //Grid criteria cm = DBUtil.DB.GetSqlStringCommandWrapper(q + AyaBizUtils.GetGridColumnCriteria(crit.CriteriaXML,true) + " " + AyaBizUtils.GetGridSortOrderColumns(crit.CriteriaXML) ); } #endregion query dr=new SafeDataReader(DBUtil.DB.ExecuteReader(cm)); DataRow r=null; while(dr.Read()) { //******************************************* #region PartInventoryAdjustment level r=ds.Tables["PartInventoryAdjustment"].NewRow(); r["ID"]=dr.GetGuid("aID"); r["LT_Common_Label_Creator"]=users[dr.GetGuid("aCreator")]; r["LT_PartInventoryAdjustment_Label_DateAdjusted"]=DBUtil.ToLocal(dr.GetSmartDate("aDateAdjusted")).Date; r["LT_PartInventoryAdjustment_Label_AdjustmentNumber"]=dr.GetInt32("AADJUSTMENTNUMBER").ToString(); r["LT_PartInventoryAdjustment_Label_ReasonForAdjustment"]=dr.GetString("aReasonForAdjustment"); ds.Tables["PartInventoryAdjustment"].Rows.Add(r); #endregion purchase order receipt level #region Item Level SafeDataReader dritems=DBUtil.GetReaderFromSQLString( "SELECT aPartWarehouse.aName AS aPartWarehouseName, " + " aVendor.aName AS aMANUFACTURERNAME, aPart.aName, " + " aPart.aPartNumber, aPart.aUPC, " + "aPartCategory.aName AS aPARTCATEGORYNAME, aPartAssembly.aName " + "AS aPARTASSEMBLYNAME, aPartInventoryAdjustmentItem.aID, " + " aPartInventoryAdjustmentItem.aQuantityAdjustment " + "FROM aPartInventoryAdjustmentItem " + "LEFT JOIN aPart ON aPartInventoryAdjustmentItem.aPartID " + "= aPart.aID " + "LEFT JOIN aPartWarehouse ON aPartInventoryAdjustmentItem.aPartWarehouseID " + "= aPartWarehouse.aID " + "LEFT OUTER JOIN aPartAssembly ON aPart.aPartAssemblyID " + "= aPartAssembly.aID LEFT " + "OUTER JOIN aVendor ON aPart.aManufacturerID " + "= aVendor.aID LEFT OUTER JOIN aPartCategory " + "ON aPart.aPartCategoryID = aPartCategory.aID " + "WHERE (aPartInventoryAdjustmentItem.aPartInventoryAdjustmentID " + "= @ID)" ,dr.GetGuid("aID")); while(dritems.Read()) { r=ds.Tables["Item"].NewRow(); r["ItemID"]=dritems.GetGuid("aID"); r["LT_O_PartWarehouse"]=dritems.GetString("aPartWarehouseName"); r["LT_O_Part"]=Part.PartDisplayFormatter( dritems.GetString("aName"), dritems.GetString("aPARTNUMBER"), dritems.GetString("aUPC"), dritems.GetString("aMANUFACTURERNAME"), dritems.GetString("aPARTCATEGORYNAME"), dritems.GetString("aPARTASSEMBLYNAME"), AyaBizUtils.GlobalSettings.DefaultPartDisplayFormat); r["LT_PartInventoryAdjustmentItem_Label_QuantityAdjustment"]=dritems.GetDecimal("aQuantityAdjustment"); r["ParentID"]=dr.GetGuid("aID"); ds.Tables["Item"].Rows.Add(r); #region Serial numbers Level //AADJUSTMENTID SafeDataReader drsn=DBUtil.GetReaderFromSQLString( "SELECT aSerialNumber FROM " + "aPartSerial WHERE (AADJUSTMENTID " + "= @ID)" ,dritems.GetGuid("aID")); while(drsn.Read()) { r=ds.Tables["SN"].NewRow(); r["ParentItemID"]=dritems.GetGuid("aID"); r["LT_Common_Label_SerialNumber"]=drsn.GetString("aSerialNumber"); ds.Tables["SN"].Rows.Add(r); } drsn.Close(); #endregion Serial number level fields } dritems.Close(); #endregion item level fields //******************************************* } } finally { if(dr!=null) dr.Close(); } } #endregion #region criteria /// /// Criteria for identifying existing object /// [Serializable] private class Criteria { public List IDList; public string CriteriaXML; public int MaxRecords; public Criteria(string _CriteriaXML, List _IDList, int _MaxRecords) { CriteriaXML = _CriteriaXML; IDList = _IDList; MaxRecords = _MaxRecords; } } #endregion }//end Bool }//end Boolspace GZTW.AyaNova.BLL