Ejemplo n.º 1
0
        private void CallProcess(int lead_id)
        {
            string sql           = "select ad_process_id from ad_process where name = 'C_Lead BPartner'";
            int    AD_Process_ID = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_TrxName())); // 1000025;

            MPInstance instance = new MPInstance(GetCtx(), AD_Process_ID, GetRecord_ID());

            if (!instance.Save())
            {
                return;
            }

            ProcessInfo pi = new ProcessInfo("VInOutGen", AD_Process_ID);

            pi.SetAD_PInstance_ID(instance.GetAD_PInstance_ID());

            // Add Parameter - Selection=Y
            MPInstancePara para = new MPInstancePara(instance, 10);

            // Add Parameter - M_Warehouse_ID=x
            para = new MPInstancePara(instance, 20);
            para.setParameter("_C_Lead_ID", lead_id);
            if (!para.Save())
            {
                String msg = "No DocAction Parameter added";  //  not translated
                // lblStatusInfo.Text = msg.ToString();
                log.Log(Level.SEVERE, msg);
                return;
            }

            //Execute Process
            //ASyncProcess asp=null;
            //ProcessCtl worker = new ProcessCtl(asp,pi, null);
            //worker.Run();     //  complete tasks in unlockUI / generateInvoice_complete
        }
        }       //	getParameter

        /**************************************************************************
         *  Process SQL Procedures w/o parameter
         *	@param Record_ID record
         *	@return Process Instance
         */
        public MPInstance ProcessIt(int Record_ID)
        {
            MPInstance pInstance = new MPInstance(this, Record_ID);

            //	Lock
            pInstance.SetIsProcessing(true);
            //pInstance.save();

            bool ok = true;

            //	PL/SQL Procedure
            String ProcedureName = GetProcedureName();

            //	String Classname = getClassname();
            if (ProcedureName != null && ProcedureName.Length > 0)
            {
                ok = StartProcess(ProcedureName, pInstance);
            }
            //	else if (Classname != null && Classname.length() > 0)
            //		ok = startClass(Classname, pi, trx);


            //	Unlock
            pInstance.SetResult(ok ? MPInstance.RESULT_OK : MPInstance.RESULT_ERROR);
            pInstance.SetIsProcessing(false);
            //pInstance.save();
            //
            //pInstance.log();
            return(pInstance);
        }       //	process
