Beispiel #1
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;
        }
Beispiel #2
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;
        }
Beispiel #3
0
        public static bool UpdateCnsDataRefType(CNS_DataRefType cnsDataRefType)
        {
            bool ret = false;
            Database db = HaveDb();
            if (db != null)
            {
                CNS_DataRefType cnsDataRefTypeExisting = GetCnsDataRefType(cnsDataRefType.DataRefTypeID, "");
                if (cnsDataRefTypeExisting != null)
                {
					cnsDataRefType.RevisionNo = GetMaxCnsDataRefTypeRevisionNo() + 1;                      
					using (ITransaction scope = db.GetTransaction())
					{
                        db.Update(cnsDataRefType);
                        scope.Complete();
                        ret = true;
                    }
                }
            }
            else
            {
                Dictionary<Guid, CNS_DataRefType> fileCnsDataRefTypeList = FileSource.LoadCNSDataRefTypeData();                
                if (fileCnsDataRefTypeList.ContainsKey(cnsDataRefType.DataRefTypeGUID) == true)
                {
                    fileCnsDataRefTypeList.Remove(cnsDataRefType.DataRefTypeGUID);
                    fileCnsDataRefTypeList.Add(cnsDataRefType.DataRefTypeGUID, cnsDataRefType);
                    FileSource.SaveCNSDataRefTypeData(fileCnsDataRefTypeList);
                }
            }

            return ret;
        }
        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;
        }
Beispiel #5
0
        public static long InsertCnsDataRefType(CNS_DataRefType cnsDataRefType)
        {
            long id = 0;
            if (cnsDataRefType.DataRefTypeGUID != Guid.Empty) throw new Exception("Cannot Set the GUID for a Insert");
            cnsDataRefType.DataRefTypeGUID = Guid.NewGuid();
            cnsDataRefType.RevisionNo = GetMaxCnsDataRefTypeRevisionNo() + 1;

            Database db = HaveDb();
            if (db != null)
            {
                using (ITransaction scope = db.GetTransaction())
                {
                    db.Insert(cnsDataRefType);
                    id = cnsDataRefType.DataRefTypeID;
                    scope.Complete();
                }
            }
            else
            {
                Dictionary<Guid, CNS_DataRefType> fileCnsDataRefTypeList = FileSource.LoadCNSDataRefTypeData();
  
                fileCnsDataRefTypeList.Add(cnsDataRefType.DataRefTypeGUID, cnsDataRefType);
                FileSource.SaveCNSDataRefTypeData(fileCnsDataRefTypeList);

                id = cnsDataRefType.DataRefTypeID;
            }

            return id;
        }