private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (ScholarshipID.Text == "")
                {
                    MessageBox.Show("Please select Scholarship ID", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    ScholarshipID.Focus();
                    return;
                }
                if (ScholarNo.Text == "")
                {
                    MessageBox.Show("Please select Scholar No.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    ScholarNo.Focus();
                    return;
                }


                if (ModeOfPayment.Text == "")
                {
                    MessageBox.Show("Please select mode of payment", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    ModeOfPayment.Focus();
                    return;
                }
                if (TotalPaid.Text == "")
                {
                    MessageBox.Show("Please enter total paid", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    TotalPaid.Focus();
                    return;
                }
                if (int.Parse(TotalPaid.Text) > int.Parse(Amount.Text))
                {
                    MessageBox.Show("total paid can not be more than scholarship amount", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    TotalPaid.Text = "";
                    TotalPaid.Focus();
                    return;
                }

                auto();
                con = new SqlConnection(cs);
                con.Open();
                string ct = "select ScholarshipPaymentID from ScholarshipPayment where ScholarshipPaymentID=@find";

                cmd            = new SqlCommand(ct);
                cmd.Connection = con;
                cmd.Parameters.Add(new SqlParameter("@find", System.Data.SqlDbType.NChar, 20, "ScholarshipPaymentID"));
                cmd.Parameters["@find"].Value = ScholarshipPaymentID.Text;
                rdr = cmd.ExecuteReader();

                if (rdr.Read())
                {
                    MessageBox.Show("Scholarship Payment ID Already Exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    ScholarshipPaymentID.Text = "";



                    if ((rdr != null))
                    {
                        rdr.Close();
                    }
                    return;
                }

                con = new SqlConnection(cs);
                con.Open();

                string cb = "insert into ScholarshipPayment(ScholarshipPaymentID,Scholarshipid,Scholarshipname,amount,ScholarNo,StudentName,Course,Branch,PaymentDate,PaymentMode,PaymentModeDetails,TotalPaid,DuePayment) VALUES (@d1,@d2,@d3,@d5,@d6,@d7,@d8,@d9,@d10,@d11,@d12,@d13,@d14)";

                cmd = new SqlCommand(cb);

                cmd.Connection = con;
                cmd.Parameters.Add(new SqlParameter("@d1", System.Data.SqlDbType.NChar, 20, "ScholarshipPaymentID"));

                cmd.Parameters.Add(new SqlParameter("@d2", System.Data.SqlDbType.NChar, 20, "ScholarshipID"));

                cmd.Parameters.Add(new SqlParameter("@d3", System.Data.SqlDbType.NChar, 30, "Scholarshipname"));


                cmd.Parameters.Add(new SqlParameter("@d5", System.Data.SqlDbType.NChar, 10, "Amount"));
                cmd.Parameters.Add(new SqlParameter("@d6", System.Data.SqlDbType.NChar, 15, "ScholarNo"));

                cmd.Parameters.Add(new SqlParameter("@d7", System.Data.SqlDbType.NChar, 30, "StudentName"));
                cmd.Parameters.Add(new SqlParameter("@d8", System.Data.SqlDbType.NChar, 20, "Course"));

                cmd.Parameters.Add(new SqlParameter("@d9", System.Data.SqlDbType.NChar, 30, "Branch"));



                cmd.Parameters.Add(new SqlParameter("@d10", System.Data.SqlDbType.NChar, 30, "PaymentDate"));

                cmd.Parameters.Add(new SqlParameter("@d11", System.Data.SqlDbType.NChar, 20, "PaymentMode"));
                cmd.Parameters.Add(new SqlParameter("@d12", System.Data.SqlDbType.VarChar, 200, "PaymentModeDetails"));
                cmd.Parameters.Add(new SqlParameter("@d13", System.Data.SqlDbType.NChar, 10, "TotalPaid"));
                cmd.Parameters.Add(new SqlParameter("@d14", System.Data.SqlDbType.NChar, 10, "DueFees"));
                cmd.Parameters["@d1"].Value = ScholarshipPaymentID.Text.Trim();
                cmd.Parameters["@d2"].Value = ScholarshipID.Text.Trim();
                cmd.Parameters["@d3"].Value = ScholarshipName.Text.Trim();

                cmd.Parameters["@d5"].Value = Amount.Text.Trim();
                cmd.Parameters["@d6"].Value = ScholarNo.Text.Trim();
                cmd.Parameters["@d7"].Value = StudentName.Text.Trim();
                cmd.Parameters["@d8"].Value = Course.Text.Trim();
                cmd.Parameters["@d9"].Value = Branch.Text.Trim();


                cmd.Parameters["@d10"].Value = (PaymentDate.Text);
                cmd.Parameters["@d11"].Value = (ModeOfPayment.Text);
                cmd.Parameters["@d12"].Value = (PaymentModeDetails.Text);
                cmd.Parameters["@d13"].Value = (TotalPaid.Text);

                cmd.Parameters["@d14"].Value = (DuePayment.Text);
                cmd.ExecuteNonQuery();
                MessageBox.Show("Successfully saved", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information);
                btnSave.Enabled = false;

                con.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 2
0
 private void frmScholarship_Load(object sender, EventArgs e)
 {
     Autocomplete();
     ScholarshipID.Focus();
 }