Esempio n. 1
0
        private Hashtable GetContentItems(Template contentTemplate)
        {
            DataCommandService dataCommandDB = DataCommandService.GetInstance();
            PageDB             pageDB        = new PageDB();
            Hashtable          retVal        = new Hashtable();

            var dataItems = from t in contentTemplate.DataItems
                            join c in Me.DataItems
                            on t.Name.ToLower() equals c.DataItem.ToLower()
                            select new
            {
                t.Name,
                Item = c
            };

            foreach (var dataItem in dataItems)
            {
                List <ScreenDataCommandParameter> parameters = pageDB.GetPopulatedCommandParameters(dataItem.Item.DataCommand, page);
                DataTable data = dataCommandDB.GetDataForDataCommand(dataItem.Item.DataCommand, parameters);


                retVal.Add(dataItem.Name, data);
            }



            return(retVal);
        }
Esempio n. 2
0
        private string GetDynamicPageTemplate(ScreenPageTemplate pageTemplate)
        {
            string retVal = null;

            log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            try
            {
                DataCommandService dataCommandDB = DataCommandService.GetInstance();
                PageDB             pageDB        = new PageDB();

                List <ScreenDataCommandParameter> parameters = pageDB.GetPopulatedCommandParameters(pageTemplate.DataCommand, this);

                DataTable dt = dataCommandDB.GetDataForDataCommand(pageTemplate.DataCommand, parameters);
                if (dt.Rows.Count > 0)
                {
                    if (dt.Columns.Contains(pageTemplate.DataField))
                    {
                        retVal = dt.Rows[0][pageTemplate.DataField].ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                DisplayErrorAlert(ex);

                log.Error(ex);
            }

            return(retVal);
        }
Esempio n. 3
0
        public override void PopulateControl()
        {
            base.PopulateControl();

            if (!String.IsNullOrEmpty(Me.SelectDataCommand))
            {
                PageDB pageDB = new PageDB();
                List <ScreenDataCommandParameter> parameters;
                BasePage           page        = ((BasePage)this.Page);
                DataCommandService dataCommand = DataCommandService.GetInstance();

                parameters = pageDB.GetPopulatedCommandParameters(Me.SelectDataCommand, (BasePage)this.Page);

                DataTable data = dataCommand.GetDataForDataCommand(Me.SelectDataCommand, parameters);
                if (data.Rows.Count > 0)
                {
                    this.Content.Text = PopulateContent(Me.Content, data.Rows[0]);
                }
                else
                {
                    this.Content.Text = Me.Content;
                }
            }
            else
            {
                this.Content.Text = Me.Content;
            }
        }
Esempio n. 4
0
        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);
            }
        }
Esempio n. 5
0
        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);
                }
            }
        }
Esempio n. 6
0
        private string GetDatabaseDisplayValue(string value)
        {
            string retVal = null;
            DataCommandService dataCommandDB = DataCommandService.GetInstance();

            if (String.IsNullOrEmpty(Me.PickerObject.DataCommand))
            {
                throw new ApplicationException("Picker does not have a datacommand specified in configuration");
            }

            DataCommand command = DataCommand.GetDataCommand(Me.PickerObject.DataCommand);

            if (command == null)
            {
                throw new ApplicationException(String.Format("DataCommand {0} does not exist in configuration", Me.PickerObject.DataCommand));
            }

            List<ScreenDataCommandParameter> parameters = new List<ScreenDataCommandParameter>();
            ScreenDataCommandParameter parameter = new ScreenDataCommandParameter();

            parameter.Name = command.Parameters[0].Name;
            parameter.Value = value;

            parameters.Add(parameter);

            DataTable dt = dataCommandDB.GetDataForDataCommand(command.Name, parameters);

            if (dt.Rows.Count > 0)
            {
                retVal = dt.Rows[0][Me.PickerObject.DisplayField].ToString();

            }

            return retVal;
        }
        private void DefaultForm()
        {
            log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            try
            {
                DataCommandService dataCommandDB = DataCommandService.GetInstance();
                PageDB             pageDB        = new PageDB();

                if (!String.IsNullOrEmpty(Me.DefaultCommand))
                {
                    List <ScreenDataCommandParameter> parameters = null;
                    parameters = pageDB.GetPopulatedCommandParameters(Me.DefaultCommand, Page);
                    DataTable retVal = dataCommandDB.GetDataForDataCommand(Me.DefaultCommand, parameters);

                    foreach (Section section in Page.Screen.Sections)
                    {
                        Page.PopulateFormByDataTable(section.Widgets, retVal);
                    }
                }
            }
            catch (Exception ex)
            {
                Page.DisplayErrorAlert(ex);

                log.Error(ex);
            }
        }
