Beispiel #1
0
 public static long GetDefaultCnsDataTypeId()
 {
     long defaultDataTypeId = 1;
     CNS_DataType defaultCnsDataType = GetDefaultCnsDataType();
     if (defaultCnsDataType != null) defaultDataTypeId = defaultCnsDataType.DataTypeID;
     return defaultDataTypeId;
 }
Beispiel #2
0
        public static bool DeleteCnsDataType(long dataTypeId, out string retMessage)
        {
            bool   ret     = false;
            string message = "";

            try
            {
                bool validationFail = false;
                if (UtilsSecurity.HaveAdminRole() == false)
                {
                    message        = "Please login as User having admin Role to Delete DataType";
                    validationFail = true;
                }

                if (validationFail == false)
                {
                    if (dataTypeId == 0)
                    {
                        message        = "Missing or Empty DataType ID Argument";
                        validationFail = true;
                    }
                }

                if (validationFail == false)
                {
                    CNS_DataType cnsDataTypeExisting = GetCnsDataType(dataTypeId);
                    if (cnsDataTypeExisting == null)
                    {
                        message        = "The DataType with ID [" + dataTypeId.ToString(CultureInfo.InvariantCulture) + "] does not exist";
                        validationFail = true;
                    }
                    else if (cnsDataTypeExisting.IsSystem)
                    {
                        message        = "The System DataType Cannot be Deleted";
                        validationFail = true;
                    }
                    else if (cnsDataTypeExisting.IsDefault)
                    {
                        message        = "Please set another DataType as Default and then Delete this DataType";
                        validationFail = true;
                    }
                }

                if (validationFail == false)
                {
                    DataSource.BeginTransaction();
                    DataSource.DeleteCnsDataType(dataTypeId);
                    DataSource.CompleteTransaction();
                    ret = true;
                }
            }
            catch (Exception ex)
            {
                message = "DBError:" + ex.Message;
                LogManager.Log(LogLevel.Error, "DataCommon-DeleteCnsDataType", message);
            }

            retMessage = message;
            return(ret);
        }
Beispiel #3
0
        public static CNS_DataType GetDefaultCnsDataType()
        {
            CNS_DataType defaultCnsDataType = null;

            Database db = HaveDb();
            if (db != null)
            {
                defaultCnsDataType = db.SingleOrDefault<CNS_DataType>("SELECT * FROM CNS_DataType Where IsDefault=@0", 1);
            }
            else
            {
                Dictionary<Guid, CNS_DataType> allCnsDataTypeList = FileSource.LoadCNSDataTypeData();
                foreach (KeyValuePair<Guid, CNS_DataType> item in allCnsDataTypeList)
                {
                    if (item.Value.IsDefault == true)
                    {
                        defaultCnsDataType = item.Value;
                        break;
                    }
                }

            }

            return defaultCnsDataType;
        }
Beispiel #4
0
        private static string GetListSingleItemView(CNS_DataType cnsDataType, long pageNo, long itemsPerPage, long dataIndex, string templateSuffix)
        {
            string htmlTextItem = "";

            if (cnsDataType != null)
            {
                string message;
                List <TemplateDataTypeListDetailItem.EditAction> editActionList = new List <TemplateDataTypeListDetailItem.EditAction>();
                if (UtilsSecurity.HaveAdminRole() == true)
                {
                    editActionList.Add(new TemplateDataTypeListDetailItem.EditAction
                    {
                        Id             = cnsDataType.DataTypeID.ToString(),
                        DataIndex      = dataIndex.ToString(),
                        PageNo         = pageNo.ToString(),
                        ItemsPerPage   = itemsPerPage.ToString(),
                        TemplateSuffix = templateSuffix
                    });
                }

                var templateItem = new TemplateDataTypeListDetailItem
                {
                    DataType   = cnsDataType.DataType,
                    IsDefault  = cnsDataType.IsDefault,
                    IsInActive = !cnsDataType.IsActive,

                    EditActionList = editActionList
                };

                htmlTextItem = templateItem.GetFilled(templateSuffix, UtilsGeneric.Validate, UtilsGeneric.ThrowException, out message);
            }
            return(htmlTextItem);
        }
