Ejemplo n.º 1
0
        /// <summary>
        /// Validates this instance.
        /// </summary>
        /// <returns></returns>
        public override bool Validate(RowCell cell)
        {
            if (DenyValidate())
            {
                return(true);
            }

            if (!Equals(cell.Value, cell.DataSourceValue) && cell.Value is System.DateTime)
            {
                return(true);
            }
            if (!cell.GotPostBackData && (cell.Value != null && cell.Value is System.DateTime == false))
            {
                cell.PostBackValue = cell.Value.ToString();
            }
            bool res = base.Validate(cell);

            if (!res)
            {
                return(true);
            }
            if (string.IsNullOrEmpty(cell.PostBackValue))
            {
                cell.Value = null;
                return(true);
            }

            System.DateTime result;
            if (
                !System.DateTime.TryParseExact(cell.PostBackValue, Format, CultureInfo.InvariantCulture,
                                               DateTimeStyles.None, out result))
            {
                if (string.IsNullOrEmpty(SystemMessage) == false)
                {
                    Grid.SystemMessage.Add(SystemMessage, SystemMessageStyle,
                                           cell.Row.GetColumnInitKeys(ColumnId));
                }
                else if (Grid.DisplayView == DisplayView.Grid && SystemMessageStyle != SystemMessageStyle.WebGrid)
                {
                    Grid.SystemMessage.Add(
                        String.Format(Grid.GetSystemMessage("SystemMessage_Grid_date"), Format),
                        SystemMessageStyle, cell.Row.GetColumnInitKeys(ColumnId));
                }
                else
                {
                    Grid.SystemMessage.Add(
                        String.Format(Grid.GetSystemMessage("SystemMessage_Date"), Title, Format),
                        SystemMessageStyle, cell.Row.GetColumnInitKeys(ColumnId));
                }
                return(false);
            }
            cell.Value = result;
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Validates this instance.
        /// </summary>
        /// <returns></returns>
        public override bool Validate(RowCell cell)
        {
            if (DenyValidate())
            {
                return(true);
            }

            if (!Equals(cell.Value, cell.DataSourceValue))
            {
                cell.PostBackValue = cell.Value != null?cell.Value.ToString() : null;
            }

            if (string.IsNullOrEmpty(cell.PostBackValue) /*|| cell.PostBackValue == Grid.NULLCONSTANT*/)
            {
                if (AllowEmpty && Required == false)
                {
                    return(true); // no further checking necessary
                }
                if (string.IsNullOrEmpty(SystemMessage) == false)
                {
                    Grid.SystemMessage.Add(SystemMessage, SystemMessageStyle,
                                           cell.Row.GetColumnInitKeys(ColumnId));
                }
                else if (Grid.DisplayView == DisplayView.Grid && SystemMessageStyle != SystemMessageStyle.WebGrid)
                {
                    Grid.SystemMessage.Add(String.Format(Grid.GetSystemMessage("SystemMessage_Grid_required")),
                                           SystemMessageStyle, cell.Row.GetColumnInitKeys(ColumnId));
                }
                else
                {
                    string title = Title;
                    if (string.IsNullOrEmpty(title))
                    {
                        title = ColumnId;
                    }
                    Grid.SystemMessage.Add(
                        String.Format(Grid.GetSystemMessage("SystemMessage_Required"), title),
                        SystemMessageStyle, cell.Row.GetColumnInitKeys(ColumnId));
                }
                return(false);
            }
            cell.Value = cell.PostBackValue;

            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Validates this instance.
        /// </summary>
        /// <returns></returns>
        public override bool Validate(RowCell cell)
        {
            if (DenyValidate())
            {
                return(true);
            }
            bool res = base.Validate(cell);

            if (res)
            {
                if (AllowEmpty && string.IsNullOrEmpty(cell.PostBackValue))
                {
                    if (cell.GotPostBackData)
                    {
                        cell.Value = cell.PostBackValue;
                    }
                    return(true);
                }

                if (IsEmail && Mail.ValidEmails(cell.PostBackValue) == false)
                {
                    if (string.IsNullOrEmpty(SystemMessage) == false)
                    {
                        Grid.SystemMessage.Add(SystemMessage, SystemMessageStyle,
                                               cell.Row.GetColumnInitKeys(ColumnId));
                    }
                    else if (Grid.DisplayView == DisplayView.Grid && SystemMessageStyle != SystemMessageStyle.WebGrid)
                    {
                        Grid.SystemMessage.Add(String.Format(Grid.GetSystemMessage("SystemMessage_Grid_email")),
                                               SystemMessageStyle, cell.Row.GetColumnInitKeys(ColumnId));
                    }
                    else
                    {
                        Grid.SystemMessage.Add(String.Format(Grid.GetSystemMessage("SystemMessage_Email"), Title),
                                               SystemMessageStyle, cell.Row.GetColumnInitKeys(ColumnId));
                    }
                    return(false);
                }
            }
            else
            {
                return(false);
            }
            if (cell.PostBackValue != null && MaxSize > 0 && cell.PostBackValue.Length > MaxSize)
            {
                if (!String.IsNullOrEmpty(SystemMessage))
                {
                    Grid.SystemMessage.Add(SystemMessage, SystemMessageStyle,
                                           cell.Row.GetColumnInitKeys(ColumnId));
                }
                else if (Grid.DisplayView == DisplayView.Grid && SystemMessageStyle != SystemMessageStyle.WebGrid)
                {
                    Grid.SystemMessage.Add(
                        String.Format(Grid.GetSystemMessage("SystemMessage_Grid_maxLength"), MaxSize),
                        SystemMessageStyle, cell.Row.GetColumnInitKeys(ColumnId));
                }
                else
                {
                    Grid.SystemMessage.Add(
                        String.Format(Grid.GetSystemMessage("SystemMessage_MaxLength"), Title, MaxSize),
                        SystemMessageStyle, cell.Row.GetColumnInitKeys(ColumnId));
                }
                return(false);
            }

            if (cell.PostBackValue != null && MinSize > 0 && cell.PostBackValue.Length < MinSize)
            {
                if (!String.IsNullOrEmpty(SystemMessage))
                {
                    Grid.SystemMessage.Add(SystemMessage, SystemMessageStyle,
                                           cell.Row.GetColumnInitKeys(ColumnId));
                }
                else if (Grid.DisplayView == DisplayView.Grid && SystemMessageStyle != SystemMessageStyle.WebGrid)
                {
                    Grid.SystemMessage.Add(
                        String.Format(Grid.GetSystemMessage("SystemMessage_Grid_minLength"), MinSize),
                        SystemMessageStyle, cell.Row.GetColumnInitKeys(ColumnId));
                }
                else
                {
                    Grid.SystemMessage.Add(
                        String.Format(Grid.GetSystemMessage("SystemMessage_MinLength"), Title, MinSize),
                        SystemMessageStyle, cell.Row.GetColumnInitKeys(ColumnId));
                }
                return(false);
            }
            cell.Value = cell.PostBackValue;
            return(true);
        }
Ejemplo n.º 4
0
        internal override void RenderLabelView(WebGridHtmlWriter writer, RowCell cell)
        {
            if (cell == null)
            {
                return;
            }
            switch (SystemColumnType)
            {
            case Enums.SystemColumn.PagerColumn:
                if (Grid.RecordCount > Grid.PageSize)
                {
                    return;
                }
                cell.Row.m_Table.m_Grid.PagerSettings.SliderOperation = System.Web.UI.WebControls.Orientation.Vertical;
                writer.Write(cell.Row.m_Table.m_Grid.PagerSettings.GetPager);
                cell.Row.m_Table.m_Grid.PagerSettings.PagerType = PagerType.None;
                break;

            case Enums.SystemColumn.SelectColumn:
                writer.Write(
                    SelectableRows.GetItemCheckbox(Grid, cell.Row.PrimaryKeyValues, string.Empty,
                                                   Grid.ColorToHtml(Grid.SelectRowColor)));
                break;

            case Enums.SystemColumn.DeleteColumn:
                if (cell.Row.AllowDelete == false)
                {
                    Visibility = Visibility.None;
                    Title      = null;
                }
                else
                {
                    string strConfirmDelete = Grid.GetSystemMessage("ConfirmDelete");
                    if (Html == null)
                    {
                        writer.Write(Buttons.Anchor(Grid, " ", "RecordDeleteClick",
                                                    new[] { cell.Row.PrimaryKeyValues }, strConfirmDelete,
                                                    Grid.GetSystemMessage("DeleteRow"), "ui-icon ui-icon-trash",
                                                    null, false));
                    }

                    else
                    {
                        writer.Write(
                            Buttons.TextButtonControl(Grid, Html, "RecordDeleteClick",
                                                      new[] { cell.Row.PrimaryKeyValues }, null,
                                                      strConfirmDelete));
                    }
                }
                break;

            case Enums.SystemColumn.SpacingColumn:
                WidthColumnHeaderTitle = System.Web.UI.WebControls.Unit.Empty;
                writer.Write("&nbsp;");
                break;

            case Enums.SystemColumn.CopyColumn:
                if (cell.Row.AllowCopy == false)
                {
                    Visibility = Visibility.None;
                    Title      = null;
                }
                else
                {
                    const string strConfirmCopy = null;
                    if (Html == null)
                    {
                        writer.Write(

                            Buttons.Anchor(Grid, " ", "RecordCopyClick",
                                           new[] { string.Empty, cell.Row.PrimaryKeyValues }, strConfirmCopy,
                                           Grid.GetSystemMessage("CopyRow"), "ui-icon ui-icon-copy",
                                           null, false));
                    }

                    else
                    {
                        writer.Write(
                            Buttons.TextButtonControl(Grid, Html, "RecordCopyClick",
                                                      new[] { string.Empty, cell.Row.PrimaryKeyValues }, null,
                                                      strConfirmCopy));
                    }
                }
                break;

            case Enums.SystemColumn.NewRecordColumn:
                if (Grid.AllowNew == false)
                {
                    Visibility = Visibility.None;
                    Title      = null;
                }
                else
                {
                    if (Html == null)
                    {
                        writer.Write(
                            Buttons.TextButtonControl(Grid, Grid.GetSystemMessage("NewRecord"), "NewRecordClick",
                                                      new string[] { },
                                                      Grid.GetSystemMessageClass("NewRecord", "wgnewrecord")));
                    }
                    else
                    {
                        writer.Write(
                            Buttons.TextButtonControl(Grid, Html, "NewRecordClick", new string[] { },
                                                      Grid.GetSystemMessageClass("NewRecord", "wgnewrecord")));
                    }
                }
                break;

            case Enums.SystemColumn.UpdateGridRecordsColumn:
                if (Grid.AllowUpdate == false)
                {
                    Visibility = Visibility.None;
                    Title      = null;
                }
                else
                {
                    if (Html == null)
                    {
                        writer.Write(
                            Buttons.TextButtonControl(Grid, Grid.GetSystemMessage("UpdateRows"), "UpdateRowsClick",
                                                      new string[] { },
                                                      Grid.GetSystemMessageClass("UpdateRows", "wgUpdateRows")));
                    }
                    else
                    {
                        writer.Write(
                            Buttons.TextButtonControl(Grid, Html, "UpdateRowsClick", new string[] { },
                                                      Grid.GetSystemMessageClass("UpdateRows", "wgUpdateRows")));
                    }
                }
                break;

            case Enums.SystemColumn.UpdateGridRecordColumn:
                if (Grid.AllowUpdate == false)
                {
                    Visibility = Visibility.None;
                    Title      = null;
                }
                else
                {
                    StringBuilder sb = new StringBuilder();
                    StringWriter  sw = new StringWriter(sb);
                    System.Web.UI.HtmlTextWriter textwriter = new System.Web.UI.HtmlTextWriter(sw);

                    if (Html == null)
                    {
                        textwriter.Write(Buttons.TextButtonControl(Grid, Grid.GetSystemMessage("UpdateRow"), "UpdateRowClick",
                                                                   new[] { cell.Row.PrimaryKeyValues },
                                                                   Grid.GetSystemMessageClass("UpdateRow", "wgUpdateRow")));
                    }
                    else
                    {
                        textwriter.Write(Buttons.TextButtonControl(Grid, Html, "UpdateRowClick",
                                                                   new[] { cell.Row.PrimaryKeyValues },
                                                                   Grid.GetSystemMessageClass("UpdateRow", "wgUpdateRow")));
                    }

                    writer.Write(sb);
                }
                break;
            }
            // base.RenderLabelView(writer,cell);
            RenderGrid(null, writer, cell);
        }
Ejemplo n.º 5
0
        internal override void RenderEditView(WebGridHtmlWriter writer, RowCell cell)
        {
            if (AllowEdit == false || (Grid.DisplayView == DisplayView.Grid && AllowEditInGrid == false) ||
                !Grid.GotHttpContext)
            {
                RenderLabelView(writer, cell);
                return;
            }

            StringBuilder s          = new StringBuilder(string.Empty);
            StringBuilder javascript = new StringBuilder(string.Empty);

            s.Append(FileSource(false, cell));

            StringBuilder onblur = new StringBuilder(" onblur=\"");

            if (Grid.InputHighLight != Color.Empty)
            {
                javascript.AppendFormat(
                    " onfocus=\"accessKey = style.backgroundColor;style.backgroundColor='{0}';\"",
                    Grid.ColorToHtml(Grid.InputHighLight));
                onblur.Append("style.backgroundColor=accessKey;");
            }
            if (Grid.ColumnChangedColour != Color.Empty)
            {
                onblur.AppendFormat("isChanged(this,'{0}');", Grid.ColorToHtml(Grid.ColumnChangedColour));
            }

            onblur.Append("\"");
            javascript.Append(onblur);

            s.AppendFormat("<br/><input {0} {2} type=\"file\" class=\"wgeditfield\"  name=\"{1}\" id=\"{1}\"/>",
                           javascript, cell.CellClientId, Attributes);

            if (AllowEmpty && Required == false && Grid.InternalId != null && ((cell.Value != null)
                                                                               ||
                                                                               (FileNameColumn != null &&
                                                                                (cell.Value != null))))
            {
                s.AppendFormat(
                    "<br/><input class=\"wglinkfield\" name=\"{0}_delete\" id=\"{0}_delete\"  value=\"TRUE\" type=\"checkbox\" /><label class=\"wgnowrap wglabel\" id=\"label_{0}\" for=\"{0}_delete\">{1}</label>",
                    cell.CellClientId,
                    Grid.GetSystemMessage("RemoveImage"));
            }

            if (Grid.FindForm != null)
            {
                if (Grid.EnableCallBack)
                {
                    if (Grid.FindForm.Enctype.Equals("multipart/form-data", StringComparison.OrdinalIgnoreCase) ==
                        false)
                    {
                        Manager.AddScriptForClientSideEval(string.Format("document.getElementById(\"{0}\").encoding = \"multipart/form-data\";", Grid.FindForm.ClientID));
                    }
                }
                else
                {
                    Grid.FindForm.Enctype = "multipart/form-data";
                }
            }
            else
            {
                throw new GridException(
                          string.Format("HtmlForm is not found for grid '{0}' and column '{1}'", Grid.ID, ColumnId));
            }
            if (string.IsNullOrEmpty(ToolTipInput) == false)
            {
                s = new StringBuilder(Tooltip.Add(s.ToString(), ToolTipInput));
            }

            EditHtml(s.ToString(), writer, cell);
        }
Ejemplo n.º 6
0
        // 2005.01.09 - jorn, string optimize
        internal string FileSource(bool onlyParameters, RowCell cell)
        {
            bool isNewRecord = String.Compare(cell.Row.PrimaryKeyValues, Grid.EMPTYSTRINGCONSTANT, false) == 0;
            //(cell.Row.GetPrimarykeysInitialValues() == Grid.EMPTYSTRINGCONSTANT);

            StringBuilder s = new StringBuilder(string.Empty);

            if (IsBlob)
            {
                if (isNewRecord)
                {
                    return(String.Empty);
                }
                if ((cell.Value == null) && string.IsNullOrEmpty(FileName(cell)))
                {
                    return(String.Empty);
                }

                s.Append("<a class=\"wglinkfield\" href=\"");

                if (onlyParameters)
                {
                    s = new StringBuilder(string.Empty);
                }

                if (Grid.GotHttpContext && HttpContext.Current.Request["QUERY_STRING"] != null)
                {
                    s.AppendFormat("?{0}", HttpContext.Current.Request["QUERY_STRING"]);
                    s.AppendFormat("&amp;wgdbimgdl=true");
                }
                else
                {
                    s.AppendFormat("?wgdbimgdl=true");
                }
                s.AppendFormat(
                    "&amp;wgblob=true&amp;wgfilenameoption={0}&amp;wgfilename={1}&amp;wgdbimgeditorid={2}&amp;wgdbimgimageid={3}&amp;wgdbimgcolumnname={4}",
                    (int)FileNameOption, HttpUtility.UrlEncode(FileName(cell), Encoding.Default),
                    HttpUtility.UrlEncode(Grid.ClientID, Encoding.Default),
                    HttpUtility.UrlEncode(cell.Row.PrimaryKeyValues, Encoding.Default),
                    HttpUtility.UrlEncode(ColumnId, Encoding.Default));

                if (onlyParameters)
                {
                    return(s.ToString());
                }

                s.AppendFormat("\">{0}", Grid.GetSystemMessage("Attachment"));
                if (DisplayFileName(cell))
                {
                    string systemMessage = Grid.GetSystemMessage("Attachment");
                    string fil;
                    if (FileNameColumn != null && cell.Row[FileNameColumn].Value != null)
                    {
                        fil = cell.Row[FileNameColumn].Value.ToString();
                    }
                    else
                    {
                        fil = FileName(cell);
                    }
                    if (!string.IsNullOrEmpty(systemMessage))
                    {
                        fil = String.Format("({0})", fil);
                    }
                    s.AppendFormat("{0}", fil);
                }
                s.Append("</a>");
            }
            else
            {
                if (isNewRecord)
                {
                    return(String.Empty);
                }

                if (IsInDataSource)
                {
                    if (cell.Value == null)
                    {
                        return(String.Empty);
                    }
                    else if (string.IsNullOrEmpty(FileName(cell)))
                    {
                        return(String.Empty);
                    }
                }

                s.AppendFormat("<a  class=\"wglinkfield\" href=\"{0}{1}\">{2}", Directory, GetStoredfileName(cell),
                               Grid.GetSystemMessage("Attachment"));

                if (DisplayFileName(cell))
                {
                    string systemMessage = Grid.GetSystemMessage("Attachment");
                    string fil;
                    if (FileNameColumn != null && cell.Row[FileNameColumn].Value != null)
                    {
                        fil = cell.Row[FileNameColumn].Value.ToString();
                    }
                    else
                    {
                        fil = FileName(cell);
                    }
                    if (!string.IsNullOrEmpty(systemMessage))
                    {
                        fil = String.Format("({0})", fil);
                    }
                    s.AppendFormat("{0}", fil);
                }

                s.Append("</a>");
            }
            return(s.ToString());
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.PreRender"></see> event.
        /// </summary>
        /// <param name="writer">The writer.</param>
        internal void RenderControl(TextWriter writer)
        {
            if (m_EventRanpreRender)
            {
                return;
            }
            m_EventRanpreRender = true;

            if (PagerType == PagerType.None || m_PagerGrid.PageSize >= m_PagerGrid.RecordCount)
            {
                return;
            }

            m_Pages = m_PagerGrid.PageSize == 0 ? 1 : (m_PagerGrid.RecordCount / m_PagerGrid.PageSize);
            if (m_PagerGrid.RecordCount % m_PagerGrid.PageSize != 0)
            {
                m_Pages++;
            }
            PreviousTemplate = string.Format(PreviousTemplate, ImagePath, m_PagerGrid.GetSystemMessage("Prev"));
            NextTemplate     = string.Format(NextTemplate, ImagePath, m_PagerGrid.GetSystemMessage("Next"));
            FirstTemplate    = string.Format(FirstTemplate, ImagePath, m_PagerGrid.GetSystemMessage("First"));
            LastTemplate     = string.Format(LastTemplate, ImagePath, m_PagerGrid.GetSystemMessage("Last"));

            writer.Write("<table class=\"wgpager\"><tr>");
            if (PagerType != PagerType.RangedSlider)
            {
                if (DisplayFirstLast /*&& !(PagerType == PagerType.DropDown && CompactDropDown)*/)
                {
                    writer.Write("<td>{0}</td>",
                                 Buttons.Anchor(m_PagerGrid, FirstTemplate, "PagerClick", new[] { "1" }, null,
                                                m_PagerGrid.GetSystemMessage("First"),
                                                m_PagerGrid.GetSystemMessageClass("First", "ui-icon ui-icon-seek-first"),
                                                null, false));
                }
                if (DisplayPreviousNext /*&& !(PagerType == PagerType.DropDown && CompactDropDown)*/)
                {
                    writer.Write("<td>{0}</td>",
                                 Buttons.Anchor(m_PagerGrid, PreviousTemplate, "PagerClick",
                                                new[] { (m_PagerGrid.PageIndex - 1).ToString() }, null,
                                                m_PagerGrid.GetSystemMessage("Prev"),
                                                "ui-icon ui-icon-seek-prev", null, false));
                }
            }
            switch (PagerType)
            {
            case PagerType.DropDown:
                writer.Write("<td>");
                writer.Write(CreateDropDownPager(DisplayAll));
                writer.Write("</td>");
                break;

            case PagerType.Slider:
            case PagerType.RangedSlider:
                writer.Write("<td>");
                writer.Write(CreateSlider());
                writer.Write("</td>");
                break;

            default:
                writer.Write(CreateBarPager(DisplayAll));
                break;
            }
            if (PagerType != PagerType.RangedSlider)
            {
                if (DisplayPreviousNext
                    /*&& !(PagerType == PagerType.DropDown && CompactDropDown)*/)
                {
                    int next = (m_PagerGrid.PageIndex + 1);
                    if (next > m_Pages)
                    {
                        next = m_Pages;
                    }
                    writer.Write("<td>{0}</td>",
                                 Buttons.Anchor(m_PagerGrid, NextTemplate, "PagerClick", new[] { (next).ToString() },
                                                null,
                                                m_PagerGrid.GetSystemMessage("Next"),
                                                m_PagerGrid.GetSystemMessageClass("Next", "ui-icon ui-icon-seek-next"),
                                                null,
                                                false));
                }
                if (DisplayFirstLast
                    /*&& !(PagerType == PagerType.DropDown && CompactDropDown)*/)
                {
                    writer.Write("<td>{0}</td>", Buttons.Anchor(m_PagerGrid, LastTemplate, "PagerClick",
                                                                new[] { m_Pages.ToString() }, null,
                                                                m_PagerGrid.GetSystemMessage("Last"),
                                                                m_PagerGrid.GetSystemMessageClass("Last",
                                                                                                  "ui-icon ui-icon-seek-end"),
                                                                null, false));
                }
            }
            writer.Write("</tr></table>");
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Validates this instance.
        /// </summary>
        /// <returns></returns>
        public override bool Validate(RowCell cell)
        {
            if (DenyValidate())
            {
                return(true);
            }

            if (!Equals(cell.Value, cell.DataSourceValue) && cell.Value is long)
            {
                return(true);
            }
            if (!cell.GotPostBackData && (cell.Value != null && cell.Value is long == false))
            {
                cell.PostBackValue = cell.Value.ToString();
            }

            bool res = base.Validate(cell);

            if (res)
            {
                if (!string.IsNullOrEmpty(cell.PostBackValue))
                {
                    long result;
                    if (!long.TryParse(Regex.Replace(cell.PostBackValue, @"\s", string.Empty), NumberStyles.Any | NumberStyles.AllowTrailingWhite |
                                       NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingWhite |
                                       NumberStyles.AllowTrailingWhite, Grid.Culture, out result))
                    {
                        if (string.IsNullOrEmpty(SystemMessage) == false)
                        {
                            Grid.SystemMessage.Add(SystemMessage, SystemMessageStyle,
                                                   cell.Row.GetColumnInitKeys(ColumnId));
                        }
                        else if (Grid.DisplayView == DisplayView.Grid && SystemMessageStyle != SystemMessageStyle.WebGrid)
                        {
                            Grid.SystemMessage.Add(String.Format(Grid.GetSystemMessage("SystemMessage_Grid_Int")),
                                                   SystemMessageStyle, cell.Row.GetColumnInitKeys(ColumnId));
                        }
                        else
                        {
                            Grid.SystemMessage.Add(
                                String.Format(
                                    string.Format("{0}({1})", Grid.GetSystemMessage("SystemMessage_Int"), cell.Value),
                                    Title),
                                SystemMessageStyle, cell.Row.GetColumnInitKeys(ColumnId));
                        }
                        res = false;
                    }
                    else
                    {
                        cell.Value = result;
                    }
                }
                else
                {
                    cell.Value = null;
                }
            }
            else
            {
                return(false);
            }

            if (Value(cell) != null)
            {
                if (MaxSize != 0 && Value(cell) > MaxSize)
                {
                    if (!String.IsNullOrEmpty(SystemMessage))
                    {
                        Grid.SystemMessage.Add(SystemMessage, SystemMessageStyle,
                                               cell.Row.GetColumnInitKeys(ColumnId));
                    }
                    else if (Grid.DisplayView == DisplayView.Grid && SystemMessageStyle != SystemMessageStyle.WebGrid)
                    {
                        Grid.SystemMessage.Add(
                            string.Format("Maximum allowed value is {0}.", MaxSize.ToString(Format, Grid.Culture)),
                            SystemMessageStyle,
                            cell.Row.GetColumnInitKeys(ColumnId));
                    }
                    else
                    {
                        Grid.SystemMessage.Add(
                            string.Format("Maximum allowed value for '{0}' is {1}.", Title,
                                          MaxSize.ToString(Format, Grid.Culture)),
                            SystemMessageStyle, cell.Row.GetColumnInitKeys(ColumnId));
                    }
                    return(false);
                }

                if (MinSize != 0 && Value(cell) < MinSize)
                {
                    if (!String.IsNullOrEmpty(SystemMessage))
                    {
                        Grid.SystemMessage.Add(SystemMessage, SystemMessageStyle,
                                               cell.Row.GetColumnInitKeys(ColumnId));
                    }
                    else if (Grid.DisplayView == DisplayView.Grid && SystemMessageStyle != SystemMessageStyle.WebGrid)
                    {
                        Grid.SystemMessage.Add(
                            string.Format("Minimum allowed value is {0}.", MinSize.ToString(Format, Grid.Culture)),
                            SystemMessageStyle,
                            cell.Row.GetColumnInitKeys(ColumnId));
                    }
                    else
                    {
                        Grid.SystemMessage.Add(
                            string.Format("Minimum allowed value for '{0}' is {1}.", Title,
                                          MinSize.ToString(Format, Grid.Culture)),
                            SystemMessageStyle, cell.Row.GetColumnInitKeys(ColumnId));
                    }
                    return(false);
                }
            }
            return(res);
        }
Ejemplo n.º 9
0
        // 2005.01.09 - jorn, string optimize
        internal string FileSource(bool onlyParameters, RowCell cell)
        {
            bool          isNewRecord = String.Compare(cell.Row.PrimaryKeyValues, Grid.EMPTYSTRINGCONSTANT, false) == 0;
            StringBuilder s           = new StringBuilder(string.Empty);

            if (IsBlob)
            {
                if (isNewRecord)
                {
                    return(String.Empty);
                }
                //   if (Value == null && string.IsNullOrEmpty(FileName))
                //       return String.Empty;
                s.AppendFormat(
                    !DisplayFileNameOnly
                        ? "<img alt=\"{0}\" border=\"0\" class=\"wgimage\" src=\""
                        : "<a alt=\"{0}\" target=\"gridfile\" href=\"", Title);

                if (onlyParameters)
                {
                    s = new StringBuilder(string.Empty);
                }

                if (Grid.GotHttpContext && HttpContext.Current.Request["QUERY_STRING"] != null)
                {
                    s.AppendFormat("?{0}", HttpContext.Current.Request["QUERY_STRING"]);
                    s.AppendFormat("&amp;wgdbimgdl=false");
                }
                else
                {
                    s.AppendFormat("?wgdbimgdl=false");
                }

                s.AppendFormat(
                    "&amp;wgblob=true&amp;wgfilenameoption={0}&amp;wgfilename={1}&amp;wgdbimgeditorid={2}&amp;wgdbimgimageid={3}&amp;wgdbimgcolumnname={4}",
                    (int)FileNameOption, HttpUtility.UrlEncode(FileName(cell), Encoding.Default),
                    HttpUtility.UrlEncode(Grid.ClientID, Encoding.Default),
                    HttpUtility.UrlEncode(cell.Row.PrimaryKeyValues, Encoding.Default),
                    HttpUtility.UrlEncode(ColumnId, Encoding.Default));
                if (onlyParameters)
                {
                    return(s.ToString());
                }

                s.Append("\"");

                if (!ValidateFile(cell))
                {
                    if (WidthEditableColumn != Unit.Empty)
                    {
                        s.AppendFormat(" width=\"{0}\"", WidthEditableColumn);
                    }
                    if (HeightEditableColumn != Unit.Empty)
                    {
                        s.AppendFormat(" height=\"{0}\"", HeightEditableColumn);
                    }
                }
                s.Append(" />");

                if (DisplayFileNameOnly)
                {
                    string systemMessage = Grid.GetSystemMessage("Attachment");
                    string fil;
                    if (FileNameColumn != null && cell.Row[FileNameColumn].Value != null)
                    {
                        fil = cell.Row[FileNameColumn].Value.ToString();
                    }
                    else
                    {
                        fil = FileName(cell);
                    }
                    if (!string.IsNullOrEmpty(systemMessage))
                    {
                        fil = String.Format("{1} ({0})", fil, systemMessage);
                    }
                    s.AppendFormat("{0}</a>", fil);
                }
            }
            else
            {
                if (isNewRecord)
                {
                    return(String.Empty);
                }

                if (IsInDataSource)
                {
                    if (Value(cell) == null)
                    {
                        return(String.Empty);
                    }
                    else if (string.IsNullOrEmpty(FileName(cell)))
                    {
                        return(String.Empty);
                    }
                }

                s.AppendFormat(
                    !DisplayFileNameOnly
                        ? "<img alt=\"{0}\" title=\"{0}\" border=\"0\" class=\"wgimage\" src=\""
                        : "<a alt=\"{0}\" title=\"{0}\" target=\"gridfile\" href=\"", Title);

                if (onlyParameters)
                {
                    s = new StringBuilder(string.Empty);
                }

                s.AppendFormat("{0}{1}", Directory, GetStoredfileName(cell));

                if (onlyParameters)
                {
                    return(s.ToString());
                }
                s.Append("\"");
                if (!ValidateFile(cell))
                {
                    if (WidthEditableColumn != Unit.Empty)
                    {
                        s.AppendFormat(" width=\"{0}\"", WidthEditableColumn);
                    }
                    if (HeightEditableColumn != Unit.Empty)
                    {
                        s.AppendFormat(" height=\"{0}\"", HeightEditableColumn);
                    }
                }
                s.Append(" />");

                if (DisplayFileNameOnly)
                {
                    string systemMessage = Grid.GetSystemMessage("Attachment");
                    string fil;
                    if (FileNameColumn != null && cell.Row[FileNameColumn].Value != null)
                    {
                        fil = cell.Row[FileNameColumn].Value.ToString();
                    }
                    else
                    {
                        fil = FileName(cell);
                    }
                    if (!string.IsNullOrEmpty(systemMessage))
                    {
                        fil = String.Format("{1} ({0})", fil, systemMessage);
                    }
                    s.AppendFormat("{0}</a>", fil);
                }
            }
            return(s.ToString());
        }