Example #1
0
        // private ITemplate m_Controls;



        #endregion

        #region Data handling


        /// <summary>
        /// Validates this instance.
        /// </summary>
        /// <returns></returns>
        public override bool Validate(RowCell cell)
        {
            if (DenyValidate())
                return true;
            const bool res = true;


            return res;
        }
Example #2
0
 // 2004.10.27, jorn - Added this, because bits must always be updated. Stupid HTML!
 internal override void OnUpdateInsert(CellUpdateInsertArgument ea, RowCell cell)
 {
     ea.AddApostrophe = false;
     ea.IgnoreChanges = false;
 }
Example #3
0
        private void OnUpdateInsertDataSource(CellUpdateInsertArgument ea,RowCell cell)
        {
            if (!Grid.GotHttpContext)
                return;
            if (HttpContext.Current.Session[cell.CellClientId + "_imgdata"] == null)
            {
                ea.IgnoreChanges = true;
                return;
            }
            BinaryReader br;
            switch (FileTemporaryMode)
            {
                case FileTemporaryMode.Memory:

                    System.Drawing.Image img = (System.Drawing.Image)HttpContext.Current.Session[cell.CellClientId + "_imgdata"];

                    //if (Sizes.Count > 0)
                    //    img = Sizes[0].Resize(img);

                    MemoryStream ms = new MemoryStream();
                    img.Save(ms, img.RawFormat);
                    br = new BinaryReader(ms);

                    br.BaseStream.Position = 0;
                    ea.Parameter = br;
                    ea.IgnoreChanges = false;
                    break;
                case FileTemporaryMode.File:
                    {
                        FileStream fs =
                            System.IO.File.Open((string)HttpContext.Current.Session[cell.CellClientId + "_imgdata"],
                                                FileMode.Open, FileAccess.Read, FileShare.Read);
                        br = new BinaryReader(fs);
                        fs.Close();
                        br.BaseStream.Position = 0;
                        ea.Parameter = br;
                        ea.IgnoreChanges = false;
                    }
                    break;
            }
        }
Example #4
0
        private static void DeleteSession(RowCell cell)
        {
            if (!Grid.GotHttpContext)
                return;

            HttpContext.Current.Session.Remove(cell.CellClientId + "_img");
            HttpContext.Current.Session.Remove(cell.CellClientId + "_imgdata");
        }
Example #5
0
 internal bool ValidateFile(RowCell cell)
 {
     return !string.IsNullOrEmpty(FileName(cell));
 }
Example #6
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);
        }
Example #7
0
        internal override void GetColumnPostBackData(RowCell cell)
        {
            if (cell.GotPostBackData || !Grid.GotHttpContext)
                return;
            // Gets the posted file and saves it to a temporary image.
            // Updates views tate saying that the file needs to be renamed
            using (HtmlInputFile f = new HtmlInputFile())
            {
                f.ID = cell.CellClientId;

                if (f.PostedFile == null || f.PostedFile.FileName.Length == 0) return;
                if (AllowExtension(f.PostedFile.FileName) == false)
                {
                    Grid.SystemMessage.Add("You are not allowed to upload files of this type.",
                                           SystemMessageStyle, cell.Row.GetColumnInitKeys(ColumnId));
                    return;
                }

                string fileName = Path.GetFileName(f.PostedFile.FileName);

                // We must set the filename column before we do any stuff
                if (FileNameColumn != null)
                    cell.Row[FileNameColumn].Value = fileName;
                if (FileTemporaryMode == FileTemporaryMode.File)
                {
                    string tempFile = Path.GetTempFileName();
                    f.PostedFile.SaveAs(tempFile);
                    if (SaveSession(fileName, tempFile,cell) == false)
                        return;
                }
                else if (SaveSession(fileName, f.PostedFile.InputStream,cell) == false)
                    return;

                cell.Value = fileName;
                cell.GotPostBackData = true;
            }
        }
