Exemplo n.º 1
0
        public static void getUserDefaults(ICswResources CswResources, CswNbtAuthReturn Ret, object Request)
        {
            CswNbtResources NbtResources = (CswNbtResources)CswResources;

            if (CswTools.IsPrimaryKey(NbtResources.CurrentNbtUser.DefaultLocationId))
            {
                Ret.Data.DefaultLocationId = NbtResources.CurrentNbtUser.DefaultLocationId.ToString();
            }
            if (CswTools.IsPrimaryKey(NbtResources.CurrentNbtUser.DefaultPrinterId))
            {
                Ret.Data.DefaultPrinterId = NbtResources.CurrentNbtUser.DefaultPrinterId.ToString();
            }
            if (CswTools.IsPrimaryKey(NbtResources.CurrentNbtUser.DefaultBalanceId))
            {
                Ret.Data.DefaultBalanceId = NbtResources.CurrentNbtUser.DefaultBalanceId.ToString();
            }
            if (CswTools.IsPrimaryKey(NbtResources.CurrentNbtUser.JurisdictionId))
            {
                Ret.Data.JurisdictionId = NbtResources.CurrentNbtUser.JurisdictionId.ToString();
            }
            if (CswTools.IsPrimaryKey(NbtResources.CurrentNbtUser.CurrentWorkUnitId))
            {
                Ret.Data.WorkUnitId = NbtResources.CurrentNbtUser.CurrentWorkUnitId.ToString();
            }
            Ret.Data.DateFormatDn = NbtResources.CurrentNbtUser.DateFormat;
            Ret.Data.TimeFormatDn = NbtResources.CurrentNbtUser.TimeFormat;
            Ret.Data.DateFormatJs = CswTools.ConvertNetToPHP(NbtResources.CurrentNbtUser.DateFormat);
            Ret.Data.TimeFormatJs = CswTools.ConvertNetToPHP(NbtResources.CurrentNbtUser.TimeFormat);
        }
Exemplo n.º 2
0
        public void CswTimeFormatToPhpDateFormat_UnitTest()
        {
            foreach (CswEnumTimeFormat Format in CswEnumTimeFormat.All)
            {
                switch (Format)
                {
                case CswEnumTimeFormat.Hmmss:
                    const string PhpHmmss        = "G:i:s";
                    string       ConversionHmmss = CswTools.ConvertNetToPHP(Format);
                    Assert.AreEqual(PhpHmmss, ConversionHmmss, "Valid PHP format [" + PhpHmmss + "] is not equal to Converted format [" + ConversionHmmss + "]!");
                    break;

                case CswEnumTimeFormat.hmmsstt:
                    const string PhpHmmsstt        = "g:i:s a";
                    string       ConversionHmmsstt = CswTools.ConvertNetToPHP(Format);
                    Assert.AreEqual(PhpHmmsstt, ConversionHmmsstt, "Valid PHP format [" + PhpHmmsstt + "] is not equal to Converted format [" + ConversionHmmsstt + "]!");
                    break;
                }
            }
        }