Esempio n. 8
0
        private void Save_Click(object sender, EventArgs e)
        {
            try
            {
                if (ValidateSaveRequest())
                {
                    DataCommand cmd = new DataCommand();

                    cmd.Name           = CommandName.Text;
                    cmd.DataConnection = DataConnectionList.Text;
                    cmd.Type           = CommandTypeList.Text.ToString();
                    cmd.Text           = CommandText.Text;
                    cmd.ReturnType     = (DataCommandReturnType)Enum.Parse(typeof(DataCommandReturnType), CommandReturnTypeList.Text.ToString());

                    DataConnection       connection = Project.GetDataConnection(cmd);
                    IDataCommandProvider DataSource = DataCommandService.GetInstance().GetProvider(connection);
                    DataSource.RefreshSchema(connection, cmd);

                    DataCommand.Save(cmd);

                    Configuration.GetInstance().DataCommands.Add(cmd);


                    this.DialogResult = DialogResult.OK;
                }
            }
            catch (Exception ex)
            {
                ErrorManager.HandleError(ex);
            }
        }
Esempio n. 9
0
        public override void PopulateControl()
        {
            base.PopulateControl();

            string DataCommandName = null;

            if (DetailsSection != null)
            {
                DataCommandName = DetailsSection.SelectDataCommand;
            }


            if (!String.IsNullOrEmpty(DataCommandName))
            {
                DataCommandService dataCommandDB = DataCommandService.GetInstance();
                PageDB             pageDB        = new PageDB();

                List <ScreenDataCommandParameter> parameters = null;
                BasePage page = (BasePage)this.Page;

                parameters = GetParameters(DataCommandName);
                DataTable data = dataCommandDB.GetDataForDataCommand(DataCommandName, parameters);

                page.PopulateFormByDataTable(Section.Widgets, data);
            }

            ExecuteAfterPopulateSection();
        }
Esempio n. 10
0
        protected virtual void RenderReport()
        {
            DataCommandService dataCommandDB = DataCommandService.GetInstance();
            PageDB             pageDB        = new PageDB();

            //get report data
            Hashtable dataItems = new Hashtable();

            foreach (CodeTorch.Core.ReportDataSource dataSource in Me.ReportDataSources)
            {
                DataTable data = GetData(dataCommandDB, pageDB, dataSource);
                dataItems.Add(dataSource.Name, data);
            }

            //render report
            string mime = null;
            string ext  = null;

            byte[] report = ReportFunctions.RenderReport(Me, dataItems, out mime, out ext);

            Page.Response.Expires = 0;
            Page.Response.Buffer  = true;
            Page.Response.Clear();
            Page.Response.ClearContent();
            Page.Response.ClearHeaders();
            Page.Response.AddHeader("Content-Disposition", String.Format("attachment;filename={0}.{1}", (String.IsNullOrEmpty(Me.ExportFileName) ? "export" : Me.ExportFileName), ext));
            Page.Response.ContentType = mime;
            Page.Response.BinaryWrite(report);
            Page.Response.End();
        }
