Пример #1
0
 public static long GetDefaultCnsDataRefTypeId()
 {
     long defaultRefTypeId = 1;
     CNS_DataRefType defaultCnsDataRefType = GetDefaultCnsDataRefType();
     if (defaultCnsDataRefType != null) defaultRefTypeId = defaultCnsDataRefType.DataRefTypeID;
     return defaultRefTypeId;
 }
Пример #2
0
        public static bool DeleteCnsDataRefType(long dataRefTypeId, 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 RefType";
                    validationFail = true;
                }

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

                if (validationFail == false)
                {
                    CNS_DataRefType cnsDataRefTypeExisting = GetCnsDataRefType(dataRefTypeId);
                    if (cnsDataRefTypeExisting == null)
                    {
                        message        = "The DataRefType with ID [" + dataRefTypeId.ToString(CultureInfo.InvariantCulture) + "] does not exist";
                        validationFail = true;
                    }
                    else if (cnsDataRefTypeExisting.IsSystem)
                    {
                        message        = "The System Data RefType Cannot be Deleted";
                        validationFail = true;
                    }
                    else if (cnsDataRefTypeExisting.IsDefault)
                    {
                        message        = "Please set another DataRefType as Default and then Delete this RefType";
                        validationFail = true;
                    }
                }

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

            retMessage = message;
            return(ret);
        }
Пример #3
0
        public static CNS_DataRefType GetDefaultCnsDataRefType()
        {
            CNS_DataRefType defaultCnsDataRefType = null;

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

            }

            return defaultCnsDataRefType;
        }
Пример #4
0
        private static string GetListSingleItemView(CNS_DataRefType cnsDataRefType, long pageNo, long itemsPerPage, long dataIndex, string templateSuffix)
        {
            string htmlTextItem = "";

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

                var templateItem = new TemplateDataRefTypeListDetailItem
                {
                    DataRefType = cnsDataRefType.DataRefType,
                    IsDefault   = cnsDataRefType.IsDefault,
                    IsInActive  = !cnsDataRefType.IsActive,

                    EditActionList = editActionList
                };
                htmlTextItem = templateItem.GetFilled(templateSuffix, UtilsGeneric.Validate,
                                                      UtilsGeneric.ThrowException,
                                                      out message);
            }
            return(htmlTextItem);
        }
Пример #5
0
        public static bool SaveCNSDataRefTypeData(Dictionary <Guid, CNS_DataRefType> cnsDataRefTypeList)
        {
            bool ret = false;

            if (cnsDataRefTypeList.Count > 0)
            {
                List <CNS_DataRefType> cnsDataRefTypeValueList = new List <CNS_DataRefType>();
                CNS_DataRefType[]      cnsDataRefTypeArray     = new CNS_DataRefType[cnsDataRefTypeList.Values.Count];
                cnsDataRefTypeList.Values.CopyTo(cnsDataRefTypeArray, 0);
                cnsDataRefTypeValueList.AddRange(cnsDataRefTypeArray);
                ret = JsonStore <CNS_DataRefType> .SaveData(cnsDataRefTypeValueList, true);
            }

            return(ret);
        }
Пример #6
0
        public static long SaveCnsDataRefType(string dataRefType, bool dataRefTypeIsDefault, bool dataRefTypeIsActive, long dataRefTypeId, out string retMessage)
        {
            long   id      = 0;
            string message = "";

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

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

                if (validationFail == false)
                {
                    CNS_DataRefType cnsDataRefTypeExisting = GetCnsDataRefType(dataRefType);
                    if ((cnsDataRefTypeExisting != null) && (cnsDataRefTypeExisting.DataRefTypeID != dataRefTypeId))
                    {
                        message        = "The DataRefType [" + dataRefType + "] allready exists";
                        validationFail = true;
                    }
                }

                var cnsDataRefType = new CNS_DataRefType();
                if (validationFail == false)
                {
                    if (dataRefTypeId != 0)
                    {
                        cnsDataRefType = GetCnsDataRefType(dataRefTypeId);
                        if (cnsDataRefType == null)
                        {
                            message        = "The DataRefType having ID [" + dataRefTypeId + "] cannot be Retrieved";
                            validationFail = true;
                        }
                    }
                }

                if (validationFail == false)
                {
                    long maxRefTypeId = GetMaxCnsDataRefTypeId() + 1;
                    cnsDataRefType.IsActive = dataRefTypeIsActive;
                    if (dataRefTypeId == 0)
                    {
                        cnsDataRefType.Sequence = maxRefTypeId;
                        cnsDataRefType.IsActive = true;
                        cnsDataRefType.IsSystem = false;
                    }
                    cnsDataRefType.DataRefType = dataRefType;
                    cnsDataRefType.IsDefault   = dataRefTypeIsDefault;


                    DataSource.BeginTransaction();
                    if (cnsDataRefType.IsDefault)
                    {
                        CNS_DataRefType defaultCnsDataRefType = GetDefaultCnsDataRefType();
                        if (defaultCnsDataRefType != null)
                        {
                            if (defaultCnsDataRefType.DataRefTypeID != cnsDataRefType.DataRefTypeID)
                            {
                                defaultCnsDataRefType.IsDefault = false;
                                DataSource.UpdateCnsDataRefType(defaultCnsDataRefType);
                            }
                        }
                    }

                    if (cnsDataRefType.DataRefTypeID == 0)
                    {
                        cnsDataRefType.DataRefTypeID = maxRefTypeId;
                        DataSource.InsertCnsDataRefType(cnsDataRefType);
                        id = cnsDataRefType.DataRefTypeID;
                    }
                    else
                    {
                        DataSource.UpdateCnsDataRefType(cnsDataRefType);
                        id = cnsDataRefType.DataRefTypeID;
                    }
                    DataSource.CompleteTransaction();
                }
            }
            catch (Exception ex)
            {
                id      = 0;
                message = "DBError:" + ex.Message;
                LogManager.Log(LogLevel.Error, "DataCommon-SaveCnsDataRefType", message);
                DataSource.AbortTransaction();
            }

            retMessage = message;
            return(id);
        }
