PK Singh

PK Singh

  • NA
  • 165
  • 14.6k

Error show pleas solve any one code in C# langue

Feb 11 2021 4:01 PM
 
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualBasic;
using System.Data.SqlClient;
using System.Data;
public class frmFeeHeads
{
private DataAccessLayer objDAl = new DataAccessLayer();
// Dim FID As Integer
private int FeeHeadID;
private new Validations Validated = new Validations();
private SqlConnection sqlcon = objDAl.Connection();
public void LoadFeeHeads()
{
DataTable dtFeeHeads = new DataTable();
dtFeeHeads = objDAl.FillDataTable_Query("Select * from mstFeeHead");
dgvFeeHeads.DataSource = dtFeeHeads;
dgvFeeHeads.Columns.Item(0).Visible = false;
for (int m = 4; m <= 15; m++)
dgvFeeHeads.Columns.Item(m).Visible = false;
for (int i = 0; i <= dgvFeeHeads.Columns.Count - 1; i++)
{
dgvFeeHeads.Columns.Item(i).SortMode = DataGridViewColumnSortMode.NotSortable;
dgvFeeHeads.Columns(i).Width = 124;
}
}
public bool InsertFeeHead(string procedurename)
{
string[,] arr = new[] { { "January", 0 }, { "Februry", 0 }, { "March", 0 }, { "April", 0 }, { "May", 0 }, { "June", 0 }, { "July", 0 }, { "August", 0 }, { "September", 0 }, { "October", 0 }, { "November", 0 }, { "December", 0 } };
bool flag = false;
try
{
SqlConnection sqlcon = objDAl.Connection();
SqlCommand sqlcmd = new SqlCommand(procedurename, sqlcon);
sqlcmd.CommandType = CommandType.Text;
if (rbtnMonthly.Checked == true)
{
if (chklbMonth.GetItemChecked(3))
arr[3, 1] = 1;
if (chklbMonth.GetItemChecked(4))
arr[4, 1] = 1;
if (chklbMonth.GetItemChecked(5))
arr[5, 1] = 1;
if (chklbMonth.GetItemChecked(6))
arr[6, 1] = 1;
if (chklbMonth.GetItemChecked(7))
arr[7, 1] = 1;
if (chklbMonth.GetItemChecked(8))
arr[8, 1] = 1;
if (chklbMonth.GetItemChecked(9))
arr[9, 1] = 1;
if (chklbMonth.GetItemChecked(10))
arr[10, 1] = 1;
if (chklbMonth.GetItemChecked(11))
arr[11, 1] = 1;
if (chklbMonth.GetItemChecked(0))
arr[0, 1] = 1;
if (chklbMonth.GetItemChecked(1))
arr[1, 1] = 1;
if (chklbMonth.GetItemChecked(2))
arr[2, 1] = 1;
int counter = 0;
for (int i = 0; i <= chklbMonth.Items.Count - 1; i++)
{
if (chklbMonth.GetItemCheckState(i))
counter = counter + 1;
}
if (counter != 12)
{
Interaction.MsgBox("Select all Months!!!!!!!!!");
return;
}
}
else if (rbtnQuarterly.Checked == true)
{
if (chklbMonth.GetItemChecked(3))
arr[3, 1] = 1;
if (chklbMonth.GetItemChecked(4))
arr[4, 1] = 1;
if (chklbMonth.GetItemChecked(5))
arr[5, 1] = 1;
if (chklbMonth.GetItemChecked(6))
arr[6, 1] = 1;
if (chklbMonth.GetItemChecked(7))
arr[7, 1] = 1;
if (chklbMonth.GetItemChecked(8))
arr[8, 1] = 1;
if (chklbMonth.GetItemChecked(9))
arr[9, 1] = 1;
if (chklbMonth.GetItemChecked(10))
arr[10, 1] = 1;
if (chklbMonth.GetItemChecked(11))
arr[11, 1] = 1;
if (chklbMonth.GetItemChecked(0))
arr[0, 1] = 1;
if (chklbMonth.GetItemChecked(1))
arr[1, 1] = 1;
if (chklbMonth.GetItemChecked(2))
arr[2, 1] = 1;
int counter = 0;
for (int i = 0; i <= chklbMonth.Items.Count - 1; i++)
{
if (chklbMonth.GetItemCheckState(i))
counter = counter + 1;
}
if (counter != 4)
{
Interaction.MsgBox("Select any 4 Months!!!!!!!!!");
return;
}
}
else if (rbtnHalfYearly.Checked == true)
{
if (chklbMonth.GetItemChecked(3))
arr[3, 1] = 1;
if (chklbMonth.GetItemChecked(4))
arr[4, 1] = 1;
if (chklbMonth.GetItemChecked(5))
arr[5, 1] = 1;
if (chklbMonth.GetItemChecked(6))
arr[6, 1] = 1;
if (chklbMonth.GetItemChecked(7))
arr[7, 1] = 1;
if (chklbMonth.GetItemChecked(8))
arr[8, 1] = 1;
if (chklbMonth.GetItemChecked(9))
arr[9, 1] = 1;
if (chklbMonth.GetItemChecked(10))
arr[10, 1] = 1;
if (chklbMonth.GetItemChecked(11))
arr[11, 1] = 1;
if (chklbMonth.GetItemChecked(0))
arr[0, 1] = 1;
if (chklbMonth.GetItemChecked(1))
arr[1, 1] = 1;
if (chklbMonth.GetItemChecked(2))
arr[2, 1] = 1;
int counter = 0;
for (int i = 0; i <= chklbMonth.Items.Count - 1; i++)
{
if (chklbMonth.GetItemCheckState(i))
counter = counter + 1;
}
if (counter != 2)
{
Interaction.MsgBox("Select any two Months!!!!!!!!!");
return;
}
}
else if (rbtnVariant.Checked == true)
{
if (chklbMonth.GetItemChecked(3))
arr[3, 1] = 1;
if (chklbMonth.GetItemChecked(4))
arr[4, 1] = 1;
if (chklbMonth.GetItemChecked(5))
arr[5, 1] = 1;
if (chklbMonth.GetItemChecked(6))
arr[6, 1] = 1;
if (chklbMonth.GetItemChecked(7))
arr[7, 1] = 1;
if (chklbMonth.GetItemChecked(8))
arr[8, 1] = 1;
if (chklbMonth.GetItemChecked(9))
arr[9, 1] = 1;
if (chklbMonth.GetItemChecked(10))
arr[10, 1] = 1;
if (chklbMonth.GetItemChecked(11))
arr[11, 1] = 1;
if (chklbMonth.GetItemChecked(0))
arr[0, 1] = 1;
if (chklbMonth.GetItemChecked(1))
arr[1, 1] = 1;
if (chklbMonth.GetItemChecked(2))
arr[2, 1] = 1;
int counter = 0;
for (int i = 0; i <= chklbMonth.Items.Count - 1; i++)
{
if (chklbMonth.GetItemCheckState(i))
counter = counter + 1;
}
if (counter == 0)
{
Interaction.MsgBox("Select atleast any one Month!!!!!!!!");
return;
}
}
else if (rbtnAnually.Checked == true)
{
if (chklbMonth.GetItemChecked(3))
arr[3, 1] = 1;
if (chklbMonth.GetItemChecked(4))
arr[4, 1] = 1;
if (chklbMonth.GetItemChecked(5))
arr[5, 1] = 1;
if (chklbMonth.GetItemChecked(6))
arr[6, 1] = 1;
if (chklbMonth.GetItemChecked(7))
arr[7, 1] = 1;
if (chklbMonth.GetItemChecked(8))
arr[8, 1] = 1;
if (chklbMonth.GetItemChecked(9))
arr[9, 1] = 1;
if (chklbMonth.GetItemChecked(10))
arr[10, 1] = 1;
if (chklbMonth.GetItemChecked(11))
arr[11, 1] = 1;
if (chklbMonth.GetItemChecked(0))
arr[0, 1] = 1;
if (chklbMonth.GetItemChecked(1))
arr[1, 1] = 1;
if (chklbMonth.GetItemChecked(2))
arr[2, 1] = 1;
int counter = 0;
for (int i = 0; i <= chklbMonth.Items.Count - 1; i++)
{
if (chklbMonth.GetItemCheckState(i))
counter = counter + 1;
}
if (counter != 1)
{
Interaction.MsgBox("Select any one Month!!!!!!!!");
return;
}
}
sqlcmd.Parameters.Add("@FeeHeadName", SqlDbType.VarChar).Value = txtNameofHead.Text.Trim();
if (rbtnRefundable.Checked == true)
sqlcmd.Parameters.Add("@TypeofHead", SqlDbType.VarChar).Value = "Refundable";
else
sqlcmd.Parameters.Add("@TypeofHead", SqlDbType.VarChar).Value = "NonRefundable";
if (rbtnAnually.Checked == true)
sqlcmd.Parameters.Add("@Frequency", SqlDbType.VarChar).Value = "Annualy";
else if (rbtnHalfYearly.Checked == true)
sqlcmd.Parameters.Add("@Frequency", SqlDbType.VarChar).Value = "Half Yearly";
else if (rbtnQuarterly.Checked == true)
sqlcmd.Parameters.Add("@Frequency", SqlDbType.VarChar).Value = "Quarterly";
else if (rbtnMonthly.Checked == true)
sqlcmd.Parameters.Add("@Frequency", SqlDbType.VarChar).Value = "Monthly";
else if (rbtnVariant.Checked == true)
sqlcmd.Parameters.Add("@Frequency", SqlDbType.VarChar).Value = "Variant";
sqlcmd.Parameters.Add("@January", SqlDbType.VarChar).Value = (arr[0, 1]);
sqlcmd.Parameters.Add("@February", SqlDbType.VarChar).Value = (arr[1, 1]);
sqlcmd.Parameters.Add("@March", SqlDbType.VarChar).Value = (arr[2, 1]);
sqlcmd.Parameters.Add("@April", SqlDbType.VarChar).Value = (arr[3, 1]);
sqlcmd.Parameters.Add("@May", SqlDbType.VarChar).Value = (arr[4, 1]);
sqlcmd.Parameters.Add("@June", SqlDbType.VarChar).Value = (arr[5, 1]);
sqlcmd.Parameters.Add("@July", SqlDbType.VarChar).Value = (arr[6, 1]);
sqlcmd.Parameters.Add("@August", SqlDbType.VarChar).Value = (arr[7, 1]);
sqlcmd.Parameters.Add("@September", SqlDbType.VarChar).Value = (arr[8, 1]);
sqlcmd.Parameters.Add("@October", SqlDbType.VarChar).Value = (arr[9, 1]);
sqlcmd.Parameters.Add("@November", SqlDbType.VarChar).Value = (arr[10, 1]);
sqlcmd.Parameters.Add("@December", SqlDbType.VarChar).Value = (arr[11, 1]);
sqlcon.Open();
int rowAffected = sqlcmd.ExecuteNonQuery();
Interaction.MsgBox("Fee Head is Saved Successfully!!!");
sqlcon.Close();
sqlcon.Dispose();
flag = true;
return flag;
}
catch (Exception ex)
{
flag = false;
Interaction.MsgBox("Error in Saving. Select Relevant Information !!!", MsgBoxStyle.Exclamation);
return flag;
}
}
public void DisplayFeeHead()
{
DataTable dt = new DataTable();
dt = objDAl.FillDataTable_Query("Select * From mstFeeHead");
dgvFeeHeads.DataSource = dt;
}
public bool DeleteFeeHead(string procedurename)
{
bool flag = false;
try
{
SqlConnection sqlcon = objDAl.Connection;
SqlCommand sqlcmd = new SqlCommand(procedurename, sqlcon);
sqlcmd.CommandType = CommandType.Text;
sqlcmd.Parameters.Add("@FeeHeadID", SqlDbType.Int).Value = FeeHeadID;
sqlcon.Open();
int rowaffected = sqlcmd.ExecuteNonQuery();
sqlcmd.Dispose();
sqlcon.Close();
Interaction.MsgBox("Fee Head is Successfully Deleted");
flag = true;
return flag;
}
catch (SqlException ex)
{
if ((ex.Number == 547))
{
Interaction.MsgBox("This Fee Head cannot be deleted. Please Delete Allocated Fee Plans and Students first!!", MsgBoxStyle.Exclamation);
return flag;
}
}
catch (Exception ex)
{
Interaction.MsgBox("Unsuccessful");
return flag;
}
}
private void frmFeeHeads_Load(System.Object sender, System.EventArgs e)
{
this.MdiParent = MainForm;
this.Dock = DockStyle.Fill;
this.Location = new Point(0, 0);
LoadFeeHeads();
btnDelete.Enabled = false;
btnCreate.Enabled = false;
rbtnAnually.Checked = false;
rbtnHalfYearly.Checked = false;
rbtnMonthly.Checked = false;
rbtnQuarterly.Checked = false;
rbtnNonRefundable.Checked = false;
rbtnRefundable.Checked = false;
btnCreate.Enabled = true;
btnDelete.Enabled = false;
rbtnVariant.Checked = false;
}
private void Button3_Click(System.Object sender, System.EventArgs e)
{
this.Close();
MainForm.objOpenedForm = new Form();
}
private void btnCreate_Click(System.Object sender, System.EventArgs e)
{
StringBuilder str = new StringBuilder();
str.Append(Validated.Validate(txtNameofHead, true, Validated.StringAll, "NameofHead"));
if (str.Length != 0)
{
MessageBox.Show(str.ToString());
return;
}
SqlCommand cmd = new SqlCommand("Select FeeHeadName from mstFeeHead where FeeHeadName=@FeeHeadName", sqlcon);
cmd.Parameters.Add("@FeeHeadName", SqlDbType.VarChar).Value = txtNameofHead.Text.Trim();
DataTable dt = new DataTable();
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(dt);
if (dt.Rows.Count)
{
Interaction.MsgBox("Fee Head Name is already existed!!!!!");
Clear();
return;
}
InsertFeeHead("insert into mstFeeHead([FeeHeadName],[TypeofHead],[Frequency],[January],[February],[March],[April],[May],[June],[July],[August],[September],[October],[November],[December]) values (@FeeHeadName,@TypeofHead,@Frequency,@January,@February,@March,@April,@May,@June,@July,@August,@September,@October,@November,@December)");
LoadFeeHeads();
txtNameofHead.Text = "";
rbtnAnually.Checked = false;
rbtnHalfYearly.Checked = false;
rbtnMonthly.Checked = false;
rbtnQuarterly.Checked = false;
rbtnNonRefundable.Checked = false;
rbtnRefundable.Checked = false;
rbtnVariant.Checked = false;
btnCreate.Enabled = false;
for (int i = 0; i <= chklbMonth.Items.Count - 1; i++)
chklbMonth.SetItemCheckState(i, CheckState.Unchecked);
txtNameofHead.Focus();
}
private void btnDelete_Click(System.Object sender, System.EventArgs e)
{
MsgBoxResult msgresult = Interaction.MsgBox("Do you really want to delete!!!!", MsgBoxStyle.YesNo);
if (msgresult == MsgBoxResult.Yes)
DeleteFeeHead(" delete from mstFeeHead where FeeHeadID=@FeeHeadID");
LoadFeeHeads();
txtNameofHead.Text = null;
rbtnAnually.Checked = false;
rbtnHalfYearly.Checked = false;
rbtnMonthly.Checked = false;
rbtnQuarterly.Checked = false;
rbtnNonRefundable.Checked = false;
rbtnRefundable.Checked = false;
rbtnVariant.Checked = false;
btnDelete.Enabled = false;
btnCreate.Enabled = false;
for (int i = 0; i <= chklbMonth.Items.Count - 1; i++)
chklbMonth.SetItemCheckState(i, CheckState.Unchecked);
txtNameofHead.Focus();
}
private void dgvFeeHeads_CellDoubleClick(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
{
if (dgvFeeHeads.RowCount > 0)
{
btnDelete.Enabled = true;
btnCreate.Enabled = false;
for (int index = 0; index <= chklbMonth.Items.Count - 1; index++)
chklbMonth.SetItemChecked(index, false);
FeeHeadID = dgvFeeHeads.CurrentRow.Cells("FeeHeadID").Value;
txtNameofHead.Text = dgvFeeHeads.CurrentRow.Cells("FeeHeadName").Value;
if (dgvFeeHeads.CurrentRow.Cells("Frequency").Value.ToString() == "Quarterly")
rbtnQuarterly.Checked = true;
else if (dgvFeeHeads.CurrentRow.Cells("Frequency").Value.ToString() == "Half Yearly")
rbtnHalfYearly.Checked = true;
else if (dgvFeeHeads.CurrentRow.Cells("Frequency").Value.ToString() == "Annualy")
rbtnAnually.Checked = true;
else if (dgvFeeHeads.CurrentRow.Cells("Frequency").Value.ToString() == "Monthly")
rbtnMonthly.Checked = true;
else if (dgvFeeHeads.CurrentRow.Cells("Frequency").Value.ToString() == "Variant")
rbtnVariant.Checked = true;
if (dgvFeeHeads.CurrentRow.Cells("TypeofHead").Value.ToString().Trim() == "Refundable")
rbtnRefundable.Checked = true;
if (dgvFeeHeads.CurrentRow.Cells("TypeofHead").Value.ToString().Trim() == "NonRefundable")
rbtnNonRefundable.Checked = true;
if (dgvFeeHeads.CurrentRow.Cells("January").Value.ToString() == "True")
chklbMonth.SetItemChecked(0, true);
if (dgvFeeHeads.CurrentRow.Cells("February").Value.ToString() == "True")
chklbMonth.SetItemChecked(1, true);
if (dgvFeeHeads.CurrentRow.Cells("March").Value.ToString() == "True")
chklbMonth.SetItemChecked(2, true);
if (dgvFeeHeads.CurrentRow.Cells("April").Value.ToString() == "True")
chklbMonth.SetItemChecked(3, true);
if (dgvFeeHeads.CurrentRow.Cells("May").Value.ToString() == "True")
chklbMonth.SetItemChecked(4, true);
if (dgvFeeHeads.CurrentRow.Cells("June").Value.ToString() == "True")
chklbMonth.SetItemChecked(5, true);
if (dgvFeeHeads.CurrentRow.Cells("July").Value.ToString() == "True")
chklbMonth.SetItemChecked(6, true);
if (dgvFeeHeads.CurrentRow.Cells("August").Value.ToString() == "True")
chklbMonth.SetItemChecked(7, true);
if (dgvFeeHeads.CurrentRow.Cells("September").Value.ToString() == "True")
chklbMonth.SetItemChecked(8, true);
if (dgvFeeHeads.CurrentRow.Cells("October").Value.ToString() == "True")
chklbMonth.SetItemChecked(9, true);
if (dgvFeeHeads.CurrentRow.Cells("November").Value.ToString() == "True")
chklbMonth.SetItemChecked(10, true);
if (dgvFeeHeads.CurrentRow.Cells("December").Value.ToString() == "True")
chklbMonth.SetItemChecked(11, true);
btnCreate.Enabled = false;
}
}
private void txtNameofHead_TextChanged(object sender, System.EventArgs e)
{
btnCreate.Enabled = true;
}
private void txtNameofHead_KeyDown(System.Object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
rbtnMonthly.Focus();
}
private void rbtnMonthly_KeyDown(System.Object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode == Keys.Down)
rbtnQuarterly.Focus();
}
private void rbtnQuarterly_KeyDown(System.Object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
rbtnHalfYearly.Focus();
}
private void rbtnHalfYearly_KeyDown(System.Object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
rbtnAnually.Focus();
}
private void rbtnAnually_KeyDown(System.Object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
rbtnVariant.Focus();
}
private void rbtnVariant_KeyDown(System.Object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
chklbMonth.Focus();
}
private void btnClear_Click(System.Object sender, System.EventArgs e)
{
Clear();
txtNameofHead.Focus();
}
private void Clear()
{
for (int index = 0; index <= chklbMonth.Items.Count - 1; index++)
chklbMonth.SetItemChecked(index, false);
txtNameofHead.Text = "";
rbtnAnually.Checked = false;
rbtnHalfYearly.Checked = false;
rbtnMonthly.Checked = false;
rbtnQuarterly.Checked = false;
rbtnNonRefundable.Checked = false;
rbtnRefundable.Checked = false;
rbtnVariant.Checked = false;
btnCreate.Enabled = true;
btnDelete.Enabled = false;
}
private void rbtnRefundable_KeyDown(System.Object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode == Keys.Down)
rbtnNonRefundable.Focus();
}
private void rbtnNonRefundable_KeyDown(System.Object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode == Keys.Down)
rbtnRefundable.Focus();
}
private void frmFeeHeads_KeyDown(System.Object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyValue == 27)
{
this.Close();
MainForm.objOpenedForm = new Form();
}
}
}
use table 
CREATE TABLE [dbo].[mstFeeHead](
[FeeHeadID] [int] IDENTITY(1,1) NOT NULL,
[FeeHeadName] [varchar](50) NULL,
[TypeofHead] [nchar](50) NULL,
[Frequency] [varchar](50) NULL,
[January] [bit] NULL,
[February] [bit] NULL,
[March] [bit] NULL,
[April] [bit] NULL,
[May] [bit] NULL,
[June] [bit] NULL,
[July] [bit] NULL,
[August] [bit] NULL,
[September] [bit] NULL,
[October] [bit] NULL,
[November] [bit] NULL,
[December] [bit] NULL,
CONSTRAINT [PK_mstFeeHead] PRIMARY KEY CLUSTERED
(
[FeeHeadID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
-------------------
one text use name
txtNameofHead
use Five radioButton name
rbtnMonthly
rbtnQuarterly
rbtnHalfYearly
rbtnAnually
rbtnVariant
one checkedlistbox use name
chklbMonth
Collection item name Jan,Feb, March, April, May ,June, July, Aug, sep,Oct,Nov,Dec
two radioButton use name
rbtnRefundable
rbtnNonRefundable
One gridview use name
dgvFeeHeads
Four Button new,save, Clear, Delete, close,Update

Answers (2)