public static void HandleInsertCommand(BasePage page, RadGrid Grid, CodeTorch.Core.Grid GridConfig, string InsertCommandName, object source, GridCommandEventArgs e) { DataCommandService dataCommandDB = DataCommandService.GetInstance(); PageDB pageDB = new PageDB(); log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); if (page.IsValid) { try { List <ScreenDataCommandParameter> parameters = null; log.Info("\r\n\r\nIn Insert Mode"); if (String.IsNullOrEmpty(InsertCommandName)) { throw new ApplicationException("InsertCommand is invalid"); } log.DebugFormat("InsertCommand:{0}", InsertCommandName); parameters = pageDB.GetPopulatedCommandParameters(InsertCommandName, page); dataCommandDB.ExecuteDataCommand(InsertCommandName, parameters); } catch (Exception ex) { e.Canceled = true; page.DisplayErrorAlert(ex); } } }
public void ExecuteCommand() { DataCommandService dataCommandDB = DataCommandService.GetInstance(); PageDB pageDB = new PageDB(); log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); try { if (Command != null) { Me = (ExecuteDataCommand)Command; } if (String.IsNullOrEmpty(Me.DataCommand)) { throw new ApplicationException(String.Format("Command {0} - ExecuteDataCommand - DataCommand is invalid", Me.Name)); } log.DebugFormat("DataCommand:{0}", Me.DataCommand); List <ScreenDataCommandParameter> parameters = null; parameters = pageDB.GetPopulatedCommandParameters(Me.DataCommand, Page); dataCommandDB.ExecuteDataCommand(Me.DataCommand, parameters); } catch (Exception ex) { Page.DisplayErrorAlert(ex); log.Error(ex); } }
public static void HandleUpdateCommand(BasePage page, RadGrid Grid, CodeTorch.Core.Grid GridConfig, string UpdateCommandName, object source, GridCommandEventArgs e) { DataCommandService dataCommandDB = DataCommandService.GetInstance(); PageDB pageDB = new PageDB(); log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); if (page.IsValid) { try { List <ScreenDataCommandParameter> parameters = null; log.Info("In Edit Mode"); if (String.IsNullOrEmpty(UpdateCommandName)) { throw new ApplicationException("UpdateCommand is invalid"); } log.DebugFormat("UpdateCommand:{0}", UpdateCommandName); if (String.IsNullOrEmpty(GridConfig.DataKeyNames) || String.IsNullOrEmpty(GridConfig.DataKeyParameterNames)) { throw new ApplicationException("Grid DataKeyNames or DataKeyParameterNames is not set in configuration"); } parameters = pageDB.GetPopulatedCommandParameters(UpdateCommandName, page); string[] dataKeyArray = GridConfig.DataKeyNames.Split(','); string[] dataKeyParamArray = GridConfig.DataKeyParameterNames.Split(','); if ((dataKeyArray.Length > 0)) { //map grid data keys to the screen data command parameters for (int i = 0; i < dataKeyArray.Length; i++) { if (i < dataKeyParamArray.Length) { SetGridDataKeysScreenDataCommandParameter(parameters, dataKeyParamArray[i], Grid.MasterTableView.DataKeyValues[e.Item.ItemIndex][dataKeyParamArray[i].Replace("@", "")]); } } } else { throw new ApplicationException("Grid DataKeyNames is not set in configuration"); } dataCommandDB.ExecuteDataCommand(UpdateCommandName, parameters); } catch (Exception ex) { e.Canceled = true; page.DisplayErrorAlert(ex); } } }
public static void HandleDeleteCommand(BasePage page, RadGrid Grid, CodeTorch.Core.Grid GridConfig, object source, GridCommandEventArgs e) { DataCommandService dataCommandDB = DataCommandService.GetInstance(); PageDB pageDB = new PageDB(); try { if (GridConfig.DeleteDataCommand != String.Empty) { if (String.IsNullOrEmpty(GridConfig.DataKeyNames) || String.IsNullOrEmpty(GridConfig.DataKeyParameterNames)) { throw new ApplicationException("Grid DataKeyNames or DataKeyParameterNames is not set in configuration"); } else { List <ScreenDataCommandParameter> parameters = pageDB.GetPopulatedCommandParameters(GridConfig.DeleteDataCommand, page); string[] dataKeyArray = GridConfig.DataKeyNames.Split(','); string[] dataKeyParamArray = GridConfig.DataKeyParameterNames.Split(','); if ((dataKeyArray.Length > 0)) { //map grid data keys to the screen data command parameters for (int i = 0; i < dataKeyArray.Length; i++) { if (i < dataKeyParamArray.Length) { SetGridDataKeysScreenDataCommandParameter(parameters, dataKeyParamArray[i], e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex][dataKeyArray[i]] ); } } dataCommandDB.ExecuteDataCommand(GridConfig.DeleteDataCommand, parameters); } else { throw new ApplicationException("Grid DataKeyNames is not set in configuration"); } } } else { throw new ApplicationException("DeleteCommand is invalid"); } } catch (Exception ex) { page.DisplayErrorAlert(ex); Common.LogException(ex, false); } }
public void InsertMailMessage(EmailMessage message) { List <ScreenDataCommandParameter> parameters = new List <ScreenDataCommandParameter>(); ScreenDataCommandParameter p = null; p = new ScreenDataCommandParameter(ParameterMailMessageID, message.ID); parameters.Add(p); p = new ScreenDataCommandParameter(ParameterMailSubject, message.Subject); parameters.Add(p); p = new ScreenDataCommandParameter(ParameterMailBody, message.Body); parameters.Add(p); p = new ScreenDataCommandParameter(ParameterPriority, message.Priority); parameters.Add(p); p = new ScreenDataCommandParameter(ParameterIsBodyHtml, message.IsBodyHtml); parameters.Add(p); p = new ScreenDataCommandParameter(ParameterTemplate, message.Template); parameters.Add(p); p = new ScreenDataCommandParameter(ParameterEntityType, message.EntityType); parameters.Add(p); p = new ScreenDataCommandParameter(ParameterEntityID, message.EntityID); parameters.Add(p); string userName; userName = UserIdentityService.GetInstance().IdentityProvider.GetUserName(); p = new ScreenDataCommandParameter(ParameterCreatedBy, userName); parameters.Add(p); //get data from data command sql.ExecuteDataCommand(DataCommandWMailInsertMailMessage, parameters); }
public void InsertDocument( string DocumentID, string StorageType, string EntityID, string EntityType, string DocumentName, string DocumentTypeCode, string ContentType, int Size, int?status, string DocumentUrl, byte[] File, bool IsEntityTypeDefault, string CreatedBy) { DataCommandService sql = DataCommandService.GetInstance(); List <ScreenDataCommandParameter> parameters = new List <ScreenDataCommandParameter>(); ScreenDataCommandParameter p = null; p = new ScreenDataCommandParameter(ParameterDocumentID, DocumentID); parameters.Add(p); p = new ScreenDataCommandParameter(ParameterStorageType, StorageType); parameters.Add(p); p = new ScreenDataCommandParameter(ParameterEntityID, EntityID); parameters.Add(p); p = new ScreenDataCommandParameter(ParameterEntityType, EntityType); parameters.Add(p); p = new ScreenDataCommandParameter(ParameterDocumentName, DocumentName); parameters.Add(p); p = new ScreenDataCommandParameter(ParameterDocumentTypeCode, DocumentTypeCode); parameters.Add(p); p = new ScreenDataCommandParameter(ParameterDocumentUrl, DocumentUrl); parameters.Add(p); p = new ScreenDataCommandParameter(ParameterFile, File); parameters.Add(p); p = new ScreenDataCommandParameter(ParameterStatus, status); parameters.Add(p); p = new ScreenDataCommandParameter(ParameterIsEntityTypeDefault, IsEntityTypeDefault); parameters.Add(p); p = new ScreenDataCommandParameter(ParameterContentType, ContentType); parameters.Add(p); p = new ScreenDataCommandParameter(ParameterSize, Size); parameters.Add(p); p = new ScreenDataCommandParameter(ParameterCreatedBy, CreatedBy); parameters.Add(p); sql.ExecuteDataCommand(DataCommandDocumentInsert, parameters); }
private string ExecuteDataCommand(string retVal) { DataCommandService dataCommandDB = DataCommandService.GetInstance(); PageDB pageDB = new PageDB(); DataCommand command = DataCommand.GetDataCommand(Me.DataCommand); List <ScreenDataCommandParameter> parameters = pageDB.GetPopulatedCommandParameters(Me.DataCommand, Page); DataTable data = null; object commandRetVal = null; if (command == null) { throw new ApplicationException(String.Format("DataCommand {0} could not be found in configuration", Me.DataCommand)); } if (command.ReturnType == DataCommandReturnType.DataTable) { data = dataCommandDB.GetDataForDataCommand(Me.DataCommand, parameters); } else { commandRetVal = dataCommandDB.ExecuteDataCommand(Me.DataCommand, parameters); } if (command.ReturnType == DataCommandReturnType.DataTable) { if (data != null) { if (!String.IsNullOrEmpty(Me.RedirectUrlField)) { if (data.Rows.Count == 1) { retVal = data.Rows[0][Me.RedirectUrlField].ToString(); } else { throw new ApplicationException("Invalid number of rows returned - " + data.Rows.Count); } } } } else { if (commandRetVal != null) { retVal = commandRetVal.ToString(); } } return(retVal); }
private void ExecuteDataCommand(string dataCommand, List <ScreenDataCommandParameter> parameters) { if (Connection == null) { sql.ExecuteDataCommand(dataCommand, parameters); } else { DataCommand command = DataCommand.GetDataCommand(dataCommand); if (command == null) { throw new Exception(String.Format("DataCommand {0} could not be found in configuration", dataCommand)); } sql.ExecuteCommand(null, Connection, command, parameters, command.Text); } }
public void ProcessRequest(HttpContext context) { App app = CodeTorch.Core.Configuration.GetInstance().App; StringBuilder builder = new StringBuilder(); StringWriter writer = new StringWriter(builder); try { if (Me == null) { if (context.Request.Path.ToLower().EndsWith("xml")) { Format = "xml"; } throw new ApplicationException("No service has been configured for this path"); } DataCommand command = null; RestServiceMethodReturnTypeEnum returnType = RestServiceMethodReturnTypeEnum.None; //collect parameters DataTable dt = null; XmlDocument doc = null; context.Response.TrySkipIisCustomErrors = true; if (Format.ToLower() == "json") { context.Response.ContentType = "application/json"; } else { context.Response.ContentType = "text/xml"; } BaseRestServiceMethod method = Me.Methods.Where(i => (i.Action.ToString() == HttpContext.Current.Request.HttpMethod)).SingleOrDefault(); if (method != null) { //pass parameters - minus dbcommand parameters to datacommand DataCommandService dataCommandDB = DataCommandService.GetInstance(); if (String.IsNullOrEmpty(method.RequestDataCommand)) { throw new ApplicationException(String.Format("Request Data Command has not been configured for this service - {0}", Me.Name)); } command = DataCommand.GetDataCommand(method.RequestDataCommand); if (command == null) { throw new ApplicationException(String.Format("Request Data Command - {0} - could not be found in configuration", method.RequestDataCommand)); } List <ScreenDataCommandParameter> parameters = GetPopulatedCommandParameters(method.RequestDataCommand, method.DataCommands, null); returnType = method.ReturnType; //execute request datacommand and return data if applicable switch (command.ReturnType) { case DataCommandReturnType.Integer: object newID = dataCommandDB.ExecuteDataCommand(method.RequestDataCommand, parameters); if (method is PostRestServiceMethod) { DataCommand postCommand = null; PostRestServiceMethod postMethod = (PostRestServiceMethod)method; returnType = postMethod.ReturnType; if (!String.IsNullOrEmpty(postMethod.ResponseDataCommand)) { postCommand = DataCommand.GetDataCommand(postMethod.ResponseDataCommand); if (postCommand == null) { throw new ApplicationException(String.Format("Response Data Command - {0} - could not be found in configuration", postMethod.ResponseDataCommand)); } parameters = GetPopulatedCommandParameters(postMethod.ResponseDataCommand, method.DataCommands, newID); switch (returnType) { case RestServiceMethodReturnTypeEnum.DataRow: case RestServiceMethodReturnTypeEnum.DataTable: dt = dataCommandDB.GetDataForDataCommand(postMethod.ResponseDataCommand, parameters); break; case RestServiceMethodReturnTypeEnum.Xml: doc = dataCommandDB.GetXmlDataForDataCommand(postMethod.ResponseDataCommand, parameters); break; } } } if (method is PutRestServiceMethod) { PutRestServiceMethod putMethod = (PutRestServiceMethod)method; returnType = putMethod.ReturnType; if (!String.IsNullOrEmpty(putMethod.ResponseDataCommand)) { parameters = GetPopulatedCommandParameters(putMethod.ResponseDataCommand, method.DataCommands, newID); dt = dataCommandDB.GetDataForDataCommand(putMethod.ResponseDataCommand, parameters); } } break; case DataCommandReturnType.Xml: doc = dataCommandDB.GetXmlDataForDataCommand(method.RequestDataCommand, parameters); break; default: dt = dataCommandDB.GetDataForDataCommand(method.RequestDataCommand, parameters); break; } //in certain cases execute response datacommand } else { throw new NotSupportedException(); } //get data if any if ( ((dt != null) && (returnType == RestServiceMethodReturnTypeEnum.DataTable)) || ((dt != null) && (returnType == RestServiceMethodReturnTypeEnum.DataRow)) || ((doc != null) && (returnType == RestServiceMethodReturnTypeEnum.Xml)) ) { if (Format.ToLower() == "json") { using (JsonWriter json = new JsonTextWriter(writer)) { DataColumnCollection columns = null; switch (returnType) { case RestServiceMethodReturnTypeEnum.DataTable: columns = dt.Columns; BuildJsonArrayResponse(app, context, method, command, dt, json, columns); break; case RestServiceMethodReturnTypeEnum.DataRow: columns = dt.Columns; BuildJsonObjectResponse(app, context, method, command, dt, json, columns); break; case RestServiceMethodReturnTypeEnum.Xml: BuildJsonXmlObjectResponse(app, method, builder, doc); break; } } } else { //xml using (XmlWriter xml = new XmlTextWriter(writer)) { DataColumnCollection columns = null; switch (method.ReturnType) { case RestServiceMethodReturnTypeEnum.DataTable: columns = dt.Columns; BuildXmlListResponse(app, context, method, command, dt, xml, columns); break; case RestServiceMethodReturnTypeEnum.DataRow: columns = dt.Columns; BuildXmlItemResponse(app, context, method, command, dt, xml, columns); break; case RestServiceMethodReturnTypeEnum.Xml: BuildXmlObjectResponse(app, method, doc, xml); break; } } } } //perform any special post processing //string url = ((System.Web.Routing.Route)(RouteData.Route)).Url; //context.Response.Write("From the handler at " + DateTime.Now + " - " + Me.Name + " - " + url + " - " + HttpContext.Current.Request.HttpMethod); //context.Response.ContentType = "text/xml"; //context.Response.Write(dt.DataSet.GetXml()); context.Response.StatusCode = (int)HttpStatusCode.OK; context.Response.Write(builder.ToString()); } catch (CodeTorchException cex) { builder = new StringBuilder(); RestServiceException exception = new RestServiceException(); exception.Status = (int)HttpStatusCode.InternalServerError; exception.Message = cex.Message; exception.MoreInfo = cex.MoreInfo; exception.ErrorCode = cex.ErrorCode; context.Response.TrySkipIisCustomErrors = true; context.Response.StatusCode = exception.Status; SerializeRestException(app, context, builder, writer, exception); } catch (Exception ex) { builder = new StringBuilder(); RestServiceException exception = new RestServiceException(); exception.Status = (int)HttpStatusCode.InternalServerError; exception.Message = ex.Message; context.Response.TrySkipIisCustomErrors = true; context.Response.StatusCode = exception.Status; SerializeRestException(app, context, builder, writer, exception); } }
protected async void SaveEditForm() { DataCommandService dataCommandDB = DataCommandService.GetInstance(); bool SuccessIndicator = false; string retVal = null; if (true)//Page.IsValid) { try { object r = null; List <ScreenDataCommandParameter> parameters = null; switch (PageMode) { case FormViewMode.View: CodeTorch.Core.Common.LogInfo("\r\n\r\nIn Insert Mode"); if (String.IsNullOrEmpty(Me.InsertCommand)) { throw new Exception("InsertCommand is invalid"); } CodeTorch.Core.Common.LogDebug(String.Format("InsertCommand:{0}", Me.InsertCommand)); parameters = Common.GetPopulatedCommandParameters(Me.InsertCommand, IPage); DataCommand command = DataCommand.GetDataCommand(Me.InsertCommand); switch (command.ReturnType) { case DataCommandReturnType.DataTable: r = await dataCommandDB.GetDataForDataCommand(Me.InsertCommand, parameters); break; case DataCommandReturnType.Integer: r = await dataCommandDB.ExecuteDataCommand(Me.InsertCommand, parameters); break; case DataCommandReturnType.Xml: throw new NotImplementedException(); break; case DataCommandReturnType.None: break; } if (r != null) { if (!String.IsNullOrEmpty(Me.AfterInsertSettings)) { if (r is DataTable) { DataTable dt = r as DataTable; if (dt.Rows.Count > 0) { DataRow row = dt.Rows[0]; Common.DataRowToSettings(row, Me.AfterInsertSettings); } } } //if r is datatable - see if any of the values need to be stored in settings //retVal = r.ToString(); //CodeTorch.Core.Common.LogDebug(String.Format("Output Parameter:{0}", retVal)); } CodeTorch.Core.Common.LogDebug(String.Format("RedirectAfterInsert:{0}", Me.RedirectAfterInsert)); if (Me.RedirectAfterInsert) { if (!String.IsNullOrEmpty(Me.AfterInsertRedirectScreen)) { Page p = MobilePage.GetPage(Me.AfterInsertRedirectScreen).GetPage(); Page.Navigation.PushAsync(p); } else { //TODO: do what -tell about config error } //string url = GetRedirectUrl(retVal); //log.DebugFormat("RedirectUrl:{0}", url); //Page.Response.Redirect(url,false); //HttpContext.Current.ApplicationInstance.CompleteRequest(); } else { Page.DisplayAlert("Alert", Me.AfterInsertConfirmationMessage, "OK"); //Page.DisplaySuccessAlert(String.Format(Me.AfterInsertConfirmationMessage, retVal)); //RefreshSections(); } break; //case FormViewMode.Edit: // log.Info("In Edit Mode"); // if (String.IsNullOrEmpty(Me.UpdateCommand)) // { // throw new ApplicationException("UpdateCommand is invalid"); // } // log.DebugFormat("UpdateCommand:{0}", Me.UpdateCommand); // parameters = pageDB.GetPopulatedCommandParameters(Me.UpdateCommand, Page); // dataCommandDB.ExecuteDataCommand(Me.UpdateCommand, parameters); // log.DebugFormat("RedirectAfterUpdate:{0}", Me.RedirectAfterUpdate); // if (Me.RedirectAfterUpdate) // { // string url = GetRedirectUrl(Page.Request.QueryString[Me.EntityID]); // log.DebugFormat("RedirectUrl:{0}", url); // Page.Response.Redirect(url, false); // HttpContext.Current.ApplicationInstance.CompleteRequest(); // } // else // { // Page.DisplaySuccessAlert(String.Format(Me.AfterUpdateConfirmationMessage, retVal)); // RefreshSections(); // } // break; } SuccessIndicator = true; } catch (Exception ex) { SuccessIndicator = false; IPage.DisplayErrorAlert(ex.Message); //log.Error(ex); } } //return SuccessIndicator; }
protected bool SaveEditForm() { DataCommandService dataCommandDB = DataCommandService.GetInstance(); PageDB pageDB = new PageDB(); bool SuccessIndicator = false; string retVal = null; log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); if (Page.IsValid) { try { object r = null; List <ScreenDataCommandParameter> parameters = null; switch (PageMode) { case FormViewMode.Insert: log.Info("\r\n\r\nIn Insert Mode"); if (String.IsNullOrEmpty(Me.InsertCommand)) { throw new ApplicationException("InsertCommand is invalid"); } log.DebugFormat("InsertCommand:{0}", Me.InsertCommand); parameters = pageDB.GetPopulatedCommandParameters(Me.InsertCommand, Page); r = dataCommandDB.ExecuteDataCommand(Me.InsertCommand, parameters); if (r != null) { retVal = r.ToString(); log.DebugFormat("Output Parameter:{0}", retVal); } log.DebugFormat("RedirectAfterInsert:{0}", Me.RedirectAfterInsert); if (Me.RedirectAfterInsert) { string url = GetRedirectUrl(retVal); log.DebugFormat("RedirectUrl:{0}", url); Page.Response.Redirect(url, false); HttpContext.Current.ApplicationInstance.CompleteRequest(); } else { Page.DisplaySuccessAlert(String.Format(Me.AfterInsertConfirmationMessage, retVal)); RefreshSections(); } break; case FormViewMode.Edit: log.Info("In Edit Mode"); if (String.IsNullOrEmpty(Me.UpdateCommand)) { throw new ApplicationException("UpdateCommand is invalid"); } log.DebugFormat("UpdateCommand:{0}", Me.UpdateCommand); parameters = pageDB.GetPopulatedCommandParameters(Me.UpdateCommand, Page); dataCommandDB.ExecuteDataCommand(Me.UpdateCommand, parameters); log.DebugFormat("RedirectAfterUpdate:{0}", Me.RedirectAfterUpdate); if (Me.RedirectAfterUpdate) { string url = GetRedirectUrl(Page.Request.QueryString[Me.EntityID]); log.DebugFormat("RedirectUrl:{0}", url); Page.Response.Redirect(url, false); HttpContext.Current.ApplicationInstance.CompleteRequest(); } else { Page.DisplaySuccessAlert(String.Format(Me.AfterUpdateConfirmationMessage, retVal)); RefreshSections(); } break; } SuccessIndicator = true; } catch (Exception ex) { SuccessIndicator = false; Page.DisplayErrorAlert(ex); log.Error(ex); } } return(SuccessIndicator); }