private void btnSubmit_Click(object sender, EventArgs e)
        {
            Transaction obTransaction = new Transaction();
            obTransaction.TransactionID = PublicFunction.EncryptPassword(DateTime.Now.ToString());
            obTransaction.Action = (int)actionID;
            obTransaction.Amount = (int)numericUpDown_Amount.Value;
            obTransaction.Reason = txtReason.Text;
            obTransaction.Time = dateTimePicker_Time.Value;

            Data obData = PublicVariables.listData.Find(ob => ob.Year == obTransaction.Time.Year);
            if (obData == null)
            {
                obData = new Data();
                obData.Year = obTransaction.Time.Year;
                List<Transaction> listTransaction = new List<Transaction>();
                listTransaction.Add(obTransaction);
                obData.Transactions = listTransaction;
                PublicFunction.WriteData(obData.Year, obData);
            }
            else
            {
                obData.Transactions.Add(obTransaction);
                PublicFunction.WriteData(obData.Year, obData);
            }

            this.Hide();
        }
示例#2
0
        private static int CompareDataTime(Transaction x, Transaction y)
        {
            if (x == null)
            {
                if (y == null)
                {
                    // If x is null and y is null, they're
                    // equal.
                    return 0;
                }
                else
                {
                    // If x is null and y is not null, y
                    // is greater.
                    return -1;
                }
            }
            else
            {
                // If x is not null...
                //
                if (y == null)
                // ...and y is null, x is greater.
                {
                    return 1;
                }
                else
                {
                    // ...and y is not null, compare the
                    // lengths of the two strings.
                    //
                    int retval = x.Time.CompareTo(y.Time);

                    if (retval != 0)
                    {
                        // If the strings are not of equal length,
                        // the longer string is greater.
                        //
                        return retval;
                    }
                    else
                    {
                        // If the strings are of equal length,
                        // sort them with ordinary string comparison.
                        //
                        return x.Time.CompareTo(y.Time);
                    }
                }
            }
        }