Ejemplo n.º 3
0
        //public JsonResult SaveChangePassword(int AD_User_ID, string currentPws, string newPws)
        //{
        //    if (Session["Ctx"] != null)
        //    {
        //        var ctx = Session["ctx"] as Ctx;
        //        UserPreferenceModel obj = new UserPreferenceModel();
        //        var val = obj.SaveChangePassword(ctx, AD_User_ID, currentPws, newPws);
        //        return Json(new { result = val }, JsonRequestBehavior.AllowGet);
        //    }
        //    return Json(new { result = "ok" }, JsonRequestBehavior.AllowGet);
        //}
        /// <summary>
        /// Change login user password
        /// </summary>
        /// <param name="AD_User_ID"></param>
        /// <param name="currentPws"></param>
        /// <param name="newPws"></param>
        /// <returns></returns>
        public JsonResult SaveChangePassword(int AD_User_ID, string currentPws, string newPws)
        {
            string message = string.Empty;

            if (Session["Ctx"] != null)
            {
                String msg = "";
                var    ctx = Session["ctx"] as Ctx;

                var AD_Process_ID = Util.GetValueOfInt(DB.ExecuteScalar("SELECT AD_PROCESS_ID  FROM AD_PROCESS WHERE NAME = 'Reset Your Password'", null, null)); // Get Reset Your Password process id
                // Prepare Process
                MPInstance instance = new MPInstance(ctx, AD_Process_ID, 0);                                                                                      // create object of MPInstance
                if (!instance.Save())
                {
                    msg = Msg.GetMsg(ctx, "ProcessNoInstance");
                    return(Json(new { result = msg }, JsonRequestBehavior.AllowGet));
                }
                VAdvantage.ProcessEngine.ProcessInfo pi = new VAdvantage.ProcessEngine.ProcessInfo("ChangePassword", AD_Process_ID);
                pi.SetAD_PInstance_ID(instance.GetAD_PInstance_ID());
                pi.SetAD_User_ID(AD_User_ID);
                pi.SetAD_Client_ID(ctx.GetAD_Client_ID());
                // Add Parameter - CurrentPassword
                MPInstancePara para = new MPInstancePara(instance, 10);

                para.setParameter("CurrentPassword", currentPws);
                if (!para.Save())
                {
                    msg = "No Selection Parameter added";   //  not translated
                    // msg = Msg.GetMsg(ctx, "ProcessNoInstance");
                    return(Json(new { result = msg }, JsonRequestBehavior.AllowGet));
                }
                // Add Parameter - NewPassword
                para = new MPInstancePara(instance, 20);
                para.setParameter("NewPassword", newPws);
                if (!para.Save())
                {
                    msg = "No DocAction Parameter added";   //  not translated
                    // msg = Msg.GetMsg(ctx, "ProcessNoInstance");
                    return(Json(new { result = msg }, JsonRequestBehavior.AllowGet));
                }
                para = new MPInstancePara(instance, 30);
                para.setParameter("AD_User_ID", AD_User_ID);
                if (!para.Save())
                {
                    msg = "No DocAction Parameter added";  //  not translated
                    //msg = Msg.GetMsg(ctx, "ProcessNoInstance");
                    return(Json(new { result = msg }, JsonRequestBehavior.AllowGet));
                }
                ASyncProcess _parent = null;
                // Execute Process
                ProcessCtl worker = new ProcessCtl(ctx, _parent, pi, null);

                worker.Run();     //  complete tasks in unlockUI / generateInvoice_complete
                message = pi.GetSummary();
            }
            return(Json(new { result = message }, JsonRequestBehavior.AllowGet));
            //return Json(new { result = "ok" }, JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// Based on Report ID, Generate report and then save it in physcal location
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="_trx"></param>
        /// <param name="AD_TableID"></param>
        /// <param name="recordID"></param>
        /// <param name="AD_UserID"></param>
        /// <param name="AD_ClientID"></param>
        /// <param name="nodeName"></param>
        /// <param name="windowID"></param>
        /// <param name="WFActivity"></param>
        /// <returns>file info.</returns>
        public FileInfo GetPdfReportForMail(Ctx ctx, Trx _trx, int AD_TableID, int recordID, int AD_UserID, int AD_ClientID, string nodeName, int windowID, int WFActivity)
        {
            try
            {
                int reportID = GetDoctypeBasedReport(ctx, AD_TableID, recordID, windowID, WFActivity);

                if (reportID == 0)
                {
                    VLogger.Get().Warning("No Report found on DocType and Window Tab. For Table=" + AD_TableID);
                    return(null);
                }
                FileInfo temp    = null;
                MProcess process = MProcess.Get(ctx, reportID);

                ProcessInfo pi = new ProcessInfo(nodeName, reportID,
                                                 AD_TableID, recordID);
                pi.SetAD_User_ID(AD_UserID);
                pi.SetAD_Client_ID(AD_ClientID);
                MPInstance pInstance = new MPInstance(process, recordID);
                //FillParameter(pInstance, trx);
                pi.SetAD_PInstance_ID(pInstance.GetAD_PInstance_ID());

                if (process.GetIsCrystalReport() == "Y")
                {
                    pi.SetIsCrystal(true);
                }
                else
                {
                    pi.SetIsCrystal(false);
                }

                pi.SetAD_ReportFormat_ID(process.GetAD_ReportFormat_ID());
                pi.SetAD_ReportMaster_ID(process.GetAD_ReportMaster_ID());
                process.ProcessIt(pi, _trx);

                IReportEngine repo    = ReportRun(pi, ctx, _trx);
                byte[]        bytes   = repo.GetReportBytes();
                string        repPath = repo.GetReportFilePath(true, out bytes);

                repPath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + repPath;
                ctx.SetContext("FetchingDocReport", "N");
                if (!string.IsNullOrEmpty(repPath))
                {
                    temp = new FileInfo(repPath);
                    if (temp.Exists)
                    {
                        return(temp);
                    }
                    return(null);
                }
                return(null);
            }
            catch
            {
                ctx.SetContext("FetchingDocReport", "N");
                return(null);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="AD_Column_ID"></param>
        /// <param name="AD_Table_ID"></param>
        /// <returns></returns>
        public string CreateMasterVersionTable(int AD_Column_ID, int AD_Table_ID)
        {
            int        AD_Process_ID = Util.GetValueOfInt(DB.ExecuteScalar("SELECT AD_Process_ID FROM AD_Process WHERE Value = 'MasterDataVersions'", null, Get_Trx()));
            MPInstance instance      = new MPInstance(GetCtx(), AD_Process_ID, 0);

            if (!instance.Save())
            {
                log.Info(Msg.GetMsg(GetCtx(), "ProcessNoInstance"));
                return(Msg.GetMsg(GetCtx(), "ProcessNoInstance"));
            }

            ProcessInfo pi = new ProcessInfo("", AD_Process_ID);

            pi.SetAD_PInstance_ID(instance.GetAD_PInstance_ID());
            pi.SetAD_Client_ID(GetCtx().GetAD_Client_ID());

            //	Add Parameters
            MPInstancePara para = new MPInstancePara(instance, 10);

            //para.setParameter("Selection", "Y");
            para.setParameter("AD_Table_ID", AD_Table_ID);
            if (!para.Save())
            {
                String msg = "Table parameter not found";
                log.Info(msg.ToString());
                //log.Log(Level.SEVERE, msg);
                return(msg.ToString());
            }

            para = new MPInstancePara(instance, 20);
            para.setParameter("AD_Column_ID", AD_Column_ID);
            if (!para.Save())
            {
                String msg = "Column parameter not found";
                log.Info(msg.ToString());
                //log.Log(Level.SEVERE, msg);
                return(msg.ToString());
            }

            ProcessCtl worker = new ProcessCtl(GetCtx(), null, pi, Get_Trx());

            worker.Run();
            string retMsg = pi.GetSummary();

            return("Test");
        }
        }       //	process

        /**
         *  Process It (sync)
         *	@param pi Process Info
         *	@param trx transaction
         *	@return true if OK
         */
        public bool ProcessIt(ProcessInfo pi, Trx trx)
        {
            if (pi.GetAD_PInstance_ID() == 0)
            {
                MPInstance pInstance = new MPInstance(this, pi.GetRecord_ID());
                //	Lock
                pInstance.SetIsProcessing(true);
                pInstance.Save();
            }

            bool ok = false;

            //	 Class
            String Classname = GetClassname();

            if (Classname != null && Classname.Length > 0)
            {
                ok = StartClass(Classname, pi, trx);
            }
            // checked if procedure is linked with Process
            // then execute procedure
            else if (GetProcedureName() != null && GetProcedureName().Trim().Length > 0)
            {
                ProcessCtl pc = new ProcessCtl(GetCtx(), null, pi, trx);
                ok = pc.StartDBProcess(GetProcedureName());
            }
            else
            {
                if (!IsReport())
                {
                    String msg = "No Classname for " + GetName();
                    pi.SetSummary(msg, ok);
                }
                else
                {
                    String msg = Msg.GetMsg(GetCtx(), "Success") + " " + GetValue();
                    pi.SetSummary(msg, ok);
                }
                //log.warning(msg);
            }

            return(ok);
        }
        // vinay bhatt window id

        /// <summary>
        /// Excecute Process
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="AD_Process_ID"></param>
        /// <param name="Name"></param>
        /// <param name="AD_Table_ID"></param>
        /// <param name="Record_ID"></param>
        /// <param name="WindowNo"></param>
        /// <param name="fileType"></param>
        /// <param name="AD_Window_ID"></param>
        /// <returns></returns>
        internal static ProcessReportInfo Process(Ctx ctx, Dictionary <string, string> processInfo)
        {
            ProcessReportInfo ret      = new ProcessReportInfo();
            MPInstance        instance = null;

            try
            {
                instance = new MPInstance(ctx, Util.GetValueOfInt(processInfo["Process_ID"]), Util.GetValueOfInt(processInfo["Record_ID"]));
            }
            catch (Exception e)
            {
                ret.IsError = true;
                ret.Message = e.Message;
                return(ret);
            }

            if (!instance.Save())
            {
                ret.IsError = true;
                ret.Message = Msg.GetMsg(ctx, "ProcessNoInstance");
                return(ret);
            }
            ret.AD_PInstance_ID = instance.GetAD_PInstance_ID();

            //	Get Parameters (Dialog)
            //Check If Contaon Parameter

            List <GridField> fields = ProcessParameter.GetParametersList(ctx, Util.GetValueOfInt(processInfo["Process_ID"]), Util.GetValueOfInt(processInfo["WindowNo"]));

            if (fields.Count < 1) //no Parameter
            {
                processInfo["AD_PInstance_ID"] = ret.AD_PInstance_ID.ToString();
                ret = ExecuteProcessCommon(ctx, processInfo, null);
            }
            else
            {
                ret.ShowParameter = true;
                ret.ProcessFields = fields;
            }
            return(ret);
        }
Ejemplo n.º 8
0
        internal static ProcessReportInfo Process(Ctx ctx, int AD_Process_ID, string Name, int AD_Table_ID, int Record_ID, int WindowNo, bool csv, bool pdf)
        {
            ProcessReportInfo ret      = new ProcessReportInfo();
            MPInstance        instance = null;

            try
            {
                instance = new MPInstance(ctx, AD_Process_ID, Record_ID);
            }
            catch (Exception e)
            {
                ret.IsError = true;
                ret.Message = e.Message;
                return(ret);
            }

            if (!instance.Save())
            {
                ret.IsError = true;
                ret.Message = Msg.GetMsg(ctx, "ProcessNoInstance");
                return(ret);
            }
            ret.AD_PInstance_ID = instance.GetAD_PInstance_ID();

            //	Get Parameters (Dialog)
            //Check If Contaon Parameter

            List <GridField> fields = ProcessParameter.GetParametersList(ctx, AD_Process_ID, WindowNo);

            if (fields.Count < 1) //no Parameter
            {
                ret = ExecuteProcess(ctx, AD_Process_ID, Name, ret.AD_PInstance_ID, AD_Table_ID, Record_ID, null, csv, pdf);
            }
            else
            {
                ret.ShowParameter = true;
                ret.ProcessFields = fields;
            }
            return(ret);
        }
        //public bool IsJavaProcess()
        //{
        //    String Classname = GetClassname();
        //    return (Classname != null && Classname.Length > 0);
        //}

        private bool StartProcess(String ProcedureName, MPInstance pInstance)
        {
            int AD_PInstance_ID = pInstance.GetAD_PInstance_ID();
            //  execute on this thread/connection
            String sql = "{call " + ProcedureName + "(@instanceid)}";

            try
            {
                SqlParameter[] param = new SqlParameter[1];
                param[0] = new SqlParameter("@instanceid", AD_PInstance_ID);
                int i = DataBase.DB.ExecuteQuery(sql, param);
            }
            catch (Exception e)
            {
                log.Log(VAdvantage.Logging.Level.SEVERE, sql, e);
                pInstance.SetResult(MPInstance.RESULT_ERROR);
                pInstance.SetErrorMsg(e.Message);
                return(false);
            }
            pInstance.SetResult(MPInstance.RESULT_OK);
            return(true);
        }
Ejemplo n.º 10
0
        }       //	process

        /**
         *  Process It (sync)
         *	@param pi Process Info
         *	@param trx transaction
         *	@return true if OK
         */
        public bool ProcessIt(ProcessInfo pi, Trx trx)
        {
            if (pi.GetAD_PInstance_ID() == 0)
            {
                MPInstance pInstance = new MPInstance(this, pi.GetRecord_ID());
                //	Lock
                pInstance.SetIsProcessing(true);
                pInstance.Save();
            }

            bool ok = false;

            //	Java Class
            String Classname = GetClassname();

            if (Classname != null && Classname.Length > 0)
            {
                ok = StartClass(Classname, pi, trx);
            }
            else
            {
                if (!IsReport())
                {
                    String msg = "No Classname for " + GetName();
                    pi.SetSummary(msg, ok);
                }
                else
                {
                    String msg = Msg.GetMsg(GetCtx(), "Success") + " " + GetValue();
                    pi.SetSummary(msg, ok);
                }
                //log.warning(msg);
            }

            return(ok);
        }
        /// <summary>
        /// Perform Process.
        /// - Fill Table with QtyOnHand for Warehouse and Valuation Date
        /// - Perform Price Calculations
        /// </summary>
        /// <returns>message</returns>
        protected override String DoIt()
        {
            log.Info("M_Warehouse_ID=" + _M_Warehouse_ID
                     + ",C_Currency_ID=" + _C_Currency_ID
                     + ",DateValue=" + _DateValue
                     + ",M_PriceList_Version_ID=" + _M_PriceList_Version_ID
                     + ",M_CostElement_ID=" + _M_CostElement_ID);

            MWarehouse  wh  = MWarehouse.Get(GetCtx(), _M_Warehouse_ID);
            MClient     c   = MClient.Get(GetCtx(), wh.GetAD_Client_ID());
            MAcctSchema mas = c.GetAcctSchema();

            //  Delete (just to be sure)
            StringBuilder sql = new StringBuilder("DELETE FROM T_InventoryValue WHERE AD_PInstance_ID=");

            sql.Append(GetAD_PInstance_ID());
            int        no          = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName());
            MPInstance instance    = new MPInstance(GetCtx(), GetAD_PInstance_ID(), null);
            DateTime   Createddate = instance.GetCreated();

            Createddate = Createddate.AddHours(-1);

            string qry            = "select MAX(AD_PINSTANCE_ID) from AD_PINSTANCE WHERE AD_Process_ID=" + instance.GetAD_Process_ID() + " AND created<  TO_Date('" + Createddate.ToString("MM/dd/yyyy HH:mm:ss") + "', 'MM-DD-YYYY HH24:MI:SS')";
            int    MaxInstance_ID = Util.GetValueOfInt(DB.ExecuteScalar(qry, null, null));

            int no1 = DB.ExecuteQuery("DELETE FROM T_InventoryValue WHERE AD_PInstance_ID <=" + MaxInstance_ID);

            //	Insert Standard Costs
            sql = new StringBuilder("INSERT INTO T_InventoryValue "
                                    + "(AD_PInstance_ID, M_Warehouse_ID, M_Product_ID, M_AttributeSetInstance_ID,"
                                    + " AD_Client_ID, AD_Org_ID, CostStandard) "
                                    + "SELECT ").Append(GetAD_PInstance_ID())
                  .Append(", w.M_Warehouse_ID, c.M_Product_ID, c.M_AttributeSetInstance_ID,"
                          + " w.AD_Client_ID, w.AD_Org_ID, c.CurrentCostPrice "
                          + "FROM M_Warehouse w"
                          + " INNER JOIN AD_ClientInfo ci ON (w.AD_Client_ID=ci.AD_Client_ID)"
                          + " INNER JOIN C_AcctSchema acs ON (ci.C_AcctSchema1_ID=acs.C_AcctSchema_ID)"
                          + " INNER JOIN M_Cost c ON (acs.C_AcctSchema_ID=c.C_AcctSchema_ID AND acs.M_CostType_ID=c.M_CostType_ID AND c.AD_Org_ID IN (0, w.AD_Org_ID))"
                          + " INNER JOIN M_CostElement ce ON (c.M_CostElement_ID=ce.M_CostElement_ID AND ce.CostingMethod='S' AND ce.CostElementType='M') "
                          + "WHERE w.M_Warehouse_ID=").Append(_M_Warehouse_ID);
            int noInsertStd = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName());

            log.Fine("Inserted Std=" + noInsertStd);
            if (noInsertStd == 0)
            {
                return("No Standard Costs found");
            }

            //	Insert addl Costs
            int noInsertCost = 0;

            if (_M_CostElement_ID != 0)
            {
                sql = new StringBuilder("INSERT INTO T_InventoryValue "
                                        + "(AD_PInstance_ID, M_Warehouse_ID, M_Product_ID, M_AttributeSetInstance_ID,"
                                        + " AD_Client_ID, AD_Org_ID, CostStandard, Cost, M_CostElement_ID) "
                                        + "SELECT ").Append(GetAD_PInstance_ID())
                      .Append(", w.M_Warehouse_ID, c.M_Product_ID, c.M_AttributeSetInstance_ID,"
                              + " w.AD_Client_ID, w.AD_Org_ID, 0, c.CurrentCostPrice, c.M_CostElement_ID "
                              + "FROM M_Warehouse w"
                              + " INNER JOIN AD_ClientInfo ci ON (w.AD_Client_ID=ci.AD_Client_ID)"
                              + " INNER JOIN C_AcctSchema acs ON (ci.C_AcctSchema1_ID=acs.C_AcctSchema_ID)"
                              + " INNER JOIN M_Cost c ON (acs.C_AcctSchema_ID=c.C_AcctSchema_ID AND acs.M_CostType_ID=c.M_CostType_ID AND c.AD_Org_ID IN (0, w.AD_Org_ID)) "
                              + "WHERE w.M_Warehouse_ID=").Append(_M_Warehouse_ID)
                      .Append(" AND c.M_CostElement_ID=").Append(_M_CostElement_ID)
                      .Append(" AND NOT EXISTS (SELECT * FROM T_InventoryValue iv "
                              + "WHERE iv.AD_PInstance_ID=").Append(GetAD_PInstance_ID())
                      .Append(" AND iv.M_Warehouse_ID=w.M_Warehouse_ID"
                              + " AND iv.M_Product_ID=c.M_Product_ID"
                              + " AND iv.M_AttributeSetInstance_ID=c.M_AttributeSetInstance_ID)");
                noInsertCost = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName());
                log.Fine("Inserted Cost=" + noInsertCost);
                //	Update Std Cost Records
                sql = new StringBuilder("UPDATE T_InventoryValue iv "
                                        + "SET (Cost, M_CostElement_ID)="
                                        + "(SELECT c.CurrentCostPrice, c.M_CostElement_ID "
                                        + "FROM M_Warehouse w"
                                        + " INNER JOIN AD_ClientInfo ci ON (w.AD_Client_ID=ci.AD_Client_ID)"
                                        + " INNER JOIN C_AcctSchema acs ON (ci.C_AcctSchema1_ID=acs.C_AcctSchema_ID)"
                                        + " INNER JOIN M_Cost c ON (acs.C_AcctSchema_ID=c.C_AcctSchema_ID"
                                        + " AND acs.M_CostType_ID=c.M_CostType_ID AND c.AD_Org_ID IN (0, w.AD_Org_ID)) "
                                        + "WHERE c.M_CostElement_ID=" + _M_CostElement_ID
                                        + " AND w.M_Warehouse_ID=iv.M_Warehouse_ID"
                                        + " AND c.M_Product_ID=iv.M_Product_ID"
                                        + " AND c.M_AttributeSetInstance_ID=iv.M_AttributeSetInstance_ID AND rownum=1 AND w.m_warehouse_ID=" + _M_Warehouse_ID + ") "
                                        + "WHERE EXISTS (SELECT * FROM T_InventoryValue ivv "
                                        + "WHERE ivv.AD_PInstance_ID=" + GetAD_PInstance_ID()
                                        + " AND ivv.M_CostElement_ID IS NULL) AND iv.AD_PInstance_ID =" + GetAD_PInstance_ID());
                int noUpdatedCost = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName());
                log.Fine("Updated Cost=" + noUpdatedCost);
            }
            if ((noInsertStd + noInsertCost) == 0)
            {
                return("No Costs found");
            }

            //  Update Constants
            //  YYYY-MM-DD HH24:MI:SS.mmmm  JDBC Timestamp format
            // String myDate = _DateValue.ToString();
            sql = new StringBuilder("UPDATE T_InventoryValue SET ")
                  //.Append("DateValue=To_Date('").Append(myDate.Substring(0,10))
                  //.Append("23:59:59','MM-DD-YYYY HH24:MI:SS'),")
                  .Append("DateValue=").Append(GlobalVariable.TO_DATE(_DateValue, true)).Append(",")
                  .Append("M_PriceList_Version_ID=").Append(_M_PriceList_Version_ID).Append(",")
                  .Append("C_Currency_ID=").Append(_C_Currency_ID);
            if (_M_CostElement_ID != 0)
            {
                sql.Append(",").Append("M_CostElement_ID=").Append(_M_CostElement_ID);
            }
            no = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName());
            log.Fine("Constants=" + no);

            //  Get current QtyOnHand with ASI
            sql = new StringBuilder("UPDATE T_InventoryValue iv SET QtyOnHand = "
                                    + "(SELECT SUM(QtyOnHand) FROM M_Storage s"
                                    + " INNER JOIN M_Locator l ON (l.M_Locator_ID=s.M_Locator_ID) "
                                    + "WHERE iv.M_Product_ID=s.M_Product_ID"
                                    + " AND iv.M_Warehouse_ID=l.M_Warehouse_ID"
                                    + " AND iv.M_AttributeSetInstance_ID=s.M_AttributeSetInstance_ID) "
                                    + "WHERE AD_PInstance_ID=").Append(GetAD_PInstance_ID())
                  .Append(" AND iv.M_AttributeSetInstance_ID<>0");
            no = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName());
            log.Fine("QtHand with ASI=" + no);
            //  Get current QtyOnHand without ASI
            sql = new StringBuilder("UPDATE T_InventoryValue iv SET QtyOnHand = "
                                    + "(SELECT SUM(QtyOnHand) FROM M_Storage s"
                                    + " INNER JOIN M_Locator l ON (l.M_Locator_ID=s.M_Locator_ID) "
                                    + "WHERE iv.M_Product_ID=s.M_Product_ID"
                                    + " AND iv.M_Warehouse_ID=l.M_Warehouse_ID) "
                                    + "WHERE AD_PInstance_ID=").Append(GetAD_PInstance_ID())
                  .Append(" AND iv.M_AttributeSetInstance_ID=0");
            no = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName());
            log.Fine("QtHand w/o ASI=" + no);

            //  Adjust for Valuation Date
            sql = new StringBuilder("UPDATE T_InventoryValue iv "
                                    + "SET QtyOnHand="
                                    + "(SELECT iv.QtyOnHand - NVL(SUM(t.MovementQty), 0) "
                                    + "FROM M_Transaction t"
                                    + " INNER JOIN M_Locator l ON (t.M_Locator_ID=l.M_Locator_ID) "
                                    + "WHERE t.M_Product_ID=iv.M_Product_ID"
                                    + " AND t.M_AttributeSetInstance_ID=iv.M_AttributeSetInstance_ID"
                                    + " AND t.MovementDate > iv.DateValue"
                                    + " AND l.M_Warehouse_ID=iv.M_Warehouse_ID) "
                                    + "WHERE iv.M_AttributeSetInstance_ID<>0");
            no = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName());
            log.Fine("Update with ASI=" + no);
            //
            sql = new StringBuilder("UPDATE T_InventoryValue iv "
                                    + "SET QtyOnHand="
                                    + "(SELECT iv.QtyOnHand - NVL(SUM(t.MovementQty), 0) "
                                    + "FROM M_Transaction t"
                                    + " INNER JOIN M_Locator l ON (t.M_Locator_ID=l.M_Locator_ID) "
                                    + "WHERE t.M_Product_ID=iv.M_Product_ID"
                                    + " AND t.MovementDate > iv.DateValue"
                                    + " AND l.M_Warehouse_ID=iv.M_Warehouse_ID) "
                                    + "WHERE iv.M_AttributeSetInstance_ID=0");
            no = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName());
            log.Fine("Update w/o ASI=" + no);

            //  Delete Records w/o OnHand Qty
            sql = new StringBuilder("DELETE FROM T_InventoryValue "
                                    + "WHERE (QtyOnHand=0 OR QtyOnHand IS NULL) AND AD_PInstance_ID=").Append(GetAD_PInstance_ID());
            int noQty = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName());

            log.Fine("NoQty Deleted=" + noQty);

            //  Update Prices
            no = DataBase.DB.ExecuteQuery("UPDATE T_InventoryValue iv "
                                          + "SET PricePO = "
                                          + "(SELECT MAX(currencyConvert (po.PriceList,po.C_Currency_ID,iv.C_Currency_ID,iv.DateValue,null, po.AD_Client_ID,po.AD_Org_ID))"
                                          + " FROM M_Product_PO po WHERE po.M_Product_ID=iv.M_Product_ID"
                                          + " AND po.IsCurrentVendor='Y'), "
                                          + "PriceList = "
                                          + "(SELECT currencyConvert(pp.PriceList,pl.C_Currency_ID,iv.C_Currency_ID,iv.DateValue,null, pl.AD_Client_ID,pl.AD_Org_ID)"
                                          + " FROM M_PriceList pl, M_PriceList_Version plv, M_ProductPrice pp"
                                          + " WHERE pp.M_Product_ID=iv.M_Product_ID AND pp.M_PriceList_Version_ID=iv.M_PriceList_Version_ID"
                                          + " AND pp.M_PriceList_Version_ID=plv.M_PriceList_Version_ID"
                                          + " AND plv.M_PriceList_ID=pl.M_PriceList_ID), "
                                          + "PriceStd = "
                                          + "(SELECT currencyConvert(pp.PriceStd,pl.C_Currency_ID,iv.C_Currency_ID,iv.DateValue,null, pl.AD_Client_ID,pl.AD_Org_ID)"
                                          + " FROM M_PriceList pl, M_PriceList_Version plv, M_ProductPrice pp"
                                          + " WHERE pp.M_Product_ID=iv.M_Product_ID AND pp.M_PriceList_Version_ID=iv.M_PriceList_Version_ID"
                                          + " AND pp.M_PriceList_Version_ID=plv.M_PriceList_Version_ID"
                                          + " AND plv.M_PriceList_ID=pl.M_PriceList_ID), "
                                          + "PriceLimit = "
                                          + "(SELECT currencyConvert(pp.PriceLimit,pl.C_Currency_ID,iv.C_Currency_ID,iv.DateValue,null, pl.AD_Client_ID,pl.AD_Org_ID)"
                                          + " FROM M_PriceList pl, M_PriceList_Version plv, M_ProductPrice pp"
                                          + " WHERE pp.M_Product_ID=iv.M_Product_ID AND pp.M_PriceList_Version_ID=iv.M_PriceList_Version_ID"
                                          + " AND pp.M_PriceList_Version_ID=plv.M_PriceList_Version_ID"
                                          + " AND plv.M_PriceList_ID=pl.M_PriceList_ID)"
                                          , null, Get_TrxName());
            String msg = "";

            if (no == 0)
            {
                msg = "No Prices";
            }

            //	Convert if different Currency
            if (mas.GetC_Currency_ID() != _C_Currency_ID)
            {
                sql = new StringBuilder("UPDATE T_InventoryValue iv "
                                        + "SET CostStandard= "
                                        + "(SELECT currencyConvert(iv.CostStandard,acs.C_Currency_ID,iv.C_Currency_ID,iv.DateValue,null, iv.AD_Client_ID,iv.AD_Org_ID) "
                                        + "FROM C_AcctSchema acs WHERE acs.C_AcctSchema_ID=" + mas.GetC_AcctSchema_ID() + "),"
                                        + "	Cost= "
                                        + "(SELECT currencyConvert(iv.Cost,acs.C_Currency_ID,iv.C_Currency_ID,iv.DateValue,null, iv.AD_Client_ID,iv.AD_Org_ID) "
                                        + "FROM C_AcctSchema acs WHERE acs.C_AcctSchema_ID=" + mas.GetC_AcctSchema_ID() + ") "
                                        + "WHERE AD_PInstance_ID=" + GetAD_PInstance_ID());
                no = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName());
                log.Fine("Convered=" + no);
            }

            //  Update Values
            no = DataBase.DB.ExecuteQuery("UPDATE T_InventoryValue SET "
                                          + "PricePOAmt = QtyOnHand * PricePO, "
                                          + "PriceListAmt = QtyOnHand * PriceList, "
                                          + "PriceStdAmt = QtyOnHand * PriceStd, "
                                          + "PriceLimitAmt = QtyOnHand * PriceLimit, "
                                          + "CostStandardAmt = QtyOnHand * CostStandard, "
                                          + "CostAmt = QtyOnHand * Cost "
                                          + "WHERE AD_PInstance_ID=" + GetAD_PInstance_ID(), null, Get_TrxName());
            log.Fine("Calculation=" + no);
            //
            return(msg);
        }
        /// <summary>
        /// Complete the Payment Record
        /// </summary>
        /// <param name="ctx">Context</param>
        /// <param name="Record_ID">C_Payment_ID</param>
        /// <param name="Process_ID">AD_Process_ID</param>
        /// <param name="DocAction">Documnet Action</param>
        /// <returns>return message</returns>
        public string CompletePayment(Ctx ctx, int Record_ID, int Process_ID, string DocAction)
        {
            string result = "";
            MRole  role   = MRole.Get(ctx, ctx.GetAD_Role_ID());

            if (Util.GetValueOfBool(role.GetProcessAccess(Process_ID)))
            {
                DB.ExecuteQuery("UPDATE C_Payment SET DocAction = '" + DocAction + "' WHERE C_Payment_ID = " + Record_ID);

                MProcess   proc = new MProcess(ctx, Process_ID, null);
                MPInstance pin  = new MPInstance(proc, Record_ID);
                if (!pin.Save())
                {
                    ValueNamePair vnp      = VLogger.RetrieveError();
                    string        errorMsg = "";
                    if (vnp != null)
                    {
                        errorMsg = vnp.GetName();
                        if (errorMsg == "")
                        {
                            errorMsg = vnp.GetValue();
                        }
                    }
                    if (errorMsg == "")
                    {
                        result = Msg.GetMsg(ctx, "DocNotCompleted");
                    }

                    return(result);
                }

                MPInstancePara para = new MPInstancePara(pin, 20);
                para.setParameter("DocAction", DocAction);
                if (!para.Save())
                {
                    //String msg = "No DocAction Parameter added"; // not translated
                }
                ProcessInfo pi = new ProcessInfo("WF", Process_ID);
                pi.SetAD_User_ID(ctx.GetAD_User_ID());
                pi.SetAD_Client_ID(ctx.GetAD_Client_ID());
                pi.SetAD_PInstance_ID(pin.GetAD_PInstance_ID());
                pi.SetRecord_ID(Record_ID);
                pi.SetTable_ID(335); //AD_Table_ID=335 for C_Payment

                ProcessCtl worker = new ProcessCtl(ctx, null, pi, null);
                worker.Run();

                if (pi.IsError())
                {
                    ValueNamePair vnp      = VLogger.RetrieveError();
                    string        errorMsg = "";
                    if (vnp != null)
                    {
                        errorMsg = vnp.GetName();
                        if (errorMsg == "")
                        {
                            errorMsg = vnp.GetValue();
                        }
                    }

                    if (errorMsg == "")
                    {
                        errorMsg = pi.GetSummary();
                    }

                    if (errorMsg == "")
                    {
                        errorMsg = Msg.GetMsg(ctx, "DocNotCompleted");
                    }
                    result = errorMsg;
                    return(result);
                }
                else
                {
                    result = "";
                }
            }
            else
            {
                result = Msg.GetMsg(ctx, "NoAccess");
                return(result);
            }
            return(result);
        }
        /// <summary>
        /// This function executes when user select record (one OR more) from window and click print button.
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="AD_Process_ID"></param>
        /// <param name="Name"></param>
        /// <param name="AD_Table_ID"></param>
        /// <param name="Record_ID"></param>
        /// <param name="WindowNo"></param>
        /// <param name="recIDs"></param>
        /// <param name="fileType"></param>
        /// <returns></returns>
        public static ProcessReportInfo GeneratePrint(Ctx ctx, int AD_Process_ID, string Name, int AD_Table_ID, int Record_ID, int WindowNo, string recIDs, string fileType)
        {
            ProcessReportInfo ret      = new ProcessReportInfo();
            MPInstance        instance = null;

            try
            {
                instance = new MPInstance(ctx, AD_Process_ID, Record_ID);
            }
            catch (Exception e)
            {
                ret.IsError = true;
                ret.Message = e.Message;
                return(ret);
            }

            if (!instance.Save())
            {
                ret.IsError = true;
                ret.Message = Msg.GetMsg(ctx, "ProcessNoInstance");
                return(ret);
            }
            ret.AD_PInstance_ID = instance.GetAD_PInstance_ID();



            //ReportEngine_N re = null;

            string lang = ctx.GetAD_Language().Replace("_", "-");

            System.Globalization.CultureInfo original = System.Threading.Thread.CurrentThread.CurrentCulture;

            System.Threading.Thread.CurrentThread.CurrentCulture   = new System.Globalization.CultureInfo(lang);
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(lang);


            ////////log/////
            //string clientName = ctx.GetAD_Org_Name() + "_" + ctx.GetAD_User_Name();
            //string storedPath = Path.Combine(HostingEnvironment.ApplicationPhysicalPath, "");
            //storedPath += clientName;
            //VLogMgt.Initialize(true, storedPath);
            ////////////////
            ProcessInfo pi = new ProcessInfo(Name, AD_Process_ID, AD_Table_ID, Record_ID, recIDs);

            pi.SetFileType(fileType);
            TryPrintFromDocType(pi);
            //if (ret != null)
            //{
            //    return ret;
            //}


            ret = new ProcessReportInfo();
            ret.AD_PInstance_ID = instance.GetAD_PInstance_ID();
            byte[] report      = null;
            string rptFilePath = null;

            // ProcessReportInfo rep = new ProcessReportInfo();
            try
            {
                pi.SetAD_User_ID(ctx.GetAD_User_ID());
                pi.SetAD_Client_ID(ctx.GetAD_Client_ID());
                pi.SetAD_PInstance_ID(ret.AD_PInstance_ID);

                //report = null;
                ProcessCtl ctl = new ProcessCtl();
                //ctl.SetIsPrintFormat(true);
                //ctl.IsArabicReportFromOutside = false;
                //ctl.SetIsPrintCsv(csv);
                //ctl.SetFileType(fileType);
                Dictionary <string, object> d = ctl.Process(pi, ctx, out report, out rptFilePath);
                //rep = new ProcessReportInfo();
                ret.ReportProcessInfo = d;
                ret.Report            = report;
                ret.ReportString      = ctl.ReportString;
                ret.ReportFilePath    = rptFilePath;
                ret.HTML            = ctl.GetRptHtml();
                ret.IsRCReport      = ctl.IsRCReport();
                ret.TotalRecords    = pi.GetTotalRecords();
                ret.IsReportFormat  = pi.GetIsReportFormat();
                ret.IsTelerikReport = pi.GetIsTelerik();
                ctl.ReportString    = null;


                //Env.GetCtx().Clear();
            }
            catch (Exception e)
            {
                ret.IsError = true;
                ret.Message = e.Message;
            }

            System.Threading.Thread.CurrentThread.CurrentCulture   = original;
            System.Threading.Thread.CurrentThread.CurrentUICulture = original;

            //return ret;
            //ret = ExecuteProcess(ctx, AD_Process_ID, Name, ret.AD_PInstance_ID, AD_Table_ID, Record_ID, null,true);
            // VAdvantage.Classes.CleanUp.Get().Start();
            return(ret);
        }
