this is my c sharp code and i want to count the village members and show the value in label or panal
how i can
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 Pirwal_Khel.Models.VillageMembersModel;
using Pirwal_Khel.Templets;
using Pirwal_Khel.Utilities;
using Pirwal_Khel.Utilities.Lists;
using PKDBFrameWork;
using PKDBFrameWork.Windows;
namespace Pirwal_Khel
{
public enum EnrollmentStatus
{
Enrolled = 1,
Unerolled = 2,
}
public enum Gender
{
Male = 1,
Female = 2,
}
public partial class AddNewVillageMemberForm : TamplateForm
{
public AddNewVillageMemberForm()
{
InitializeComponent();
}
public int VillMemberId { get; set; }
private void AddNewVillageMemberForm_Load(object sender, EventArgs e)
{
LoadDataintoComboBox();
LoadDataandBindWithConrolIfUpdated();
}
private void LoadDataintoComboBox()
{
ListData.LoadDataIntoComboBox(GuradianRelationshipComboBox, "usp_GetGurdianRelationshipComboBox");
ListData.LoadDataIntoComboBox(BankComboBox, "usp_GetBanksComboBox");
ListData.LoadDataIntoComboBox(VillageComboBox, "usp_GetVillageComboBox");
ListData.LoadDataIntoComboBox(VillageAdminComboBox, "usp_GetVillageAdminComboBox");
ListData.LoadDataIntoComboBox(VillageOccupationComboBox, "usp_GetVillageOccupationComboBox");
ListData.LoadDataIntoComboBox(MaritalStatusComboBox, "usp_GetValuesforMaritalStatusComboBox");
ListData.LoadDataIntoComboBox(LivingStatusComboBox, "usp_GetValuesForLivingStatusComboBox");
}
private void LoadDataandBindWithConrolIfUpdated()
{
if (this.IsUpdate)
{
DBSQLServer db = new DBSQLServer(AppSetting.ConnectionString());
DataTable dtVillageMember = db.GetDataList("usp_GetVillageMembersbyVillageMemberId", new DBParameters
{
parameters = "@VillageMemberid",
value = this.VillMemberId
});
DataRow row = dtVillageMember.Rows[0];
FamilyNumberTextBox.Text = row["Family_Number"].ToString();
MemberNameTextBox.Text = row["Name"].ToString();
MemberGuardianNameTextBox.Text = row["G_Name"].ToString();
GuradianRelationshipComboBox.SelectedValue = row["Relationship_Id"];
MemberCNICTextBox.Text = row["CNIC"].ToString();
MemberGuardianCNICTextBox.Text = row["G_CNIC"].ToString();
DateOfBirthDateTimePicker.Text = row["Date_Of_Birth"].ToString();
MemberMobileNumberTextBox.Text = row["Contact"].ToString();
MaleRadioButton.Checked = (Convert.ToInt32(row["Gender_Id"]) == 1) ? true : false;
FemaleRadioButton.Checked = (Convert.ToInt32(row["Gender_Id"]) == 2) ? true : false;
MaritalStatusComboBox.SelectedValue = row["Marital_Status_Id"];
GuradianAccountNoTextBox.Text = row["Account_No"].ToString();
BankComboBox.SelectedValue = row["Bank_Id"];
VillageComboBox.SelectedValue = row["Vill_Id"];
VillageAdminComboBox.SelectedValue = row["Vill_Admin_Id"];
LivingStatusComboBox.SelectedValue = row["Living_Status_Id"];
VillageOccupationComboBox.SelectedValue = row["Vill_Ocup_id"];
EnrolledRadioButton.Checked = (Convert.ToInt32(row["Active_Status_Id"]) == 1) ? true : false;
UnEnrolledRadioButton.Checked = (Convert.ToInt32(row["Active_Status_Id"]) == 2) ? true : false;
}
}
private void UnMarriedRadioButton_CheckedChanged(object sender, EventArgs e)
{
}
private void SaveButton_Click(object sender, EventArgs e)
{
if (IsFormValidate())
{
if (this.IsUpdate)
{
UpdatRecord();
PKMessageBox.ShowSuccessMessage("ترمیم شدہ ریکاڈ کامیابی کیساتھ محفوظ ہوگیا");
}
else
{
SaveRecord();
PKMessageBox.ShowSuccessMessage("نیا ریکاڈ کامیابی کیساتھ محفوظ ہوگیا");
}
this.Close();
}
}
private void UpdatRecord()
{
DBSQLServer db = new DBSQLServer(AppSetting.ConnectionString());
db.SaveOrUpdateRecord("usp_UpdateVillageMemberTableRecord", GetObject());
}
private void SaveRecord()
{
DBSQLServer db = new DBSQLServer(AppSetting.ConnectionString());
db.SaveOrUpdateRecord("usp_InsertIntoVillageMemberTable", GetObject());
}
private VillageMembersModel GetObject()
{
VillageMembersModel villmember = new VillageMembersModel();
villmember.Vill_Mem_Id = (this.IsUpdate) ? this.VillMemberId : 0;
villmember.Name = MemberNameTextBox.Text;
villmember.G_Name = MemberGuardianNameTextBox.Text;
villmember.CNIC = string.IsNullOrEmpty(MemberCNICTextBox.Text)?MemberCNICTextBox.Text:null ;
villmember.G_CNIC = MemberGuardianCNICTextBox.Text;
villmember.Family_Number = Convert.ToInt32(FamilyNumberTextBox.Text);
villmember.Vill_Id = Convert.ToInt32(VillageComboBox.SelectedValue);
villmember.Vill_Admin_Id = Convert.ToInt32(VillageAdminComboBox.SelectedValue);
villmember.Relationship_Id = Convert.ToInt32(GuradianRelationshipComboBox.SelectedValue);
villmember.Bank_Id = Convert.ToInt32((BankComboBox.SelectedValue == null) ? null : BankComboBox.SelectedValue);
villmember.Date_Of_Birth = DateOfBirthDateTimePicker.Value.Date;
villmember.Contact = MemberMobileNumberTextBox.Text;
villmember.Account_No = string.IsNullOrEmpty(GuradianAccountNoTextBox.Text)?GuradianAccountNoTextBox.Text:null;
villmember.Gender_Id = GetGenderRadioButton();
villmember.Active_Status_Id = GetEnrollement();
villmember.Vill_Ocup_id = Convert.ToInt32(VillageOccupationComboBox.SelectedValue);
villmember.Marital_Status_Id = Convert.ToInt32(MaritalStatusComboBox.SelectedValue);
villmember.Living_Status_Id = Convert.ToInt32(LivingStatusComboBox.SelectedValue);
DateTime startdate = DateOfBirthDateTimePicker.Value;
DateTime enddate = DateTime.Now;
villmember.Age = CalculateAge(startdate,enddate).ToString("0");
return villmember;
}
private int GetEnrollement()
{
if (EnrolledRadioButton.Checked)
{
return (int)EnrollmentStatus.Enrolled;
}
else
{
return (int)EnrollmentStatus.Unerolled;
}
}
private int GetGenderRadioButton()
{
if (MaleRadioButton.Checked)
{
return (int)Gender.Male;
}
else
{
return (int)Gender.Female;
}
}
private bool IsFormValidate()
{
if (MemberNameTextBox.Text.Trim() == string.Empty)
{
PKMessageBox.ShowErrorMessage("ممبر نام درکار ہے");
MemberNameTextBox.Focus();
return false;
}
return true;
}
private double CalculateAge(DateTime dbDob,DateTime PreDate)
{
double age = 0;
DateTime DOB = dbDob;
DateTime PresentDate = PreDate;
TimeSpan TSpan = PresentDate - DOB;
double days = TSpan.TotalDays;
age = (days / 365);
return age;
}
}
}
What I have tried:
this is my c sharp code and i want to count the village members and show the value in label or panal
how i can
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 Pirwal_Khel.Models.VillageMembersModel;
using Pirwal_Khel.Templets;
using Pirwal_Khel.Utilities;
using Pirwal_Khel.Utilities.Lists;
using PKDBFrameWork;
using PKDBFrameWork.Windows;
namespace Pirwal_Khel
{
public enum EnrollmentStatus
{
Enrolled = 1,
Unerolled = 2,
}
public enum Gender
{
Male = 1,
Female = 2,
}
public partial class AddNewVillageMemberForm : TamplateForm
{
public AddNewVillageMemberForm()
{
InitializeComponent();
}
public int VillMemberId { get; set; }
private void AddNewVillageMemberForm_Load(object sender, EventArgs e)
{
LoadDataintoComboBox();
LoadDataandBindWithConrolIfUpdated();
}
private void LoadDataintoComboBox()
{
ListData.LoadDataIntoComboBox(GuradianRelationshipComboBox, "usp_GetGurdianRelationshipComboBox");
ListData.LoadDataIntoComboBox(BankComboBox, "usp_GetBanksComboBox");
ListData.LoadDataIntoComboBox(VillageComboBox, "usp_GetVillageComboBox");
ListData.LoadDataIntoComboBox(VillageAdminComboBox, "usp_GetVillageAdminComboBox");
ListData.LoadDataIntoComboBox(VillageOccupationComboBox, "usp_GetVillageOccupationComboBox");
ListData.LoadDataIntoComboBox(MaritalStatusComboBox, "usp_GetValuesforMaritalStatusComboBox");
ListData.LoadDataIntoComboBox(LivingStatusComboBox, "usp_GetValuesForLivingStatusComboBox");
}
private void LoadDataandBindWithConrolIfUpdated()
{
if (this.IsUpdate)
{
DBSQLServer db = new DBSQLServer(AppSetting.ConnectionString());
DataTable dtVillageMember = db.GetDataList("usp_GetVillageMembersbyVillageMemberId", new DBParameters
{
parameters = "@VillageMemberid",
value = this.VillMemberId
});
DataRow row = dtVillageMember.Rows[0];
FamilyNumberTextBox.Text = row["Family_Number"].ToString();
MemberNameTextBox.Text = row["Name"].ToString();
MemberGuardianNameTextBox.Text = row["G_Name"].ToString();
GuradianRelationshipComboBox.SelectedValue = row["Relationship_Id"];
MemberCNICTextBox.Text = row["CNIC"].ToString();
MemberGuardianCNICTextBox.Text = row["G_CNIC"].ToString();
DateOfBirthDateTimePicker.Text = row["Date_Of_Birth"].ToString();
MemberMobileNumberTextBox.Text = row["Contact"].ToString();
MaleRadioButton.Checked = (Convert.ToInt32(row["Gender_Id"]) == 1) ? true : false;
FemaleRadioButton.Checked = (Convert.ToInt32(row["Gender_Id"]) == 2) ? true : false;
MaritalStatusComboBox.SelectedValue = row["Marital_Status_Id"];
GuradianAccountNoTextBox.Text = row["Account_No"].ToString();
BankComboBox.SelectedValue = row["Bank_Id"];
VillageComboBox.SelectedValue = row["Vill_Id"];
VillageAdminComboBox.SelectedValue = row["Vill_Admin_Id"];
LivingStatusComboBox.SelectedValue = row["Living_Status_Id"];
VillageOccupationComboBox.SelectedValue = row["Vill_Ocup_id"];
EnrolledRadioButton.Checked = (Convert.ToInt32(row["Active_Status_Id"]) == 1) ? true : false;
UnEnrolledRadioButton.Checked = (Convert.ToInt32(row["Active_Status_Id"]) == 2) ? true : false;
}
}
private void UnMarriedRadioButton_CheckedChanged(object sender, EventArgs e)
{
}
private void SaveButton_Click(object sender, EventArgs e)
{
if (IsFormValidate())
{
if (this.IsUpdate)
{
UpdatRecord();
PKMessageBox.ShowSuccessMessage("ترمیم شدہ ریکاڈ کامیابی کیساتھ محفوظ ہوگیا");
}
else
{
SaveRecord();
PKMessageBox.ShowSuccessMessage("نیا ریکاڈ کامیابی کیساتھ محفوظ ہوگیا");
}
this.Close();
}
}
private void UpdatRecord()
{
DBSQLServer db = new DBSQLServer(AppSetting.ConnectionString());
db.SaveOrUpdateRecord("usp_UpdateVillageMemberTableRecord", GetObject());
}
private void SaveRecord()
{
DBSQLServer db = new DBSQLServer(AppSetting.ConnectionString());
db.SaveOrUpdateRecord("usp_InsertIntoVillageMemberTable", GetObject());
}
private VillageMembersModel GetObject()
{
VillageMembersModel villmember = new VillageMembersModel();
villmember.Vill_Mem_Id = (this.IsUpdate) ? this.VillMemberId : 0;
villmember.Name = MemberNameTextBox.Text;
villmember.G_Name = MemberGuardianNameTextBox.Text;
villmember.CNIC = string.IsNullOrEmpty(MemberCNICTextBox.Text)?MemberCNICTextBox.Text:null ;
villmember.G_CNIC = MemberGuardianCNICTextBox.Text;
villmember.Family_Number = Convert.ToInt32(FamilyNumberTextBox.Text);
villmember.Vill_Id = Convert.ToInt32(VillageComboBox.SelectedValue);
villmember.Vill_Admin_Id = Convert.ToInt32(VillageAdminComboBox.SelectedValue);
villmember.Relationship_Id = Convert.ToInt32(GuradianRelationshipComboBox.SelectedValue);
villmember.Bank_Id = Convert.ToInt32((BankComboBox.SelectedValue == null) ? null : BankComboBox.SelectedValue);
villmember.Date_Of_Birth = DateOfBirthDateTimePicker.Value.Date;
villmember.Contact = MemberMobileNumberTextBox.Text;
villmember.Account_No = string.IsNullOrEmpty(GuradianAccountNoTextBox.Text)?GuradianAccountNoTextBox.Text:null;
villmember.Gender_Id = GetGenderRadioButton();
villmember.Active_Status_Id = GetEnrollement();
villmember.Vill_Ocup_id = Convert.ToInt32(VillageOccupationComboBox.SelectedValue);
villmember.Marital_Status_Id = Convert.ToInt32(MaritalStatusComboBox.SelectedValue);
villmember.Living_Status_Id = Convert.ToInt32(LivingStatusComboBox.SelectedValue);
DateTime startdate = DateOfBirthDateTimePicker.Value;
DateTime enddate = DateTime.Now;
villmember.Age = CalculateAge(startdate,enddate).ToString("0");
return villmember;
}
private int GetEnrollement()
{
if (EnrolledRadioButton.Checked)
{
return (int)EnrollmentStatus.Enrolled;
}
else
{
return (int)EnrollmentStatus.Unerolled;
}
}
private int GetGenderRadioButton()
{
if (MaleRadioButton.Checked)
{
return (int)Gender.Male;
}
else
{
return (int)Gender.Female;
}
}
private bool IsFormValidate()
{
if (MemberNameTextBox.Text.Trim() == string.Empty)
{
PKMessageBox.ShowErrorMessage("ممبر نام درکار ہے");
MemberNameTextBox.Focus();
return false;
}
return true;
}
private double CalculateAge(DateTime dbDob,DateTime PreDate)
{
double age = 0;
DateTime DOB = dbDob;
DateTime PresentDate = PreDate;
TimeSpan TSpan = PresentDate - DOB;
double days = TSpan.TotalDays;
age = (days / 365);
return age;
}
}
}