Example #8
0
        internal override void AfterUpdate(string editIndex,RowCell cell)
        {
            string uniqueID = cell.CellClientId;
            // Renames file
            if (!Grid.GotHttpContext ||
                HttpContext.Current.Session[string.Format("{0}_imgdata", uniqueID)] == null)
                return;

            string filename = (FileNameOption == FileNameOption.Original)
                                 ? HttpContext.Current.Session[uniqueID + "_img"] as string
                                 :
                                     string.Format("{0}_{1}.{2}", editIndex, ColumnId, GetExtension((string)HttpContext.Current.Session[uniqueID + "_img"]));
            System.Drawing.Image img = CreateImageSizes(filename,cell);
            if (IsBlob || (IsBlob && FileNameOption != FileNameOption.UsePrimaryKey && ColumnId != FileNameColumn))
            {
                DeleteSession(cell);
                return;
            }

            try
            {
                System.IO.File.Delete(AbsoluteDirectory + filename);
            }
            catch (Exception ee)
            {
                Grid.SystemMessage.Add(string.Format("Warning: Failed to delete existing file '{0}'. Turn on debug for more information.", HttpContext.Current.Session[uniqueID + "_img"]));
                if (Grid.Debug)
                    Grid.m_DebugString.Append(ee);
            }

            try
            {
                img.Save(AbsoluteDirectory + filename, img.RawFormat);
            }
            catch (Exception ee)
            {
                Grid.SystemMessage.Add(
                    "Warning: Failed saving file to disk. Turn on debug for more information.");
                if (Grid.Debug)
                    Grid.m_DebugString.Append(ee);
            }
            //}
            img.Dispose();

            if (Grid.GotHttpContext &&
                HttpContext.Current.Session[uniqueID + "_imgdata"] is Image)
                ((Image)HttpContext.Current.Session[uniqueID + "_imgdata"]).Dispose();
            if (Grid.GotHttpContext &&
                HttpContext.Current.Session[uniqueID + "_imgdata"] is Stream)
                ((Stream)HttpContext.Current.Session[uniqueID + "_imgdata"]).Close();

            DeleteSession(cell);
        }
Example #9
0
        internal override void RenderLabelView(WebGridHtmlWriter writer, RowCell cell)
        {

            if (cell.Value != null && Visibility != Visibility.None)
                writer.Write(RenderTemplate(cell));
        }
Example #10
0
        private void ApplyInternalValues(RowCell cell, Control ctrl)
        {
            foreach (Control control in ctrl.Controls)
            {
                if (control is LiteralControl == false)
                    continue;

                LiteralControl ctr = control as LiteralControl;
                if (ctr == null)
                    continue;
                string innerhtml = ctr.Text;
                if (!string.IsNullOrEmpty(innerhtml) &&
                    innerhtml.IndexOf(string.Format("[{0}]", ColumnId),
                                      StringComparison.OrdinalIgnoreCase) != -1)
                    throw new GridException(
                        string.Format("The template '{0}' can't contain reference to itself.",
                                      ColumnId));

                if (string.IsNullOrEmpty(innerhtml) || !innerhtml.Contains("["))
                    continue;
                string content = innerhtml;
                cell.Row.Columns.ForEach(delegate(Column column)
                {
                    if (
                        content.IndexOf(string.Format("[{0}]", column.ColumnId),
                                        StringComparison.OrdinalIgnoreCase) == -1)
                        return;
                    WebGridHtmlWriter writer = new WebGridHtmlWriter(Grid);
                    Visibility columnvisibility = column.Visibility;
                    column.Visibility = Visibility;
                    column.SystemMessageStyle = SystemMessageStyle.WebGrid;
                    if (Grid.Trace.IsTracing)
                        Grid.Trace.Trace(
                            "Rendering ColumnName: {0} in column: {1}",
                            column.ColumnId, ColumnId);
                    column.RenderEditView(writer, cell.Row.Cells[column.ColumnId]);
                    column.Visibility = columnvisibility;
                    if (column.AllowEdit)
                        writer.Write(
                            "<input type=\"hidden\" value=\"validate\" name=\"{0}_{1}_validate\" />",
                            Grid.ClientID, column.ColumnId);
                    content = content.Replace(string.Format("[{0}]", column.ColumnId),
                                        writer.ToString());
                });
                ((LiteralControl)control).Text = content;
            }
        }
Example #11
0
        internal Control RenderTemplate(RowCell cell)
        {
            if (cell.Value != null)
            {

                Control ctrl = cell.Value as Control;

                if (ctrl != null)
                {

                    ctrl.Visible = true;
                    ApplyInternalValues(cell, ctrl);

                    return ctrl;
                }
                string isindb = string.Empty;
                if (IsInDataSource)
                    isindb = " The value provided was loaded from your data source. You can disable data source load for this column by 'IsInDataSource=false'";
                throw new GridException(string.Format("ColumnTemplate '{0}' requires a Cell.Value of type 'System.Web.UI.Control'. '{1}' type was provided." + isindb, ColumnId, cell.Value.GetType()));

            }
            return null;
        }