Ejemplo n.º 14
0
        public static ProcessReportInfo GeneratePrint(Ctx ctx, int AD_Process_ID, string Name, int AD_Table_ID, int Record_ID, int WindowNo, bool csv)
        {
            ProcessReportInfo ret      = new ProcessReportInfo();
            MPInstance        instance = null;

            try
            {
                instance = new MPInstance(ctx, AD_Process_ID, Record_ID);
            }
            catch (Exception e)
            {
                ret.IsError = true;
                ret.Message = e.Message;
                return(ret);
            }

            if (!instance.Save())
            {
                ret.IsError = true;
                ret.Message = Msg.GetMsg(ctx, "ProcessNoInstance");
                return(ret);
            }
            ret.AD_PInstance_ID = instance.GetAD_PInstance_ID();

            List <GridField> fields = ProcessParameter.GetParametersList(ctx, AD_Process_ID, WindowNo);

            if (fields.Count < 1) //no Parameter
            {
                //ReportEngine_N re = null;

                string lang = ctx.GetAD_Language().Replace("_", "-");
                System.Globalization.CultureInfo original = System.Threading.Thread.CurrentThread.CurrentCulture;

                System.Threading.Thread.CurrentThread.CurrentCulture   = new System.Globalization.CultureInfo(lang);
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(lang);


                ////////log/////
                string clientName = ctx.GetAD_Org_Name() + "_" + ctx.GetAD_User_Name();
                string storedPath = Path.Combine(HostingEnvironment.ApplicationPhysicalPath, "");
                storedPath += clientName;
                VLogMgt.Initialize(true, storedPath);
                ////////////////

                byte[] report      = null;
                string rptFilePath = null;
                // ProcessReportInfo rep = new ProcessReportInfo();
                try
                {
                    ProcessInfo pi = new ProcessInfo(Name, AD_Process_ID, AD_Table_ID, Record_ID);
                    pi.SetAD_User_ID(ctx.GetAD_User_ID());
                    pi.SetAD_Client_ID(ctx.GetAD_Client_ID());
                    pi.SetAD_PInstance_ID(ret.AD_PInstance_ID);

                    //report = null;
                    ProcessCtl ctl = new ProcessCtl();
                    ctl.SetIsPrintFormat(true);
                    ctl.IsArabicReportFromOutside = false;
                    ctl.SetIsPrintCsv(csv);
                    Dictionary <string, object> d = ctl.Process(pi, ctx, out report, out rptFilePath);
                    //rep = new ProcessReportInfo();
                    ret.ReportProcessInfo = d;
                    ret.Report            = report;
                    ret.ReportString      = ctl.ReportString;
                    ret.ReportFilePath    = rptFilePath;
                    ret.HTML         = ctl.GetRptHtml();
                    ret.IsRCReport   = ctl.IsRCReport();
                    ctl.ReportString = null;


                    //Env.GetCtx().Clear();
                }
                catch (Exception e)
                {
                    ret.IsError = true;
                    ret.Message = e.Message;
                }

                System.Threading.Thread.CurrentThread.CurrentCulture   = original;
                System.Threading.Thread.CurrentThread.CurrentUICulture = original;

                //return ret;
                //ret = ExecuteProcess(ctx, AD_Process_ID, Name, ret.AD_PInstance_ID, AD_Table_ID, Record_ID, null,true);
            }
            else
            {
                ret.ShowParameter = true;
                ret.ProcessFields = fields;
            }
            return(ret);
        }
        // Method added by mohit to get reports as byteArray. 19 April 2019

        /// <summary>
        /// Method to get byte array of report.
        /// </summary>
        /// <param name="ctx">Current Context.</param>
        /// <param name="AD_Process_ID">Process ID.</param>
        /// <param name="Name">Name of process.</param>
        /// <param name="AD_Table_ID">Table id for fetching report.</param>
        /// <param name="Record_ID">Record id.</param>
        /// <param name="WindowNo">Window Number if process fired from window.</param>
        /// <param name="recIDs">String of record id's/</param>
        /// <param name="fileType">Report type.</param>
        /// <param name="report">Out parameter to get byte array.</param>
        /// <returns>Returns Process Info list and report byte array.</returns>
        public Dictionary <string, object> GetReport(Ctx ctx, int AD_Process_ID, string Name, int AD_Table_ID, int Record_ID, int WindowNo, string recIDs, string fileType, out byte[] report, out string rptFilePath)
        {
            Dictionary <string, object> d = null;

            report      = null;
            rptFilePath = null;

            // Create PInstance
            MPInstance instance = null;

            try
            {
                instance = new MPInstance(ctx, AD_Process_ID, Record_ID);
            }
            catch (Exception e)
            {
                VLogger.Get().SaveError("GetReport-Instance Save", e.Message);
                return(d);
            }

            if (!instance.Save())
            {
                ValueNamePair vp = VLogger.RetrieveError();
                if (vp != null)
                {
                    VLogger.Get().SaveError("GetReport-Instance Save", vp.Name ?? vp.GetValue());
                }
                else
                {
                    VLogger.Get().SaveError("GetReport-Instance Save", "PInstanceNotSaved");
                }

                return(d);
            }

            // Culture.
            string lang = ctx.GetAD_Language().Replace("_", "-");

            System.Globalization.CultureInfo original = System.Threading.Thread.CurrentThread.CurrentCulture;

            System.Threading.Thread.CurrentThread.CurrentCulture   = new System.Globalization.CultureInfo(lang);
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(lang);


            // Process info
            ProcessInfo pi = new ProcessInfo(Name, AD_Process_ID, AD_Table_ID, Record_ID, recIDs);

            pi.SetFileType(fileType);
            TryPrintFromDocType(pi);

            try
            {
                pi.SetAD_User_ID(ctx.GetAD_User_ID());
                pi.SetAD_Client_ID(ctx.GetAD_Client_ID());
                pi.SetAD_PInstance_ID(instance.GetAD_PInstance_ID());
                ProcessCtl ctl = new ProcessCtl();
                d = new Dictionary <string, object>();
                d = ctl.Process(pi, ctx, out report, out rptFilePath);
                ctl.ReportString = null;
            }
            catch (Exception e)
            {
                VLogger.Get().SaveError("GetReport", e.Message);
                report = null;
            }
            return(d);
        }
