280 Adding Validations to Entities Classes

CustomerExceptions.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HJHBank.Exceptions
{
    /// <summary>
    /// Exception class that represents error raised in Customer class
    /// </summary>
    public class CustomerException : ApplicationException
    {
        /// <summary>
        /// Constructor that initializes exception message
        /// </summary>
        /// <param name="message">exception message</param>
        public CustomerException(string message) : base(message)
        {
        }

        /// <summary>
        /// Constructor that initializes exception message and inner exception
        /// </summary>
        /// <param name="message">Exception message</param>
        /// <param name="innerException">Inner exception</param>
        public CustomerException(string message, Exception innerException) : base(message, innerException)
        {
        }
    }
}

Customer.cs

using HJHBank.Entities.Contracts;
using HJHBank.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HJHBank.Entities
{
    /// <summary>
    /// Represents customer of the bank
    /// </summary>
    public class Customer : ICustomer
    {
        #region Private fields
        private Guid _customerID;
        private long _customerCode;
        private string _customerName;
        private string _address;
        private string _landmark;
        private string _city;
        private string _country;
        private string _mobile;
        #endregion

        #region Public Properties
        /// <summary>
        /// Guid of Customer for Unique identfication
        /// </summary>
        public Guid CustomerID { get => _customerID; set => _customerID = value; }

        /// <summary>
        /// Auto-generated code number of the customer
        /// </summary>
        public long CustomerCode
        {
            get => _customerCode;
            set
            {
                //customer code should be positive
                if (value > 0)
                {
                    _customerCode = value;
                }
                else
                {
                    throw new CustomerException("Customer code should be positive only.");
                }
            }
        }

        /// <summary>
        /// Name of the customer
        /// </summary>
        public string CustomerName
        {
            get => _customerName;
            set
            {
                //customer name should be less than 40 characters
                if (value.Length <= 40 && string.IsNullOrEmpty(value) == false)
                {
                    _customerName = value;
                }
                else
                {
                    throw new CustomerException("Customer Name should not be null and less than 40 characters long.");
                }
            }
        }

        /// <summary>
        /// Address of the customer
        /// </summary>
        public string Address { get => _address; set => _address = value; }

        /// <summary>
        /// Landmark of the customer's address
        /// </summary>
        public string Landmark { get => _landmark; set => _landmark = value; }

        /// <summary>
        /// City of the customer
        /// </summary>
        public string City { get => _city; set => _city = value; }

        /// <summary>
        /// Country of the customer
        /// </summary>
        public string Country { get => _country; set => _country = value; }

        /// <summary>
        /// 10-digit Mobile number of the customer
        /// </summary>
        public string Mobile
        {
            get => _mobile;
            set
            {
                //mobile number should be 10 digit mobile number
                if (value.Length == 10)
                {
                    _mobile = value;
                }
                else
                {
                    throw new CustomerException("Mobile number should be a 10-digit number");
                }
            }
        }
        #endregion
    }
}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
To add custom functions to the NX menu, you can use the NXOpen.MenuBar class in NXOpen.NET API. Here is an example code that demonstrates how to add a custom function to the NX menu: ```vb Imports System Imports NXOpen Module Module1 Sub Main() ' Get the NX session Dim theSession As Session = Session.GetSession() ' Get the UI work part Dim theUI As UI = theSession.UI Dim lw As ListingWindow = theSession.ListingWindow ' Get the menu bar Dim menuBar As MenuBar = theUI.MenuBar ' Get the File menu Dim fileMenu As Menu = menuBar.GetMenu("File") ' Add a separator to the File menu fileMenu.AddSeparator() ' Add a custom function to the File menu Dim menuItem As MenuItem = fileMenu.AddMenuItem("Custom Function", AddressOf CustomFunction) ' Show a message box when the custom function is clicked Sub CustomFunction(ByVal item As MenuItem) lw.Open() lw.WriteLine("Custom function is clicked!") lw.Close() End Sub ' Start the NX message loop to display the menu theUI.NXMessageBox.Show("Menu Example", NXMessageBox.DialogType.Information, "Click OK to display the menu") theUI.NXMessageBox.GetMessage() ' Remove the custom function from the menu fileMenu.RemoveMenuItem(menuItem) End Sub End Module ``` In the above code, we first obtain the NX session and UI work part. Then, we get the MenuBar object using `theUI.MenuBar`. Next, we retrieve the desired menu (e.g., "File") using `GetMenu()` method. We can add a separator using `AddSeparator()` method and add a custom function using `AddMenuItem()` method, specifying the function to be called when the menu item is clicked. In the example above, the `CustomFunction` is a sub that will be executed when the custom function menu item is clicked. You can customize the behavior of this function to perform your desired actions. After adding the custom function, we start the NX message loop using `theUI.NXMessageBox.Show()` and `theUI.NXMessageBox.GetMessage()` to display the menu. Finally, we remove the custom function from the menu using `RemoveMenuItem()` method. Please note that above code is just an example, and you may need to adjust it based on your specific requirements and menu structure in NX.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

黄健华Yeah

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值