Beispiel #1
0
        private void btnempreg_Click(object sender, EventArgs e)
        {
            if (txtclientName.Text == "" || txtcnic.Text == "" || txtcaddrees.Text == "" || txtcphone.Text == "" || rdoMale.Checked == false && rdoFemale.Checked == false || cmbcdrug.Text == "" || cmbccounciller.Text == "" || txtcjob.Text == "" || txtcguardian.Text == "" || rdopayment.Checked == false && rdonunpayment.Checked == false)
            {
                MessageBox.Show("Please check the form again");

                if (txtclientName.Text == "")
                {
                    pnlfullname.Show();
                }
                if (txtcnic.Text == "")
                {
                    pnlcNic.Show();
                }
                if (txtcaddrees.Text == "")
                {
                    pnlcaddress.Show();
                }
                if (txtcphone.Text == "")
                {
                    pnlcPhone.Show();
                }
                if (rdoMale.Checked == false && rdoFemale.Checked == false)
                {
                    pnlcGender.Show();
                }
                if (cmbcdrug.Text == "")
                {
                    pnlcDrug.Show();
                }
                if (cmbccounciller.Text == "")
                {
                    pnlccounciller.Show();
                }
                if (txtcjob.Text == "")
                {
                    pnlcJob.Show();
                }
                if (txtcguardian.Text == "")
                {
                    pnlcGuardian.Show();
                }
                if (rdopayment.Checked == false && rdonunpayment.Checked == false)
                {
                    pnlrdopaymentorNon.Show();
                }
            }
            else
            {
                if (rdopayment.Checked == true || rdonunpayment.Checked == true)
                {
                    if (rdopayment.Checked == true)
                    {
                        clienttotal = "15000";

                        if (txtcpayment.Text == "")
                        {
                            MessageBox.Show("please check the form again");

                            pnlcPay.Show();
                        }
                        else
                        {
                            SqlDataAdapter adt = new SqlDataAdapter("select count(*) from ClientRegistation where NIC='" + txtcnic.Text + "'", con);
                            DataTable      dt  = new DataTable();
                            adt.Fill(dt);

                            if (dt.Rows[0][0].ToString() == "1")
                            {
                                MessageBox.Show("Already complete the Registation");
                            }


                            else
                            {
                                byte[] im = null;

                                FileStream   streem = new FileStream(imagelocation3, FileMode.Open, FileAccess.Read);
                                BinaryReader brs    = new BinaryReader(streem);
                                im = brs.ReadBytes((int)streem.Length);


                                con.Open();

                                SqlCommand cmd = new SqlCommand("INSERT INTO ClientRegistation(ClientID,FullName,Address,NIC,PhoneNumber,Birthday,Gender,MainDrug,Counciller,Job,GuardianName,JoinDate,PaymentOrNot,Total,Payment,DischargeDate,ClientPhoto)VALUES('" + clientId + "','" + txtclientName.Text + "','" + txtcaddrees.Text + "','" + txtcnic.Text + "','" + txtcphone.Text + "','" + dtpcbirth.Text + "','" + Gender + "','" + cmbcdrug.Text + "','" + cmbccounciller.Text + "','" + txtcjob.Text + "','" + txtcguardian.Text + "','" + Jdate + "','" + paymentNot + "','" + clienttotal + "','" + txtcpayment.Text + "','" + discharge + "',@im)", con);



                                cmd.Parameters.Add(new SqlParameter("@im", im));
                                cmd.ExecuteNonQuery();
                                con.Close();

                                MessageBox.Show("Save completed");

                                selectClient();

                                this.Close();

                                Home r = new Home(para, para2, typerec);

                                r.ShowDialog();
                            }
                        }
                    }
                    if (rdonunpayment.Checked == true)
                    {
                        clienttotal = "0";
                        SqlDataAdapter adt2 = new SqlDataAdapter("select count(*) from ClientRegistation where NIC='" + txtcnic.Text + "'", con);
                        DataTable      dt2  = new DataTable();
                        adt2.Fill(dt2);

                        if (dt2.Rows[0][0].ToString() == "1")
                        {
                            MessageBox.Show("Already complete the Registation");
                        }

                        else
                        {
                            byte[] img = null;

                            FileStream   streem = new FileStream(imagelocation3, FileMode.Open, FileAccess.Read);
                            BinaryReader brs    = new BinaryReader(streem);
                            img = brs.ReadBytes((int)streem.Length);


                            con.Open();

                            SqlCommand cmd = new SqlCommand("INSERT INTO ClientRegistation(ClientID,FullName,Address,NIC,PhoneNumber,Birthday,Gender,MainDrug,Counciller,Job,GuardianName,JoinDate,PaymentOrNot,Total,Payment,DischargeDate,ClientPhoto)VALUES('" + clientId + "','" + txtclientName.Text + "','" + txtcaddrees.Text + "','" + txtcnic.Text + "','" + txtcphone.Text + "','" + dtpcbirth.Text + "','" + Gender + "','" + cmbcdrug.Text + "','" + cmbccounciller.Text + "','" + txtcjob.Text + "','" + txtcguardian.Text + "','" + Jdate + "','" + paymentNot + "','" + clienttotal + "','" + txtcpayment.Text + "','" + discharge + "',@img)", con);



                            cmd.Parameters.Add(new SqlParameter("@img", img));
                            cmd.ExecuteNonQuery();
                            con.Close();

                            MessageBox.Show("Save completed");

                            selectClient();

                            this.Close();

                            Home r = new Home(para, para2, typerec);

                            r.ShowDialog();
                        }
                    }
                }
            }
        }