Exemplo n.º 3
0
        public void CswDateFormatToPhpDateFormat_UnitTest()
        {
            foreach (CswEnumDateFormat Format in CswEnumDateFormat.All)
            {
                switch (Format)
                {
                case CswEnumDateFormat.Mdyyyy:
                    const string PhpMdyyyy     = "n/j/Y";
                    string       ConversionNjy = CswTools.ConvertNetToPHP(Format);
                    Assert.AreEqual(PhpMdyyyy, ConversionNjy, "Valid PHP format [" + PhpMdyyyy + "] is not equal to Converted format [" + ConversionNjy + "]!");
                    break;

                case CswEnumDateFormat.dMyyyy:
                    const string PhpDmyyyy        = "j-n-Y";
                    string       ConversionDmyyyy = CswTools.ConvertNetToPHP(Format);
                    Assert.AreEqual(PhpDmyyyy, ConversionDmyyyy, "Valid PHP format [" + PhpDmyyyy + "] is not equal to Converted format [" + ConversionDmyyyy + "]!");
                    break;

                case CswEnumDateFormat.ddMMMyyyy:
                    const string PhpDdMMMyyyy        = "d M Y";
                    string       ConversionDdmmmyyyy = CswTools.ConvertNetToPHP(Format);
                    Assert.AreEqual(PhpDdMMMyyyy, ConversionDdmmmyyyy, "Valid PHP format [" + PhpDdMMMyyyy + "] is not equal to Converted format [" + ConversionDdmmmyyyy + "]!");
                    break;

                case CswEnumDateFormat.yyyyMMdd_Dashes:
                    const string PhpYyyyMMdd        = "Y-m-d";
                    string       ConversionYyyyMMdd = CswTools.ConvertNetToPHP(Format);
                    Assert.AreEqual(PhpYyyyMMdd, ConversionYyyyMMdd, "Valid PHP format [" + PhpYyyyMMdd + "] is not equal to Converted format [" + ConversionYyyyMMdd + "]!");
                    break;

                case CswEnumDateFormat.yyyyMd:
                    const string PhpYyyyMd         = "Y/n/j";
                    string       ConversionYyyyMMd = CswTools.ConvertNetToPHP(Format);
                    Assert.AreEqual(PhpYyyyMd, ConversionYyyyMMd, "Valid PHP format [" + PhpYyyyMd + "] is not equal to Converted format [" + ConversionYyyyMMd + "]!");
                    break;
                }
            }
        }