Esempio n. 11
0
        private DataTable GetData(DataCommandService dataCommandDB, PageDB pageDB, CodeTorch.Core.ReportDataSource dataSource)
        {
            List <ScreenDataCommandParameter> parameters = pageDB.GetPopulatedCommandParameters(dataSource.ReportCommand, page);
            DataTable data = dataCommandDB.GetDataForDataCommand(dataSource.ReportCommand, parameters);

            return(data);
        }
Esempio n. 12
0
        void DataCommandValidator_ServerValidate(object source, ServerValidateEventArgs args)
        {
            bool IsValid = false;
            DataCommandService dataCommand = DataCommandService.GetInstance();
            PageDB             pageDB      = new PageDB();

            try
            {
                CustomDataCommandValidator        validator  = (CustomDataCommandValidator)source;
                List <ScreenDataCommandParameter> parameters = pageDB.GetPopulatedCommandParameters(validator.DataCommand, ((CodeTorch.Web.Templates.BasePage) this.Page));

                if (validator.UseValueParameter)
                {
                    ScreenDataCommandParameter valueParameter = parameters.Where(p =>
                                                                                 (
                                                                                     (p.Name.ToLower() == validator.ValueParameter.ToLower())
                                                                                 )
                                                                                 )
                                                                .SingleOrDefault();

                    if (valueParameter != null)
                    {
                        valueParameter.Value = args.Value;
                    }
                }

                DataTable data = dataCommand.GetDataForDataCommand(validator.DataCommand, parameters);

                if (data.Rows.Count == 1)
                {
                    if (validator.UseErrorMessageField)
                    {
                        if (String.IsNullOrEmpty(validator.ErrorMessageField))
                        {
                            throw new ApplicationException(String.Format("ErrorMessageField for validator {0} is not configured", validator.ID));
                        }
                        else
                        {
                            if (data.Columns.Contains(validator.ErrorMessageField))
                            {
                                validator.ErrorMessage = data.Rows[0][validator.ErrorMessageField].ToString();
                            }
                        }
                    }

                    if (data.Columns.Contains(validator.ValidationField))
                    {
                        IsValid = Convert.ToBoolean(data.Rows[0][validator.ValidationField]);
                    }
                }
            }
            catch (Exception ex)
            {
                args.IsValid = false;
                ((System.Web.UI.WebControls.BaseValidator)source).ErrorMessage = "Validator: " + ex.Message;
            }

            args.IsValid = IsValid;
        }
Esempio n. 13
0
        public static DataTable GetUsers(WorkflowDynamicSecurityGroup group, Workflow workflow, WorkflowStep step, string EntityID, string UserName)
        {
            DataTable retVal = null;


            DataCommandService dataCommandDB = DataCommandService.GetInstance();


            DataCommand command = Core.DataCommand.GetDataCommand(group.DataCommand);

            if (command == null)
            {
                throw new ApplicationException(String.Format("DataCommand {0} could not be found in configuration", group.DataCommand));
            }


            List <ScreenDataCommandParameter> parameters = new List <ScreenDataCommandParameter>();
            ScreenDataCommandParameter        parameter  = null;

            if (!String.IsNullOrEmpty(group.WorkflowCodeParameter))
            {
                parameter       = new ScreenDataCommandParameter();
                parameter.Name  = group.WorkflowCodeParameter;
                parameter.Value = workflow.Code;
                parameters.Add(parameter);
            }

            if (!String.IsNullOrEmpty(group.CurrentWorkflowStepCodeParameter))
            {
                parameter       = new ScreenDataCommandParameter();
                parameter.Name  = group.CurrentWorkflowStepCodeParameter;
                parameter.Value = step.Code;
                parameters.Add(parameter);
            }

            if (!String.IsNullOrEmpty(group.EntityIDParameter))
            {
                parameter       = new ScreenDataCommandParameter();
                parameter.Name  = group.EntityIDParameter;
                parameter.Value = EntityID;
                parameters.Add(parameter);
            }

            if (!String.IsNullOrEmpty(group.UsernameParameter))
            {
                parameter       = new ScreenDataCommandParameter();
                parameter.Name  = group.UsernameParameter;
                parameter.Value = UserName;
                parameters.Add(parameter);
            }

            //execute command with transaction
            //CommandType type = (command.Type == DataCommandCommandType.StoredProcedure) ? CommandType.StoredProcedure : CommandType.Text;
            retVal = dataCommandDB.GetDataForDataCommand(command.Name, parameters);


            return(retVal);
        }
