Esempio n. 1
0
        /// <summary>Allow to declaratively show what records must be included or excluded</summary>
        /// <param name="condition">The condition used to include or exclude each record</param>
        /// <param name="selector">The selector for the condition.</param>
        public ConditionalRecordAttribute(RecordCondition condition, string selector)
        {
            ExHelper.CheckNullOrEmpty(selector, "selector");

            mCondition         = condition;
            mConditionSelector = selector;
        }
        /// <summary>
        /// Converts the enum into a string that can be displayed
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public static string ToFriendlyString(this RecordCondition condition)
        {
            switch (condition)
            {
            case RecordCondition.Mint:
                return("Mint");

            case RecordCondition.NearMint:
                return("Near Mint");

            case RecordCondition.VeryGoodPlus:
                return("Very Good Plus");

            case RecordCondition.GoodPlus:
                return("Good Plus");

            case RecordCondition.Good:
                return("Good");

            case RecordCondition.Fair:
                return("Fair");

            case RecordCondition.Poor:
                return("Poor");

            default:
                return("");
            }
        }
		/// <summary>Allow to declarative show what records must be included or excluded</summary>
		/// <param name="condition">The condition used to include or exclude each record</param>
		/// <param name="selector">The selector for the condition.</param>
		public ConditionalRecordAttribute(RecordCondition condition, string selector)
		{
			if (selector == null ||  selector.Length == 0)
				throw new BadUsageException("The selector arg for the ConditionalRecordAttribute can't be null or empty.");
			
			mCondition = condition;
			mConditionSelector = selector;
		}
        /// <summary>Allow to declarative show what records must be included or excluded</summary>
        /// <param name="condition">The condition used to include or exclude each record</param>
        /// <param name="selector">The selector for the condition.</param>
        public ConditionalRecordAttribute(RecordCondition condition, string selector)
        {
            if (selector == null || selector.Length == 0)
            {
                throw new BadUsageException("The selector arg for the ConditionalRecordAttribute can't be null or empty.");
            }

            mCondition         = condition;
            mConditionSelector = selector;
        }
Esempio n. 5
0
        public int GetCount(RecordCondition condition)
        {
            DynamicParameters parameters = new DynamicParameters();

            StringBuilder fromScript = new StringBuilder();

            fromScript.Append("select count(*) as total from SKR_RECORD_M as r");

            StringBuilder whereScript = new StringBuilder();

            if (condition.CreateDate.HasValue)
            {
                whereScript.Append(" and r.CRE_DTE > @createDate");
                parameters.Add("@createDate", condition.CreateDate.Value);
            }

            if (!string.IsNullOrWhiteSpace(condition.StoreId))
            {
                whereScript.Append(" and r.STORE_SEQ_NO = @storeId");
                parameters.Add("@storeId", condition.StoreId);
            }

            if (!string.IsNullOrWhiteSpace(condition.UserId))
            {
                whereScript.Append(" and r.USER_SEQ_NO = @userId");
                parameters.Add("@userId", condition.UserId);
            }

            string sql = whereScript.Length > 0
                ? $"{fromScript.ToString()} where 1=1 {whereScript.ToString()}"
                : fromScript.ToString();

            int result = 0;

            using (DbFixture)
            {
                try
                {
                    IEnumerable <dynamic> dataRows = DbFixture.Db.Connection.Query(sql, parameters);

                    if (dataRows != null && dataRows.Count() > 0)
                    {
                        IDictionary <string, object> row = dataRows.FirstOrDefault() as IDictionary <string, object>;

                        result = row["total"] as int? ?? 0;
                    }
                }
                catch (Exception exception)
                {
                    Logger.Write(Domain.Enum.EnumLogCategory.Error, exception.ToString());
                }
            }

            return(result);
        }
 /// <summary>
 /// This method edits the record, and changes all the values of it, even if the value passed and the one already there are the same.
 /// </summary>
 /// <param name="name"></param>
 /// <param name="artist"></param>
 /// <param name="year"></param>
 /// <param name="recCond"></param>
 /// <param name="sleeveCond"></param>
 /// <param name="price"></param>
 public void editRecord(string name, string artist, int year, RecordCondition recCond, RecordCondition sleeveCond, double price, string albumArt, string note)
 {
     info.RecordName      = name;
     info.RecordCondition = recCond;
     info.SleeveCondition = sleeveCond;
     info.RecordCondition = recCond;
     info.Year            = year;
     info.Artist          = artist;
     info.Price           = price;
     info.AlbumArt        = albumArt;
     info.Note            = note;
 }
