예제 #1
0
        private void Insertbtn_Click(object sender, EventArgs e)
        {
            if (nameTxt.Text == "")
            {
                nameTxt.BackColor = Color.LightPink;
                MessageBox.Show("Name is required", "validation error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                nameTxt.Focus();
                return;
            }
            if (dtmtxt.Text == "")
            {
                dtmtxt.BackColor = Color.LightPink;
                MessageBox.Show("Name is required", "validation error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                dtmtxt.Focus();
                return;
            }
            if (ConNumtxt.Text == "")
            {
                ConNumtxt.BackColor = Color.LightPink;
                MessageBox.Show("Name is required", "validation error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                ConNumtxt.Focus();
                return;
            }

            if (Addresstxt.Text == "")
            {
                Addresstxt.BackColor = Color.LightPink;
                MessageBox.Show("Name is required", "validation error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Addresstxt.Focus();
                return;
            }
            if (Agetxt.Text == "")
            {
                Agetxt.BackColor = Color.LightPink;
                MessageBox.Show("Name is required", "validation error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Agetxt.Focus();
                return;
            }
            if (HosChartxt.Text == "")
            {
                HosChartxt.BackColor = Color.LightPink;
                MessageBox.Show("Name is required", "validation error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                HosChartxt.Focus();
                return;
            }
            if (ProfChartxt.Text == "")
            {
                ProfChartxt.BackColor = Color.LightPink;
                MessageBox.Show("Name is required", "validation error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                ProfChartxt.Focus();
                return;
            }
            try
            {
                if (con.State == ConnectionState.Closed)
                {
                    con.Open();
                }
                if (Insertbtn.Text == "Insert")
                {
                    SqlCommand sqlCmd = new SqlCommand("OutPBill", con);
                    sqlCmd.CommandType = CommandType.StoredProcedure;
                    sqlCmd.Parameters.AddWithValue("@mode", "Add");
                    sqlCmd.Parameters.AddWithValue("@PatientId", 0);
                    sqlCmd.Parameters.AddWithValue("@Name", nameTxt.Text.Trim());
                    sqlCmd.Parameters.AddWithValue("@Date", dtmtxt.Value.Date);
                    sqlCmd.Parameters.AddWithValue("@Contact_Number", ConNumtxt.Text.Trim());
                    sqlCmd.Parameters.AddWithValue("@Address", Addresstxt.Text.Trim());
                    sqlCmd.Parameters.AddWithValue("@Age", Agetxt.Text.Trim());
                    sqlCmd.Parameters.AddWithValue("@Hospital_Charge", HosChartxt.Text.Trim());
                    sqlCmd.Parameters.AddWithValue("@profs_Charge", ProfChartxt.Text.Trim());
                    sqlCmd.ExecuteNonQuery();
                    MessageBox.Show("Data inserted successfully");
                }
                Reset();
                FillDataGridView();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error Message");
            }
            finally
            {
                con.Close();
            }
            try
            {
                if (con.State == ConnectionState.Closed)
                {
                    con.Open();
                }
                if (Insertbtn.Text == "Insert")
                {
                    SqlCommand sqlCmd = new SqlCommand("OutPDProc", con);
                    sqlCmd.CommandType = CommandType.StoredProcedure;
                    sqlCmd.Parameters.AddWithValue("@mode", "Add");
                    sqlCmd.Parameters.AddWithValue("@PatientId", 0);
                    sqlCmd.Parameters.AddWithValue("@Name", nameTxt.Text.Trim());
                    sqlCmd.Parameters.AddWithValue("@Contact_Number", ConNumtxt.Text.Trim());
                    sqlCmd.Parameters.AddWithValue("@Address", Addresstxt.Text.Trim());
                    sqlCmd.Parameters.AddWithValue("@Age", Agetxt.Text.Trim());
                }
                Reset1();
                FillDataGridView1();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error Message");
            }
            finally
            {
                con.Close();
            }
        }