Esempio n. 14
0
        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);
                }
            }
        }
        private void FillGrid()
        {
            if (String.IsNullOrEmpty(Me.Grid.SelectDataCommand))
            {
                throw new ApplicationException("Invalid SelectDataCommand");
            }

            DataCommandService dataCommand = DataCommandService.GetInstance();
            List <ScreenDataCommandParameter> parameters = GetParameters();

            Grid.DataSource = dataCommand.GetDataForDataCommand(Me.Grid.SelectDataCommand, parameters);
        }
Esempio n. 16
0
        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);
            }
        }
Esempio n. 17
0
        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);
        }
Esempio n. 18
0
        public static string GetProfileProperty(string PropertyName, List <string> profileProperties)
        {
            string profileSessionKey = "CodeTorch.Profile";
            App    app           = CodeTorch.Core.Configuration.GetInstance().App;
            string retVal        = "";
            int    propertyIndex = Enumerable.Range(0, profileProperties.Count).First(i => profileProperties[i].ToLower() == PropertyName.ToLower());

            if (app.AuthenticationMode is FormsAuthenticationMode)
            {
                //get profile property from form authentication cookie
                FormsIdentity             identity = (FormsIdentity)HttpContext.Current.User.Identity;
                FormsAuthenticationTicket ticket   = identity.Ticket;

                retVal = ticket.UserData.Split('|')[propertyIndex];
            }
            else
            {
                throw new NotImplementedException();


                //get profile property from session object
                DataTable dtProfile = null;
                if (HttpContext.Current != null)
                {
                    if (HttpContext.Current.Session[profileSessionKey] != null)
                    {
                        dtProfile = (DataTable)HttpContext.Current.Session[profileSessionKey];
                    }
                    else
                    {
                        //TODO - needs to be moved to app authenticate
                        DataCommandService dataCommandDB = DataCommandService.GetInstance();
                        PageDB             pageDB        = new PageDB();


                        List <ScreenDataCommandParameter> parameters = pageDB.GetPopulatedCommandParameters(app.ProfileCommand, null);

                        dtProfile = dataCommandDB.GetDataForDataCommand(app.ProfileCommand, parameters);

                        HttpContext.Current.Session[profileSessionKey] = dtProfile;
                    }

                    if ((dtProfile != null) && (dtProfile.Rows.Count == 1))
                    {
                        retVal = dtProfile.Rows[0][PropertyName].ToString();
                    }
                }
            }
            return(retVal);
        }
Esempio n. 19
0
        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);
        }
Esempio n. 20
0
        private DataTable GetContentTemplateData()
        {
            DataCommandService dataCommandDB = DataCommandService.GetInstance();
            PageDB             pageDB        = new PageDB();

            if (String.IsNullOrEmpty(Me.ContentTemplateDataCommand))
            {
                throw new ApplicationException("ContentTemplateDataCommand is not configured");
            }

            List <ScreenDataCommandParameter> parameters = pageDB.GetPopulatedCommandParameters(Me.ContentTemplateDataCommand, page);
            DataTable data = dataCommandDB.GetDataForDataCommand(Me.ContentTemplateDataCommand, parameters);

            return(data);
        }