Beispiel #5
0
        public static bool SaveCNSDataTypeData(Dictionary <Guid, CNS_DataType> cnsDataTypeList)
        {
            bool ret = false;

            if (cnsDataTypeList.Count > 0)
            {
                List <CNS_DataType> cnsDataTypeValueList = new List <CNS_DataType>();
                CNS_DataType[]      cnsDataTypeArray     = new CNS_DataType[cnsDataTypeList.Values.Count];
                cnsDataTypeList.Values.CopyTo(cnsDataTypeArray, 0);
                cnsDataTypeValueList.AddRange(cnsDataTypeArray);
                ret = JsonStore <CNS_DataType> .SaveData(cnsDataTypeValueList, true);
            }

            return(ret);
        }
Beispiel #6
0
        public static string GetListAllItemView(long pageNo, long itemsPerPage, long dataIndex, string templateSuffix)
        {
            string message = "";

            if (itemsPerPage == 0)
            {
                itemsPerPage = UtilsGeneric.DefaultItemsPerPage;
            }
            long   totalPages;
            long   totalItems;
            string htmlTextItemList = "";
            string htmlAddItemList  = "";

            if (UtilsSecurity.HaveAdminRole() == false)
            {
                TemplateDataTypeView dataTypeView = new TemplateDataTypeView
                {
                    DataIndex      = dataIndex.ToString(),
                    PageNo         = pageNo.ToString(),
                    ItemsPerPage   = itemsPerPage.ToString(),
                    TemplateSuffix = templateSuffix,
                };
                htmlTextItemList = dataTypeView.GetFilled(templateSuffix, UtilsGeneric.Validate, UtilsGeneric.ThrowException, out message);
            }
            else
            {
                #region Add Link

                if (UtilsSecurity.HaveAdminRole() == true)
                {
                    TemplateDataTypeSaveAdd templateSaveAdd = new TemplateDataTypeSaveAdd
                    {
                        DataIndex      = dataIndex.ToString(),
                        PageNo         = pageNo.ToString(),
                        ItemsPerPage   = itemsPerPage.ToString(),
                        TemplateSuffix = templateSuffix,
                    };
                    htmlAddItemList = templateSaveAdd.GetFilled(templateSuffix, UtilsGeneric.Validate, UtilsGeneric.ThrowException, out message);
                }

                #endregion

                #region Get Fill List

                #region Get Paged Data

                List <CNS_DataType> cnsDataTypeList = DataCommon.GetAllCnsDataType(pageNo, itemsPerPage, out totalPages, out totalItems);

                #endregion

                if (cnsDataTypeList.Count > 0)
                {
                    #region Get Pager Details

                    string topPagerDetails    = UtilsGeneric.GetItemPagerView(pageNo, itemsPerPage, dataIndex, templateSuffix, totalPages, RefreshListFunctionName, "");
                    string bottomPagerDetails = UtilsGeneric.GetLinkPagerView(pageNo, itemsPerPage, dataIndex, templateSuffix, totalPages, totalItems, RefreshListFunctionName, "");

                    #endregion

                    #region Append Top Pager

                    if (topPagerDetails.Trim().Length > 0)
                    {
                        htmlTextItemList += topPagerDetails;
                    }

                    #endregion

                    #region Append Items

                    int index = 0;
                    for (; index < cnsDataTypeList.Count; index++)
                    {
                        CNS_DataType cnsDataType          = cnsDataTypeList[index];
                        string       htmlTextItemTemplate = GetListSingleItemView(cnsDataType, pageNo, itemsPerPage, dataIndex, templateSuffix);
                        htmlTextItemList += htmlTextItemTemplate;
                    }

                    #endregion

                    #region Append Bottom Pager

                    if (bottomPagerDetails.Trim().Length > 0)
                    {
                        htmlTextItemList += bottomPagerDetails;
                    }

                    #endregion
                }

                #endregion

                #region Set Fill List

                if (htmlTextItemList.Length == 0)
                {
                    TemplateDataTypeListDetailEmpty dataTypeListDetailEmpty = new TemplateDataTypeListDetailEmpty
                    {
                        DataIndex      = dataIndex.ToString(),
                        PageNo         = pageNo.ToString(),
                        ItemsPerPage   = itemsPerPage.ToString(),
                        TemplateSuffix = templateSuffix,
                    };
                    htmlTextItemList = dataTypeListDetailEmpty.GetFilled(templateSuffix, UtilsGeneric.Validate, UtilsGeneric.ThrowException, out message);
                }

                #endregion
            }

            return(htmlAddItemList + htmlTextItemList);
        }
