protected void CheckLock(ActiveRecord record) { if (record == null) { return; } lockobj.InitLocking(Security.LoggedInUserID); if (!lockobj.LockTable(record.GetTableName(), (record[record.GetPrimaryKeyName()] + "").ToIntOrDie(), record.GetName())) { Web.ErrorMessage = lockobj.LockMessage; } }
public static void AddPhrase(ActiveRecord record, string phrase = null, bool splitPhrase = false, string delimiter = ",") { if (phrase == null) { phrase = record.GetName(); } if (record.GetIsActive()) { AddPhrase(record.GetTableName(), record.ID_Field.ToInt(), phrase, splitPhrase, delimiter); } else { DeletePhrase(record); } }
/// <summary> /// write the lg for a given record, or null if log is disabled /// </summary> /// <param name="obj"></param> /// <returns></returns> public static string ShowModificationLog(ActiveRecord obj) { #if ModificationLog if (!Util.GetSettingBool("UseModificationLog", false)) { return(null); } int pkvalue = obj.ID_Field.ToInt(0); string tableName = obj.GetTableName(); string ModLogTableName = "ModificationLog"; var sql = new Sql("select top 100 * from ", ModLogTableName.SqlizeName(), " where TableName=", tableName.Sqlize_Text(), " "); sql.Add(" and RecordID=", pkvalue, ""); sql.Add(" order by updatedate desc"); string res = @"<tr class=""dontprint""> <td class=label>Change History</td> <td class=field><a href="""" onclick=""$('.modlog').show();$(this).hide();return false;"">show</a><div class=""modlog"" style=""display:none"">" ; int scan = 0; using (DbDataReader dbDataReader = sql.GetReader()) { foreach (DbDataRecord rsLog in dbDataReader) { var person = Person.LoadID((rsLog["PersonID"] + "").ToInt(0)); var UserName = (person != null) ? person.FullName : "not available"; string descr = rsLog["ChangeDescription"].ToString().FmtPlainTextAsHtml(); if (!(descr.Contains("Date Modified changed") && descr.Length < 94)) //eg skip Date Modified changed from "29 Oct 2013 19:49am" to "29 Oct 2013 10:51am" //descr = descr.Replace("<br>", " | "); // removed and applied nice formatting below (JVB) { res += "<b>" + rsLog["ActionType"] + "</b> on " + Fmt.DateTime(rsLog["UpdateDate"] + "") + " by " + UserName + ":<br/> - " + descr + "<br/><br/>"; scan++; if (scan > 100) { res += "more..."; break; } } } } res += @"</div> </td> </tr>" ; //todo: remove any old mod logs when drawing a mod log page. return(res); #else return("Not available."); #endif }
public static MvcHtmlString DraggableSortPosition(this HtmlHelper htmlHelper, ActiveRecord listItem, int?sortPositionCurrentValue, object sortGroup = null, string action = "SaveSortOrder") { Beweb.Util.IncludeJavascriptFile("~/js/redips_drag/redips-drag.min.js"); string url = new UrlHelper(htmlHelper.ViewContext.RequestContext).Action(action); url += "?t=" + Crypto.Encrypt(listItem.GetTableName()) + "&p=" + Crypto.Encrypt(listItem.GetPrimaryKeyName()); Beweb.Util.IncludeJavascript("$(function() { svyInitSortPositionTableDrag(\"" + url + "\"); });"); string html = "<td class=\"rowhandler\"><div class=\"drag row\" title=\"Drag to change sort position\"><i class=\"icon-align-justify\"></i> <span class=\"svyRowSort\" data-pkid=" + listItem.ID_Field.ToString() + " data-sortgroup=" + sortGroup + ">" + sortPositionCurrentValue + "</span><input type=\"hidden\" name=\"SortPosition" + Forms.CurrentRowSuffix + "\" value=\"" + sortPositionCurrentValue + "\"></div></td>"; if (Web.Request["Search"].IsNotBlank() || (Web.Request["ColSortField"].IsNotBlank() && Web.Request["ColSortField"] != "SortPosition")) // hide sortable if in middle of a search filter { html = "<td class=\"rowhandler\"><div class=\"row\">" + sortPositionCurrentValue + "</div></td>"; } return(MvcHtmlString.Create(html)); }
public static void DeletePhrase(ActiveRecord record) { DeletePhrase(record.GetTableName(), record.ID_Field.ToInt()); }
public static void CheckAttachmentsForDocOrPDFText(ActiveRecord record) { //walk the field list for this record looking for attachments foreach (var fieldName in record.GetFieldNames()) { if (fieldName.Contains("Attachment") && fieldName.DoesntContain("RawText")) { //if (record.Fields.Attachment.IsDirty) { if (ActiveFieldBase.IsDirtyObj(record[fieldName].ValueObject, record[fieldName].OriginalValueObject)) { if (record[fieldName].ToString().Contains(".doc") || record[fieldName].ToString().EndsWith(".pdf") || record[fieldName].ToString().EndsWith(".rtf")) { if (!record.FieldExists(fieldName + "RawText")) { (new Sql("ALTER TABLE ", record.GetTableName().SqlizeName(), " ADD [" + fieldName + "RawText] nvarchar (MAX);")).Execute(); } string output = ""; if (record[fieldName].ToString().ToLower().EndsWith(".doc")) { OfficeFileReader.OfficeFileReader objOFR = new OfficeFileReader.OfficeFileReader(); if (objOFR.GetText(Web.MapPath(Web.Attachments) + record[fieldName].ToString(), ref output) > 0) { //ok } } else if (record[fieldName].ToString().ToLower().EndsWith(".docx")) { BewebCore.ThirdParty.ReadWordDocText.DocxToText objOFR = new DocxToText(Web.MapPath(Web.Attachments) + record[fieldName].ToString()); if ((output = objOFR.ExtractText()).Length > 0) { //ok } } else if (record[fieldName].ToString().Contains(".pdf")) { PdfToText.PDFParser pdf = new PDFParser(); if (pdf.ExtractText(Web.MapPath(Web.Attachments) + record[fieldName].ToString(), ref output)) { //ok } } else if (record[fieldName].ToString().Contains(".rtf")) { #if RTFProcessingAvailable //Create the RTF tree object RtfTree tree = new RtfTree(); //Load and parse RTF document tree.LoadRtfFile(Web.MapPath(Web.Attachments) + record[fieldName].ToString()); output = tree.Text; #else throw new Exception("rtf library not included"); #endif } if (output.Trim() != "") { (new Sql("update ", record.GetTableName().SqlizeName(), "set " + fieldName + "RawText=", output.SqlizeText(), " where ", record.GetPrimaryKeyName().SqlizeName(), "=", record.ID_Field.Sqlize(), "")).Execute(); } } else { //no doc any more if (record.FieldExists(fieldName + "RawText")) { (new Sql("update ", record.GetTableName().SqlizeName(), "set " + fieldName + "RawText=null where ", record.GetPrimaryKeyName().SqlizeName(), "=", record.ID_Field.Sqlize(), "")).Execute(); } } } } } }