Пример #1
0
    /// <summary>
    /// override
    /// saves the values in the dialog and fires the save
    /// event if the save was successful
    /// </summary>
    /// <returns></returns>
    public override CStatus SaveControl()
    {
        CServiceDataItem di = new CServiceDataItem();

        di.ServiceLabel = txtService.Text;
        di.IsActive     = chkActive.Checked;

        CServiceData service = new CServiceData(BaseMstr.BaseData);
        CStatus      status  = new CStatus();

        switch (EditMode)
        {
        case k_EDIT_MODE.INSERT:
            long lServiceID = -1;
            status = service.InsertService(di, out lServiceID);
            if (status.Status)
            {
                LongID   = lServiceID;
                EditMode = k_EDIT_MODE.UPDATE;
            }
            break;

        case k_EDIT_MODE.UPDATE:
            di.ServiceID = LongID;
            status       = service.UpdateService(di);
            break;

        default:
            status.Status        = false;
            status.StatusCode    = k_STATUS_CODE.Failed;
            status.StatusComment = Resources.ErrorMessages.ERROR_INVALID_EDITMODE;
            break;
        }

        if (!status.Status)
        {
            return(status);
        }

        if (_Save != null)
        {
            CAppUserControlArgs args = new CAppUserControlArgs(
                k_EVENT.INSERT,
                k_STATUS_CODE.Success,
                string.Empty,
                LongID.ToString());

            _Save(this, args);
        }

        return(new CStatus());
    }
    /// <summary>
    /// save the control
    /// </summary>
    /// <returns></returns>
    public override CStatus SaveControl()
    {
        CStatus status = new CStatus();

        //user input is ok so save
        switch (EditMode)
        {
        case k_EDIT_MODE.INSERT:
            long lOSID = -1;
            status = InsertOutcomeState(out lOSID);
            if (status.Status)
            {
                LongID   = lOSID;
                EditMode = k_EDIT_MODE.UPDATE;
            }
            break;

        case k_EDIT_MODE.UPDATE:
            status = UpdateOutcomeState(LongID);
            break;

        default:
            status.Status        = false;
            status.StatusCode    = k_STATUS_CODE.Failed;
            status.StatusComment = Resources.ErrorMessages.ERROR_INVALID_EDITMODE;
            break;
        }

        if (!status.Status)
        {
            return(status);
        }

        if (_Save != null)
        {
            CAppUserControlArgs args = new CAppUserControlArgs(
                k_EVENT.INSERT,
                k_STATUS_CODE.Success,
                string.Empty,
                LongID.ToString());

            _Save(this, args);
        }

        return(new CStatus());
    }
        public void TestLongID()
        {
            LongID LongID0 = new LongID();
            LongID LongID1 = new LongID();

            if (LongID0.CompareTo(LongID1) > 0)
            {
                Assert.IsTrue(LongID1.CompareTo(LongID0) < 0);
            }
            else if (LongID0.CompareTo(LongID1) < 0)
            {
                Assert.IsTrue(LongID1.CompareTo(LongID0) > 0);
            }

            Assert.IsTrue(LongID0.CompareTo(LongID1) != 0 && LongID1.CompareTo(LongID0) != 0);
            Assert.AreNotEqual(LongID0.Value, LongID1.Value);
            Assert.IsTrue(!ArraysAreEqual(LongID0.GetByteArray(), LongID1.GetByteArray()));
            Assert.IsTrue(!ArraysAreEqual(LongID0.GetUlongArray(), LongID1.GetUlongArray()));

            LongID0.Value = LongID1.Value;

            Assert.IsTrue(LongID0.CompareTo(LongID1) == 0 && LongID1.CompareTo(LongID0) == 0);
            Assert.AreEqual(LongID0.Value, LongID1.Value);
            Assert.IsTrue(ArraysAreEqual(LongID0.GetByteArray(), LongID1.GetByteArray()));
            Assert.IsTrue(ArraysAreEqual(LongID0.GetUlongArray(), LongID1.GetUlongArray()));

            LongID1 = new LongID(LongID0.Value);

            Assert.IsTrue(LongID0.CompareTo(LongID1) == 0 && LongID1.CompareTo(LongID0) == 0);
            Assert.AreEqual(LongID0.Value, LongID1.Value);
            Assert.IsTrue(ArraysAreEqual(LongID0.GetByteArray(), LongID1.GetByteArray()));
            Assert.IsTrue(ArraysAreEqual(LongID0.GetUlongArray(), LongID1.GetUlongArray()));

            LongID1 = new LongID(LongID0.GetByteArray());

            Assert.IsTrue(LongID0.CompareTo(LongID1) == 0 && LongID1.CompareTo(LongID0) == 0);
            Assert.AreEqual(LongID0.Value, LongID1.Value);
            Assert.IsTrue(ArraysAreEqual(LongID0.GetByteArray(), LongID1.GetByteArray()));
            Assert.IsTrue(ArraysAreEqual(LongID0.GetUlongArray(), LongID1.GetUlongArray()));

            LongID1 = new LongID(LongID0.GetUlongArray());

            Assert.IsTrue(LongID0.CompareTo(LongID1) == 0 && LongID1.CompareTo(LongID0) == 0);
            Assert.AreEqual(LongID0.Value, LongID1.Value);
            Assert.IsTrue(ArraysAreEqual(LongID0.GetByteArray(), LongID1.GetByteArray()));
            Assert.IsTrue(ArraysAreEqual(LongID0.GetUlongArray(), LongID1.GetUlongArray()));

            LongID1 = new LongID();

            if (LongID0.CompareTo(LongID1) > 0)
            {
                Assert.IsTrue(LongID1.CompareTo(LongID0) < 0);
            }
            else if (LongID0.CompareTo(LongID1) < 0)
            {
                Assert.IsTrue(LongID1.CompareTo(LongID0) > 0);
            }

            Assert.IsTrue(LongID0.CompareTo(LongID1) != 0 && LongID1.CompareTo(LongID0) != 0);
            Assert.AreNotEqual(LongID0.Value, LongID1.Value);
            Assert.IsTrue(!ArraysAreEqual(LongID0.GetByteArray(), LongID1.GetByteArray()));
            Assert.IsTrue(!ArraysAreEqual(LongID0.GetUlongArray(), LongID1.GetUlongArray()));

            string serialized = Serializer.WriteXmlDataInMemory(LongID0);

            LongID1 = Serializer.ReadXmlDataInMemory <LongID>(serialized);

            Assert.IsTrue(LongID1.Equals(LongID0) && LongID0.Equals(LongID1));
            Assert.IsTrue(LongID1 == LongID0);
            Assert.IsTrue(LongID1.CompareTo(LongID0) == 0 && LongID0.CompareTo(LongID1) == 0);
            Assert.AreEqual(LongID1.Value, LongID0.Value);
            Assert.AreEqual(LongID1.ToHexString(), LongID0.ToHexString());
            Assert.IsTrue(ArraysAreEqual(LongID1.GetByteArray(), LongID0.GetByteArray()));
            Assert.IsTrue(ArraysAreEqual(LongID1.GetUlongArray(), LongID0.GetUlongArray()));

            serialized = Serializer.WriteJsonDataInMemory(LongID0);
            LongID1    = Serializer.ReadJsonDataInMemory <LongID>(serialized);

            Assert.IsTrue(LongID1.Equals(LongID0) && LongID0.Equals(LongID1));
            Assert.IsTrue(LongID1 == LongID0);
            Assert.IsTrue(LongID1.CompareTo(LongID0) == 0 && LongID0.CompareTo(LongID1) == 0);
            Assert.AreEqual(LongID1.Value, LongID0.Value);
            Assert.AreEqual(LongID1.ToHexString(), LongID0.ToHexString());
            Assert.IsTrue(ArraysAreEqual(LongID1.GetByteArray(), LongID0.GetByteArray()));
            Assert.IsTrue(ArraysAreEqual(LongID1.GetUlongArray(), LongID0.GetUlongArray()));

            byte[] serializedData = Serializer.WriteBinaryDataInMemory(LongID0);
            LongID1 = Serializer.ReadBinaryDataInMemory <LongID>(serializedData);

            Assert.IsTrue(LongID1.Equals(LongID0) && LongID0.Equals(LongID1));
            Assert.IsTrue(LongID1 == LongID0);
            Assert.IsTrue(LongID1.CompareTo(LongID0) == 0 && LongID0.CompareTo(LongID1) == 0);
            Assert.AreEqual(LongID1.Value, LongID0.Value);
            Assert.AreEqual(LongID1.ToHexString(), LongID0.ToHexString());
            Assert.IsTrue(ArraysAreEqual(LongID1.GetByteArray(), LongID0.GetByteArray()));
            Assert.IsTrue(ArraysAreEqual(LongID1.GetUlongArray(), LongID0.GetUlongArray()));
        }