Esempio n. 21
0
        protected void RenderReport()
        {
            try
            {
                DataCommandService dataCommandDB = DataCommandService.GetInstance();
                PageDB             pageDB        = new PageDB();

                viewer.Reset();

                LoadReportDefinition(viewer.LocalReport);
                viewer.LocalReport.DataSources.Clear();

                foreach (CodeTorch.Core.ReportParameter p in GetReportParameters())
                {
                    string parameterValue = null;

                    if (p.Value != null)
                    {
                        parameterValue = p.Value.ToString();
                    }

                    Microsoft.Reporting.WebForms.ReportParameter rp = new Microsoft.Reporting.WebForms.ReportParameter(p.Name, parameterValue);
                    viewer.LocalReport.SetParameters(rp);
                }

                foreach (CodeTorch.Core.ReportDataSource dataSource in Me.ReportDataSources)
                {
                    DataTable data = GetData(dataCommandDB, pageDB, dataSource);

                    Microsoft.Reporting.WebForms.ReportDataSource rds = new Microsoft.Reporting.WebForms.ReportDataSource(dataSource.Name, data);
                    viewer.LocalReport.DataSources.Add(rds);
                }

                viewer.LocalReport.DisplayName = "Report";

                viewer.LocalReport.Refresh();
                viewer.Visible = true;

                this.Visible = true;
            }
            catch (Exception ex)
            {
                Common.LogException(ex, false);


                page.DisplayErrorAlert(String.Format("<strong>The following error(s) occurred:</strong>{0}", Common.GetExceptionMessage(ex, 4)));
            }
        }
Esempio n. 22
0
        private static void HandleEditableGridDetailPopulation(BasePage page, CodeTorch.Core.Grid GridConfig, bool UseDefaultCommand, string DefaultCommandName, GridItemEventArgs e)
        {
            if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
            {
                Control c = page.FindControlRecursive(e.Item, GridEditFormItem.EditFormUserControlID);
                if (c != null)
                {
                    GridDetail detail = ((GridDetail)c);



                    if (e.Item.OwnerTableView.IsItemInserted)
                    {
                        if (UseDefaultCommand)
                        {
                            if (!String.IsNullOrEmpty(DefaultCommandName))
                            {
                                DataCommandService dataCommandDB = DataCommandService.GetInstance();
                                PageDB             pageDB        = new PageDB();

                                List <ScreenDataCommandParameter> parameters = pageDB.GetPopulatedCommandParameters(DefaultCommandName, page);
                                DataTable data = dataCommandDB.GetDataForDataCommand(GridConfig.SelectDataCommand, parameters);
                                detail.Default(e.Item, data);
                            }
                        }
                    }
                    else
                    {
                        DataRowView data = ((DataRowView)detail.DataItem);
                        detail.Populate(e.Item);
                    }

                    detail.ExecuteAfterPopulateSections();
                }
            }
        }
Esempio n. 23
0
        public static void FillGrid(BasePage page, RadGrid Grid, CodeTorch.Core.Grid GridConfig)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            try
            {
                DataCommandService dataCommandDB = DataCommandService.GetInstance();
                PageDB             pageDB        = new PageDB();

                if (String.IsNullOrEmpty(GridConfig.SelectDataCommand))
                {
                    throw new ApplicationException("SelectDataCommand is not configured");
                }

                List <ScreenDataCommandParameter> parameters = pageDB.GetPopulatedCommandParameters(GridConfig.SelectDataCommand, page);

                Grid.DataSource = dataCommandDB.GetDataForDataCommand(GridConfig.SelectDataCommand, parameters);
            }
            catch (Exception ex)
            {
                page.DisplayErrorAlert(ex);

                log.Error(ex);
            }
        }
Esempio n. 24
0
        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);
            }
        }
Esempio n. 25
0
        public NewDataCommandDialog()
        {
            InitializeComponent();

            dataCommandDB = DataCommandService.GetInstance();
        }
