Esempio n. 1
0
        public static string[] getCheckedItemList(GridView grid, string FieldName)
        {
            List <String> scChecked = new List <String>();

            foreach (GridViewRow row in grid.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    GridviewHelper helperGrid = new GridviewHelper(row);
                    if (helperGrid.findCheckBox("chk" + FieldName).Checked)
                    {
                        scChecked.Add(grid.DataKeys[row.RowIndex].Value.ToString());
                    }
                }
            }

            return(scChecked.ToArray());
        }
Esempio n. 2
0
        public IOrderedDictionary ExtractItemTemplateValues(Control container)
        {
            OrderedDictionary dic        = new OrderedDictionary();
            string            fieldName  = _fieldName;
            object            fieldValue = null;
            string            sValue     = null;


            if (_modeID == ModeOfItem)
            {
                GridviewHelper helperGridview = new GridviewHelper(container as GridViewRow);
                Label          lb             = helperGridview.findLabel("lb" + fieldName);
                if (lb != null)
                {
                    sValue = lb.Text.Trim();
                }
                CheckBox chk = helperGridview.findCheckBox("chk" + fieldName);
                if (chk != null)
                {
                    sValue = chk.Checked.ToString();
                }

                if (_modeID == ModeOfHeader && HtmlHelper.IsNullOrEmpty(sValue))
                {
                    return(dic);
                }

                if (_fieldAllowNull && (HtmlHelper.IsNullOrEmpty(sValue) || sValue == int.MinValue.ToString()))
                {
                    switch (_fieldType)
                    {
                    case TypeOfBool:
                        fieldValue = Null.NullBoolean;
                        break;

                    case TypeOfInt:
                        fieldValue = Null.NullInteger;
                        break;

                    case TypeOfLookup:
                        fieldValue = Null.GetNullOfTypeKey(_fieldTypeKey);
                        break;

                    case TypeOfFloat:
                        fieldValue = Null.NullDouble;
                        break;

                    case TypeOfDecimal:
                        fieldValue = Null.NullDecimal;
                        break;

                    case TypeOfString:
                    case TypeOfText:
                        fieldValue = Null.NullString;
                        break;

                    case TypeOfPassword:
                        fieldValue = Null.NullString;
                        break;

                    case TypeOfDate:
                    case TypeOfDateTime:
                        fieldValue = Null.NullDate;
                        break;
                    }
                }
                else
                {
                    try
                    {
                        if (_fieldAllowNull == false && HtmlHelper.IsNullOrEmpty(sValue))
                        {
                            throw new Exception("Field '" + fieldName + "' not allow Null!");
                        }

                        switch (_fieldType)
                        {
                        case TypeOfBool:
                            fieldValue = chk.Checked;
                            break;

                        case TypeOfInt:
                            fieldValue = int.Parse(sValue);
                            break;

                        case TypeOfLookup:
                            fieldValue = Null.GetNullOfTypeKey(_fieldTypeKey);
                            switch (_fieldTypeKey.ToLower())
                            {
                            case "double":
                                fieldValue = double.Parse(sValue);
                                break;

                            case "bool":
                                fieldValue = bool.Parse(sValue);
                                break;

                            case "int":
                            case "int32":
                                fieldValue = int.Parse(sValue);
                                break;

                            case "string":
                                fieldValue = sValue;
                                break;

                            case "datetime":
                                fieldValue = DateTime.Parse(sValue);
                                break;
                            }

                            break;

                        case TypeOfFloat:
                            fieldValue = float.Parse(sValue);
                            break;

                        case TypeOfDecimal:
                            fieldValue = decimal.Parse(sValue);
                            break;

                        case TypeOfString:
                        case TypeOfText:
                            fieldValue = sValue;
                            break;

                        case TypeOfPassword:
                            fieldValue = sValue;
                            break;

                        case TypeOfDate:
                        case TypeOfDateTime:
                            fieldValue = DateTime.Parse(sValue);
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        if (_modeID == ModeOfFooter)
                        {
                            if (_fieldAllowNull)
                            {
                                switch (_fieldType)
                                {
                                case TypeOfBool:
                                    fieldValue = Null.NullBoolean;
                                    break;

                                case TypeOfInt:
                                    fieldValue = Null.NullInteger;
                                    break;

                                case TypeOfLookup:
                                    fieldValue = Null.GetNullOfTypeKey(_fieldTypeKey);
                                    break;

                                case TypeOfFloat:
                                    fieldValue = Null.NullDouble;
                                    break;

                                case TypeOfDecimal:
                                    fieldValue = Null.NullDecimal;
                                    break;

                                case TypeOfString:
                                case TypeOfText:
                                    fieldValue = Null.NullString;
                                    break;

                                case TypeOfPassword:
                                    fieldValue = Null.NullString;
                                    break;

                                case TypeOfDate:
                                case TypeOfDateTime:
                                    fieldValue = Null.NullDate;
                                    break;
                                }
                            }
                            else
                            {
                                throw ex;
                            }
                        }
                    }
                }
            }



            if (fieldValue != null)
            {
                dic.Add(fieldName, fieldValue);
            }

            return(dic);
        }
Esempio n. 3
0
        public IOrderedDictionary ExtractValues(Control container)
        {
            OrderedDictionary dic = new OrderedDictionary();

            if (_modeID == ModeOfItem)
            {
                return(dic);
            }

            string fieldName  = _fieldName;
            object fieldValue = null;
            string sValue     = null;

            GridviewHelper helperGridview = new GridviewHelper(container as GridViewRow);
            TextBox        txt            = helperGridview.findTextBox("txt" + fieldName);

            if (txt != null)
            {
                sValue = txt.Text.Trim();
            }
            DropDownList cbo = helperGridview.findDropDownList("cbo" + fieldName);

            if (cbo != null)
            {
                sValue = cbo.SelectedValue.Trim();
            }

            if (_modeID == ModeOfHeader && HtmlHelper.IsNullOrEmpty(sValue))
            {
                return(dic);
            }

            if (_fieldAllowNull && (HtmlHelper.IsNullOrEmpty(sValue) || sValue == int.MinValue.ToString()))
            {
                switch (_fieldType)
                {
                case TypeOfBool:
                    fieldValue = Null.NullBoolean;
                    break;

                case TypeOfInt:
                    fieldValue = Null.NullInteger;
                    break;

                case TypeOfByte:
                    fieldValue = Null.NullShort;
                    break;

                case TypeOfLookup:
                    fieldValue = Null.GetNullOfTypeKey(_fieldTypeKey);
                    break;

                case TypeOfFloat:
                    fieldValue = Null.NullDouble;
                    break;

                case TypeOfDecimal:
                    fieldValue = Null.NullDecimal;
                    break;

                case TypeOfString:
                case TypeOfText:
                    fieldValue = Null.NullString;
                    break;

                case TypeOfPassword:
                    fieldValue = Null.NullString;
                    break;

                case TypeOfDate:
                case TypeOfDateTime:
                    fieldValue = Null.NullDate;
                    break;
                }
            }
            else
            {
                try
                {
                    if (_fieldAllowNull == false && HtmlHelper.IsNullOrEmpty(sValue))
                    {
                        throw new Exception("Field '" + fieldName + "' not allow Null!");
                    }

                    switch (_fieldType)
                    {
                    case TypeOfBool:
                        fieldValue = cbo.SelectedValue != "0";
                        break;

                    case TypeOfInt:
                        fieldValue = int.Parse(sValue);
                        break;

                    case TypeOfByte:
                        fieldValue = byte.Parse(sValue);
                        break;

                    case TypeOfLookup:
                        fieldValue = Null.GetNullOfTypeKey(_fieldTypeKey);
                        switch (_fieldTypeKey.ToLower())
                        {
                        case "double":
                            fieldValue = double.Parse(sValue);
                            break;

                        case "bool":
                            fieldValue = bool.Parse(sValue);
                            break;

                        case "byte":
                            fieldValue = byte.Parse(sValue);
                            break;

                        case "int":
                        case "int32":
                            fieldValue = int.Parse(sValue);
                            break;

                        case "string":
                            fieldValue = sValue;
                            break;

                        case "datetime":
                            fieldValue = DateTime.Parse(sValue);
                            break;
                        }

                        break;

                    case TypeOfFloat:
                        fieldValue = float.Parse(sValue);
                        break;

                    case TypeOfDecimal:
                        fieldValue = decimal.Parse(sValue);
                        break;

                    case TypeOfString:
                    case TypeOfText:
                        fieldValue = sValue;
                        break;

                    case TypeOfPassword:
                        fieldValue = sValue;
                        break;

                    case TypeOfDate:
                    case TypeOfDateTime:
                        fieldValue = DateTime.Parse(sValue);
                        break;
                    }
                }
                catch (Exception ex)
                {
                    if (_modeID == ModeOfFooter)
                    {
                        if (_fieldAllowNull)
                        {
                            switch (_fieldType)
                            {
                            case TypeOfBool:
                                fieldValue = Null.NullBoolean;
                                break;

                            case TypeOfInt:
                                fieldValue = Null.NullInteger;
                                break;

                            case TypeOfLookup:
                                fieldValue = Null.GetNullOfTypeKey(_fieldTypeKey);
                                break;

                            case TypeOfFloat:
                                fieldValue = Null.NullDouble;
                                break;

                            case TypeOfDecimal:
                                fieldValue = Null.NullDecimal;
                                break;

                            case TypeOfString:
                            case TypeOfText:
                                fieldValue = Null.NullString;
                                break;

                            case TypeOfPassword:
                                fieldValue = Null.NullString;
                                break;

                            case TypeOfDate:
                            case TypeOfDateTime:
                                fieldValue = Null.NullDate;
                                break;
                            }
                        }
                        else
                        {
                            throw ex;
                        }
                    }
                }
            }

            if (fieldValue != null)
            {
                dic.Add(fieldName, fieldValue);
            }

            return(dic);
        }
Esempio n. 4
0
        public void InstantiateIn(Control container)
        {
            switch (_modeID)
            {
            case ModeOfItem:
                switch (_fieldType)
                {
                case TypeOfCheckBox:
                    container.Controls.Add(GridviewHelper.newCheckBox("chk" + _fieldName, new EventHandler(BindItemCheckBox)));
                    break;

                default:
                    if (!_fieldAllowLink)
                    {
                        container.Controls.Add(GridviewHelper.newLabel("lb" + _fieldName, new EventHandler(BindItemLabel)));
                    }
                    else
                    {
                        container.Controls.Add(GridviewHelper.newHyperLink(new EventHandler(BindItemHyperLink)));
                    }
                    break;
                }
                break;

            case ModeOfEditItem:
                switch (_fieldType)
                {
                case TypeOfCheckBox:
                    container.Controls.Add(GridviewHelper.newCheckBox("chk" + _fieldName, new EventHandler(BindItemCheckBox)));
                    break;

                case TypeOfBool:
                    container.Controls.Add(GridviewHelper.newBooleanDropDownList("cbo" + _fieldName, new EventHandler(BindEditItemBooleanDropDownList), _fieldAllowNull, true, null));
                    break;

                case TypeOfLookup:
                    container.Controls.Add(GridviewHelper.newDropDownList("cbo" + _fieldName, new EventHandler(BindEditItemDropDownList), _fieldLookupHelper, false, null));
                    break;

                default:
                    if (_readOnly)
                    {
                        container.Controls.Add(GridviewHelper.newLabel(new EventHandler(BindItemLabel)));
                    }
                    else
                    {
                        container.Controls.Add(GridviewHelper.newTextBox("txt" + _fieldName, new EventHandler(BindEditItemTextBox), null));
                    }
                    break;
                }
                break;

            case ModeOfFooter:
                switch (_fieldType)
                {
                case TypeOfLookup:
                    container.Controls.Add(GridviewHelper.newDropDownList("cbo" + _fieldName, null, _fieldLookupHelper, false, null));
                    break;

                case TypeOfBool:
                    container.Controls.Add(GridviewHelper.newBooleanDropDownList("cbo" + _fieldName, null, _fieldAllowNull, false, null));
                    break;

                default:
                    container.Controls.Add(GridviewHelper.newTextBox("txt" + _fieldName, null, null));
                    break;
                }
                break;

            case ModeOfHeader:
                container.Controls.Add(GridviewHelper.newHeaderButton(_fieldName, _headerText));

                switch (_fieldType)
                {
                case TypeOfPassword:
                    break;

                case TypeOfBool:
                    container.Controls.Add(GridviewHelper.newBooleanDropDownList("cbo" + _fieldName, new EventHandler(BindEditItemBooleanDropDownList), _fieldAllowNull, true, null));
                    break;

                case TypeOfCheckBox:
                    container.Controls.Add(GridviewHelper.newCheckBox("chkAll" + _fieldName, new EventHandler(BindEditItemCheckBox)));
                    break;

                case TypeOfLookup:
                    container.Controls.Add(GridviewHelper.newDropDownList("cbo" + _fieldName, new EventHandler(BindEditItemDropDownList), _fieldLookupHelper, true, null));
                    break;

                default:
                    container.Controls.Add(GridviewHelper.newTextBox("txt" + _fieldName, new EventHandler(BindEditItemTextBox), null));
                    break;
                }
                break;
            }
        }