Пример #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());
        }
Пример #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);
        }