Beispiel #7
0
        public static string GetSaveDetailView(long dataTypeId, long pageNo, long itemsPerPage, long dataIndex, string templateSuffix)
        {
            string message           = "";
            string htmlSaveDetail    = "";
            long   revisionNo        = 0;
            string dataTypeName      = "";
            bool   dataTypeIsDefault = false;
            bool   dataTypeIsActive  = true;
            bool   dataTypeIsSystem  = false;

            if (UtilsSecurity.HaveAdminRole() == false)
            {
                TemplateDataTypeView dataTypeView = new TemplateDataTypeView
                {
                    DataIndex      = dataIndex.ToString(),
                    PageNo         = pageNo.ToString(),
                    ItemsPerPage   = itemsPerPage.ToString(),
                    TemplateSuffix = templateSuffix
                };
                htmlSaveDetail = dataTypeView.GetFilled(templateSuffix, UtilsGeneric.Validate, UtilsGeneric.ThrowException, out message);
            }
            else
            {
                #region Get DataType Details

                if (dataTypeId > 0)
                {
                    CNS_DataType cnsDataTypeExisting = DataCommon.GetCnsDataType(dataTypeId);
                    if (cnsDataTypeExisting != null)
                    {
                        dataTypeName = cnsDataTypeExisting.DataType;

                        dataTypeIsDefault = cnsDataTypeExisting.IsDefault;
                        dataTypeIsActive  = cnsDataTypeExisting.IsActive;
                        dataTypeIsSystem  = cnsDataTypeExisting.IsSystem;
                        revisionNo        = cnsDataTypeExisting.RevisionNo;
                    }
                }

                #endregion

                #region Set Action

                bool showAdminInfo = false;
                bool enableSave    = true;
                bool enableDelete  = true;
                if (UtilsSecurity.HaveAdminRole() == false)
                {
                    showAdminInfo = true;
                    enableSave    = false;
                    enableDelete  = false;
                }

                #endregion

                #region Set Template

                string addActionHtml  = "";
                string editActionHtml = "";
                if (dataTypeId == 0)
                {
                    var templateSaveAdd = new TemplateDataTypeSaveDetailAdd
                    {
                        AddActionDisabled = !enableSave,
                        DataIndex         = dataIndex.ToString("N0", CultureInfo.InvariantCulture),
                        PageNo            = pageNo.ToString("N0", CultureInfo.InvariantCulture),
                        ItemsPerPage      = itemsPerPage.ToString("N0", CultureInfo.InvariantCulture),
                        TemplateSuffix    = templateSuffix,
                    };
                    addActionHtml = templateSaveAdd.GetFilled(templateSuffix, UtilsGeneric.Validate, UtilsGeneric.ThrowException, out message);
                }
                else
                {
                    var templateSaveEdit = new TemplateDataTypeSaveDetailEdit
                    {
                        Id             = dataTypeId.ToString(),
                        DataIndex      = dataIndex.ToString("N0", CultureInfo.InvariantCulture),
                        PageNo         = pageNo.ToString("N0", CultureInfo.InvariantCulture),
                        ItemsPerPage   = itemsPerPage.ToString("N0", CultureInfo.InvariantCulture),
                        TemplateSuffix = templateSuffix,

                        SaveActionDisabled   = !enableSave,
                        DeleteActionDisabled = !enableDelete,
                    };
                    editActionHtml = templateSaveEdit.GetFilled(templateSuffix, UtilsGeneric.Validate, UtilsGeneric.ThrowException, out message);
                }

                List <TemplateDataTypeSaveDetail.IsActiveVisible> isActiveVisibleList = new List <TemplateDataTypeSaveDetail.IsActiveVisible>();
                if (dataTypeIsActive == true)
                {
                    isActiveVisibleList.Add(new TemplateDataTypeSaveDetail.IsActiveVisible
                    {
                        IsActive = dataTypeIsActive
                    });
                }

                var templateSaveDetail = new TemplateDataTypeSaveDetail
                {
                    //Id = dataRefTypeId.ToString("N0", CultureInfo.InvariantCulture),
                    RevisionNo           = revisionNo.ToString(),
                    DataTypeName         = dataTypeName,
                    DataTypeNameDisabled = dataTypeIsSystem,
                    IsDefault            = dataTypeIsDefault,
                    IsActiveVisibleList  = isActiveVisibleList,

                    AddAction     = addActionHtml,
                    EditAction    = editActionHtml,
                    ShowAdminInfo = showAdminInfo,
                };

                htmlSaveDetail = templateSaveDetail.GetFilled(templateSuffix, UtilsGeneric.Validate, UtilsGeneric.ThrowException,
                                                              out message);

                #endregion
            }

            return(htmlSaveDetail);
        }
