protected override void divLeft_DataBinding(object sender, EventArgs e)
        {
            HtmlContainerControl divLeft = (HtmlContainerControl)sender;
            var context = DataBinder.GetDataItem(divLeft.NamingContainer);
            //divLeft.ID = "TDIV_" + divLeft.NamingContainer.ID;

            CffGenGridView gV    = (Cff.SaferTrader.Web.UserControls.gGridViewControls.CffGenGridView)(divLeft.NamingContainer.BindingContainer);
            GridViewRow    gvRow = ((System.Web.UI.WebControls.GridViewRow)(divLeft.Controls[0].BindingContainer));

            if ((gV != null) && (gV.IsInEditMode) && (gV.EditIndex == gvRow.RowIndex) && (gV.EditingMode == CffGridViewEditingMode.InLine))
            { //if is in editmode and edit index == current row and is inline edit
                HtmlGenericControl LineBreak = new HtmlGenericControl("br");
                HtmlGenericControl par       = new HtmlGenericControl("p");

                TextBox TBox = new TextBox();
                if (DataBinder.Eval(context, DataField) != null)
                {
                    TBox.Text = DataBinder.Eval(context, DataField) == null ? "" : DataBinder.Eval(context, DataField).ToString();
                }
                else
                {
                    TBox.Text = "";
                }

                TBox.ID = "Tbx" + DataField;
                TBox.ControlStyle.CssClass = "cffGV_CellTextBox";
                TBox.Style.Add(HtmlTextWriterStyle.BorderStyle, "none");

                TBox.Visible      = true;
                TBox.ReadOnly     = this.ReadOnly;
                TBox.Enabled      = !this.ReadOnly;
                TBox.AutoPostBack = this.ReadOnly;;

                Label label = new Label();
                label.ControlStyle.Width    = Unit.Pixel((DataHeader.Length + 1) * 2);
                label.ControlStyle.CssClass = "cffGGV_CellLabel";
                label.Style.Add(HtmlTextWriterStyle.BorderStyle, "none");
                label.Style.Add(HtmlTextWriterStyle.Margin, "0px 0px 0px 0px;");

                label.Text = DataHeader + ":";
                par.Controls.Add(label);
                par.Controls.Add(LineBreak);
                par.Controls.Add(TBox);
                par.Style.Add(HtmlTextWriterStyle.Padding, "0px 0px 0px 0px;");
                par.Style.Add(HtmlTextWriterStyle.Margin, "0px 0px 0px 0px;");
                par.Attributes.Add("align", "left");

                divLeft.Controls.Add(par);
                divLeft.Style.Add(HtmlTextWriterStyle.Width, "100%");
                divLeft.Style.Add(HtmlTextWriterStyle.Height, "150px");
                divLeft.Style.Add(HtmlTextWriterStyle.Padding, "0px 0px 0px 0px");
                divLeft.Style.Add(HtmlTextWriterStyle.Margin, "0px 0px 0px 0px");
                gvRow.Height = Unit.Pixel(150);
            }
            else
            {
                Label label = new Label();
                label.ControlStyle.CssClass = this._textCss;
                try {
                    label.Text = "";
                    if (this._columnType == CffGridViewColumnType.Date)
                    {
                        object o = DataBinder.Eval(context, DataField);
                        if (DataBinder.Eval(context, DataField) != null)
                        {
                            if (o != null)
                            {
                                label.Text = o.ToString();
                            }
                            else
                            {
                                label.Text = CffGenGridViewCommon.FormatDataColumn(this._columnType, DataBinder.Eval(context, DataField) == null ? "" : DataBinder.Eval(context, DataField).ToString());
                            }
                        }
                    }
                    else if (this._columnType == CffGridViewColumnType.DateTime)   // added by dbb
                    {
                        object ct = context.GetType().GetProperty("Created").GetValue(context, null);
                        object dt = ct.GetType().GetProperty("DateTime").GetValue(ct, null);

                        label.Text = CffGenGridViewCommon.FormatDataColumn(this._columnType, DataBinder.Eval(context, DataField) == null ? "" : dt.ToString());
                    }
                    else
                    {
                        if (DataBinder.Eval(context, DataField) != null)
                        {
                            label.Text = CffGenGridViewCommon.FormatDataColumn(this._columnType, DataBinder.Eval(context, DataField) == null ? "" : DataBinder.Eval(context, DataField).ToString());
                        }
                    }
                } catch (Exception exc) {
                    label.Text = exc.Message;
                }

                label.ControlStyle.BorderWidth = Unit.Pixel(0);
                if (this._columnType == CffGridViewColumnType.Currency)
                {
                    label.ControlStyle.CssClass = "cffGGV_currencyCell";
                }

                divLeft.Controls.Add(label);
            }
        }
        protected override void divLeft_DataBinding(object sender, EventArgs e)
        {
            CffGenGridView gV    = null;
            GridViewRow    gvRow = null;

            HtmlContainerControl divLeft = (HtmlContainerControl)sender;
            var context = DataBinder.GetDataItem(divLeft.NamingContainer);

            //divLeft.ID = "TDIV_" + divLeft.NamingContainer.ID;

            if ((Cff.SaferTrader.Web.UserControls.gGridViewControls.CffGenGridView)(divLeft.NamingContainer.BindingContainer) != null)
            {
                gV    = (Cff.SaferTrader.Web.UserControls.gGridViewControls.CffGenGridView)(divLeft.NamingContainer.BindingContainer);
                gvRow = ((System.Web.UI.WebControls.GridViewRow)(divLeft.Controls[0].BindingContainer));
            }

            if ((gV != null) && gV.IsInEditMode && (gV.EditIndex == gvRow.RowIndex) && (gV.EditingMode == CffGridViewEditingMode.InLine))
            {
                //if is in editmode and edit index == current row and is inline edit
                HtmlGenericControl LineBreak = new HtmlGenericControl("br");
                HtmlGenericControl par       = new HtmlGenericControl("p");

                TextBox TBox    = new TextBox();
                String  strText = "";
                if (DataBinder.Eval(context, DataField) != null)
                {
                    strText = DataBinder.Eval(context, DataField) == null
                        ? ""
                        : DataBinder.Eval(context, DataField).ToString();
                    TBox.Text = strText;
                }
                else
                {
                    TBox.Text = "";
                }

                TBox.ID = "Tbx" + DataField;

                TBox.CssClass = "cffGV_CellTextBox";
                TBox.Style.Add(HtmlTextWriterStyle.BorderStyle, "none");
                TBox.Style.Add(HtmlTextWriterStyle.Width, "100%");

                TBox.Width    = Unit.Percentage(100);
                TBox.Height   = Unit.Pixel(100);
                TBox.TextMode = TextBoxMode.MultiLine;
                //TBox.CssClass = "maxPopupScreenWidth";
                TBox.Attributes.Add("runat", "server");
                TBox.Attributes.Add("Rows", "100");

                TBox.Wrap         = true;
                TBox.Enabled      = !this.ReadOnly;
                TBox.AutoPostBack = false;

                Label label = new Label();
                //label.ControlStyle.Width = Unit.Pixel((DataHeader.Length + 1) * 2);  //dbb
                label.ControlStyle.Width    = Unit.Pixel((DataHeader.Length) * 2);
                label.ControlStyle.CssClass = "cffGGV_CellLabel";
                label.Style.Add(HtmlTextWriterStyle.Margin, "0px 0px 0px 0px;");

                label.Text = DataHeader + ": ";
                par.Controls.Add(label);
                par.Controls.Add(LineBreak);
                par.Controls.Add(TBox);

                par.Style.Add(HtmlTextWriterStyle.Padding, "0px 0px 0px 0px;");
                par.Style.Add(HtmlTextWriterStyle.Margin, "0px 0px 0px 0px;");
                par.Attributes.Add("align", "left");

                divLeft.Controls.Add(par);
                divLeft.Style.Add(HtmlTextWriterStyle.Width, "100%");
                divLeft.Style.Add(HtmlTextWriterStyle.Height, "150px");
                divLeft.Style.Add(HtmlTextWriterStyle.Padding, "0px 0px 0px 0px");
                divLeft.Style.Add(HtmlTextWriterStyle.Margin, "0px 0px 0px 0px");
                gvRow.Height = Unit.Pixel(150);
            }
            else
            {
                HtmlGenericControl MemoPar = new HtmlGenericControl("p");
                MemoPar.Attributes.CssStyle.Value = this._textCss;
                MemoPar.Attributes.Add("readonly", "true");
                MemoPar.Style.Add(HtmlTextWriterStyle.TextAlign, "justify");
                MemoPar.Style.Add(HtmlTextWriterStyle.BorderWidth, "0px");
                MemoPar.Style.Add(HtmlTextWriterStyle.BorderColor, "none");
                MemoPar.Style.Add(HtmlTextWriterStyle.MarginTop, "5px");
                MemoPar.Style.Add(HtmlTextWriterStyle.MarginBottom, "5px");
                MemoPar.Style.Add(HtmlTextWriterStyle.MarginLeft, "6px");
                MemoPar.Style.Add(HtmlTextWriterStyle.MarginRight, "10px");
                MemoPar.Style.Add(HtmlTextWriterStyle.BackgroundColor, "transparent");

                double rows = 1;
                double initRows;
                double finalRows;
                double preCol   = 0;
                double finalCol = 0;

                if (DataBinder.Eval(context, DataField) != null)
                {
                    System.Text.StringBuilder strText = new System.Text.StringBuilder("");
                    strText = new System.Text.StringBuilder(CffGenGridViewCommon.FormatDataColumn(this._columnType, DataBinder.Eval(context, DataField) == null ? "" : DataBinder.Eval(context, DataField).ToString()));
                    strText.Replace("<br />", " ");

                    if (!string.IsNullOrEmpty(strText.ToString()))
                    {
                        MemoPar.InnerText = strText.ToString();

                        if (strText.Length > 120)      //*todo: do a dynamic way of getting the max length
                        {
                            if (strText.Length >= 150) //*todo: find a way dynamically adjust row column grids based on the length of memo data
                            {
                                initRows  = ((double)(strText.Length / 130.00));
                                finalRows = Math.Round(initRows, 2) + 1;
                                rows      = finalRows;
                                string rowDec   = rows.ToString();
                                string rowsFDec = rowDec.Substring(rowDec.Length - 1, 1);
                                int    rowDisp  = int.Parse(rowsFDec);
                                if (rowDisp > 0)
                                {
                                    rows = rows + 1;
                                }
                                preCol   = (strText.Length / finalRows);
                                finalCol = (preCol + (130 - preCol)) - 10;
                                MemoPar.Attributes.Add("cols", strText.Length >= 120 ? "130" : finalCol.ToString());
                                //MemoPar.Attributes.Add("cols", finalCol.ToString());
                            }
                            else
                            {
                                MemoPar.Attributes.Add("cols", "115");
                                rows = ((int)(strText.Length / 115)) + 1;
                            }
                        }
                        else
                        {
                            MemoPar.Attributes.Add("cols", "120");
                            rows = ((int)(strText.Length) / 120);   // 50 - dbb
                        }

                        if (rows <= 0)
                        {
                            rows = 1;
                        }
                        MemoPar.Attributes.Add("rows", rows.ToString());
                    }
                    else
                    {
                        MemoPar.Attributes.Add("rows", "0");
                        MemoPar.Attributes.Add("cols", "140");
                    }
                }
                else
                {
                    MemoPar.Attributes.Add("rows", "0");
                    MemoPar.Attributes.Add("cols", "140");
                }
                MemoPar.Attributes.Add("wrap", "hard");   // dbb [20160804]
                MemoPar.Style.Add(HtmlTextWriterStyle.FontSize, "12px");
                MemoPar.Style.Add(HtmlTextWriterStyle.FontFamily, "Tahoma, Arial, Helvetica, sans-serif");
                MemoPar.Style.Add(HtmlTextWriterStyle.Overflow, "hidden");
                //if (rows < 6) { MemoPar.Style.Add(HtmlTextWriterStyle.Overflow, "hidden"); }  //dbb
                divLeft.Controls.Add(MemoPar);
                //divLeft.Style.Add(HtmlTextWriterStyle.Width, "100%");
            }
        }