Ejemplo n.º 16
0
        ///**
        // *    Create PDF
        // *	@return File or null
        // */
        //public File createPDF ()
        //{
        //    try
        //    {
        //        File temp = File.createTempFile(get_TableName()+get_ID()+"_", ".pdf");
        //        return createPDF (temp);
        //    }
        //    catch (Exception e)
        //    {
        //        //log.severe("Could not create PDF - " + e.getMessage());
        //    }
        //    return null;
        //}	//	getPDF

        ///**
        // *    Create PDF file
        // *	@param file output file
        // *	@return file if success
        // */
        //public File createPDF (File file)
        //{
        ////	ReportEngine re = ReportEngine.Get (GetCtx(), ReportEngine.INVOICE, getC_Invoice_ID());
        ////	if (re == null)
        //        return null;
        ////	return re.getPDF(file);
        //}

        /// <summary>
        /// Create PDF
        /// </summary>
        /// <returns>File or null</returns>
        public FileInfo CreatePDF()
        {
            //try
            //{
            //    string fileName = Get_TableName() + Get_ID() + "_" + CommonFunctions.GenerateRandomNo()
            //                        + ".txt"; //.pdf
            //    string filePath = Path.GetTempPath() + fileName;

            //    //File temp = File.createTempFile(Get_TableName() + Get_ID() + "_", ".pdf");
            //    //FileStream fOutStream = new FileStream(filePath, FileMode.Create, FileAccess.Write);

            //    FileInfo temp = new FileInfo(filePath);
            //    if (!temp.Exists)
            //    {
            //        return CreatePDF(temp);
            //    }
            //}
            //catch (Exception e)
            //{
            //    log.Severe("Could not create PDF - " + e.Message);
            //}
            //return null;



            try
            {
                //string fileName = Get_TableName() + Get_ID() + "_" + CommonFunctions.GenerateRandomNo()
                String fileName = Get_TableName() + Get_ID() + "_" + CommonFunctions.GenerateRandomNo() + ".pdf";
                string filePath = Path.Combine(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath, "TempDownload", fileName);

                int        processID = Util.GetValueOfInt(DB.ExecuteScalar("SELECT AD_Process_Id FROM AD_Process WHERE VALUE='CashJournalReport'", null, null));
                MPInstance instance  = new MPInstance(GetCtx(), processID, GetC_Cash_ID());
                instance.Save();
                ProcessInfo pi = new ProcessInfo("", processID, Get_Table_ID(), GetC_Cash_ID());
                pi.SetAD_PInstance_ID(instance.GetAD_PInstance_ID());

                ProcessCtl ctl = new ProcessCtl();
                ctl.IsArabicReportFromOutside = false;
                byte[]         report         = null;
                ReportEngine_N re             = null;
                Dictionary <string, object> d = ctl.Process(pi, GetCtx(), out report, out re);

                File.WriteAllBytes(filePath, report);
                return(new FileInfo(filePath));
                //re.GetView();
                //bool b = re.CreatePDF(filePath);

                //File temp = File.createTempFile(Get_TableName() + Get_ID() + "_", ".pdf");
                //FileStream fOutStream = new FileStream(filePath, FileMode.Create, FileAccess.Write);

                //FileInfo temp = new FileInfo(filePath);

                //if (!temp.Exists)
                //{
                //    b = re.CreatePDF(filePath);
                //    if (b)
                //    {
                //        return new FileInfo(filePath);
                //    }
                //    return null;
                //}
                //else
                //    return temp;
            }
            catch (Exception e)
            {
                log.Severe("Could not create PDF - " + e.Message);
            }
            return(null);
        }
