L
labjac
Guest
Hallo
I'm trying to understand the best way to validate input values from a form passes to a object of a class using constructors and parameters.
We create a company class as per below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WCS_Cap.BLL
{
public class Company_BLL
{
public string CompanyName { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }
public string City { get; set; }
public string Region { get; set; }
public int PostalCode { get; set; }
public string PhoneNumber {get;set;}
public string Email { get; set; }
public Company_BLL(string companyName, string address1, string address2, string city, string region, int postalCode, string phonenumber, string email)
{
if (CompanyName.Length > 0)
{
}
}
}
}
We don't want to do the validation on the forms but want to pass this to the object for validation... (if possible doing the validation in the constructor.
We will create different methods within the class for Insert and Select to another class which will handle the data.
Below the form with a text box. (But we need to pass all the information to the object in some way).
Just passing the parameters was easy:
Company_BLL company = new Company_BLL();
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WCS_Cap.BLL;
namespace WCS_Cap.PLL
{
public partial class FrCustomers : Form
{
public FrCustomers()
{
InitializeComponent();
}
private void btExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnSave_Click(object sender, EventArgs e)
{
Company_BLL Company = new Company_BLL(); (this needs to constructor, but want the class to validate).
Company.CompanyName = txtCustomerName.Text.ToString();
}
}
}
but now we have to initiate the object with the values and cannot set the parameters. (I know there is some misunderstanding of the concept, so if somebody can please explain where the validation of the textbox should sit it will be appreciated.
labjac
Continue reading...
I'm trying to understand the best way to validate input values from a form passes to a object of a class using constructors and parameters.
We create a company class as per below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WCS_Cap.BLL
{
public class Company_BLL
{
public string CompanyName { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }
public string City { get; set; }
public string Region { get; set; }
public int PostalCode { get; set; }
public string PhoneNumber {get;set;}
public string Email { get; set; }
public Company_BLL(string companyName, string address1, string address2, string city, string region, int postalCode, string phonenumber, string email)
{
if (CompanyName.Length > 0)
{
}
}
}
}
We don't want to do the validation on the forms but want to pass this to the object for validation... (if possible doing the validation in the constructor.
We will create different methods within the class for Insert and Select to another class which will handle the data.
Below the form with a text box. (But we need to pass all the information to the object in some way).
Just passing the parameters was easy:
Company_BLL company = new Company_BLL();
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WCS_Cap.BLL;
namespace WCS_Cap.PLL
{
public partial class FrCustomers : Form
{
public FrCustomers()
{
InitializeComponent();
}
private void btExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnSave_Click(object sender, EventArgs e)
{
Company_BLL Company = new Company_BLL(); (this needs to constructor, but want the class to validate).
Company.CompanyName = txtCustomerName.Text.ToString();
}
}
}
but now we have to initiate the object with the values and cannot set the parameters. (I know there is some misunderstanding of the concept, so if somebody can please explain where the validation of the textbox should sit it will be appreciated.
labjac
Continue reading...