private String ManageExportID(int PrimaryKey, String tableName, String refTable) { try { if (String.IsNullOrEmpty(refTable)) { refTable = tableName; } if (module == null) { module = new X_AD_ModuleInfo(GetCtx(), _AD_ModuleInfo_ID, null); } //String exportid = module.GetPrefix() + PrimaryKey; //export id to be picked from msequence table int expID = MSequence.GetNextExportID(GetCtx().GetAD_Client_ID(), tableName, null); if (expID == -1) { throw new InvalidConstraintException("ExportID -1 for TableName: " + tableName); } String exportid = module.GetPrefix() + expID; String _updateSql = "Update " + refTable + " SET Export_ID = " + DB.TO_STRING(exportid) + " WHERE " + tableName + "_ID = " + PrimaryKey; int result = DB.ExecuteQuery(_updateSql); return(exportid); } catch (Exception ex) { throw ex; return(""); } }
private String ManageExportID(int PrimaryKey, String tableName, String refTable) { try { if (String.IsNullOrEmpty(refTable)) { refTable = tableName; } if (module == null) { module = new X_AD_ModuleInfo(GetCtx(), _AD_ModuleInfo_ID, null); } //String exportid = module.GetPrefix() + PrimaryKey; //export id to be picked from msequence table String exportid = module.GetPrefix() + MSequence.GetNextExportID(GetCtx().GetAD_Client_ID(), tableName, null); String _updateSql = "Update " + refTable + " SET Export_ID = " + DB.TO_STRING(exportid) + " WHERE " + tableName + "_ID = " + PrimaryKey; int result = DB.ExecuteQuery(_updateSql); return(exportid); } catch { return(""); } }
private String ManageExportID(int recordID, int AD_Colone_ID, String tableName, int _table_ID) { try { //if (String.IsNullOrEmpty(refTable)) // refTable = tableName; if (module == null) { module = new X_AD_ModuleInfo(GetCtx(), _AD_ModuleInfo_ID, null); } //String exportid = module.GetPrefix() + PrimaryKey; //export id to be picked from msequence table int expID = MSequence.GetNextExportID(GetCtx().GetAD_Client_ID(), tableName, null); if (expID == -1) { throw new InvalidConstraintException("ExportID -1 for TableName: " + tableName); } String exportid = module.GetPrefix() + expID; string[] ds = GetParentColumns(_table_ID); //String _updateSql = "Update " + tableName + " SET Export_ID = " + DB.TO_STRING(exportid) + " WHERE " + tableName + "_ID = " + recordID; String _updateSql = "Update " + tableName + " SET Export_ID = " + DB.TO_STRING(exportid) + " WHERE "; // _updateSql += ds.Tables[0].Rows[0]["ColumnName"].ToString() + " =" + recordID; _updateSql += ds[0] + " =" + recordID; if (ds.Length > 1) { //_updateSql += " and " + ds.Tables[0].Rows[1]["ColumnName"].ToString() + " =" + AD_Colone_ID; _updateSql += " and " + ds[1] + " =" + AD_Colone_ID; } int result = DB.ExecuteQuery(_updateSql); return(exportid); } catch (Exception ex) { throw ex; return(""); } }
/// <summary> /// Executes the process /// </summary> /// <returns></returns> protected override string DoIt() { // lock object lock (_lock) { // check if process is already running for any module, then return with message. if (PrepareModuleSchema.running) { return("Module process already running, Please wait for some time...."); } PrepareModuleSchema.running = true; } try { File.AppendAllText(HostingEnvironment.ApplicationPhysicalPath + "\\log\\XMLLog.txt", "DoIT"); _ExportRecordList = GetExportData(); //fetch all the records to be exported / marked by a user ds = new DataSet(); //init ds DataTable SeqTable = new DataTable(); SeqTable.TableName = "ExportTableSequence"; SeqTable.Columns.Add("RowNum"); SeqTable.Columns.Add("TableName"); SeqTable.Columns.Add("Record_ID"); SeqTable.Columns.Add("AD_ColOne_ID"); ds.Tables.Add(SeqTable); //Parse through the marked record one by one foreach (ExportDataRecords exportdata in _ExportRecordList) { MTable currentTable = MTable.Get(GetCtx(), exportdata.AD_Table_ID); if (currentTable == null) //should not be null { continue; //skip the record and move further for next record } if (currentTable.Get_ID() == 0) //should not be 0 { log.Log(Level.SEVERE, "Table record not found. Continuing with next record"); continue; //move next } File.AppendAllText(HostingEnvironment.ApplicationPhysicalPath + "\\log\\XMLLog.txt", "GetFData" + currentTable); msg = GetForeignData(currentTable, exportdata); if (msg.Length > 0) { PrepareModuleSchema.running = false; return(msg); } } if (module == null) { module = new X_AD_ModuleInfo(GetCtx(), _AD_ModuleInfo_ID, null); } prefix = module.GetPrefix(); Module_Name = module.GetName(); versionNo = module.GetVersionNo(); // versionId = module.GetVersionID(); _FilePath = Path.Combine(HostingEnvironment.ApplicationPhysicalPath, prefix, Module_Name.Trim() + "_" + versionNo, "Data"); if (!Directory.Exists(_FilePath)) { Directory.CreateDirectory(_FilePath); } for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { try { DataRow r = ds.Tables[0].Rows[i]; string str = "Record_ID='" + r["Record_ID"].ToString() + "' and TableName='" + r["TableName"].ToString() + "'"; File.AppendAllText(HostingEnvironment.ApplicationPhysicalPath + "\\log\\XMLLog.txt", str); if (r["AD_ColOne_ID"] != DBNull.Value && r["AD_ColOne_ID"] != null && r["AD_ColOne_ID"].ToString() != "") { str += " and AD_ColOne_ID=" + Util.GetValueOfString(r["AD_ColOne_ID"]); } DataRow[] row = ds.Tables[0].Select(str); int findmax = Convert.ToInt32(row[row.Count() - 1]["RowNum"]); bool isDeleted = false; foreach (DataRow a in row) { if (!Convert.ToInt32(a["RowNum"]).Equals(findmax)) { a.Delete(); isDeleted = true; } } if (isDeleted) { --i; } } catch (Exception ex) { PrepareModuleSchema.running = false; return(ex.Message); } } // Delete Marking of records which were not found. DeleteRecordsMarked(); } finally { PrepareModuleSchema.running = false; } return(ds.ToXml(_FilePath)); }