Esempio n. 26
0
        private void DownloadDocument()
        {
            log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            try
            {
                DataCommandService dataCommandDB = DataCommandService.GetInstance();
                PageDB             pageDB        = new PageDB();

                if (!String.IsNullOrEmpty(Me.RetrieveCommand))
                {
                    List <ScreenDataCommandParameter> parameters = null;
                    parameters = pageDB.GetPopulatedCommandParameters(Me.RetrieveCommand, Page);
                    DataTable dt = dataCommandDB.GetDataForDataCommand(Me.RetrieveCommand, parameters);

                    if (dt.Rows.Count != 0)
                    {
                        byte[] data        = null;
                        string DocumentUrl = dt.Rows[0]["DocumentUrl"].ToString();

                        Page.Response.Clear();
                        Page.Response.ContentType = dt.Rows[0]["ContentType"].ToString();

                        //Force file download with content disposition
                        if (Me.ForceDownloadWithContentDisposition)
                        {
                            Page.Response.AddHeader("Content-Disposition", "attachment;filename=" + dt.Rows[0]["DocumentName"].ToString());
                        }

                        if (String.IsNullOrEmpty(DocumentUrl))
                        {
                            data = (byte[])dt.Rows[0]["File"];

                            Page.Response.OutputStream.Write(data, 0, Convert.ToInt32(dt.Rows[0]["Size"]));

                            // Flush the data
                            Page.Response.Flush();
                        }
                        else
                        {
                            //redirect to the document url location
                            UriBuilder remoteDocument = new UriBuilder(DocumentUrl);

                            HttpWebRequest  fileReq  = (HttpWebRequest)HttpWebRequest.Create(remoteDocument.Uri.AbsoluteUri);
                            HttpWebResponse fileResp = (HttpWebResponse)fileReq.GetResponse();

                            if (fileReq.ContentLength > 0)
                            {
                                fileResp.ContentLength = fileReq.ContentLength;
                            }

                            Stream stream      = fileResp.GetResponseStream();
                            int    bytesToRead = 10000;
                            int    length;
                            data = new Byte[bytesToRead];
                            do
                            {
                                // Verify that the client is connected.
                                if (Page.Response.IsClientConnected)
                                {
                                    // Read data into the buffer.
                                    length = stream.Read(data, 0, bytesToRead);

                                    // and write it out to the response's output stream
                                    Page.Response.OutputStream.Write(data, 0, length);

                                    // Flush the data
                                    Page.Response.Flush();

                                    //Clear the buffer
                                    data = new Byte[bytesToRead];
                                }
                                else
                                {
                                    // cancel the download if client has disconnected
                                    length = -1;
                                }
                            } while (length > 0); //Repeat until no data is read
                        }



                        HttpContext.Current.ApplicationInstance.CompleteRequest();
                    }
                    else
                    {
                        throw new Exception("File Not Found");
                    }
                }
            }
            catch (Exception ex)
            {
                Page.DisplayErrorAlert(ex);

                log.Error(ex);
            }
        }
