Ejemplo n.º 1
0
        }       //	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
Ejemplo n.º 2
0
        }       //	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
Ejemplo n.º 3
0
        }       //	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