Example #12
0
 internal new virtual bool Value(RowCell cell)
 {
     LoadValueFromColumnDataSource(cell);
     if (cell.Value == null)
         return false;
     if (cell.Value is bool)
         return (bool)cell.Value;
     bool result;
     if (bool.TryParse(Regex.Replace(cell.Value.ToString(), @"\s", string.Empty), out result))
         return (bool)(cell.Value = result);
     return false;
 }
Example #13
0
 internal override void RenderLabelView(WebGridHtmlWriter writer, RowCell cell)
 {
     m_IsFormElement = false;
     RenderDetail(false, writer, cell);
 }
Example #14
0
 internal override void RenderEditView(WebGridHtmlWriter writer, RowCell cell)
 {
     if (AllowEdit == false)
     {
         RenderLabelView(writer, cell);
         return;
     }
     m_IsFormElement = false;
     RenderDetail(true, writer, cell);
 }
Example #15
0
        // 2005.01.09 - jorn -  String.Compare, string.Length
        // 2005.01.05 - Jorn -  Added check to see if there actually is a checkbox on "previous page".
        //                        Need to add a hidden field since checkbox "returns null" both for unchecked and non-existing
        internal void RenderDetail(bool enabled, WebGridHtmlWriter writer, RowCell cell)
        {
            if (AllowEdit == false || (Grid.DisplayView == DisplayView.Grid && AllowEditInGrid == false))
                enabled = false;

            string uniqueId = cell.CellClientId;
            string strValue = DisplayText(cell);
            const string checkedValue = TrueValue;
            const string uncheckedValue = FalseValue;

            StringBuilder sb;

            if (String.Compare(strValue, checkedValue, true) == 0 && CheckedAlias != null && enabled == false)
                sb = new StringBuilder(CheckedAlias);
            else if (String.Compare(strValue, uncheckedValue, true) == 0 && UncheckedAlias != null &&
                     enabled == false)
                sb = new StringBuilder(UncheckedAlias);
            else
            {
                string bitchecked = string.Empty;
                string bitEnabled = string.Empty;
                if (String.Compare(strValue, checkedValue, true) == 0)
                    bitchecked = " checked=\"checked\"";
                if (enabled == false)
                    bitEnabled = " disabled=\"disabled\"";

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

                if (AutoPostback || string.IsNullOrEmpty(ConfirmMessage) == false)
                {
                    StringBuilder eventScript = new StringBuilder(" onclick=\"");
                    if (string.IsNullOrEmpty(ConfirmMessage) == false)
                        eventScript.AppendFormat(" if(wgconfirm('{0}',this,'{1}')) ", ConfirmMessage.Replace("'", "\\'"), Grid.DialogTitle.Replace("'", "\\'"));
                    string link = Grid.EnableCallBack && !ForcePostBack ? Asynchronous.GetCallbackEventReference(Grid,
                                                                                               string.Format("ElementPostBack!{0}!{1}",
                                                                                                             ColumnId, cell.Row.PrimaryKeyValues), false,
                                                                                               string.Empty, string.Empty) : Grid.Page.ClientScript.GetPostBackEventReference(Grid,
                                                                                                                                                                              string.Format(
                                                                                                                                                                                  "ElementPostBack!{0}!{1}", ColumnId, cell.Row.PrimaryKeyValues));
                    eventScript.AppendFormat("{0}\"", link);

                    javascript.Append(eventScript);
                }
                javascript.Append(onblur);
                sb =
                     new StringBuilder(
                         string.Format(
                             "<input {0} type=\"checkbox\" {1} {2} {4}  id=\"cb_{3}\" name=\"{3}\" value=\"1\"/>",
                             javascript, bitchecked, bitEnabled, uniqueId, Attributes));
                if (string.IsNullOrEmpty(m_Displaylabel) == false)
                    sb.AppendFormat(
                        "<label class=\"wglabel\" id=\"label_{0}\" for=\"cb_{0}\">{1}</label>", uniqueId, m_Displaylabel);

                if (enabled)
                    writer.Write("<input type=\"hidden\" id=\"{0}_cb\" name=\"{0}_cb\" value=\"{1}\" />",
                                 uniqueId, checkedValue);
            }

            if (string.IsNullOrEmpty(ToolTipInput) == false)
                sb = new StringBuilder(Tooltip.Add(sb.ToString(), ToolTipInput));

            EditHtml(sb.ToString(), writer, cell);
        }
