У меня есть форма с четырьмя выпадающими списками, например: cbmefrom (age from) cbmeto (age to) cbperiod (значения periodtype, такие как «следующие 7 дней» ......) и cbgender (cbgender) ..
У меня также есть представление таблицы данных (dgvreports) ..
что я пытаюсь сделать, так это заполнить данные о членах тех, чей возраст составляет от 20 до 40 лет, и срок действия членства которых истекает в следующие 8 или 24 дня или около того ...
для этого я написал один класс, который я указал ниже ...
public static string ConvertGender(string Gender)
{
switch (Gender)
{
case "Male": return "M";
case "Female": return "F";
default: return "";
}
}
public BindingSource getmebershipexpirymembers(string gender , DateTime strtdate,DateTime enddate,DateTime min , DateTime max)
{
bs2.DataSource = null;
var membersreports = from report in eclipse.members
let dob= eclipse.members.Take(1).Select(x=>report.member_Dob).Cast<DateTime>().FirstOrDefault()
let strtdatees = eclipse.membertomships.Take(1).Select(x=>x.memberToMship_EndDate).Cast<DateTime>().FirstOrDefault()
join memtomship in eclipse.membertomships on report.member_Id equals memtomship.member_Id
into joinmemtomship from memtomship in joinmemtomship.DefaultIfEmpty()
join mshoption in eclipse.mshipoptions on memtomship.mshipOption_Id equals mshoption.mshipOption_Id
into joinmshipoption from mshoption in joinmshipoption.DefaultIfEmpty()
join membershiptypes in eclipse.mshiptypes on mshoption.mshipType_Id equals membershiptypes.mshipType_Id
into joinmembershipdifftypes from membershiptypes in joinmembershipdifftypes.DefaultIfEmpty()
join membershipstatustypes in eclipse.mshipstatustypes on memtomship.mshipStatusType_Id equals membershipstatustypes.mshipStatusType_Id
into joinmemberstatusdifftypes from membershipstatustypes in joinmemberstatusdifftypes.DefaultIfEmpty()
where (report.member_Gender.StartsWith(gender) || string.IsNullOrEmpty(gender))
&& dob >= min && dob < max
&& (strtdatees > strtdate && strtdatees < enddate)
select new
{
MemberID = report.member_Id,
Lastname = report.member_Lastname,
Firstname = report.member_Firstname,
Postcode = report.member_Postcode,
Reference = report.member_Reference,
CardNum = report.member_CardNum,
IsBiometric = report.member_IsBiometric,
DOB = report.member_Dob,
MShipType = membershiptypes.mshipType_Name,
StatusType = membershipstatustypes.mshipStatusType_Name,
EndDate = memtomship.memberToMship_EndDate
};
bs2.DataSource = membersreports;
return bs2;
}
и я получаю доступ к вышеуказанному классу в форме, которую я упомянул ниже ...
public void Getgroupcorporatemembers()
{
int startdays = 0;
int enddays = 0;
if (cbMeperiodType.Text == membershipexpiry.type1)
{
startdays = 0;
enddays = 7;
}
if (cbMeperiodType.Text == membershipexpiry.type2)
{
startdays = 8;
enddays = 14;
}
if (cbMeperiodType.Text == membershipexpiry.type3)
{
startdays = 15;
enddays = 30;
}
if (cbMeperiodType.Text == membershipexpiry.type4)
{
startdays = 31;
enddays = 90;
}
DateTime today = DateTime.Now;
DateTime strtdate = today.AddDays(startdays);
DateTime enddate = today.AddDays(enddays);
int agefrom = Convert.ToInt32(cbMeFrom.Text);
int ageto = Convert.ToInt32(CbMeTo.Text);
DateTime max = today.AddYears(-agefrom);
DateTime min = today.AddYears(-ageto);
string gender = "";
gender = Classes.reportmembers.ConvertGender(cbMEGendertype.Text);
dgvReportMembers.DataSource = objreports.getmebershipexpirymembers(gender, strtdate, enddate, max, min);// here i am accessing the method in class
SetDgvheaders();
}
struct membershipexpiry
{
public const string type1 = "Next 7 Days";
public const string type2 = "8 - 14 Days";
public const string type3 = "15 - 30 Days";
public const string type4 = "31 - 90 Days";
}
но я получаю сообщение об ошибке в этой строке ... bs2.DataSource = membersreports;
Error :Nullreference excpetion was unhandled
Object reference not set to an instance of an object.