Exemplo n.º 4
0
        } // _getUniquePrefix()

        public JObject TreeToJson(string Title, CswNbtView View, ICswNbtTree Tree, bool IsPropertyGrid = false, string GroupByCol = "")
        {
            JObject Ret = new JObject();

            if (null != View)
            {
                string gridUniquePrefix = _getUniquePrefix(View);

                CswExtJsGrid grid = new CswExtJsGrid(gridUniquePrefix);
                if (string.IsNullOrEmpty(GroupByCol))
                {
                    GroupByCol = View.GridGroupByCol;
                }
                grid.groupfield = GroupByCol;
                grid.title      = Title;
                if (_CswNbtResources.CurrentNbtUser != null && _CswNbtResources.CurrentNbtUser.PageSize > 0)
                {
                    grid.PageSize = _CswNbtResources.CurrentNbtUser.PageSize;
                }

                if (IsPropertyGrid && Tree.getChildNodeCount() > 0)
                {
                    Tree.goToNthChild(0);
                }

                grid.Truncated = Tree.getCurrentNodeChildrenTruncated();

                CswExtJsGridDataIndex nodeIdDataIndex = new CswExtJsGridDataIndex(gridUniquePrefix, "nodeId");
                {
                    CswExtJsGridField nodeIdFld = new CswExtJsGridField {
                        dataIndex = nodeIdDataIndex
                    };
                    grid.fields.Add(nodeIdFld);
                    CswExtJsGridColumn nodeIdCol = new CswExtJsGridColumn {
                        header = "Internal ID", dataIndex = nodeIdDataIndex, hidden = true
                    };
                    grid.columns.Add(nodeIdCol);
                }
                CswExtJsGridDataIndex nodekeyDataIndex = new CswExtJsGridDataIndex(gridUniquePrefix, "nodekey");
                {
                    CswExtJsGridField nodekeyFld = new CswExtJsGridField {
                        dataIndex = nodekeyDataIndex
                    };
                    grid.fields.Add(nodekeyFld);
                    CswExtJsGridColumn nodekeyCol = new CswExtJsGridColumn {
                        header = "Internal Key", dataIndex = nodekeyDataIndex, hidden = true
                    };
                    grid.columns.Add(nodekeyCol);
                }
                CswExtJsGridDataIndex nodenameDataIndex = new CswExtJsGridDataIndex(gridUniquePrefix, "nodename");
                {
                    CswExtJsGridField nodenameFld = new CswExtJsGridField {
                        dataIndex = nodenameDataIndex
                    };
                    grid.fields.Add(nodenameFld);
                    CswExtJsGridColumn nodenameCol = new CswExtJsGridColumn {
                        header = "Internal Name", dataIndex = nodenameDataIndex, hidden = true
                    };
                    grid.columns.Add(nodenameCol);
                }
                CswExtJsGridDataIndex NodeTypeDataIndex = new CswExtJsGridDataIndex(gridUniquePrefix, "nodetypeid");
                {
                    CswExtJsGridField NodeTypeField = new CswExtJsGridField {
                        dataIndex = NodeTypeDataIndex
                    };
                    grid.fields.Add(NodeTypeField);
                    CswExtJsGridColumn NodeTypeColumn = new CswExtJsGridColumn {
                        header = "Internal Type ID", dataIndex = NodeTypeDataIndex, hidden = true
                    };
                    grid.columns.Add(NodeTypeColumn);
                }
                CswExtJsGridDataIndex ObjectClassDataIndex = new CswExtJsGridDataIndex(gridUniquePrefix, "objectclassid");
                {
                    CswExtJsGridField ObjectClassField = new CswExtJsGridField {
                        dataIndex = ObjectClassDataIndex
                    };
                    grid.fields.Add(ObjectClassField);
                    CswExtJsGridColumn ObjectClassColumn = new CswExtJsGridColumn {
                        header = "Internal Parent Type ID", dataIndex = ObjectClassDataIndex, hidden = true
                    };
                    grid.columns.Add(ObjectClassColumn);
                }
                // View Properties determine Columns and Fields
                foreach (CswNbtViewProperty ViewProp in View.getOrderedViewProps(true))
                {
                    if (null != ViewProp)
                    {
                        ICswNbtMetaDataProp MetaDataProp = null;
                        if (ViewProp.Type == CswEnumNbtViewPropType.NodeTypePropId)
                        {
                            MetaDataProp = ViewProp.NodeTypeProp;
                        }
                        else if (ViewProp.Type == CswEnumNbtViewPropType.ObjectClassPropId)
                        {
                            MetaDataProp = ViewProp.ObjectClassProp;
                        }

                        // Because properties in the view might be by object class, but properties on the tree will always be by nodetype,
                        // we have to use name, not id, as the dataIndex
                        if (null != MetaDataProp)
                        {
                            string header = MetaDataProp.PropNameWithQuestionNo;
                            CswExtJsGridDataIndex dataIndex = new CswExtJsGridDataIndex(gridUniquePrefix, MetaDataProp.PropName);   // don't use PropNameWithQuestionNo here, because it won't match the propname from the tree

                            // Potential bug here!
                            // If the same property is added to the view more than once, we'll only use the grid definition for the first instance
                            if (false == grid.columnsContains(header))
                            {
                                CswExtJsGridField fld = new CswExtJsGridField {
                                    dataIndex = dataIndex
                                };
                                CswExtJsGridColumn col = new CswExtJsGridColumn {
                                    header = header, dataIndex = dataIndex, hidden = (false == ViewProp.ShowInGrid)
                                };
                                switch (ViewProp.FieldType)
                                {
                                case CswEnumNbtFieldType.Button:
                                    col.MenuDisabled = true;
                                    col.IsSortable   = false;
                                    break;

                                case CswEnumNbtFieldType.Number:
                                    fld.type  = "number";
                                    col.xtype = CswEnumExtJsXType.numbercolumn;
                                    break;

                                case CswEnumNbtFieldType.DateTime:
                                    fld.type  = "date";
                                    col.xtype = CswEnumExtJsXType.datecolumn;

                                    // case 26782 - Set dateformat as client date format
                                    string dateformat      = string.Empty;
                                    string DateDisplayMode = CswEnumNbtDateDisplayMode.Date.ToString();
                                    if (ViewProp.Type == CswEnumNbtViewPropType.NodeTypePropId && ViewProp.NodeTypeProp != null)
                                    {
                                        DateDisplayMode = ViewProp.NodeTypeProp.DesignNode.getAttributeValueByName(CswNbtFieldTypeRuleDateTime.AttributeName.DateType);
                                    }
                                    else if (ViewProp.Type == CswEnumNbtViewPropType.ObjectClassPropId && ViewProp.ObjectClassProp != null)
                                    {
                                        DateDisplayMode = ViewProp.ObjectClassProp.Extended;
                                    }
                                    if (DateDisplayMode == string.Empty ||
                                        DateDisplayMode == CswEnumNbtDateDisplayMode.Date.ToString() ||
                                        DateDisplayMode == CswEnumNbtDateDisplayMode.DateTime.ToString())
                                    {
                                        dateformat += CswTools.ConvertNetToPHP(_CswNbtResources.CurrentNbtUser.DateFormat);
                                        if (DateDisplayMode == CswEnumNbtDateDisplayMode.DateTime.ToString())
                                        {
                                            dateformat += " ";
                                        }
                                    }
                                    if (DateDisplayMode == CswEnumNbtDateDisplayMode.Time.ToString() ||
                                        DateDisplayMode == CswEnumNbtDateDisplayMode.DateTime.ToString())
                                    {
                                        dateformat += CswTools.ConvertNetToPHP(_CswNbtResources.CurrentNbtUser.TimeFormat);
                                    }
                                    col.dateformat = dateformat;
                                    break;
                                }
                                if (ViewProp.Width > 0)
                                {
                                    col.width = ViewProp.Width * 7; // approx. characters to pixels
                                }
                                grid.columns.Add(col);
                                grid.fields.Add(fld);
                            } // if( false == grid.columnsContains( header ) )
                        }     // if(null != MetaDataProp )
                    }         // if( ViewProp != null )
                }             // foreach( CswNbtViewProperty ViewProp in View.getOrderedViewProps() )

                // Nodes in the Tree determine Rows
                for (Int32 c = 0; c < Tree.getChildNodeCount(); c++)
                {
                    CswExtJsGridRow gridrow = new CswExtJsGridRow(c, gridUniquePrefix);
                    Tree.goToNthChild(c);

                    CswNbtTreeNode TreeNode = Tree.getCurrentTreeNode();

                    gridrow.data.Add(nodeIdDataIndex, Tree.getNodeIdForCurrentPosition().ToString());
                    gridrow.data.Add(nodekeyDataIndex, Tree.getNodeKeyForCurrentPosition().ToString());
                    gridrow.data.Add(nodenameDataIndex, Tree.getNodeNameForCurrentPosition().ToString());
                    gridrow.data.Add(NodeTypeDataIndex, TreeNode.NodeTypeId.ToString());
                    gridrow.data.Add(ObjectClassDataIndex, TreeNode.ObjectClassId.ToString());

                    CswNbtMetaDataNodeType NodeType = _CswNbtResources.MetaData.getNodeType(Tree.getNodeKeyForCurrentPosition().NodeTypeId);

                    gridrow.canView = _CswNbtResources.Permit.canNodeType(CswEnumNbtNodeTypePermission.View, NodeType) &&
                                      _CswNbtResources.Permit.isNodeWritable(CswEnumNbtNodeTypePermission.View, NodeType, Tree.getNodeIdForCurrentPosition());
                    gridrow.canEdit = (_CswNbtResources.Permit.canNodeType(CswEnumNbtNodeTypePermission.Edit, NodeType) &&
                                       (_CswNbtResources.CurrentNbtUser.IsAdministrator() ||
                                        _CswNbtResources.Permit.isNodeWritable(CswEnumNbtNodeTypePermission.Edit,
                                                                               NodeType,
                                                                               NodeId: Tree.getNodeIdForCurrentPosition())) &&
                                       false == Tree.getNodeLockedForCurrentPosition());

                    gridrow.canDelete = (_CswNbtResources.Permit.canNodeType(CswEnumNbtNodeTypePermission.Delete,
                                                                             NodeType) &&
                                         _CswNbtResources.Permit.isNodeWritable(CswEnumNbtNodeTypePermission.Delete,
                                                                                NodeType,
                                                                                NodeId: Tree.getNodeIdForCurrentPosition())
                                         );
                    gridrow.isLocked   = Tree.getNodeLockedForCurrentPosition();
                    gridrow.isDisabled = (false == Tree.getNodeIncludedForCurrentPosition());
                    if (null != _CswNbtResources.CurrentNbtUser)
                    {
                        gridrow.isFavorite = Tree.getNodeFavoritedForCurrentPosition();
                    }

                    _TreeNodeToGrid(View, Tree, grid, gridrow);

                    Tree.goToParentNode();
                    grid.rowData.rows.Add(gridrow);
                }
                Ret = grid.ToJson();
            }
            return(Ret);
        } // TreeToJson()
