Esempio n. 1
0
        protected void grdData_CustomButtonCallback(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewCustomButtonCallbackEventArgs e)
        {
            ASPxGridView grid           = sender as ASPxGridView;
            ASPxTextBox  txt_realamount = grid.FindRowTemplateControl(e.VisibleIndex, "txt_realamount") as ASPxTextBox;

            txt_realamount.Focus();
        }
    }//end menu names loop

    #endregion

    #region gridview crud events
    /// <summary>
    /// on row created get lookup values
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void dxgrdCourier_HtmlRowCreated(object sender, ASPxGridViewTableRowEventArgs e)
    {
        ASPxGridView _grd = (ASPxGridView)sender;

        try
        {
            if (e.RowType == GridViewRowType.Data)
            {
                //company
                int    _id  = wwi_func.vint(e.GetValue("DocsDespatchID").ToString());
                string _txt = wwi_func.lookup_multi_values("CompanyName,Address1,Address2,Address3,CountryName,TelNo", "view_delivery_address", "CompanyID", _id);
                if (_txt != "")
                {
                    string[] _lx = _txt.Split(Environment.NewLine.ToCharArray());
                    //company
                    ASPxLabel _lbl = (ASPxLabel)_grd.FindRowTemplateControl(e.VisibleIndex, "dxlblDocsDespatchIDView");
                    if (_lbl != null)
                    {
                        _lbl.Text = _lx[0];
                    }
                    //address
                    _lbl = (ASPxLabel)_grd.FindRowTemplateControl(e.VisibleIndex, "dxlblDocsDespatchIDView2");
                    if (_lbl != null)
                    {
                        _lbl.Text = _txt.Replace(_lx[0], "").Trim();;
                    }
                }

                //contact
                _id  = wwi_func.vint(e.GetValue("ContactID").ToString());
                _txt = wwi_func.lookup_multi_values("ContactName,Email", "ContactTable", "ContactID", _id, "|");
                if (_txt != "")
                {
                    string[] _lx = _txt.Split("|".ToCharArray());
                    //name
                    ASPxLabel _lbl = (ASPxLabel)_grd.FindRowTemplateControl(e.VisibleIndex, "dxlblContactIDView");
                    if (_lbl != null)
                    {
                        _lbl.Text = _lx[0].Trim();
                    }
                    //email
                    _lbl = (ASPxLabel)_grd.FindRowTemplateControl(e.VisibleIndex, "dxlblContactIDView2");
                    if (_lbl != null)
                    {
                        _lbl.Text = _lx.Length > 0 ? _lx[1] : "";
                    }
                }

                //get the status value
                int    _original = wwi_func.vint(e.GetValue("Original").ToString());
                string _target   = _original <= 2 ? "Despatch Date" : "Date Emailed";

                //format date if original = 2 pass to docs despatched date, if 3 pass to emailed date
                string _dt = e.GetValue("DocumentationDespatched") != null?wwi_func.vdatetime(e.GetValue("DocumentationDespatched").ToString()).ToShortDateString() : "";

                //set caption
                ASPxLabel _lb = (ASPxLabel)_grd.FindRowTemplateControl(e.VisibleIndex, "dxlblDespatchDateCaption");
                if (_lb != null)
                {
                    _lb.Text = _target;
                }
                _lb = (ASPxLabel)_grd.FindRowTemplateControl(e.VisibleIndex, "dxlblDespatchDateView");
                if (_lb != null)
                {
                    _lb.Text = _dt;
                }
            }
            else if (e.RowType == GridViewRowType.EditForm)
            {
                //edit form stuff
                //populate company address label
                int    _id  = wwi_func.vint(e.GetValue("DocsDespatchID").ToString());
                string _txt = wwi_func.lookup_multi_values("Address1,Address2,Address3,CountryName,TelNo", "view_delivery_address", "CompanyID", _id);
                if (_txt != "")
                {
                    //string[] _lx = _txt.Split(Environment.NewLine.ToCharArray());
                    //address
                    ASPxLabel _lb = (ASPxLabel)_grd.FindEditFormTemplateControl("dxlblAddress2");
                    if (_lb != null)
                    {
                        _lb.Text = _txt;
                    }
                }

                //bind contact or we lose the contact name on edit
                ASPxComboBox _editor = (ASPxComboBox)_grd.FindEditFormTemplateControl("dxcboClientContact");
                if (_editor != null)
                {
                    string[] _cols  = { "ContactID, ContactName", "Email" };
                    string[] _order = { "ContactName" };
                    SqlQuery _qry   = new Select(_cols).From(DAL.Logistics.Tables.ContactTable).OrderAsc(_order);
                    if (_id > 0)
                    {
                        _qry.Where("CompanyID").IsEqualTo(_id);
                    }

                    IDataReader _rd1 = _qry.ExecuteReader();
                    _editor.DataSource = _rd1;
                    _editor.ValueField = "ContactID";
                    _editor.TextField  = "ContactName";
                    _editor.DataBind();
                    _editor.SelectedItem = _editor.Items.FindByValue(e.GetValue("ContactID"));
                }
            }//end if
        }
        catch (Exception ex)
        {
            string _ex = ex.Message.ToString();
            this.dxlblErr.Text         += _ex;
            this.dxpnlErr.ClientVisible = true;
        }
    }