Пример #7
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);
        }
Пример #8
0
        public static CNS_DataRefType GetCnsDataRefType(long dataRefTypeID)
        {
            CNS_DataRefType cnsDataRefType = DataSource.GetCnsDataRefType(dataRefTypeID, "");

            return(cnsDataRefType);
        }
Пример #9
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)
            {
                TemplateDataRefTypeView dataRefTypeView = new TemplateDataRefTypeView
                {
                    DataIndex      = dataIndex.ToString(),
                    PageNo         = pageNo.ToString(),
                    ItemsPerPage   = itemsPerPage.ToString(),
                    TemplateSuffix = templateSuffix,
                };
                htmlTextItemList = dataRefTypeView.GetFilled(templateSuffix, UtilsGeneric.Validate, UtilsGeneric.ThrowException, out message);
            }
            else
            {
                #region Add Link

                if (UtilsSecurity.HaveAdminRole() == true)
                {
                    TemplateDataRefTypeSaveAdd templateSaveAdd = new TemplateDataRefTypeSaveAdd
                    {
                        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_DataRefType> cnsDataRefTypeList = DataCommon.GetAllCnsDataRefType(pageNo, itemsPerPage, out totalPages, out totalItems);

                #endregion

                if (cnsDataRefTypeList.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 < cnsDataRefTypeList.Count; index++)
                    {
                        CNS_DataRefType cnsDataRefType       = cnsDataRefTypeList[index];
                        string          htmlTextItemTemplate = GetListSingleItemView(cnsDataRefType, 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)
                {
                    TemplateDataRefTypeListDetailEmpty dataRefTypeListDetailEmpty = new TemplateDataRefTypeListDetailEmpty
                    {
                        DataIndex      = dataIndex.ToString(),
                        PageNo         = pageNo.ToString(),
                        ItemsPerPage   = itemsPerPage.ToString(),
                        TemplateSuffix = templateSuffix,
                    };
                    htmlTextItemList = dataRefTypeListDetailEmpty.GetFilled(templateSuffix, UtilsGeneric.Validate, UtilsGeneric.ThrowException, out message);
                }
                #endregion
            }

            return(htmlAddItemList + htmlTextItemList);
        }
Пример #10
0
        public static string GetSaveDetailView(long dataRefTypeId, long pageNo, long itemsPerPage, long dataIndex, string templateSuffix)
        {
            string message              = "";
            string htmlSaveDetail       = "";
            long   revisionNo           = 0;
            string dataRefTypeName      = "";
            bool   dataRefTypeIsDefault = false;
            bool   dataRefTypeIsActive  = true;
            bool   dataRefTypeIsSystem  = false;

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

                if (dataRefTypeId > 0)
                {
                    CNS_DataRefType cnsDataRefTypeExisting = DataCommon.GetCnsDataRefType(dataRefTypeId);
                    if (cnsDataRefTypeExisting != null)
                    {
                        dataRefTypeName = cnsDataRefTypeExisting.DataRefType;

                        dataRefTypeIsDefault = cnsDataRefTypeExisting.IsDefault;
                        dataRefTypeIsActive  = cnsDataRefTypeExisting.IsActive;
                        dataRefTypeIsSystem  = cnsDataRefTypeExisting.IsSystem;
                        revisionNo           = cnsDataRefTypeExisting.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 (dataRefTypeId == 0)
                {
                    var templateSaveAdd = new TemplateDataRefTypeSaveDetailAdd
                    {
                        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 TemplateDataRefTypeSaveDetailEdit
                    {
                        Id                   = dataRefTypeId.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 <TemplateDataRefTypeSaveDetail.DataRefTypeNameEnabled>  dataRefTypeNameEnabledList  = new List <TemplateDataRefTypeSaveDetail.DataRefTypeNameEnabled>();
                List <TemplateDataRefTypeSaveDetail.DataRefTypeNameDisabled> dataRefTypeNameDisabledList = new List <TemplateDataRefTypeSaveDetail.DataRefTypeNameDisabled>();
                if (dataRefTypeIsSystem == false)
                {
                    dataRefTypeNameEnabledList.Add(new TemplateDataRefTypeSaveDetail.DataRefTypeNameEnabled
                    {
                        DataRefType = dataRefTypeName,
                        AddMode     = (dataRefTypeId == 0) ? true : false,
                    });
                }
                else
                {
                    dataRefTypeNameDisabledList.Add(new TemplateDataRefTypeSaveDetail.DataRefTypeNameDisabled
                    {
                        DataRefType = dataRefTypeName,
                        AddMode     = (dataRefTypeId == 0) ? true : false,
                    });
                }

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

                var templateSaveDetail = new TemplateDataRefTypeSaveDetail
                {
                    //Id = dataRefTypeId.ToString("N0", CultureInfo.InvariantCulture),
                    RevisionNo = revisionNo.ToString(),
                    DataRefTypeNameEnabledList  = dataRefTypeNameEnabledList,
                    DataRefTypeNameDisabledList = dataRefTypeNameDisabledList,
                    IsDefault           = dataRefTypeIsDefault,
                    IsActiveVisibleList = isActiveVisibleList,

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

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

            return(htmlSaveDetail);
        }