} // StartDocumentPrint static public ReportEngine_N StartFinReport(Ctx ctx, ProcessInfo pi) { int AD_Client_ID = ctx.GetAD_Client_ID(); // Create Query from Parameters String TableName = pi.GetAD_Process_ID() == 202 ? "T_Report" : "T_ReportStatement"; Query query = Query.Get(ctx, pi.GetAD_PInstance_ID(), TableName); // Get PrintFormat MPrintFormat format = (MPrintFormat)pi.GetTransientObject(); if (format == null) { format = (MPrintFormat)pi.GetSerializableObject(); } if (format == null) { s_log.Log(Level.SEVERE, "startFinReport - No PrintFormat"); return(null); } PrintInfo info = new PrintInfo(pi); ReportEngine_N re = new ReportEngine_N(ctx, format, query, info); return(re); } // startFinReport
} // get /// <summary> /// Get (default) Printformat for Report View or Table /// </summary> /// <param name="ctx">context</param> /// <param name="AD_ReportView_ID">id or 0</param> /// <param name="AD_Table_ID">id or 0</param> /// <returns>first print format found or null</returns> static public MPrintFormat Get(Ctx ctx, int AD_ReportView_ID, int AD_Table_ID) { MPrintFormat retValue = null; String sql = "SELECT * FROM AD_PrintFormat WHERE "; if (AD_ReportView_ID > 0) { sql += "AD_ReportView_ID=@val1"; } else { sql += "AD_Table_ID=@val1"; } sql += " ORDER BY IsDefault DESC"; SqlParameter[] param = new SqlParameter[1]; try { param[0] = new SqlParameter("@val1", AD_ReportView_ID > 0 ? AD_ReportView_ID : AD_Table_ID); DataSet ds = SqlExec.ExecuteQuery.ExecuteDataset(sql, param); foreach (DataRow dr in ds.Tables[0].Rows) { retValue = new MPrintFormat(ctx, dr, null); } } catch (Exception e) { s_log.Severe(e.ToString()); //log entry if any } return(retValue); }
} // setSatndardHeaderFooter public static MPrintFormat Copy(Ctx ctx, int from_AD_PrintFormat_ID, int to_AD_PrintFormat_ID, int to_Client_ID) { //_ctx = ctx; if (from_AD_PrintFormat_ID == 0) { throw new ArgumentException("From_AD_PrintFormat_ID is 0"); } // MPrintFormat from = new MPrintFormat(ctx, from_AD_PrintFormat_ID, null); MPrintFormat to = new MPrintFormat(ctx, to_AD_PrintFormat_ID, null); // could be 0 MPrintFormat.CopyValues(from, to); // New if (to_AD_PrintFormat_ID == 0) { if (to_Client_ID < 0) { to_Client_ID = ctx.GetAD_Client_ID(); } to.SetClientOrg(to_Client_ID, 0); } // Set Name - Remove TEMPLATE - add copy to.SetName(Utility.Util.Replace(to.GetName(), "TEMPLATE", to_Client_ID.ToString())); to.SetName(to.GetName() + " " + Msg.GetMsg(Env.GetContext(), "Copy", true) + " " + to.HashCode()); // unique name // to.Save(); // Copy Items to.SetItems(CopyItems(from, to)); return(to); } // copyToClient
/// <summary> /// Get Format /// </summary> /// <param name="ctx">context</param> /// <param name="AD_PrintFormat_ID">id</param> /// <param name="readFromDisk">refresh from disk</param> /// <param name="isParent">wether tab is parent or a child</param> /// <returns>Format</returns> static public MPrintFormat Get(Ctx ctx, int AD_PrintFormat_ID, bool readFromDisk) { int key = AD_PrintFormat_ID; MPrintFormat pf = null; if (!readFromDisk) { pf = (MPrintFormat)s_formats[key]; } if (pf != null) { if (string.IsNullOrEmpty(pf.GetCtx().GetContext("#TimezoneOffset"))) { pf.GetCtx().SetContext("#TimezoneOffset", ctx.GetContext("#TimezoneOffset")); } } if (pf == null) { pf = new MPrintFormat(ctx, AD_PrintFormat_ID, null); pf.GetCtx().SetContext("#TimezoneOffset", ctx.GetContext("#TimezoneOffset")); s_formats.Add(key, pf); } return(pf); } // get
} // launchReport /// <summary> /// Launch Report /// </summary> /// <param name="pf">PrintFormat Object</param> private void LaunchReport(MPrintFormat pf) { //Code to preload the format (not include as user can change setting at the last moment ) int Record_ID = 0; if (_query.GetRestrictionCount() == 1 && (_query.GetCode(0)).GetType() == typeof(int)) { Record_ID = ((int)_query.GetCode(0)); } PrintInfo info = new PrintInfo(pf.GetName(), pf.GetAD_Table_ID(), Record_ID); info.SetDescription(_query.GetInfo()); ReportEngine_N re = new ReportEngine_N(Env.GetContext(), pf, _query, info); //new Viewer(re); //new ReportDialog(pf, _query); } // launchReport
} // addMissingColumns /// <summary> /// /// </summary> /// <param name="pf"></param> /// <returns></returns> public int AddMissingColumns(MPrintFormat pf) { String sql = "SELECT c.AD_Column_ID, c.ColumnName " + "FROM AD_Column c " + "WHERE NOT EXISTS " + "(SELECT * " + "FROM AD_PrintFormatItem pfi" + " INNER JOIN AD_PrintFormat pf ON (pfi.AD_PrintFormat_ID=pf.AD_PrintFormat_ID) " + "WHERE pf.AD_Table_ID=c.AD_Table_ID" + " AND pfi.AD_Column_ID=c.AD_Column_ID" + " AND pfi.AD_PrintFormat_ID='" + pf.GetAD_PrintFormat_ID() + "')" // 1 + " AND c.AD_Table_ID='" + pf.GetAD_Table_ID() + "' " // 2 + "ORDER BY 1"; int counter = 0; IDataReader dr = null; try { dr = DataBase.DB.ExecuteReader(sql); while (dr.Read()) { int AD_Column_ID = Utility.Util.GetValueOfInt(dr[0].ToString()); String ColumnName = dr.GetString(1); MPrintFormatItem pfi = MPrintFormatItem.CreateFromColumn(pf, AD_Column_ID, 0); if (pfi.Get_ID() != 0) { //log } else { //log } } dr.Close(); } catch (Exception e) { if (dr != null) { dr.Close(); } log.Severe(e.ToString()); } return(counter); } // addMissingColumns
} // setItems /// <summary> /// Copy Items /// </summary> /// <param name="fromFormat">from print format</param> /// <param name="toFormat">to print format (client, id)</param> /// <returns>items</returns> static private MPrintFormatItem[] CopyItems(MPrintFormat fromFormat, MPrintFormat toFormat) { List <MPrintFormatItem> list = new List <MPrintFormatItem>(); MPrintFormatItem[] items = fromFormat.GetItems(); for (int i = 0; i < items.Length; i++) { MPrintFormatItem pfi = items[i].CopyToClient(toFormat.GetAD_Client_ID(), toFormat.Get_ID()); if (pfi != null) { list.Add(pfi); } } // MPrintFormatItem[] retValue = new MPrintFormatItem[list.Count]; retValue = list.ToArray(); CopyTranslationItems(items, retValue); // JTP fix return(retValue); } // copyItems
} // prepare /// <summary> /// doit /// </summary> /// <returns>info</returns> protected override string DoIt() { if (_AD_Table_ID != null && int.Parse(_AD_Table_ID.ToString()) > 0) { MPrintFormat pf = MPrintFormat.CreateFromTable(GetCtx(), int.Parse(_AD_Table_ID.ToString()), GetRecord_ID()); AddLog(Utility.Util.GetValueOfInt(_AD_Table_ID.ToString()), null, pf.GetItemCount(), pf.GetName()); return(pf.GetName() + " #" + pf.GetItemCount()); } else if (_AD_PrintFormat_ID != null && _AD_PrintFormat_ID > 0) { MPrintFormat pf = MPrintFormat.Copy(GetCtx(), Utility.Util.GetValueOfInt(_AD_PrintFormat_ID.ToString()), GetRecord_ID()); AddLog(Utility.Util.GetValueOfInt(_AD_PrintFormat_ID.ToString()), null, pf.GetItemCount(), pf.GetName()); return(pf.GetName() + " #" + pf.GetItemCount()); } else { throw new Exception(msgInvalidArguments); } }
} // getColumnName /// <summary> /// Create Print Format Item from Column /// </summary> /// <param name="format">parent</param> /// <param name="AD_Column_ID">column</param> /// <param name="seqNo">sequence of display if 0 it is not printed</param> /// <returns>Format Item</returns> public static MPrintFormatItem CreateFromColumn(MPrintFormat format, int AD_Column_ID, int seqNo) { MPrintFormatItem pfi = new MPrintFormatItem(format.GetCtx(), 0, null); pfi.SetAD_PrintFormat_ID(format.GetAD_PrintFormat_ID()); pfi.SetClientOrg(format); pfi.SetAD_Column_ID(AD_Column_ID); pfi.SetPrintFormatType(PRINTFORMATTYPE_Field); //SqlParameter[] param = null; // translation is dome by trigger String sql = "SELECT c.ColumnName,e.Name,e.PrintName, " // 1..3 + "c.AD_Reference_ID,c.IsKey,c.SeqNo " // 4..6 + "FROM AD_Column c, AD_Element e " + "WHERE c.AD_Column_ID='" + AD_Column_ID + "'" + " AND c.AD_Element_ID=e.AD_Element_ID"; // translate base entry if single language - trigger copies to trl tables //Boolean trl = !Env.IsMultiLingualDocument(format.GetCtx()) && !GlobalVariable.IsBaseLanguage(); Boolean trl = !Env.IsMultiLingualDocument(format.GetCtx()) && !Language.IsBaseLanguage(Login.Language.GetBaseAD_Language()); if (trl) { sql = "SELECT c.ColumnName,e.Name,e.PrintName, " // 1..3 + "c.AD_Reference_ID,c.IsKey,c.SeqNo " // 4..6 + "FROM AD_Column c, AD_Element_Trl e " + "WHERE c.AD_Column_ID='" + AD_Column_ID + "'" + " AND c.AD_Element_ID=e.AD_Element_ID" + " AND e.AD_Language='" + GlobalVariable.GetLanguageCode() + "'"; } IDataReader dr = null; try { dr = SqlExec.ExecuteQuery.ExecuteReader(sql); if (dr.Read()) { String ColumnName = dr[0].ToString(); pfi.SetName(dr[1].ToString()); pfi.SetPrintName(dr[2].ToString()); int displayType = dr[3].ToString() != "" ? Utility.Util.GetValueOfInt(dr[3].ToString()) : 0; if (DisplayType.IsNumeric(displayType)) { pfi.SetFieldAlignmentType(FIELDALIGNMENTTYPE_TrailingRight); } else if (displayType == DisplayType.Text || displayType == DisplayType.Memo) { pfi.SetFieldAlignmentType(FIELDALIGNMENTTYPE_Block); } else { pfi.SetFieldAlignmentType(FIELDALIGNMENTTYPE_LeadingLeft); } Boolean isKey = "Y".Equals(dr[4].ToString()); // if (isKey || ColumnName.StartsWith("Created") || ColumnName.StartsWith("Updated") || ColumnName.Equals("AD_Client_ID") || ColumnName.Equals("AD_Org_ID") || ColumnName.Equals("IsActive") || ColumnName.Equals("Export_ID") || displayType == DisplayType.Button || displayType == DisplayType.Binary || displayType == DisplayType.ID || displayType == DisplayType.Image || displayType == DisplayType.RowID || seqNo == 0) { pfi.SetIsPrinted(false); pfi.SetSeqNo(0); } else { pfi.SetIsPrinted(true); pfi.SetSeqNo(seqNo); } int idSeqNo = dr[5].ToString() != "" ? Utility.Util.GetValueOfInt(dr[5].ToString()) : 0; // IsIdentifier SortNo if (idSeqNo > 0) { pfi.SetIsOrderBy(true); pfi.SetSortNo(idSeqNo); } } dr.Close(); } catch (Exception e) { if (dr != null) { dr.Close(); } s_log.Severe(e.ToString()); } if (!pfi.Save()) { return(null); } // pfi.dump(); return(pfi); } // createFromColumn
} // createFromTable /// <summary> /// Create MPrintFormat for ReportView /// </summary> /// <param name="ctx">context</param> /// <param name="AD_ReportView_ID">AD_ReportView_ID</param> /// <param name="ReportName">optional Report Name</param> /// <returns>print format</returns> static public MPrintFormat CreateFromReportView(Ctx ctx, int AD_ReportView_ID, String ReportName) { int AD_Client_ID = ctx.GetAD_Client_ID(); MPrintFormat pf = new MPrintFormat(ctx, 0, null); pf.SetAD_ReportView_ID(AD_ReportView_ID); // Get Info String sql = "SELECT t.TableName," + " (SELECT COUNT(*) FROM AD_PrintFormat x WHERE x.AD_ReportView_ID=rv.AD_ReportView_ID AND x.AD_Client_ID=c.AD_Client_ID) AS Count," + " COALESCE (cpc.AD_PrintColor_ID, pc.AD_PrintColor_ID) AS AD_PrintColor_ID," + " COALESCE (cpf.AD_PrintFont_ID, pf.AD_PrintFont_ID) AS AD_PrintFont_ID," + " COALESCE (cpp.AD_PrintPaper_ID, pp.AD_PrintPaper_ID) AS AD_PrintPaper_ID," + " t.AD_Table_ID " + "FROM AD_ReportView rv" + " INNER JOIN AD_Table t ON (rv.AD_Table_ID=t.AD_Table_ID)," + " AD_Client c" + " LEFT OUTER JOIN AD_PrintColor cpc ON (cpc.AD_Client_ID=c.AD_Client_ID AND cpc.IsDefault='Y')" + " LEFT OUTER JOIN AD_PrintFont cpf ON (cpf.AD_Client_ID=c.AD_Client_ID AND cpf.IsDefault='Y')" + " LEFT OUTER JOIN AD_PrintPaper cpp ON (cpp.AD_Client_ID=c.AD_Client_ID AND cpp.IsDefault='Y')," + " AD_PrintColor pc, AD_PrintFont pf, AD_PrintPaper pp " + "WHERE rv.AD_ReportView_ID='" + AD_ReportView_ID + "' AND c.AD_Client_ID='" + AD_Client_ID + "'" + " AND pc.IsDefault='Y' AND pf.IsDefault='Y' AND pp.IsDefault='Y'"; bool error = true; IDataReader dr = null; try { dr = SqlExec.ExecuteQuery.ExecuteReader(sql); while (dr.Read()) { // Name String name = ReportName; if (name == null || name.Length == 0) { name = dr[0].ToString(); // TableName } int count = Utility.Util.GetValueOfInt(dr[1].ToString()); if (count > 0) { name += "_" + count; } pf.SetName(name); // pf.SetAD_PrintColor_ID(Utility.Util.GetValueOfInt(dr[2].ToString())); pf.SetAD_PrintFont_ID(Utility.Util.GetValueOfInt(dr[3].ToString())); pf.SetAD_PrintPaper_ID(Utility.Util.GetValueOfInt(dr[4].ToString())); // pf.SetAD_Table_ID(Utility.Util.GetValueOfInt(dr[5].ToString())); error = false; } dr.Close(); } catch (Exception e) { if (dr != null) { dr.Close(); } s_log.Severe(e.ToString()); //log. if any } if (error) { return(null); } // Save & complete if (!pf.Save()) { return(null); } // pf.dump(); pf.SetItems(CreateItems(ctx, pf)); // return(pf); } // createFromReportView
} // createFromTable /// <summary> /// Create MPrintFormat for Table /// </summary> /// <param name="ctx">context</param> /// <param name="AD_Table_ID">AD_Table_ID</param> /// <param name="AD_PrintFormat_ID">AD_PrintFormat_ID</param> /// <returns>print format</returns> static public MPrintFormat CreateFromTable(Ctx ctx, int AD_Table_ID, int AD_PrintFormat_ID, int AD_Tab_ID) { int AD_Client_ID = ctx.GetAD_Client_ID(); MPrintFormat pf = new MPrintFormat(ctx, AD_PrintFormat_ID, null); pf.SetAD_Table_ID(AD_Table_ID); if (AD_Tab_ID > 0) { pf.SetAD_Tab_ID(AD_Tab_ID); } // Get Info String sql = "SELECT TableName," // 1 + " (SELECT COUNT(*) FROM AD_PrintFormat x WHERE x.AD_Table_ID=t.AD_Table_ID AND x.AD_Client_ID=c.AD_Client_ID) AS Count," + " COALESCE (cpc.AD_PrintColor_ID, pc.AD_PrintColor_ID) AS AD_PrintColor_ID," // 3 + " COALESCE (cpf.AD_PrintFont_ID, pf.AD_PrintFont_ID) AS AD_PrintFont_ID," + " COALESCE (cpp.AD_PrintPaper_ID, pp.AD_PrintPaper_ID) AS AD_PrintPaper_ID " + "FROM AD_Table t, AD_Client c" + " LEFT OUTER JOIN AD_PrintColor cpc ON (cpc.AD_Client_ID=c.AD_Client_ID AND cpc.IsDefault='Y')" + " LEFT OUTER JOIN AD_PrintFont cpf ON (cpf.AD_Client_ID=c.AD_Client_ID AND cpf.IsDefault='Y')" + " LEFT OUTER JOIN AD_PrintPaper cpp ON (cpp.AD_Client_ID=c.AD_Client_ID AND cpp.IsDefault='Y')," + " AD_PrintColor pc, AD_PrintFont pf, AD_PrintPaper pp " + "WHERE t.AD_Table_ID='" + AD_Table_ID + "' AND c.AD_Client_ID='" + AD_Client_ID + "'" // #1/2 + " AND pc.IsDefault='Y' AND pf.IsDefault='Y' AND pp.IsDefault='Y'"; string sql1 = "SELECT "; string AD_Language = Utility.Env.GetAD_Language(ctx); if (AD_Language == null || AD_Language.Length == 0 || Env.IsBaseLanguage(AD_Language, "AD_Element")) { sql1 = sql1 + " t.Name, (SELECT COUNT(*) FROM AD_PrintFormat x WHERE x.AD_Tab_ID =t.AD_Tab_ID " + "AND x.AD_Client_ID=c.AD_Client_ID ) AS COUNT FROM AD_Tab t ,AD_Client c " + "WHERE t.AD_Tab_ID ='" + AD_Tab_ID + "' AND c.AD_Client_ID='" + AD_Client_ID + "'"; } else { sql1 = sql1 + " Distinct tt.Name, (SELECT COUNT(*) FROM AD_PrintFormat x WHERE x.AD_Tab_ID =t.AD_Tab_ID AND x.AD_Client_ID=c.AD_Client_ID ) AS COUNT" + "FROM AD_Client c, AD_Tab t JOIN AD_Tab_Trl tt ON (tt.AD_Tab_ID=t.ad_tab_id)" + "WHERE t.AD_Tab_ID ='" + AD_Tab_ID + "' AND tt.AD_Language='" + AD_Language + "'" + "AND c.AD_Client_ID='" + AD_Client_ID + "'"; } bool error = true; IDataReader dr = null; IDataReader idr = null; String s = ""; int count = 0; try { dr = SqlExec.ExecuteQuery.ExecuteReader(sql); idr = SqlExec.ExecuteQuery.ExecuteReader(sql1); while (idr.Read()) { s = idr[0].ToString(); count = Util.GetValueOfInt(idr[1]); } idr.Close(); while (dr.Read()) { //int count = countrec; if (count == 0 && s == null || s == "") { count = Utility.Util.GetValueOfInt(dr[1].ToString()); } // Name if (s == null || s == "") { String TableName = dr[0].ToString(); String ColumnName = TableName + "_ID"; s = ColumnName; if (!ColumnName.Equals("T_Report_ID")) { s = Msg.Translate(ctx, ColumnName); if (ColumnName.Equals(s)) // not found { s = Msg.Translate(ctx, TableName); } } } if (count > 0) { s += "_" + (count + 1); } pf.SetName(s); // pf.SetAD_PrintColor_ID(Utility.Util.GetValueOfInt(dr[2].ToString())); pf.SetAD_PrintFont_ID(Utility.Util.GetValueOfInt(dr[3].ToString())); pf.SetAD_PrintPaper_ID(Utility.Util.GetValueOfInt(dr[4].ToString())); // error = false; break; } dr.Close(); } catch (Exception e) { if (idr != null) { idr.Close(); } if (dr != null) { dr.Close(); } s_log.Severe(e.ToString()); } if (error) { return(null); } // Save & complete if (!pf.Save()) { return(null); } // pf.dump(); pf.SetItems(CreateItems(ctx, pf)); // return(pf); } // createFromTable
} // copy /// <summary> /// Create Items. /// Using the display order of Fields in some Tab /// </summary> /// <param name="ctx">context</param> /// <param name="format">format</param> /// <returns>items</returns> static private MPrintFormatItem[] CreateItems(Ctx ctx, MPrintFormat format) { List <MPrintFormatItem> list = new List <MPrintFormatItem>(); // Get Column List from Tab String sql = "SELECT AD_Column_ID " //, Name, IsDisplayed, SeqNo + "FROM AD_Field " + "WHERE AD_Tab_ID=(SELECT MIN(AD_Tab_ID) FROM AD_Tab WHERE AD_Table_ID=@AD_Table_ID)" + " AND IsEncrypted='N' AND IsDisplayed='Y' AND ObscureType IS NULL " + "ORDER BY COALESCE(IsDisplayed,'N') DESC, SortNo, COALESCE(MRSeqNo, SeqNo), Name"; IDataReader dr = null; try { SqlParameter[] param = new SqlParameter[1]; param[0] = new SqlParameter("@AD_Table_ID", format.GetAD_Table_ID()); dr = SqlExec.ExecuteQuery.ExecuteReader(sql, param); int seqNo = 1; while (dr.Read()) { MPrintFormatItem pfi = MPrintFormatItem.CreateFromColumn(format, Utility.Util.GetValueOfInt(dr[0].ToString()), seqNo++); if (pfi != null) { list.Add(pfi); } } dr.Close(); } catch (Exception e) { if (dr != null) { dr.Close(); } s_log.Severe(e.ToString()); //log, if any } // No Tab found for Table if (list.Count == 0) { sql = "SELECT AD_Column_ID " + "FROM AD_Column " + "WHERE AD_Table_ID='" + format.GetAD_Table_ID() + "' " + "ORDER BY IsIdentifier DESC, SeqNo, Name"; IDataReader idr = null; try { idr = SqlExec.ExecuteQuery.ExecuteReader(sql); // DataTable dt = new DataTable(); //dt.Load(idr); int seqNo = 1; while (idr.Read()) { MPrintFormatItem pfi = MPrintFormatItem.CreateFromColumn(format, Utility.Util.GetValueOfInt(idr[0].ToString()), seqNo++); if (pfi != null) { list.Add(pfi); } } idr.Close(); } catch (Exception e) { if (idr != null) { idr.Close(); } s_log.Severe(e.ToString()); //log, if any } } // MPrintFormatItem[] retValue = new MPrintFormatItem[list.Count]; retValue = list.ToArray(); return(retValue); } // createItems
} // createNewFormat /// <summary> /// Copy the existing format /// </summary> /// <param name="AD_PrintFormat_ID">print format id</param> /// <param name="To_Client_ID">client id</param> private void CopyFormat(int AD_PrintFormat_ID, int To_Client_ID) { MPrintFormat pf = MPrintFormat.CopyToClient(Env.GetContext(), AD_PrintFormat_ID, To_Client_ID); LaunchReport(pf); } // copyFormatFromClient
/// <summary> /// Creates the new format /// </summary> /// <param name="AD_Table_ID">table id</param> private void CreateNewFormat(int AD_Table_ID) { MPrintFormat pf = MPrintFormat.CreateFromTable(Env.GetContext(), AD_Table_ID); LaunchReport(pf); } // createNewFormat
/// <summary> /// Launch Report /// </summary> /// <param name="pp">KeyNamePair values</param> private void LaunchReport(KeyNamePair pp) { MPrintFormat pf = MPrintFormat.Get(Env.GetContext(), pp.GetKey(), true); LaunchReport(pf); } // launchReport
} // copy /// <summary> /// Create Items. /// Using the display order of Fields in some Tab /// </summary> /// <param name="ctx">context</param> /// <param name="format">format</param> /// <returns>items</returns> /// <summary> /// Create Items. /// Using the display order of Fields in some Tab /// </summary> /// <param name="ctx">context</param> /// <param name="format">format</param> /// <returns>items</returns> static private MPrintFormatItem[] CreateItems(Ctx ctx, MPrintFormat format, int AD_tab_ID, bool isMRSeq = false) { List <MPrintFormatItem> list = new List <MPrintFormatItem>(); bool runOldCode = true; // Get Column List from Tab String sql = "SELECT AD_Column_ID " //, Name, IsDisplayed, SeqNo + "FROM AD_Field " + "WHERE "; if (AD_tab_ID == 0) { sql += " AD_Tab_ID=(SELECT MIN(AD_Tab_ID) FROM AD_Tab WHERE AD_Table_ID=@AD_Table_ID)"; } else { sql += " AD_Tab_ID=@AD_Table_ID"; } //added check on 03/12/14 - "AND IsDisplayed='Y' AND IsActive='Y'" sql += " AND IsEncrypted='N' AND (IsDisplayed='Y' OR MRISDISPLAYED='Y') AND IsActive='Y' AND ObscureType IS NULL "; //Lakhwinder if (isMRSeq) { try { runOldCode = false; sql = "SELECT AD_Column_ID,Ad_Field_ID FROM AD_Field WHERE "; if (AD_tab_ID == 0) { sql += " AD_Tab_ID=(SELECT MIN(AD_Tab_ID) FROM AD_Tab WHERE AD_Table_ID=@AD_Table_ID)"; } else { sql += " AD_Tab_ID=@AD_Table_ID"; } //added check on 03/12/14 - "AND IsDisplayed='Y' AND IsActive='Y'" sql += " AND IsEncrypted='N' AND (IsDisplayed='Y' OR MRISDISPLAYED='Y') AND IsActive='Y' AND ObscureType IS NULL "; bool isMESeqDefined = false; //if multirow sequence is set on tab then MRIsDisplayed Column does have non null value int count = Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(*) FROM AD_Field WHERE AD_Tab_ID =" + AD_tab_ID + " AND MRIsDisplayed IS NOT NULL")); if (count > 0)//tab has defined multirow sequence { isMESeqDefined = true; sql += " ORDER BY MRSeqNo "; } else//tab has undefined multirow sequence { sql += " ORDER BY NVL(MRSeqNo,999999),Name "; } SqlParameter[] param = new SqlParameter[1]; if (AD_tab_ID == 0) { param[0] = new SqlParameter("@AD_Table_ID", format.GetAD_Table_ID()); } else { param[0] = new SqlParameter("@AD_Table_ID", AD_tab_ID); } DataSet ds = DB.ExecuteDataset(sql, param); if (ds != null && ds.Tables[0].Rows.Count > 0) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { MPrintFormatItem pfi = MPrintFormatItem.CreateFromColumn(format, Util.GetValueOfInt(ds.Tables[0].Rows[i]["AD_Column_ID"]), Util.GetValueOfInt(ds.Tables[0].Rows[i]["AD_Field_ID"]), i + 1, isMESeqDefined); if (pfi != null) { list.Add(pfi); } } } } catch { runOldCode = true; sql += " ORDER BY COALESCE(MRISDISPLAYED,IsDisplayed) DESC, SortNo, MRSeqNo, COALESCE(IsDisplayed,'N'), SeqNo"; } } else { sql += " ORDER BY COALESCE(MRISDISPLAYED,IsDisplayed) DESC, SortNo, MRSeqNo, COALESCE(IsDisplayed,'N'), SeqNo"; } // + "ORDER BY COALESCE(IsDisplayed,'N') DESC, SortNo, COALESCE(MRSeqNo, SeqNo), Name"; if (runOldCode) { IDataReader dr = null; try { SqlParameter[] param = new SqlParameter[1]; if (AD_tab_ID == 0) { param[0] = new SqlParameter("@AD_Table_ID", format.GetAD_Table_ID()); } else { param[0] = new SqlParameter("@AD_Table_ID", AD_tab_ID); } dr = SqlExec.ExecuteQuery.ExecuteReader(sql, param); int seqNo = 1; while (dr.Read()) { MPrintFormatItem pfi = MPrintFormatItem.CreateFromColumn(format, Utility.Util.GetValueOfInt(dr[0].ToString()), seqNo++); if (pfi != null) { list.Add(pfi); } } dr.Close(); } catch (Exception e) { if (dr != null) { dr.Close(); } s_log.Severe(e.ToString()); //log, if any } } // No Tab found for Table if (list.Count == 0) { sql = "SELECT AD_Column_ID " + "FROM AD_Column " + "WHERE AD_Table_ID='" + format.GetAD_Table_ID() + "' " + "ORDER BY IsIdentifier DESC, SeqNo, Name"; IDataReader idr = null; try { idr = SqlExec.ExecuteQuery.ExecuteReader(sql); // DataTable dt = new DataTable(); //dt.Load(idr); int seqNo = 1; while (idr.Read()) { MPrintFormatItem pfi = MPrintFormatItem.CreateFromColumn(format, Utility.Util.GetValueOfInt(idr[0].ToString()), seqNo++); if (pfi != null) { list.Add(pfi); } } idr.Close(); } catch (Exception e) { if (idr != null) { idr.Close(); } s_log.Severe(e.ToString()); //log, if any } } // MPrintFormatItem[] retValue = new MPrintFormatItem[list.Count]; retValue = list.ToArray(); return(retValue); } // createItems