Esempio n. 27
0
        private CodeTorch.Core.Menu PopulateDynamicMenuItems(CodeTorch.Core.Menu menuObject)
        {
            CodeTorch.Core.Menu retVal = null;

            DataCommandService dataCommandDB             = DataCommandService.GetInstance();
            List <ScreenDataCommandParameter> parameters = new List <ScreenDataCommandParameter>();

            var items = from item in menuObject.Items
                        where item.UseCommand == true
                        select item;

            if (items.Count() > 0)
            {
                retVal          = new Core.Menu();
                retVal.Name     = menuObject.Name;
                retVal.CssClass = menuObject.CssClass;



                foreach (Core.MenuItem item in menuObject.Items)
                {
                    if (item.UseCommand == false)
                    {
                        Core.MenuItem copiedItem = ObjectCopier.Clone <Core.MenuItem>(item);
                        retVal.Items.Add(copiedItem);
                    }
                    else
                    {
                        DataCommand cmd = DataCommand.GetDataCommand(item.CommandName);

                        foreach (DataCommandParameter cmdParam in cmd.Parameters)
                        {
                            ScreenDataCommandParameter p = new ScreenDataCommandParameter();
                            //TODO: need to support context with multiple items - presently assumes one item
                            if (!String.IsNullOrEmpty(item.Context))
                            {
                                if (cmdParam.Name.ToLower().EndsWith(item.Context.ToLower()))
                                {
                                    p.Name      = cmdParam.Name;
                                    p.InputType = ScreenInputType.QueryString;
                                    p.InputKey  = item.Context;
                                    p.Value     = this.Page.Request.QueryString[item.Context];
                                }
                            }

                            if (cmdParam.Name.ToLower().EndsWith("username"))
                            {
                                p.Name      = cmdParam.Name;
                                p.InputType = ScreenInputType.Special;
                                p.InputKey  = "UserName";
                                p.Value     = Common.UserName;
                            }

                            if (cmdParam.Name.ToLower().EndsWith("hostheader"))
                            {
                                p.Name      = cmdParam.Name;
                                p.InputType = ScreenInputType.Special;
                                p.InputKey  = "HostHeader";
                                p.Value     = Common.HostHeader;
                            }

                            parameters.Add(p);
                        }


                        DataTable dt   = dataCommandDB.GetDataForDataCommand(item.CommandName, parameters);
                        DataRow[] rows = null;

                        bool containsParentID = dt.Columns.Contains("ParentID");

                        if (containsParentID)
                        {
                            rows = dt.Select("ParentID IS NULL");
                        }
                        else
                        {
                            rows = dt.Select();
                        }

                        AddMenuItems(retVal, dt, item, rows, true);
                    }
                }
            }
            else
            {
                retVal = menuObject;
            }

            return(retVal);
        }
Esempio n. 28
0
        private bool ValidateUser()
        {
            bool IsAuthenticated = false;

            DataCommandService dataCommandDB = DataCommandService.GetInstance();
            PageDB             pageDB        = new PageDB();
            DataTable          data          = null;
            string             password      = String.Empty;

            List <ScreenDataCommandParameter> parameters = pageDB.GetPopulatedCommandParameters(Me.ProfileCommand, Page);

            foreach (ScreenDataCommandParameter p in parameters)
            {
                if (p.Name.ToLower() == Me.UserNameParameter.ToLower())
                {
                    LoginName = Page.GetEntityIDValue(Page.Screen, p.InputKey, p.InputType);
                    break;
                }
            }
            password = Page.GetEntityIDValue(Page.Screen, Me.PasswordEntityID, Me.PasswordEntityInputType);

            data = dataCommandDB.GetDataForDataCommand(Me.ProfileCommand, parameters);

            if (data.Rows.Count == 1)
            {
                profile = data.Rows[0];
                string dbPassword = profile[Me.PasswordField].ToString();

                PasswordMode mode = Me.PasswordMode;

                if (!String.IsNullOrEmpty(dbPassword))
                {
                    switch (mode)
                    {
                    case PasswordMode.Hash:
                        if (Cryptographer.CompareHash(Me.PasswordAlgorithm, password, dbPassword))
                        {
                            IsAuthenticated = true;
                        }



                        break;

                    case PasswordMode.Encrypted:
                        string decryptedPassword = Cryptographer.DecryptSymmetric(Me.PasswordAlgorithm, dbPassword);
                        if (decryptedPassword == password)
                        {
                            IsAuthenticated = true;
                        }
                        break;

                    case PasswordMode.PlainText:
                        if (dbPassword == password)
                        {
                            IsAuthenticated = true;
                        }
                        break;
                    }
                }
            }

            return(IsAuthenticated);
        }