Example #16
0
 public string GetUrl(RowCell cell)
 {
     return FileSource(true,cell);
 }
Example #17
0
        /// <summary>
        /// Validates this instance.
        /// </summary>
        /// <returns></returns>
        public override bool Validate(RowCell cell)
        {
            bool res = base.Validate(cell);

            return res;
        }
Example #18
0
 internal override void GetColumnPostBackData(RowCell cell)
 {
     return;
 }
Example #19
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();
        }
Example #20
0
 internal override void OnUpdateInsert(CellUpdateInsertArgument ea, RowCell cell)
 {
     return;
 }
Example #21
0
        internal override void OnUpdateInsert(CellUpdateInsertArgument ea, RowCell cell)
        {
            if (!Grid.GotHttpContext || HttpContext.Current.Session == null)
                return;
            if (IsBlob == false && System.IO.Directory.Exists(AbsoluteDirectory) == false)
                throw new GridException(
                    string.Format("Upload directory for '{0}' does not exist ({1})", Title,
                                  AbsoluteDirectory));

            // Should we remove the file in DB?
            string strDelete = HttpContext.Current.Request[cell.CellClientId + "_delete"];

            if (strDelete != null && String.Compare(strDelete, "TRUE") == 0)
            {
                if (IsBlob == false)
                {
                    string filename;
                    if (FileNameOption == FileNameOption.UsePrimaryKey)
                        filename =
                            string.Format("{0}{1}_{2}.{3}", AbsoluteDirectory, cell.Row.PrimaryKeyUpdateValues,
                                          ColumnId, GetExtension(Value(cell)));
                    else
                        filename = AbsoluteDirectory + Value(cell);
                    if (System.IO.File.Exists(filename))
                    {
                        try
                        {
                            System.IO.File.Delete(filename);
                        }
                        catch (Exception ee)
                        {
                            Grid.SystemMessage.Add(
                                string.Format("Warning: failed to remove file associated with column '{0}'", Title));
                            if (Grid.Debug)
                                Grid.m_DebugString.Append(ee.Message);
                        }
                    }
                    if (FileNameColumn == ColumnId)
                    {
                        cell.Value = null;
                        cell.PostBackValue = null;
                    }
                }
                ea.IgnoreChanges = false;
               // ea.Value = Grid.NULLCONSTANT;
                ea.AddApostrophe = false;

                if (FileNameColumn != null && FileNameColumn != ColumnId)
                    cell.Row[FileNameColumn].Value = null;

                // TODO: Should delete old image if not blob.
                return;
            }

            ea.IgnoreChanges = true;
            if (!Grid.GotHttpContext || HttpContext.Current.Session[cell.CellClientId + "_img"] == null)
                // No image!
                return;
            if (IsBlob)
            {
                OnUpdateInsertDataSource(ea,cell);
                return;
            }
            ea.Parameter = null;
            ea.IgnoreChanges = false;

            ea.Value = HttpContext.Current.Session[cell.CellClientId + "_img"].ToString();
        }
Example #22
0
        private bool SaveSession(string fileName, string tempFile,RowCell cell)
        {
            if (!Grid.GotHttpContext)
                return false;
            HttpContext.Current.Session[cell.CellClientId + "_img"] = fileName;

            try
            {
                System.Drawing.Image.FromFile(tempFile);
            }
            catch
            {
                Grid.SystemMessage.Add(
                    string.Format("{0} is not a valid image file, '{1}' requires a valid image file.", fileName,
                                  Title),
                    SystemMessageStyle, cell.Row.GetColumnInitKeys(ColumnId));
                return false;
            }
            HttpContext.Current.Session[cell.CellClientId + "_imgdata"] = tempFile;
            return true;
        }