Esempio n. 7
0
 /// <summary>
 /// Constructor for the RecordInfo object, holding all information about the record.
 /// </summary>
 /// <param name="recName"></param>
 /// <param name="id"></param>
 /// <param name="recCond"></param>
 /// <param name="sleeveCond"></param>
 /// <param name="year"></param>
 /// <param name="artist"></param>
 /// <param name="price"></param>
 /// <param name="albumArt"></param>
 /// <param name="note"></param>
 public RecordInfo(string recName, int id, RecordCondition recCond, RecordCondition sleeveCond, int year, string artist, double price, string albumArt, string note)
 {
     this.RecordName      = recName;
     this.RecordCondition = recCond;
     this.SleeveCondition = sleeveCond;
     this.Year            = year;
     this.Artist          = artist;
     this.Price           = price;
     this.ID       = id;
     this.AlbumArt = albumArt;
     this.Note     = note;
 }
Esempio n. 8
0
        private double CalculateSecondScore(Store store, int ratio)
        {
            RecordCondition recordCondition = new RecordCondition()
            {
                CreateDate = DateTime.UtcNow.AddDays(-7)
            };
            int totalRecord = _recordDao.GetCount(recordCondition);

            recordCondition.StoreId = store.Id;
            int storeRecord = _recordDao.GetCount(recordCondition);

            return((totalRecord == 0 ? 1 : storeRecord / totalRecord) * 100 * ratio);
        }
        /// <summary>
        /// This method EDITS a record. How it works:
        ///     1. Parameters contain all the informatin about the record that is going to change ( the Id is always the same in each record and is not changeable ).
        ///     2. We loop through all the records until we match the one that matches the ID passed.
        ///     3. Then we call "editRecord" method in the record and will edit it.
        /// </summary>
        /// <param name="newName"></param>
        /// <param name="newIdToEdit"></param>
        /// <param name="newArtist"></param>
        /// <param name="newYear"></param>
        /// <param name="newRecCond"></param>
        /// <param name="newSleeveCond"></param>
        /// <param name="newPrice"></param>
        public void editRecordWithID(string newName, int newIdToEdit, string newArtist, int newYear,
                                     RecordCondition newRecCond, RecordCondition newSleeveCond, double newPrice, string albumArt, string newNote)
        {
            int len = this.recordList.Count;

            for (int i = 0; i < len; i++)
            {
                if (this.recordList[i].getInfo().ID == newIdToEdit)
                {
                    this.recordList[i].editRecord(newName, newArtist, newYear, newRecCond, newSleeveCond, newPrice, albumArt, newNote);
                }
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Will add or edit the record with the given information
        /// </summary>
        /// <param name="titleCheck"></param>
        /// <param name="albumName"></param>
        /// <param name="artistName"></param>
        /// <param name="convertedYear"></param>
        /// <param name="mediaCondEnum"></param>
        /// <param name="sleeveCondEnum"></param>
        /// <param name="value"></param>
        private void FinalizeRecord(bool titleCheck, string albumName, string artistName, int convertedYear,
                                    RecordCondition mediaCondEnum, RecordCondition sleeveCondEnum, double value, string albumArt, string note)
        {
            if (titleCheck == true)
            {
                controller.getRecordList().editRecordWithID(albumName, editRecord.getInfo().ID, artistName,
                                                            convertedYear, mediaCondEnum, sleeveCondEnum, value, albumArt, note);
                NavigateBackToHome();
            }

            else if (titleCheck == false)
            {
                controller.addNewRecord(albumName, artistName, convertedYear, mediaCondEnum, sleeveCondEnum, value, albumArt, note);
                NavigateBackToHome();
            }
        }
Esempio n. 11
0
        private IDictionary <string, double> CalculateFourthScore(Store store, int ratio, User user)
        {
            RecordCondition condition = new RecordCondition()
            {
                CreateDate = DateTime.UtcNow.AddDays(-10),
                StoreId    = store.Id,
                UserId     = user.Id
            };
            int eatInTenDayRecord = _recordDao.GetCount(condition);

            return(new Dictionary <string, double>()
            {
                { "tenDayNoEatScore", eatInTenDayRecord > 0 ? 0 : 100 * ratio },
                { "eatInTenDayRecord", eatInTenDayRecord }
            });
        }
        /// <summary>
        /// Calls for information from the UI and tells the recordList to create the new record.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="artist"></param>
        /// <param name="year"></param>
        /// <param name="recCond"></param>
        /// <param name="sleeveCond"></param>
        /// <param name="price"></param>
        /// <param name="albumArt"></param>
        /// <param name="note"></param>
        public void addNewRecord(string name, string artist, int year, RecordCondition recCond, RecordCondition sleeveCond, double price, string albumArt, string note)
        {
            this.generateNewID();
            Record newRecord = new Record(new RecordInfoBuilder()
                                          .withRecordName(name)
                                          .withArtist(artist)
                                          .withRecordCondition(recCond)
                                          .withSleeveCondition(sleeveCond)
                                          .withYear(year)
                                          .withPrice(price)
                                          .withID(currentID)
                                          .withAlbumArt(albumArt)
                                          .withNote(note)
                                          .build());

            //recordList.addRecord(newRecord);
            //CommandPattern
            recInvoker.doCommand(new AddRecord(newRecord, recordList));
        }
Esempio n. 13
0
        /// <summary>
        /// Similar to the back button, but will create the record and then add it to the list
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void addRecord_btn_Click(object sender, EventArgs e)
        {
            bool            flag           = false;
            string          albumName      = albumName_txtBox.Text;
            string          artistName     = artistName_txtBox.Text;
            int             convertedYear  = ProcessYearInput(yearReleased_txtBox.Text, ref flag);
            double          value          = ProcessValueInput(currentValue_txtBox.Text, ref flag);
            RecordCondition mediaCondEnum  = ConvertRecordCondition(mediaCondition_comboBox.Text);
            RecordCondition sleeveCondEnum = ConvertSleeveCondition(sleeveCondition_comboBox.Text);
            string          recordNote     = notes_txtBox.Text;
            string          albumArt       = updatedAlbumArtPic;

            if (this.originalAlbumArtName == this.updatedAlbumArtPic)
            {
                albumArt = this.originalAlbumArtName;
            }

            if (albumName == "" || albumName == " ")
            {
                badAlbumName_lbl.Visible = true;
                albumName_txtBox.Text    = "";
                flag = true;
            }

            if (artistName == "" || artistName == " ")
            {
                badArtistName_lbl.Visible = true;
                artistName_txtBox.Text    = "";
                flag = true;
            }

            if (flag == false)
            {
                FinalizeRecord(titleCheck, albumName, artistName, convertedYear, mediaCondEnum, sleeveCondEnum, value, albumArt, recordNote);
            }
        }
Esempio n. 14
0
 /// <summary>
 /// Adds a record condition to the record
 /// </summary>
 /// <param name="newRecCond"></param>
 /// <returns></returns>
 public RecordInfoBuilder withRecordCondition(RecordCondition newRecCond)
 {
     this.recordCondition = newRecCond;
     return(this);
 }
 /// <summary>Allow to declaratively show what records must be included or excluded</summary>
 /// <param name="condition">The condition used to include or exclude each record <see cref="RecordCondition"/>conditions</param>
 /// <param name="conditionSelector">The selector (match string) for the condition.</param>
 public ConditionalRecordAttribute(RecordCondition condition, string conditionSelector)
 {
     Condition         = condition;
     ConditionSelector = conditionSelector;
     CheckNullOrEmpty(conditionSelector, "conditionSelector");
 }
 /// <summary>Allow to declaratively show what records must be included or excluded</summary>
 /// <param name="condition">The condition used to include or exclude each record</param>
 /// <param name="conditionSelector">The selector for the condition.</param>
 public ConditionalRecordAttribute(RecordCondition condition, string conditionSelector)
 {
     Condition = condition;
     ConditionSelector = conditionSelector;
     ExHelper.CheckNullOrEmpty(conditionSelector, "conditionSelector");
 }
Esempio n. 17
0
 /// <summary>
 /// Adds a sleeve condition to the record
 /// </summary>
 /// <param name="newSleeveCond"></param>
 /// <returns></returns>
 public RecordInfoBuilder withSleeveCondition(RecordCondition newSleeveCond)
 {
     this.sleeveCondition = newSleeveCond;
     return(this);
 }
Esempio n. 18
0
		private void InitFields()
		{
			//-> Checked by the AttributeTargets
			//new BadUsageException("Structures are not supported in the FileHelperEngine only classes are allowed.");

			TypedRecordAttribute recordAttribute = null;

			if (mRecordType.IsDefined(typeof (TypedRecordAttribute), true) == false)
				throw new BadUsageException("The class " + mRecordType.Name + " must be marked with the [DelimitedRecord] or [FixedLengthRecord] Attribute.");
			else
			{
				object[] attbs = mRecordType.GetCustomAttributes(typeof (TypedRecordAttribute), true);
				recordAttribute = (TypedRecordAttribute) attbs[0];
			}

			if (mRecordType.GetConstructor(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic, null, mEmptyTypeArr, new ParameterModifier[] {}) == null)
				throw new BadUsageException("The record class " + mRecordType.Name + " need a constructor with no args (public or private)");

			if (mRecordType.IsDefined(typeof (IgnoreFirstAttribute), false))
				mIgnoreFirst = ((IgnoreFirstAttribute) mRecordType.GetCustomAttributes(typeof (IgnoreFirstAttribute), false)[0]).NumberOfLines;

			if (mRecordType.IsDefined(typeof (IgnoreLastAttribute), false))
				mIgnoreLast = ((IgnoreLastAttribute) mRecordType.GetCustomAttributes(typeof (IgnoreLastAttribute), false)[0]).NumberOfLines;

			if (mRecordType.IsDefined(typeof (IgnoreEmptyLinesAttribute), false))
			{
				mIgnoreEmptyLines = true;
				mIgnoreEmptySpaces = ((IgnoreEmptyLinesAttribute) mRecordType.GetCustomAttributes(typeof (IgnoreEmptyLinesAttribute), false)[0]).
						mIgnoreSpaces;
			}

			if (mRecordType.IsDefined(typeof (IgnoreCommentedLinesAttribute), false))
			{
				IgnoreCommentedLinesAttribute ignoreComments =
					(IgnoreCommentedLinesAttribute) mRecordType.GetCustomAttributes(typeof (IgnoreCommentedLinesAttribute), false)[0];
					mCommentMarker = ignoreComments.mCommentMarker;
					mCommentAnyPlace = ignoreComments.mAnyPlace;
			}

			if (mRecordType.IsDefined(typeof (ConditionalRecordAttribute), false))
			{
				ConditionalRecordAttribute conditional =
					(ConditionalRecordAttribute) mRecordType.GetCustomAttributes(typeof (ConditionalRecordAttribute), false)[0];

				mRecordCondition = conditional.mCondition;
				mRecordConditionSelector = conditional.mConditionSelector;

				#if ! MINI

				if (mRecordCondition == RecordCondition.ExcludeIfMatchRegex ||
					mRecordCondition == RecordCondition.IncludeIfMatchRegex)
				{
					mConditionRegEx = new Regex(mRecordConditionSelector, RegexOptions.Compiled | RegexOptions.CultureInvariant |RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
				}
				#endif
			}



#if ! MINI
			if (typeof(INotifyRead).IsAssignableFrom(mRecordType))
				mNotifyRead = true;

			if (typeof(INotifyWrite).IsAssignableFrom(mRecordType))
				mNotifyWrite = true;
#endif


			mRecordConstructor = mRecordType.GetConstructor(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic, null, mEmptyTypeArr, new ParameterModifier[] {});

			// Create fields

			ArrayList fields = new ArrayList();
			RecursiveGetFields(fields, mRecordType, recordAttribute);

			mFields = CreateCoreFields(fields, recordAttribute);
			mFieldCount = mFields.Length;
			
			if (recordAttribute is FixedLengthRecordAttribute)
			{
				// Defines the initial size of the StringBuilder
				mSizeHint = 0;
				for(int i = 0; i < mFieldCount; i++)
					mSizeHint += ((FixedLengthField) mFields[i]).mFieldLength;
			}
					

			if (mFieldCount == 0)
				throw new BadUsageException("The record class " + mRecordType.Name + " don't contains any field.");

		}
Esempio n. 19
0
        private void InitFields()
        {
            //-> Checked by the AttributeTargets
            //new BadUsageException("Structures are not supported in the FileHelperEngine only classes are allowed.");

            TypedRecordAttribute recordAttribute = null;

            if (mRecordType.IsDefined(typeof(TypedRecordAttribute), true) == false)
            {
                throw new BadUsageException("The class " + mRecordType.Name + " must be marked with the [DelimitedRecord] or [FixedLengthRecord] Attribute.");
            }
            else
            {
                var attbs = mRecordType.GetCustomAttributes(typeof(TypedRecordAttribute), true);
                recordAttribute = (TypedRecordAttribute)attbs[0];
            }

            if (mRecordType.GetConstructor(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic, null, mEmptyTypeArr, new ParameterModifier[] {}) == null)
            {
                throw new BadUsageException("The record class " + mRecordType.Name + " need a constructor with no args (public or private)");
            }

            if (mRecordType.IsDefined(typeof(IgnoreFirstAttribute), false))
            {
                mIgnoreFirst = ((IgnoreFirstAttribute)mRecordType.GetCustomAttributes(typeof(IgnoreFirstAttribute), false)[0]).NumberOfLines;
            }

            if (mRecordType.IsDefined(typeof(IgnoreLastAttribute), false))
            {
                mIgnoreLast = ((IgnoreLastAttribute)mRecordType.GetCustomAttributes(typeof(IgnoreLastAttribute), false)[0]).NumberOfLines;
            }

            if (mRecordType.IsDefined(typeof(IgnoreEmptyLinesAttribute), false))
            {
                mIgnoreEmptyLines  = true;
                mIgnoreEmptySpaces = ((IgnoreEmptyLinesAttribute)mRecordType.GetCustomAttributes(typeof(IgnoreEmptyLinesAttribute), false)[0]).
                                     mIgnoreSpaces;
            }

            if (mRecordType.IsDefined(typeof(IgnoreCommentedLinesAttribute), false))
            {
                var ignoreComments =
                    (IgnoreCommentedLinesAttribute)mRecordType.GetCustomAttributes(typeof(IgnoreCommentedLinesAttribute), false)[0];
                mCommentMarker   = ignoreComments.mCommentMarker;
                mCommentAnyPlace = ignoreComments.mAnyPlace;
            }

            if (mRecordType.IsDefined(typeof(ConditionalRecordAttribute), false))
            {
                var conditional =
                    (ConditionalRecordAttribute)mRecordType.GetCustomAttributes(typeof(ConditionalRecordAttribute), false)[0];

                mRecordCondition         = conditional.mCondition;
                mRecordConditionSelector = conditional.mConditionSelector;

#if !MINI
                if (mRecordCondition == RecordCondition.ExcludeIfMatchRegex ||
                    mRecordCondition == RecordCondition.IncludeIfMatchRegex)
                {
                    mConditionRegEx = new Regex(mRecordConditionSelector, RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
                }
#endif
            }


#if !MINI
            if (typeof(INotifyRead).IsAssignableFrom(mRecordType))
            {
                mNotifyRead = true;
            }

            if (typeof(INotifyWrite).IsAssignableFrom(mRecordType))
            {
                mNotifyWrite = true;
            }
#endif


            mRecordConstructor = mRecordType.GetConstructor(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic, null, mEmptyTypeArr, new ParameterModifier[] {});

            // Create fields

            var fields = new ArrayList();
            RecursiveGetFields(fields, mRecordType, recordAttribute);

            mFields     = CreateCoreFields(fields, recordAttribute);
            mFieldCount = mFields.Length;

            if (recordAttribute is FixedLengthRecordAttribute)
            {
                // Defines the initial size of the StringBuilder
                mSizeHint = 0;
                for (var i = 0; i < mFieldCount; i++)
                {
                    mSizeHint += ((FixedLengthField)mFields[i]).mFieldLength;
                }
            }


            if (mFieldCount == 0)
            {
                throw new BadUsageException("The record class " + mRecordType.Name + " don't contains any field.");
            }
        }
 /// <summary>
 /// This will edit the record.
 /// </summary>
 /// <param name="newName"></param>
 /// <param name="newIdToEdit"></param>
 /// <param name="newArtist"></param>
 /// <param name="newYear"></param>
 /// <param name="newRecCond"></param>
 /// <param name="newSleeveCond"></param>
 /// <param name="newPrice"></param>
 public void editRecord(string newName, int newIdToEdit, string newArtist, int newYear, RecordCondition newRecCond, RecordCondition newSleeveCond, double newPrice, string albumArt, string newNote)
 {
     recordList.editRecordWithID(newName, newIdToEdit, newArtist, newYear, newRecCond, newSleeveCond, newPrice, albumArt, newNote);
     return;
 }