Exemplo n.º 5
0
        } // _TreeNodeToGrid()

        public CswExtJsGrid DataTableToGrid(DataTable DT, bool Editable = false, string GroupByCol = "", CswEnumExtJsXType GroupByColType = null, bool IncludeEditFields = true, Dictionary <string, Type> ColumnTypeOverrides = null)
        {
            string NodeIdColName      = "nodeid";
            string MenuOptionsColName = "menuoptions";
            string gridUniquePrefix   = DT.TableName;

            CswExtJsGrid grid = new CswExtJsGrid(gridUniquePrefix, IncludeEditFields);

            grid.groupfield = GroupByCol;
            grid.title      = DT.TableName;
            if (_CswNbtResources.CurrentNbtUser != null && _CswNbtResources.CurrentNbtUser.PageSize > 0)
            {
                grid.PageSize = _CswNbtResources.CurrentNbtUser.PageSize;
            }

            //CswExtJsGridDataIndex nodeIdDataIndex = new CswExtJsGridDataIndex( gridUniquePrefix, NodeIdColName );
            //{
            //    CswExtJsGridField nodeIdFld = new CswExtJsGridField { dataIndex = nodeIdDataIndex };
            //    grid.fields.Add( nodeIdFld );
            //    CswExtJsGridColumn nodeIdCol = new CswExtJsGridColumn { header = "nodeId", dataIndex = nodeIdDataIndex, hidden = true };
            //    grid.columns.Add( nodeIdCol );
            //}


            foreach (DataColumn CurrentColumn in DT.Columns)
            {
                Type CurrentColumnType = null;
                if (null != ColumnTypeOverrides)
                {
                    if (false == ColumnTypeOverrides.ContainsKey(CurrentColumn.ColumnName))
                    {
                        CurrentColumnType = CurrentColumn.DataType;
                    }
                    else
                    {
                        CurrentColumnType = ColumnTypeOverrides[CurrentColumn.ColumnName];
                    }
                }
                else
                {
                    CurrentColumnType = CurrentColumn.DataType;
                }


                CswExtJsGridDataIndex dataIndex = new CswExtJsGridDataIndex(gridUniquePrefix, CurrentColumn.ColumnName);
                CswExtJsGridField     fld       = new CswExtJsGridField();
                grid.fields.Add(fld);
                fld.dataIndex = dataIndex;

                CswExtJsGridColumn gridcol = new CswExtJsGridColumn();
                gridcol.header    = CurrentColumn.ColumnName;
                gridcol.dataIndex = dataIndex;
                gridcol.width     = Math.Max(100, (7 + CurrentColumn.ColumnName.Length * 8));

                if ((NodeIdColName.ToLower() == CurrentColumn.ColumnName.ToLower()) || (MenuOptionsColName.ToLower() == CurrentColumn.ColumnName.ToLower()))
                {
                    gridcol.hidden = true;
                }

                if (CurrentColumnType == typeof(string))
                {
                    fld.type = "string";
                }
                else if (CurrentColumnType == typeof(bool))
                {
                    fld.type      = "bool";
                    gridcol.xtype = CswEnumExtJsXType.booleancolumn;
                }
                else if (CurrentColumnType == typeof(Int32) ||
                         (GroupByColType != null &&
                          CurrentColumn.ColumnName.ToLower().Equals(GroupByCol.ToLower()) &&
                          GroupByColType.Equals(CswEnumExtJsXType.numbercolumn)))
                {
                    fld.type       = "number";
                    gridcol.xtype  = CswEnumExtJsXType.numbercolumn;
                    gridcol.Format = "0";
                }
                else if (CurrentColumnType == typeof(DateTime) ||
                         (GroupByColType != null &&
                          CurrentColumn.ColumnName.ToLower().Equals(GroupByCol.ToLower()) &&
                          GroupByColType.Equals(CswEnumExtJsXType.datecolumn)))
                {
                    string userDateFormat = _CswNbtResources.CurrentNbtUser.DateFormat;
                    string userTimeFormat = _CswNbtResources.CurrentNbtUser.TimeFormat;
                    gridcol.dateformat = CswTools.ConvertNetToPHP(userDateFormat) + " " + CswTools.ConvertNetToPHP(userTimeFormat);

                    fld.type       = "date";
                    gridcol.xtype  = CswEnumExtJsXType.datecolumn;
                    gridcol.Format = "m/d/y H:i:s";
                }
                else if (CurrentColumnType == typeof(sbyte))    //sbyte indidcates a "button" column :-(
                {
                    gridcol.xtype        = CswEnumExtJsXType.gridcolumn;
                    gridcol.MenuDisabled = true;
                    gridcol.IsSortable   = false;
                }

                grid.columns.Add(gridcol);
            }

            Int32 RowNo = 0;

            foreach (DataRow Row in DT.Rows)
            {
                CswExtJsGridRow gridrow = new CswExtJsGridRow(RowNo, gridUniquePrefix);

                string NodeIdForGridRowData = string.Empty;
                foreach (DataColumn CurrentColumn in DT.Columns)
                {
                    Type CurrentColumnType = null;
                    if (null != ColumnTypeOverrides)
                    {
                        if (false == ColumnTypeOverrides.ContainsKey(CurrentColumn.ColumnName))
                        {
                            CurrentColumnType = CurrentColumn.DataType;
                        }
                        else
                        {
                            CurrentColumnType = ColumnTypeOverrides[CurrentColumn.ColumnName];
                        }
                    }
                    else
                    {
                        CurrentColumnType = CurrentColumn.DataType;
                    }


                    CswExtJsGridDataIndex index = null;

                    index = new CswExtJsGridDataIndex(gridUniquePrefix, CurrentColumn.ColumnName);
                    gridrow.data[index] = CswConvert.ToString(Row[CurrentColumn]);

                    if (Row.Table.Columns.Contains(NodeIdColName) && DBNull.Value != Row[NodeIdColName] && typeof(sbyte) == CurrentColumnType)
                    {
                        string MenuOptions = string.Empty;
                        if (Row.Table.Columns.Contains(MenuOptionsColName))
                        {
                            MenuOptions = Row[MenuOptionsColName].ToString();
                        }

                        NodeIdForGridRowData = Row[NodeIdColName].ToString();
                        CswExtJsGridButton CurrentButton = new CswExtJsGridButton
                        {
                            DataIndex    = index.ToString(),
                            RowNo        = RowNo,
                            MenuOptions  = MenuOptions,
                            SelectedText = CurrentColumn.ColumnName,
                            PropAttr     = NodeIdForGridRowData
                        };                                    //nu the button

                        grid.rowData.btns.Add(CurrentButton); //add the button
                    }//if it's the hi-jacked data tabe that means BUTTON
                }//iterate collumns

                grid.rowData.rows.Add(gridrow);
                RowNo += 1;
            } // foreach( DataRow Row in DT.Rows )

            return(grid);
        } // DataTableToGrid()