Beispiel #8
0
        public static long SaveCndData(long parentDataId, long dataRefId, long dataRefTypeId, long dataTypeId, string dataValue, bool dataIsActive, bool isPublic, long dataId, out string retMessage)
        {
            long   id      = 0;
            string message = "";

            try
            {
                bool validationFail = false;
                if (isPublic == false)
                {
                    if ((UtilsSecurity.HaveAdminRole() == false) && (UtilsSecurity.HaveAuthorRole() == false))
                    {
                        message        = "Please login as User Having Admin/Author Role to Save Data";
                        validationFail = true;
                    }
                }

                if (validationFail == false)
                {
                    if ((dataRefTypeId == 0) || (dataTypeId == 0) || (string.IsNullOrEmpty(dataValue) == true))
                    {
                        message        = "Missing or Empty Data Argument";
                        validationFail = true;
                    }
                }

                CND_Data cndData = new CND_Data();
                if (validationFail == false)
                {
                    if (dataId != 0)
                    {
                        cndData = GetCndData(dataId);
                        if (cndData == null)
                        {
                            message        = "The Data having ID [" + dataId + "] cannot be Retrieved";
                            validationFail = true;
                        }
                        else
                        {
                            if ((cndData.UserID != UtilsSecurity.GetUserId()) && (UtilsSecurity.HaveAdminRole() == false))
                            {
                                message        = "The Data having ID [" + dataId + "] can be edited only the User who created it";
                                validationFail = true;
                            }
                        }
                    }
                }

                Guid parentDataGuid = Guid.Empty;
                if (validationFail == false)
                {
                    if (parentDataId != 0)
                    {
                        CND_Data cndDataParent = GetCndData(parentDataId);
                        if (cndDataParent == null)
                        {
                            message        = "The Parent Data having ID [" + parentDataId + "] cannot be Retrieved";
                            validationFail = true;
                        }
                        else
                        {
                            parentDataGuid = cndDataParent.DataGUID;
                        }
                    }
                }

                CNS_DataType cnsDataType = GetCnsDataType(dataTypeId);
                if (validationFail == false)
                {
                    if (cnsDataType == null)
                    {
                        message        = "The DataType [" + dataTypeId + "] does not exist";
                        validationFail = true;
                    }
                }

                CNS_DataRefType cnsDataRefType = GetCnsDataRefType(dataRefTypeId);
                if (validationFail == false)
                {
                    if (cnsDataRefType == null)
                    {
                        message        = "The DataRefType [" + dataRefTypeId + "] does not exist";
                        validationFail = true;
                    }
                }

                if (validationFail == false)
                {
                    cndData.IsActive = dataIsActive;
                    if (dataId == 0)
                    {
                        cndData.Sequence = GetMaxCndDataId() + 1;
                        cndData.IsActive = true;
                    }

                    cndData.DataTypeID   = cnsDataType.DataTypeID;
                    cndData.DataTypeGUID = cnsDataType.DataTypeGUID;

                    cndData.DataRefTypeID   = cnsDataRefType.DataRefTypeID;
                    cndData.DataRefTypeGUID = cnsDataRefType.DataRefTypeGUID;

                    cndData.DataRefID = dataRefId;
                    cndData.DataValue = dataValue;

                    if (parentDataId > 0)
                    {
                        cndData.ParentDataID   = parentDataId;
                        cndData.ParentDataGUID = parentDataGuid;
                    }

                    DataSource.BeginTransaction();

                    if (cndData.DataID == 0)
                    {
                        DataSource.InsertCndData(cndData);
                        id = cndData.DataID;
                    }
                    else
                    {
                        DataSource.UpdateCndData(cndData);
                        id = cndData.DataID;
                    }
                    DataSource.CompleteTransaction();
                }
            }
            catch (Exception ex)
            {
                id      = 0;
                message = "DBError:" + ex.Message;
                LogManager.Log(LogLevel.Error, "DataCommon-SaveCndData", message);
                DataSource.AbortTransaction();
            }

            retMessage = message;
            return(id);
        }