Ejemplo n.º 17
0
        //[MethodImpl(MethodImplOptions.Synchronized)]
        // vinay bhatt window id
        internal static ProcessReportInfo ExecuteProcess(Ctx ctx, Dictionary <string, string> processInfo, ProcessPara[] pList)
        {
            ProcessInfo pi = new ProcessInfo().FromList(processInfo);

            pi.SetAD_User_ID(ctx.GetAD_User_ID());
            pi.SetAD_Client_ID(ctx.GetAD_Client_ID());
            if (pi.GetAD_PInstance_ID() == 0)
            {
                MPInstance instance = null;
                instance = new MPInstance(ctx, Util.GetValueOfInt(processInfo["Process_ID"]), Util.GetValueOfInt(processInfo["Record_ID"]));

                if (!instance.Save())
                {
                }
                pi.SetAD_PInstance_ID(instance.Get_ID());
            }

            int vala = 0;

            if (pList != null && pList.Length > 0) //we have process parameter
            {
                for (int i = 0; i < pList.Length; i++)
                {
                    var pp = pList[i];
                    //	Create Parameter
                    MPInstancePara para = new MPInstancePara(ctx, pi.GetAD_PInstance_ID(), i);
                    para.SetParameterName(pp.Name);

                    if (DisplayType.IsDate(pp.DisplayType))
                    {
                        if (pp.DisplayType == DisplayType.DateTime)
                        {
                            if (pp.Result != null)
                            {
                                para.SetP_Date_Time(Convert.ToDateTime(pp.Result));
                            }

                            if (pp.Result2 != null)
                            {
                                para.SetP_Date_Time_To(Convert.ToDateTime(pp.Result2));
                            }
                        }
                        if (pp.DisplayType == DisplayType.Time)
                        {
                            if (pp.Result != null)
                            {
                                para.SetP_Time(Convert.ToDateTime(pp.Result));
                            }

                            if (pp.Result2 != null)
                            {
                                para.SetP_Time_To(Convert.ToDateTime(pp.Result2));
                            }
                        }
                        else
                        {
                            if (pp.Result != null)
                            {
                                para.SetP_Date(Convert.ToDateTime(pp.Result).ToUniversalTime());
                            }

                            if (pp.Result2 != null)
                            {
                                para.SetP_Date_To(Convert.ToDateTime(pp.Result2).ToUniversalTime());
                            }
                        }
                    }

                    else if ((DisplayType.IsID(pp.DisplayType) || DisplayType.Integer == pp.DisplayType))
                    {
                        if (pp.Result != null)
                        {
                            if (DisplayType.IsLookup(pp.DisplayType) && pp.Result.Equals("-1"))
                            {
                                continue;
                            }

                            if (int.TryParse(pp.Result.ToString(), out vala))
                            {
                                para.SetP_Number(Convert.ToInt32(pp.Result));
                            }
                            else
                            {
                                para.SetP_String(pp.Result.ToString());
                            }
                        }
                        if (pp.Result2 != null)
                        {
                            if (DisplayType.IsLookup(pp.DisplayType) && pp.Result2.Equals("-1"))
                            {
                                continue;
                            }
                            if (int.TryParse(pp.Result2.ToString(), out vala))
                            {
                                para.SetP_Number_To(Convert.ToInt32(pp.Result2));
                            }
                            else
                            {
                                para.SetP_String_To(pp.Result2.ToString());
                            }
                        }
                    }
                    else if (DisplayType.IsNumeric(pp.DisplayType))
                    {
                        if (pp.Result != null)
                        {
                            para.SetP_Number(Convert.ToDecimal(pp.Result));
                        }
                        if (pp.Result2 != null)
                        {
                            para.SetP_Number_To(Convert.ToDecimal(pp.Result2));
                        }
                    }
                    else if (DisplayType.YesNo == pp.DisplayType)
                    {
                        Boolean bb    = (Boolean)pp.Result;
                        String  value = bb ? "Y" : "N";
                        para.SetP_String(value);
                    }

                    else
                    {
                        if (pp.Result != null)
                        {
                            para.SetP_String(pp.Result.ToString());
                        }
                        if (pp.Result2 != null)
                        {
                            para.SetP_String_To(pp.Result.ToString());
                        }
                    }
                    para.SetAD_Process_Para_ID(pp.AD_Column_ID);

                    para.SetInfo(pp.Info);

                    if (pp.Info_To != null)
                    {
                        para.SetInfo_To(pp.Info_To);
                    }
                    para.Save();
                }
            }

            string lang = ctx.GetAD_Language().Replace("_", "-");

            System.Globalization.CultureInfo original = System.Threading.Thread.CurrentThread.CurrentCulture;

            System.Threading.Thread.CurrentThread.CurrentCulture   = new System.Globalization.CultureInfo(lang);
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(lang);

            byte[]            report      = null;
            string            rptFilePath = null;
            ProcessReportInfo rep         = new ProcessReportInfo();

            try
            {
                //ProcessInfo pi = new ProcessInfo(Name, AD_Process_ID, AD_Table_ID, Record_ID);
                //pi.SetAD_User_ID(ctx.GetAD_User_ID());
                //pi.SetAD_Client_ID(ctx.GetAD_Client_ID());
                //pi.SetAD_PInstance_ID(AD_PInstance_ID);
                //pi.SetAD_Window_ID(AD_Window_ID);
                //pi.FileType = fileType;
                //report = null;

                pi.IsArabicReportFromOutside = false;
                ProcessCtl ctl = new ProcessCtl();

                //ctl.SetIsPrintCsv(csv);
                //ctl.SetFileType(fileType);
                //if (fileType == "P")
                //{
                //    ctl.SetIsPrintFormat(true);
                //}
                Dictionary <string, object> d = ctl.Process(pi, ctx, out report, out rptFilePath);
                rep = new ProcessReportInfo();
                rep.ReportProcessInfo = d;
                rep.Report            = report;

                //if (rep.Report != null)
                //{
                //    rep.byteString = Convert.ToBase64String(rep.Report);
                //}

                rep.ReportString = ctl.ReportString;
                //rep.AD_ReportView_ID = ctl.GetAD_ReportView_ID();
                rep.ReportFilePath = rptFilePath;
                // rep.IsRCReport = ctl.IsRCReport();
                // rep.TotalRecords = pi.GetTotalRecords();
                // rep.IsReportFormat = pi.GetIsReportFormat();
                // rep.IsTelerikReport = pi.GetIsTelerik();
                // rep.IsJasperReport = pi.GetIsJasperReport();
                //  rep.AD_PrintFormat_ID = ctl.GetAD_PrintFormat_ID();
                // if (d.ContainsKey("AD_PrintFormat_ID"))
                // {
                //    rep.AD_PrintFormat_ID = Convert.ToInt32(d["AD_PrintFormat_ID"]);
                // }
                ctl.ReportString = null;
                rep.HTML         = ctl.GetRptHtml();
                //rep.AD_Table_ID = ctl.GetReprortTableID();


                //Env.GetCtx().Clear();
            }
            catch (Exception e)
            {
                rep.IsError = true;
                rep.Message = e.Message;
            }

            System.Threading.Thread.CurrentThread.CurrentCulture   = original;
            System.Threading.Thread.CurrentThread.CurrentUICulture = original;
            //VAdvantage.Classes.CleanUp.Get().Start();
            return(rep);
        }