Example #1
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();
                }
            }
        }
Example #2
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);
            }
        }
        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);
            }
        }
Example #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 = (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);
            }
        }
Example #5
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);
        }
Example #6
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);
            }
        }
Example #7
0
        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);
        }
Example #8
0
 public void Initialize()
 {
     this.indexer   = DI.indexer;
     this.pageDB    = DI.pageDB;
     this.urlFilter = DI.urlFilter;
 }