} // createStatement /// <summary> /// Get SQL Value /// </summary> /// <param name="value">string value</param> /// <returns>sql compliant value</returns> private String GetSQLValue(String value) { if (value == null || value.Length == 0 || value.Equals("NULL")) { return("NULL"); } // Data Types if (DisplayType.IsNumeric(_column.GetAD_Reference_ID()) || DisplayType.IsID(_column.GetAD_Reference_ID())) { return(value); } if (DisplayType.YesNo == _column.GetAD_Reference_ID()) { if (value.Equals("true")) { return("'Y'"); } else { return("'N'"); } } if (DisplayType.IsDate(_column.GetAD_Reference_ID())) { return(DataBase.DB.TO_DATE(Convert.ToDateTime(value))); } // String, etc. return(DataBase.DB.TO_STRING(value)); } // getSQLValue
/// <summary> /// Column has FK (lists not included) /// </summary> /// <returns>true if has FK</returns> public bool IsFK() { int dt = GetAD_Reference_ID(); if (DisplayType.IsID(dt) && dt != DisplayType.ID && !IsKey() && !IsVirtualColumn()) { return(true); } if (dt == DisplayType.Button && GetColumnName().EndsWith("_ID")) { return(true); } return(false); }
/// <summary> /// Before Save /// </summary> /// <param name="newRecord"></param> /// <returns></returns> protected override bool BeforeSave(bool newRecord) { if (!CheckVersions(false)) { return(false); } int displayType = GetAD_Reference_ID(); // Length if (DisplayType.IsLOB(displayType)) // LOBs are 0 { if (GetFieldLength() != 0) { SetFieldLength(0); } } else if (GetFieldLength() == 0) { if (DisplayType.IsID(displayType)) { SetFieldLength(10); } else if (DisplayType.IsNumeric(displayType)) { SetFieldLength(14); } else if (DisplayType.IsDate(displayType)) { SetFieldLength(7); } else if (DisplayType.YesNo == displayType) { SetFieldLength(1); } else { log.SaveError("FillMandatory", Utility.Msg.GetElement(GetCtx(), "FieldLength")); return(false); } } /** Views are not updateable * UPDATE AD_Column c * SET IsUpdateable='N', IsAlwaysUpdateable='N' * WHERE AD_Table_ID IN (SELECT AD_Table_ID FROM AD_Table WHERE IsView='Y') **/ // Virtual Column if (IsVirtualColumn()) { if (IsMandatory()) { SetIsMandatory(false); } if (IsMandatoryUI()) { SetIsMandatoryUI(false); } if (IsUpdateable()) { SetIsUpdateable(false); } } // Updateable/Mandatory if (IsParent() || IsKey()) { SetIsUpdateable(false); SetIsMandatory(true); } if (IsAlwaysUpdateable() && !IsUpdateable()) { SetIsAlwaysUpdateable(false); } // Encrypted if (IsEncrypted()) { int dt = GetAD_Reference_ID(); if (IsKey() || IsParent() || IsStandardColumn() || IsVirtualColumn() || IsIdentifier() || IsTranslated() || DisplayType.IsLookup(dt) || DisplayType.IsLOB(dt) || "DocumentNo".ToLower().Equals(GetColumnName().ToLower()) || "Value".ToLower().Equals(GetColumnName().ToLower()) || "Name".ToLower().Equals(GetColumnName().ToLower())) { log.Warning("Encryption not sensible - " + GetColumnName()); SetIsEncrypted(false); } } // Sync Terminology if ((newRecord || Is_ValueChanged("AD_Element_ID")) && GetAD_Element_ID() != 0) { _element = new M_Element(GetCtx(), GetAD_Element_ID(), Get_TrxName()); SetColumnName(_element.GetColumnName()); SetName(_element.GetName()); SetDescription(_element.GetDescription()); SetHelp(_element.GetHelp()); } if (IsKey() && (newRecord || Is_ValueChanged("IsKey"))) { SetConstraintType(null); } return(true); }
} // isDate public bool IsID() { return(DisplayType.IsID(_displayType)); } // isID
//[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()); 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); }
internal static ProcessReportInfo ExecuteProcess(Ctx ctx, int AD_Process_ID, string Name, int AD_PInstance_ID, int AD_Table_ID, int Record_ID, ProcessPara[] pList, bool csv = false, bool pdf = false) { 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, AD_PInstance_ID, i); para.SetParameterName(pp.Name); if (DisplayType.IsDate(pp.DisplayType)) { if (pp.Result != null) { para.SetP_Date(Convert.ToDateTime(pp.Result)); } if (pp.Result2 != null) { para.SetP_Date_To(Convert.ToDateTime(pp.Result2)); } } //else if (pp.Result is int || pp.Result2 is int) //{ // if (pp.Result != null) // { // para.SetP_Number(Convert.ToInt32(pp.Result)); // } // if (pp.Result2 != null) // { // para.SetP_Number_To(Convert.ToInt32(pp.Result2)); // } //} //else if (pp.Result is decimal || pp.Result2 is decimal) //{ // if (pp.Result != null) // { // para.SetP_Number(Convert.ToDecimal(pp.Result)); // } // if (pp.Result2 != null) // { // para.SetP_Number_To(Convert.ToDecimal(pp.Result2)); // } //} //// Boolean //else if (pp.Result is Boolean) //{ // Boolean bb = (Boolean)pp.Result; // String value = bb ? "Y" : "N"; // para.SetP_String(value); // // to does not make sense //} //********* else if ((DisplayType.IsID(pp.DisplayType) || DisplayType.Integer == pp.DisplayType)) { if (pp.Result != null) { 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 (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.SetInfo(pp.Info); if (pp.Info_To != null) { para.SetInfo_To(pp.Info_To); } para.Save(); } } // 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); // VLogMgt.AddHandler(VLogFile.Get(true, storedPath, true)); //////////////// 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); //report = null; ProcessCtl ctl = new ProcessCtl(); ctl.IsArabicReportFromOutside = false; ctl.SetIsPrintCsv(csv); if (pdf) { ctl.SetIsPrintFormat(true); } Dictionary <string, object> d = ctl.Process(pi, ctx, out report, out rptFilePath); rep = new ProcessReportInfo(); rep.ReportProcessInfo = d; rep.Report = report; rep.ReportString = ctl.ReportString; rep.ReportFilePath = rptFilePath; rep.IsRCReport = ctl.IsRCReport(); // 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; return(rep); }
} // getTargetColumn /// <summary> /// Execute Auto Assignment /// </summary> /// <param name="po">PO to be modified</param> /// <returns>true if modified</returns> public bool ExecuteIt(PO po) { // Check Column MColumn column = GetTargetColumn(); String columnName = column.GetColumnName(); int index = po.Get_ColumnIndex(columnName); if (index == -1) { throw new Exception(ToString() + ": AD_Column_ID not found"); } // Check Value Object value = po.Get_Value(index); String assignRule = GetAssignRule(); if (value == null && assignRule.Equals(ASSIGNRULE_OnlyIfNOTNULL)) { return(false); } else if (value != null && assignRule.Equals(ASSIGNRULE_OnlyIfNULL)) { return(false); } // Check Criteria if (m_criteria == null) { GetCriteria(false); } bool modified = false; for (int i = 0; i < m_criteria.Length; i++) { MAssignCriteria criteria = m_criteria[i]; if (criteria.IsMet(po)) { modified = true; break; } } if (!modified) { return(false); } // Assignment String methodName = "set" + columnName; Type parameterType = null; Object parameter = null; int displayType = column.GetAD_Reference_ID(); String valueString = GetValueString(); if (DisplayType.IsText(displayType) || displayType == DisplayType.List) { parameterType = typeof(string); parameter = valueString; } else if (DisplayType.IsID(displayType) || displayType == DisplayType.Integer) { parameterType = typeof(int); if (GetRecord_ID() != 0) { parameter = GetRecord_ID(); } else if (valueString != null && valueString.Length > 0) { try { parameter = int.Parse(valueString); } catch (Exception e) { log.Warning(ToString() + " " + e); return(false); } } } else if (DisplayType.IsNumeric(displayType)) { parameterType = typeof(Decimal); if (valueString != null && valueString.Length > 0) { try { parameter = Decimal.Parse(valueString); } catch (Exception e) { log.Warning(ToString() + " " + e); return(false); } } } else if (DisplayType.IsDate(displayType)) { parameterType = typeof(DateTime); if (valueString != null && valueString.Length > 0) { try { parameter = DateTime.Parse(valueString); } catch (Exception e) { log.Warning(ToString() + " " + e); return(false); } } } else if (displayType == DisplayType.YesNo) { parameterType = typeof(bool); parameter = "Y".Equals(valueString); } else if (displayType == DisplayType.Button) { parameterType = typeof(string); parameter = GetValueString(); } else if (DisplayType.IsLOB(displayType)) // CLOB is String { parameterType = typeof(byte[]); // parameter = getValueString(); } // Assignment try { Type clazz = po.GetType(); System.Reflection.MethodInfo method = clazz.GetMethod(methodName, new Type[] { parameterType }); method.Invoke(po, new Object[] { parameter }); } catch (Exception e) { log.Log(Level.WARNING, ToString(), e); // fallback if (parameter is Boolean) { po.Set_Value(index, valueString); } else { po.Set_Value(index, parameter); } // modified = false; } return(modified); } // executeIt
} // setSummaryFromDB /// <summary> /// Set param from db /// </summary> /// <param name="pi">ProcessInfo object</param> public static void SetParameterFromDB(ProcessInfo pi, Ctx ctx) { List <ProcessInfoParameter> list = new List <ProcessInfoParameter>(); String sql = @"SELECT ip.ParameterName, ip.P_String, ip.P_String_To, ip.P_Number, ip.P_Number_To, ip.P_Date, ip.P_Date_To, ip.Info, ip.Info_To, i.AD_Client_ID, i.AD_Org_ID, i.AD_User_ID, NVL(PP.LOADRECURSIVEDATA,'N') as LOADRECURSIVEDATA, nvl(pp.ShowChildOfSelected,'N') as ShowChildOfSelected,nvl(pp.AD_Reference_ID,0) as AD_Reference_ID FROM AD_PInstance_Para ip JOIN AD_PInstance i ON (ip.AD_PINstance_ID=i.AD_PINstance_ID) Left Outer JOIN AD_Process_Para pp ON (pp.AD_Process_Para_ID=ip.AD_Process_Para_ID AND pp.AD_Process_ID=i.AD_Process_ID) WHERE ip.AD_PInstance_ID =@pinstanceid"; IDataReader dr = null; try { SqlParameter[] param = new SqlParameter[1]; param[0] = new SqlParameter("@pinstanceid", pi.GetAD_PInstance_ID()); //param[0] = new SqlParameter("@pinstanceid", 1000296); dr = DataBase.DB.ExecuteReader(sql, param, null); while (dr.Read()) { String ParameterName = dr[0].ToString(); // String Object Parameter = dr[1].ToString(); Object Parameter_To = dr[2].ToString(); Parameter = Parameter.ToString() == "" ? null : Parameter; Parameter_To = Parameter_To.ToString() == "" ? null : Parameter_To; //int displayType = 0; //if (dr[16] != null && dr[16] != DBNull.Value) //{ // displayType = Util.GetValueOfInt(dr[16]); //} // Big Decimal if ((Parameter == null && Parameter_To == null) || (Parameter.Equals("") && Parameter_To.Equals(""))) { if (!(string.IsNullOrEmpty(dr[3].ToString()))) { Parameter = Utility.Util.GetValueOfDecimal(dr[3]); } if (!(string.IsNullOrEmpty(dr[3].ToString()))) { Parameter_To = Utility.Util.GetValueOfDecimal(dr[4]); } } // Timestamp if ((Parameter == null && Parameter_To == null) || (Parameter.Equals("") && Parameter_To.Equals(""))) { //if (displayType == 0) //{ // if (!(dr[5] == DBNull.Value)) // { // Parameter = DateTime.Parse(dr[5].ToString()); // } // if (!(dr[6] == DBNull.Value)) // { // Parameter_To = DateTime.Parse(dr[6].ToString()); // } //} //else //{ //if (displayType == DisplayType.Date) //{ if (dr[5] != null && dr[5] != DBNull.Value) { Parameter = DateTime.Parse(dr[5].ToString()); } if (dr[6] != null && dr[6] != DBNull.Value) { Parameter_To = DateTime.Parse(dr[6].ToString()); } //} //else if (displayType == DisplayType.DateTime) //{ //if (dr[12] != null && dr[12] != DBNull.Value) //{ // Parameter = DateTime.Parse(dr[12].ToString()); //} //if (dr[13] != null && dr[13] != DBNull.Value) //{ // Parameter_To = DateTime.Parse(dr[13].ToString()); //} ////} ////else if (displayType == DisplayType.Time) ////{ //if (dr[14] != null && dr[14] != DBNull.Value) //{ // Parameter = DateTime.Parse(dr[14].ToString()); //} //if (dr[15] != null && dr[15] != DBNull.Value) //{ // Parameter_To = DateTime.Parse(dr[15].ToString()); //} //} //} } // Info String Info = dr[7].ToString(); String Info_To = dr[8].ToString(); if (dr[12].ToString().Equals("Y") && ((DisplayType.IsID(Utility.Util.GetValueOfInt(dr[14])) || DisplayType.MultiKey == Utility.Util.GetValueOfInt(dr[14])))) { string result = Parameter.ToString(); string recResult = GetRecursiveParameterValue(ctx, ParameterName, result.ToString(), ref result, dr[13].ToString().Equals("Y")); if (!string.IsNullOrEmpty(recResult)) { Info = Info + ", " + recResult; } Parameter = result; if (Parameter_To != null && Parameter_To.ToString().Length > 0) { result = Parameter_To.ToString(); recResult = GetRecursiveParameterValue(ctx, ParameterName, result.ToString(), ref result, dr[13].ToString().Equals("Y")); if (!string.IsNullOrEmpty(recResult)) { Info_To = Info_To + ", " + recResult; } Parameter_To = result; } } if (Parameter_To != null && Parameter_To.ToString().EndsWith(",")) { Parameter_To = Parameter_To.ToString().Substring(0, Parameter_To.ToString().Length - 1); } if (Parameter != null && Parameter.ToString().EndsWith(",")) { Parameter = Parameter.ToString().Substring(0, Parameter.ToString().Length - 1); } // list.Add(new ProcessInfoParameter(ParameterName, Parameter, Parameter_To, Info, Info_To)); // if (pi.GetAD_Client_ID() == null) { pi.SetAD_Client_ID(int.Parse(dr[9].ToString())); } if (pi.GetAD_User_ID() == null) { pi.SetAD_User_ID(int.Parse(dr[11].ToString())); } } dr.Close(); } catch (Exception e) { if (dr != null) { dr.Close(); } _log.Severe(e.ToString()); } finally { if (dr != null) { dr.Close(); } } // ProcessInfoParameter[] pars = new ProcessInfoParameter[list.Count()]; pars = list.ToArray(); pi.SetParameter(pars); } // setParameterFromDB