Esempio n. 29
0
        private void DownloadResizedDocument()
        {
            log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            try
            {
                DataCommandService dataCommandDB = DataCommandService.GetInstance();
                PageDB             pageDB        = new PageDB();

                if (!String.IsNullOrEmpty(Me.RetrieveCommand))
                {
                    List <ScreenDataCommandParameter> parameters = null;
                    parameters = pageDB.GetPopulatedCommandParameters(Me.RetrieveCommand, Page);
                    DataTable dt = dataCommandDB.GetDataForDataCommand(Me.RetrieveCommand, parameters);

                    if (dt.Rows.Count != 0)
                    {
                        byte[] data        = null;
                        string DocumentUrl = dt.Rows[0]["DocumentUrl"].ToString();

                        Page.Response.Clear();
                        Page.Response.ContentType = dt.Rows[0]["ContentType"].ToString();
                        Page.Response.AddHeader("Content-Disposition", "attachment;filename=" + dt.Rows[0]["DocumentName"].ToString());

                        if (String.IsNullOrEmpty(DocumentUrl))
                        {
                            data = (byte[])dt.Rows[0]["File"];

                            data = ScaleImageByteArray(data, MaxWidth, MaxHeight, GetImageFormatFromContentType(Page.Response.ContentType));

                            Page.Response.OutputStream.Write(data, 0, data.Length);

                            // Flush the data
                            Page.Response.Flush();
                        }
                        else
                        {
                            //redirect to the document url location
                            UriBuilder remoteDocument = new UriBuilder(DocumentUrl);

                            HttpWebRequest  fileReq  = (HttpWebRequest)HttpWebRequest.Create(remoteDocument.Uri.AbsoluteUri);
                            HttpWebResponse fileResp = (HttpWebResponse)fileReq.GetResponse();

                            if (fileReq.ContentLength > 0)
                            {
                                fileResp.ContentLength = fileReq.ContentLength;
                            }


                            Stream stream = fileResp.GetResponseStream();

                            int length = stream.Read(data, 0, Convert.ToInt32(fileResp.ContentLength));
                            data = ScaleImageByteArray(data, MaxWidth, MaxHeight, GetImageFormatFromContentType(Page.Response.ContentType));
                            Page.Response.OutputStream.Write(data, 0, data.Length);

                            // Flush the data
                            Page.Response.Flush();
                        }



                        HttpContext.Current.ApplicationInstance.CompleteRequest();
                    }
                    else
                    {
                        throw new Exception("File Not Found");
                    }
                }
            }
            catch (Exception ex)
            {
                Page.DisplayErrorAlert(ex);

                log.Error(ex);
            }
        }
Esempio n. 30
0
        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 = (SetScreenObjectsDataCommand)Command;
                }


                if (String.IsNullOrEmpty(Me.DataCommand))
                {
                    throw new ApplicationException(String.Format("Command {0} - SetScreenObjects - DataCommand is invalid", Me.Name));
                }
                log.DebugFormat("DataCommand:{0}", Me.DataCommand);

                DataCommand dataCommand = DataCommand.GetDataCommand(Me.DataCommand);
                if (dataCommand == null)
                {
                    throw new ApplicationException(String.Format("SetScreenObjects Data Command - {0} - does not exist in configuration", Me.DataCommand));
                }

                if (dataCommand.ReturnType != DataCommandReturnType.DataTable)
                {
                    throw new ApplicationException(String.Format("SetScreenObjects Data Command - {0} - invalid return type - return type must be Data Table", Me.DataCommand));
                }

                List <ScreenDataCommandParameter> parameters = null;
                parameters = pageDB.GetPopulatedCommandParameters(Me.DataCommand, Page);
                DataTable dt = dataCommandDB.GetDataForDataCommand(Me.DataCommand, parameters);

                foreach (DataRow row in dt.Rows)
                {
                    switch (row["ObjectType"].ToString().ToLower())
                    {
                    case "control":
                        SetPageControl(
                            row["Name"].ToString(),
                            row["MemberType"].ToString(),
                            row["Member"].ToString(),
                            row["Value"].ToString()
                            );
                        break;

                    case "section":
                        SetPageSection(
                            row["Name"].ToString(),
                            row["MemberType"].ToString(),
                            row["Member"].ToString(),
                            row["Value"].ToString()
                            );
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Page.DisplayErrorAlert(ex);

                log.Error(ex);
            }
        }