Example #23
0
        internal override void RenderLabelView(WebGridHtmlWriter writer,RowCell cell)
        {
            string image = FileSource(true,cell);
            if (!string.IsNullOrEmpty(PopupImageColumn))
            {

                if (!cell.Row.Columns.Contains(PopupImageColumn))
                    throw new ApplicationException(
                        string.Format(@"""PopupImageColumn"" property value for column '{0}' is not valid.", Title));
                string rel = "";
                if (m_PopupImageDisplayType == ImageDisplayType.Navigation || m_PopupImageDisplayType == ImageDisplayType.NavigationSlideShow)
                    rel = string.Format("rel=\"{0}_{1}\"", Grid.ClientID, ColumnId);
               image =
                    string.Format(@"<a href=""{1}"" title=""{3}"" {4} class=""wgimage_{5}""><img class=""wgimage"" src=""{0}"" alt=""{2}""/></a>",
                        image, ((Image)cell.Row.Columns[PopupImageColumn]).GetUrl(cell.Row[PopupImageColumn]), Title, PopupImageCaption, rel, ColumnId);
                switch (PopupImageDisplayType)
                {
                    case ImageDisplayType.Navigation:
                        Grid.AddClientScript(writer, string.Format("$(\"a[rel='{0}_{1}']\").colorbox({{slideshow:false}});", Grid.ClientID, ColumnId));
                        break;
                    case ImageDisplayType.NavigationSlideShow:
                        Grid.AddClientScript(writer, string.Format("$(\"a[rel='{0}_{1}']\").colorbox({{slideshow:true}});", Grid.ClientID, ColumnId));
                        break;
                    case ImageDisplayType.Single:
                        Grid.AddClientScript(writer, string.Format("$(document).ready(function() {{$(\".wgimage_{0}\").colorbox();}});", ColumnId));
                        break;
                }
               }
            else
                image = string.Format(@"<img class=""wgimage"" src=""{0}"" alt=""{1}""/>", image, Title);

            if (HyperLinkColumn && Grid.DisplayView == DisplayView.Grid)
            {
                string a = Grid.EnableCallBack ? Asynchronous.GetCallbackEventReference(Grid,
                                                                                        string.Format("RecordClick!{0}!{1}", ColumnId,
                                                                                                      cell.Row.PrimaryKeyValues),
                                                                                        false, string.Empty, string.Empty) : Grid.Page.ClientScript.GetPostBackEventReference(Grid,
                                                                                                                                                                              string.Format("RecordClick!{0}!{1}",
                                                                                                                                                                                            ColumnId,
                                                                                                                                                                                            cell.Row.
                                                                                                                                                                                                PrimaryKeyValues));

                string b = (String.IsNullOrEmpty(ConfirmMessage))
                               ? string.Empty
                               : String.Format("if(wgconfirm('{0}',this,'{1}')) ", ConfirmMessage.Replace("'", "\\'"), Grid.DialogTitle.Replace("'", "\\'"));

                image =
                    string.Format(
                        "<a class=\"wglinkfield\" href=\"#\" onclick=\"{0}{1}\">{2}</a>", b, a, image);
            }

            LabelHtml(image, writer,cell);
        }
Example #24
0
 /// <summary>
 /// Gets the name of the absolute directory file.
 /// </summary>
 /// <value>The name of the absolute directory file.</value>
 public string AbsoluteDirectoryFileName(RowCell cell)
 {
     if (m_AbsoluteDirectoryFileName != null)
             return m_AbsoluteDirectoryFileName;
         if (FileNameOption == FileNameOption.UsePrimaryKey)
             m_AbsoluteDirectoryFileName =
                 string.Format("{0}{1}_{2}.{3}", AbsoluteDirectory, cell.Row.PrimaryKeyUpdateValues, ColumnId,
                               GetExtension(Value(cell)));
         else
             m_AbsoluteDirectoryFileName = AbsoluteDirectory + FileName(cell);
         return m_AbsoluteDirectoryFileName;
 }
Example #25
0
 internal new virtual string Value(RowCell cell)
 {
     if (cell.Value != null) return cell.Value.ToString();
     return null;
 }
Example #26
0
        public string FileName(RowCell cell)
        {
            if (IsBlob && string.IsNullOrEmpty(FileNameColumn))
                    return null;
                if (!string.IsNullOrEmpty(FileNameColumn))
                {
                    if (!IsBlob)
                    {
                        if (ColumnId == FileNameColumn)
                            return m_FileName = Value(cell);
                        if (FileNameOption == FileNameOption.UsePrimaryKey && cell.Row[FileNameColumn].Value != null)
                            return m_FileName =
                                   string.Format("{0}_{1}.{2}", cell.Row.PrimaryKeyUpdateValues, ColumnId,
                                                 GetExtension(cell.Row[FileNameColumn].Value.ToString()));
                    }
                    if (cell.Row[FileNameColumn].Value != null)
                        return m_FileName = cell.Row[FileNameColumn].Value.ToString();
                }

                if (m_FileName == null)
                {
                    if (IsBlob)
                        return null;
                    return FileNameOption == FileNameOption.UsePrimaryKey
                               ? (m_FileName =
                                  string.Format("{0}_{1}.{2}", cell.Row.PrimaryKeyUpdateValues, ColumnId, Value(cell)))
                               : (m_FileName = Value(cell));
                }
                return m_FileName;
        }
Example #27
0
 private System.Drawing.Image CreateImageSizes(string filename, RowCell cell)
 {
     System.Drawing.Image img = null;
     if (FileTemporaryMode == FileTemporaryMode.File)
     {
         string tmpFile = HttpContext.Current.Session[string.Format("{0}_imgdata", cell.CellClientId)] as string;
         if (tmpFile != null) img = System.Drawing.Image.FromFile(tmpFile);
     }
     else // File in memory
         img =
             (System.Drawing.Image) HttpContext.Current.Session[string.Format("{0}_imgdata", cell.CellClientId)];
     if (ImageSizes != null && img != null)
         for (int i = 0; i < ImageSizes.Count; i++)
         {
             string debugstr =
                 ImageSizes[i].Resize(img, AbsoluteDirectory, filename,cell);
             if (Grid.Debug)
                 Grid.m_DebugString.AppendFormat("{0}<br/>", debugstr);
         }
     return img;
 }
Example #28
0
 /// <summary>
 /// Gets the name of the get storedfile.
 /// </summary>
 /// <value>The name of the get storedfile.</value>
 public string GetStoredfileName(RowCell cell)
 {
     string fileName;
     if (FileNameOption == FileNameOption.UsePrimaryKey && cell.Row[FileNameColumn].Value != null)
         fileName =
             string.Format("{0}_{1}.{2}", cell.Row.PrimaryKeyUpdateValues, ColumnId,
                           GetExtension(cell.Row[FileNameColumn].Value.ToString()));
     else if (FileNameColumn != null && cell.Row[FileNameColumn].Value != null)
         fileName = cell.Row[FileNameColumn].Value.ToString();
     else
     {
         if (IsBlob)
             return null;
         fileName = FileNameOption == FileNameOption.UsePrimaryKey
                        ? string.Format("{0}_{1}.{2}", cell.Row.PrimaryKeyUpdateValues, ColumnId, Value(cell))
                        : Value(cell);
     }
     return fileName;
 }
Example #29
0
        /* public static void Render(string content, string cssclass, HtmlTextWriter writer)
        {
            ColumnCell td = new ColumnCell {m_Class = cssclass};
            td.RenderBeginTag(writer);
            writer.Write(content);
            td.RenderEndTag(writer);
        }
        */
        public void RenderBeginTag(WebGridHtmlWriter writer,Column column,RowCell cell, string tagtype)
        {
            StringBuilder tdStart = new StringBuilder(tagtype);
            string name = "";
            if (column != null)
                name = column.ColumnId;
            if (m_Align != HorizontalPosition.Undefined)
                tdStart.AppendFormat(" align=\"{0}\"", m_Align.ToString().ToLowerInvariant());

            if (m_VAlign != VerticalPosition.undefined)
                tdStart.AppendFormat(" valign=\"{0}\"", m_VAlign.ToString().ToLowerInvariant());
            if( string.IsNullOrEmpty(m_Class) == false )
                tdStart.AppendFormat(" class=\"{0}\" ", m_Class);

            if (m_GridRowCount == -1)
            {
                if (m_ColumnWidth != Unit.Empty)
                    tdStart.AppendFormat(" style=\"width: {0}\"", m_ColumnWidth);
                if (string.IsNullOrEmpty(name) == false)
                    tdStart.AppendFormat(" id=\"{0}{1}r0\"", m_GridId, name);
            }
            else if (string.IsNullOrEmpty(name) == false && m_GridRowCount > 0)
                tdStart.AppendFormat(" id=\"{0}{1}r{2}\"", m_GridId, name, m_GridRowCount);
            else if (string.IsNullOrEmpty(name) == false)
                tdStart.AppendFormat(" id=\"{0}{1}\"", name, m_GridRowCount);

            if (m_ColumnSpan > 1) tdStart.AppendFormat(" colspan=\"{0}\"", m_ColumnSpan);
             //   if (m_RowSpan > 1) tdStart.AppendFormat(" rowspan=\"{0}\"", m_RowSpan);

            if(column != null && !string.IsNullOrEmpty( writer.Grid.OnClientCellClick ))
            {
                ClientCellEventArgs ea = new ClientCellEventArgs();

                ea.ColumnId = column.ColumnId;
                ea.RowIndex = m_GridRowCount;
                if (cell != null)
                    ea.Value = cell.Value;
                ea.ClientEventType = ClientEventType.OnClientColumnClick;
                string content = JavaScriptConvert.SerializeObject(ea);
                writer.Grid.JsOnData.AppendLine();
                string jsonId = string.Format("{0}r{2}{1}", m_GridId, name, m_GridRowCount).Replace("-","A");

                writer.Grid.JsOnData.AppendFormat("{0} = {1}", jsonId, content);

                tdStart.AppendFormat(@" onclick=""{0}(this,{1});return false"" ", writer.Grid.OnClientCellClick, jsonId);
            }
            if (column != null && !string.IsNullOrEmpty(writer.Grid.OnClientCellDblClick))
            {
                ClientCellEventArgs ea = new ClientCellEventArgs();

                ea.ColumnId = column.ColumnId;
                ea.RowIndex = m_GridRowCount;
                if (cell != null)
                    ea.Value = cell.Value;
                ea.ClientEventType = ClientEventType.OnClientColumnDblClick;
                string content = JavaScriptConvert.SerializeObject(ea);
                writer.Grid.JsOnData.AppendLine();
                string jsonId = string.Format("{0}r{2}{1}", m_GridId, name, m_GridRowCount).Replace("-", "A");

                writer.Grid.JsOnData.AppendFormat("{0} = {1}", jsonId, content);

                tdStart.AppendFormat(@" ondblclick=""{0}(this,{1});return false"" ", writer.Grid.OnClientCellDblClick, jsonId);
            }
            if (column != null && !string.IsNullOrEmpty(writer.Grid.OnClientCellMouseOver))
            {
                ClientCellEventArgs ea = new ClientCellEventArgs();

                ea.ColumnId = column.ColumnId;
                ea.RowIndex = m_GridRowCount;
                if (cell != null)
                    ea.Value = cell.Value;
                ea.ClientEventType = ClientEventType.OnClientColumnMouseOver;
                string content = JavaScriptConvert.SerializeObject(ea);
                writer.Grid.JsOnData.AppendLine();
                string jsonId = string.Format("{0}r{2}{1}mouseover", m_GridId, name, m_GridRowCount).Replace("-", "A");

                writer.Grid.JsOnData.AppendFormat("{0} = {1}", jsonId, content);

                tdStart.AppendFormat(@"onmouseover=""{0}(this,{1});return false""", writer.Grid.OnClientCellMouseOver, jsonId);
            }
            if (column != null && !string.IsNullOrEmpty(writer.Grid.OnClientCellMouseOut))
            {
                ClientCellEventArgs ea = new ClientCellEventArgs();

                ea.ColumnId = column.ColumnId;
                ea.RowIndex = m_GridRowCount;
                if (cell != null)
                    ea.Value = cell.Value;
                ea.ClientEventType = ClientEventType.OnClientColumnMouseOut;
                string content = JavaScriptConvert.SerializeObject(ea);
                writer.Grid.JsOnData.AppendLine();
                string jsonId = string.Format("{0}r{2}{1}mouseout", m_GridId, name, m_GridRowCount).Replace("-", "A");

                writer.Grid.JsOnData.AppendFormat("{0} = {1}", jsonId, content);

                tdStart.AppendFormat(@"onmouseout=""{0}(this,{1});return false""", writer.Grid.OnClientCellMouseOut, jsonId);
            }
            tdStart.Append(">");

            writer.Write(tdStart);
        }
Example #30
0
        internal override void GetColumnPostBackData(RowCell cell)
        {
            if (cell.GotPostBackData || !Grid.GotHttpContext)
                return;
            cell.GotPostBackData = true;
            string uniqueID = cell.CellClientId;

            // Check if we have a post back, need this since checkbox "returns null" both for unchecked and non-existing
            if (HttpContext.Current.Request[uniqueID + "_cb"] == null)
                return;

            cell.PostBackValue = HttpContext.Current.Request[uniqueID] ?? FalseValue;
        }