Ejemplo n.º 3
0
        void linkField_DataBinding(object sender, EventArgs e)
        {
            var linkField       = (HyperLink)sender;
            var context         = DataBinder.GetDataItem(linkField.NamingContainer);
            var boundFieldValue = (DataBinder.Eval(context, DataField) == null)?"":(DataBinder.Eval(context, DataField)).ToString();

            if (DisplayField == null)
            {
                linkField.Text = "";
            }
            else
            {
                linkField.Text = CffGenGridViewCommon.FormatDataColumn(this._columnType,
                                                                       (DataBinder.Eval(context, DisplayField) == null) ? "" : (DataBinder.Eval(context, DisplayField)).ToString());
            }

            string strRowIndex = ((System.Web.UI.WebControls.GridViewRow)(((System.Web.UI.Control)(linkField)).DataItemContainer)).RowIndex.ToString();

            Cff.SaferTrader.Core.LinkHelper.SetRowIndex(strRowIndex);

            linkField.CssClass = this._cssStyle;

            //link helpers - careful when modifying as this needs to coincide with production version (ref: mariper)
            if (DataField.ToUpper().IndexOf("CUSTOMER") >= 0 || DataField.ToUpper().IndexOf("CUSTID") >= 0 || DataField.ToUpper().IndexOf("CUSTOMERID") >= 0)
            {
                if (string.IsNullOrEmpty(boundFieldValue))
                {
                    linkField.NavigateUrl = Cff.SaferTrader.Core.LinkHelper.NavigateUrlFormatToDashboardForCustomer;
                }
                else
                {
                    if (SessionWrapper.Instance.Get != null)
                    {
                        if (SessionWrapper.Instance.Get.Scope == Scope.AllClientsScope)
                        {
                            linkField.NavigateUrl = Cff.SaferTrader.Core.LinkHelper.NavigateUrlFormatToDashboardForGivenCustomerId(boundFieldValue, (int?)DataBinder.Eval(context, "ClientId"));
                        }
                        else
                        {
                            linkField.NavigateUrl = Cff.SaferTrader.Core.LinkHelper.NavigateUrlFormatToDashboardForGivenCustomerId(boundFieldValue);
                        }
                    }
                }
            }
            else if (DataField.ToUpper().IndexOf("CLIENT") >= 0)
            {
                linkField.NavigateUrl = Cff.SaferTrader.Core.LinkHelper.NavigateUrlFormatToDashboardForAGivenClientId(boundFieldValue);
            }
            else if (DataField.ToUpper().IndexOf("CLIENTID") >= 0)
            {
                linkField.NavigateUrl = Cff.SaferTrader.Core.LinkHelper.NavigateUrlFormatToDashboardForAGivenClientId(boundFieldValue);
            }
            else if ((DataField.ToUpper().IndexOf("BATCH") >= 0) || (DataField.ToUpper().IndexOf("BATCHNUMBER") >= 0))
            {
                string strCustID   = "";
                string strClientID = "";
                try {
                    strClientID = (DataBinder.Eval(context, "ClientId") == null) ? "" : DataBinder.Eval(context, "ClientId").ToString();
                }
                catch (Exception) { }

                try {
                    strCustID = (DataBinder.Eval(context, "CustomerId") == null) ? "" : DataBinder.Eval(context, "CustomerId").ToString();
                } catch (Exception) { }


                bool doHyperLink = (_isReversed)?false:true;
                if (!string.IsNullOrEmpty(_boundFilterField))
                {
                    if (_boundFilterFieldValue == ((DataBinder.Eval(context, _boundFilterField) == null) ? "" : (DataBinder.Eval(context, _boundFilterField)).ToString()))
                    {
                        doHyperLink = _onOff;
                    }
                    //todo:: assign necessary filtering if arrayed filter fields
                }

                if (doHyperLink)
                {
                    if (string.IsNullOrEmpty(boundFieldValue))
                    {
                        linkField.NavigateUrl = Cff.SaferTrader.Core.LinkHelper.NavigateUrlFormatToInvoiceBatchesForClient;
                    }
                    else
                    {
                        linkField.NavigateUrl = Cff.SaferTrader.Core.LinkHelper.NavigateUrlFormatToInvoiceBatchesForClientWBatchID(boundFieldValue, strCustID, strClientID);
                    }

                    linkField.Style.Add(HtmlTextWriterStyle.TextDecoration, "underline");
                    linkField.ToolTip = "Click to View Batch";
                    linkField.Attributes.Add("title", "Click to View Batch");
                    this._navigateUrl = linkField.NavigateUrl;
                }
                else
                { //disable hyperlink
                    linkField.Style.Add(HtmlTextWriterStyle.TextDecoration, "none");
                    linkField.Style.Add(HtmlTextWriterStyle.Color, "black");
                }
            }
        }