Beispiel #9
0
        public static long SaveCnsDataType(string dataTypeName, bool dataTypeIsDefault, bool dataTypeIsActive, long dataTypeId, out string retMessage)
        {
            long   id      = 0;
            string message = "";

            try
            {
                bool validationFail = false;
                if (UtilsSecurity.HaveAdminRole() == false)
                {
                    message        = "Please login as User Having Admin Role to Save RefType";
                    validationFail = true;
                }

                if (validationFail == false)
                {
                    if (string.IsNullOrEmpty(dataTypeName) == true)
                    {
                        message        = "Missing or Empty DataType Argument";
                        validationFail = true;
                    }
                }

                if (validationFail == false)
                {
                    CNS_DataType cnsDataTypeExisting = GetCnsDataType(dataTypeName);
                    if ((cnsDataTypeExisting != null) && (cnsDataTypeExisting.DataTypeID != dataTypeId))
                    {
                        message        = "The DataType [" + dataTypeName + "] allready exists";
                        validationFail = true;
                    }
                }

                var cnsDataType = new CNS_DataType();
                if (validationFail == false)
                {
                    if (dataTypeId != 0)
                    {
                        cnsDataType = GetCnsDataType(dataTypeId);
                        if (cnsDataType == null)
                        {
                            message        = "The DataType having ID [" + dataTypeId + "] cannot be Retrieved";
                            validationFail = true;
                        }
                    }
                }

                if (validationFail == false)
                {
                    long maxDataTypeId = GetMaxCnsDataTypeId() + 1;
                    cnsDataType.IsActive = dataTypeIsActive;
                    if (dataTypeId == 0)
                    {
                        cnsDataType.Sequence = maxDataTypeId;
                        cnsDataType.IsActive = true;
                        cnsDataType.IsSystem = false;
                    }
                    cnsDataType.DataType  = dataTypeName;
                    cnsDataType.IsDefault = dataTypeIsDefault;

                    DataSource.BeginTransaction();
                    if (cnsDataType.IsDefault)
                    {
                        CNS_DataType defaultCnsDataType = GetDefaultCnsDataType();
                        if (defaultCnsDataType != null)
                        {
                            if (defaultCnsDataType.DataTypeID != cnsDataType.DataTypeID)
                            {
                                defaultCnsDataType.IsDefault = false;
                                DataSource.UpdateCnsDataType(defaultCnsDataType);
                            }
                        }
                    }

                    if (cnsDataType.DataTypeID == 0)
                    {
                        cnsDataType.DataTypeID = maxDataTypeId;
                        DataSource.InsertCnsDataType(cnsDataType);
                        id = cnsDataType.DataTypeID;
                    }
                    else
                    {
                        DataSource.UpdateCnsDataType(cnsDataType);
                        id = cnsDataType.DataTypeID;
                    }
                    DataSource.CompleteTransaction();
                }
            }
            catch (Exception ex)
            {
                id      = 0;
                message = "DBError:" + ex.Message;
                LogManager.Log(LogLevel.Error, "DataCommon-SaveCnsDataType", message);
                DataSource.AbortTransaction();
            }

            retMessage = message;
            return(id);
        }
Beispiel #10
0
        public static CNS_DataType GetCnsDataType(long dataTypeID)
        {
            CNS_DataType cnsDataType = DataSource.GetCnsDataType(dataTypeID, "");

            return(cnsDataType);
        }