} // getFunctionValue /// <summary> /// Get value to be displayed /// </summary> /// <param name="language">current language</param> /// <returns></returns> public String GetValueDisplay(VAdvantage.Login.Language language) { if (_value == null) { return(""); } String retValue = _value.ToString(); if (_displayType == DisplayType.Location) { return(GetValueDisplay_Location()); } else if (_columnName.Equals("C_BPartner_Location_ID") || _columnName.Equals("Bill_Location_ID")) { return(GetValueDisplay_BPLocation()); } else if (_displayType == 0 || _value.GetType() == typeof(String) || _value.GetType() == typeof(NamePair)) { } else if (language != null) // Optional formatting of Numbers and Dates { if (DisplayType.IsNumeric(_displayType)) { retValue = DisplayType.GetNumberFormat(_displayType).GetFormatedValue(_value); } if (DisplayType.IsDate(_displayType)) { // retValue = DisplayType.GetDateFormat(_displayType).Format(_value); } } return(retValue); } // getValueDisplay
} // 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
} // isNumeric public bool IsDate() { if (_displayType == 0) { return(_value.GetType() == typeof(DateTime)); } return(DisplayType.IsDate(_displayType)); } // isDate
/// <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); }
/// <summary> /// Create Report Column /// </summary> /// <param name="ctx">context </param> /// <param name="columnName">column name</param> /// <param name="displayType">display type</param> /// <param name="sql">sql (if null then columnName is used). </param> /// <param name="AD_Reference_Value_ID">List/Table Reference</param> /// <param name="refColumnName">UserReference column name /// Will be overwritten if TableDir or Search</param> public RColumn(Ctx ctx, String columnName, int displayType, String sql, int AD_Reference_Value_ID, String refColumnName) { _colHeader = Msg.Translate(ctx, columnName); if (refColumnName != null) { _colHeader = Msg.Translate(ctx, refColumnName); } _displayType = displayType; _colSQL = sql; if (_colSQL == null || _colSQL.Length == 0) { _colSQL = columnName; } // Strings if (DisplayType.IsText(displayType)) { _colClass = typeof(String);// String.class; // default size=30 } // Amounts else if (displayType == DisplayType.Amount) { _colClass = typeof(Decimal);// BigDecimal.class; _colSize = 70; } // Boolean else if (displayType == DisplayType.YesNo) { _colClass = typeof(Boolean);// Boolean.class; } // Date else if (DisplayType.IsDate(displayType)) { _colClass = typeof(DateTime);// Timestamp.class; } // Number else if (displayType == DisplayType.Quantity || displayType == DisplayType.Number || displayType == DisplayType.CostPrice) { _colClass = typeof(Double);// Double.class; _colSize = 70; } // Integer else if (displayType == DisplayType.Integer) { _colClass = typeof(int);// Integer.class; } // List else if (displayType == DisplayType.List) { Language language = Language.GetLanguage(Env.GetAD_Language(ctx)); _colSQL = "(" + VLookUpFactory.GetLookup_ListEmbed( language, AD_Reference_Value_ID, columnName) + ")"; _colClass = typeof(String);// String.class; _isIDcol = false; } /** Table * else if (displayType == DisplayType.Table) * { * Language language = Language.getLanguage(Env.getAD_Language(ctx)); * _colSQL += ",(" + MLookupFactory.getLookup_TableEmbed( * language, columnName, RModel.TABLE_ALIAS, AD_Reference_Value_ID) + ")"; * _colClass = String.class; * _isIDcol = false; * } **/ // TableDir, Search,... else { _colClass = typeof(String);// String.class; Language language = Language.GetLanguage(Env.GetAD_Language(ctx)); if (columnName.Equals("Account_ID") || columnName.Equals("User1_ID") || columnName.Equals("User2_ID")) { _colSQL += ",(" + VLookUpFactory.GetLookup_TableDirEmbed( language, "C_ElementValue_ID", RModel.TABLE_ALIAS, columnName) + ")"; _isIDcol = true; } else if (columnName.StartsWith("UserElement") && refColumnName != null) { _colSQL += ",(" + VLookUpFactory.GetLookup_TableDirEmbed( language, refColumnName, RModel.TABLE_ALIAS, columnName) + ")"; _isIDcol = true; } else if (columnName.Equals("C_LocFrom_ID") || columnName.Equals("C_LocTo_ID")) { _colSQL += ",(" + VLookUpFactory.GetLookup_TableDirEmbed( language, "C_Location_ID", RModel.TABLE_ALIAS, columnName) + ")"; _isIDcol = true; } else if (columnName.Equals("AD_OrgTrx_ID")) { _colSQL += ",(" + VLookUpFactory.GetLookup_TableDirEmbed( language, "AD_Org_ID", RModel.TABLE_ALIAS, columnName) + ")"; _isIDcol = true; } else if (displayType == DisplayType.TableDir) { _colSQL += ",(" + VLookUpFactory.GetLookup_TableDirEmbed( language, columnName, RModel.TABLE_ALIAS) + ")"; _isIDcol = true; } } }
//[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); }
public List <InfoColumn> GetDisplayCol(int AD_Table_ID, string AD_Language, bool IsBaseLangage, string _tableName) { try { bool _trlTableExist = false; if (!IsBaseLangage) { VAdvantage.DataBase.VConnection con = new VAdvantage.DataBase.VConnection(); string owner = con.Db_uid; if (Util.GetValueOfInt(DB.ExecuteQuery("SELECT count(*) FROM ALL_OBJECTS WHERE OBJECT_TYPE = 'TABLE' AND OWNER =upper( '" + owner + "') AND OBJECT_NAME =upper( '" + _tableName + "_TRL')", null, null)) > 0) { _trlTableExist = true; } } //Change by mohit-to handle translation in general info. //Added 2 new parametere- string AD_Language, bool IsBaseLangage. //Asked by mukesh sir - 09/03/2018 string sql = string.Empty; if (IsBaseLangage) { sql = @"SELECT c.ColumnName,c.Name, c.AD_Reference_ID, c.IsKey, f.IsDisplayed, c.AD_Reference_Value_ID, c.ColumnSQL, C.IsTranslated FROM AD_Column c INNER JOIN AD_Table t ON (c.AD_Table_ID=t.AD_Table_ID) INNER JOIN AD_Tab tab ON (t.AD_Window_ID=tab.AD_Window_ID) INNER JOIN AD_Field f ON (tab.AD_Tab_ID =f.AD_Tab_ID AND f.AD_Column_ID =c.AD_Column_ID) WHERE t.AD_Table_ID=" + AD_Table_ID + @" AND (c.IsKey ='Y' OR (f.IsEncrypted ='N' AND f.ObscureType IS NULL)) ORDER BY c.IsKey DESC, f.SeqNo"; } else { sql = @"SELECT c.ColumnName,trl.Name, c.AD_Reference_ID, c.IsKey, f.IsDisplayed, c.AD_Reference_Value_ID, c.ColumnSQL, C.IsTranslated FROM AD_Column c INNER JOIN AD_Table t ON (c.AD_Table_ID=t.AD_Table_ID) INNER JOIN AD_Column_Trl trl ON (c.ad_column_ID=trl.AD_Column_ID) INNER JOIN AD_Tab tab ON (t.AD_Window_ID=tab.AD_Window_ID) INNER JOIN AD_Field f ON (tab.AD_Tab_ID =f.AD_Tab_ID AND f.AD_Column_ID =c.AD_Column_ID) WHERE t.AD_Table_ID=" + AD_Table_ID + @" AND trl.AD_Language='" + AD_Language + @"' AND (c.IsKey ='Y' OR (f.IsEncrypted ='N' AND f.ObscureType IS NULL)) ORDER BY c.IsKey DESC, f.SeqNo"; } DataSet ds = DB.ExecuteDataset(sql); if (ds == null || ds.Tables[0].Rows.Count == 0) { return(null); } List <InfoColumn> lstCols = new List <InfoColumn>(); InfoColumn item = null; int displayType = 0; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { item = new InfoColumn(); item.IsKey = ds.Tables[0].Rows[i]["IsKey"].ToString() == "Y" ? true : false; item.IsDisplayed = ds.Tables[0].Rows[i]["IsDisplayed"].ToString() == "Y" ? true : false; displayType = Convert.ToInt32(ds.Tables[0].Rows[i]["AD_Reference_ID"]); if (item.IsKey) { } else if (!item.IsDisplayed) { continue; } else if (!(displayType == DisplayType.YesNo || displayType == DisplayType.Amount || displayType == DisplayType.Number || displayType == DisplayType.Quantity || displayType == DisplayType.Integer || displayType == DisplayType.String || displayType == DisplayType.Text || displayType == DisplayType.Memo || DisplayType.IsDate(displayType) || displayType == DisplayType.List)) { continue; } else if (!(ds.Tables[0].Rows[i]["ColumnSQL"] == null || ds.Tables[0].Rows[i]["ColumnSQL"] == DBNull.Value)) { continue; } item.ColumnName = ds.Tables[0].Rows[i]["ColumnName"].ToString(); item.Name = ds.Tables[0].Rows[i]["Name"].ToString(); item.AD_Reference_ID = Convert.ToInt32(ds.Tables[0].Rows[i]["AD_Reference_ID"]); item.IsKey = ds.Tables[0].Rows[i]["IsKey"].ToString() == "Y" ? true : false; item.IsDisplayed = ds.Tables[0].Rows[i]["IsDisplayed"].ToString() == "Y" ? true : false; if (!(ds.Tables[0].Rows[i]["AD_Reference_Value_ID"] == null || ds.Tables[0].Rows[i]["AD_Reference_Value_ID"] == DBNull.Value)) { item.AD_Reference_Value_ID = Convert.ToInt32(ds.Tables[0].Rows[i]["AD_Reference_Value_ID"]); item.RefList = GetRefList(item.AD_Reference_Value_ID); } item.ColumnSQL = ds.Tables[0].Rows[i]["ColumnSQL"].ToString(); // Change done by mohit asked by mukesh sir to show the data on info window from translated tab if logged in with langauge other than base language- 22/03/2018 item.IsTranslated = ds.Tables[0].Rows[i]["IsTranslated"].ToString() == "Y" ? true : false; item.trlTableExist = _trlTableExist; lstCols.Add(item); } return(lstCols); } catch { return(null); } }
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); }
public List <InfoColumn> GetDisplayCol(int AD_Table_ID) { try { string sql = @"SELECT c.ColumnName,c.Name, c.AD_Reference_ID, c.IsKey, f.IsDisplayed, c.AD_Reference_Value_ID, c.ColumnSQL FROM AD_Column c INNER JOIN AD_Table t ON (c.AD_Table_ID=t.AD_Table_ID) INNER JOIN AD_Tab tab ON (t.AD_Window_ID=tab.AD_Window_ID) INNER JOIN AD_Field f ON (tab.AD_Tab_ID =f.AD_Tab_ID AND f.AD_Column_ID =c.AD_Column_ID) WHERE t.AD_Table_ID=" + AD_Table_ID + @" AND (c.IsKey ='Y' OR (f.IsEncrypted ='N' AND f.ObscureType IS NULL)) ORDER BY c.IsKey DESC, f.SeqNo"; DataSet ds = DB.ExecuteDataset(sql); if (ds == null || ds.Tables[0].Rows.Count == 0) { return(null); } List <InfoColumn> lstCols = new List <InfoColumn>(); InfoColumn item = null; int displayType = 0; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { item = new InfoColumn(); item.IsKey = ds.Tables[0].Rows[i]["IsKey"].ToString() == "Y" ? true : false; item.IsDisplayed = ds.Tables[0].Rows[i]["IsDisplayed"].ToString() == "Y" ? true : false; displayType = Convert.ToInt32(ds.Tables[0].Rows[i]["AD_Reference_ID"]); if (item.IsKey) { } else if (!item.IsDisplayed) { continue; } else if (!(displayType == DisplayType.YesNo || displayType == DisplayType.Amount || displayType == DisplayType.Number || displayType == DisplayType.Quantity || displayType == DisplayType.Integer || displayType == DisplayType.String || displayType == DisplayType.Text || displayType == DisplayType.Memo || DisplayType.IsDate(displayType) || displayType == DisplayType.List)) { continue; } else if (!(ds.Tables[0].Rows[i]["ColumnSQL"] == null || ds.Tables[0].Rows[i]["ColumnSQL"] == DBNull.Value)) { continue; } item.ColumnName = ds.Tables[0].Rows[i]["ColumnName"].ToString(); item.Name = ds.Tables[0].Rows[i]["Name"].ToString(); item.AD_Reference_ID = Convert.ToInt32(ds.Tables[0].Rows[i]["AD_Reference_ID"]); item.IsKey = ds.Tables[0].Rows[i]["IsKey"].ToString() == "Y" ? true : false; item.IsDisplayed = ds.Tables[0].Rows[i]["IsDisplayed"].ToString() == "Y" ? true : false; if (!(ds.Tables[0].Rows[i]["AD_Reference_Value_ID"] == null || ds.Tables[0].Rows[i]["AD_Reference_Value_ID"] == DBNull.Value)) { item.AD_Reference_Value_ID = Convert.ToInt32(ds.Tables[0].Rows[i]["AD_Reference_Value_ID"]); item.RefList = GetRefList(item.AD_Reference_Value_ID); } item.ColumnSQL = ds.Tables[0].Rows[i]["ColumnSQL"].ToString(); lstCols.Add(item); } return(lstCols); } catch { return(null); } }
} // 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