Example #1
0
        public frm_Receipt(Receipt.DataSetForReceipt dataSetForReceipt)
        {
            InitializeComponent();

            prescriptonBindingSource.DataSource = dataSetForReceipt.Prescripton;
            ReportDataSource reportDataSource = new ReportDataSource("Prescripton", prescriptonBindingSource);

            this.reportViewer1.LocalReport.DataSources.Add(reportDataSource);
        }
Example #2
0
        private void btn_save_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Do you want to save?", "Confirmation", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                try
                {
                    str = "Data Source=.;Initial Catalog=skin_cilinic;Integrated Security=True";
                    con = new SqlConnection(str);
                    con.Open();
                    dt = new DataTable();
                    dt.Columns.Add("pid", typeof(int));
                    dt.Columns.Add("qty", typeof(int));

                    foreach (DataGridViewRow row in dataGridView1.Rows)
                    {
                        if (!row.IsNewRow)
                        {
                            int pid = int.Parse(row.Cells[3].Value.ToString());
                            int qty = int.Parse(row.Cells[2].Value.ToString());
                            dt.Rows.Add(pid, qty);
                        }
                    }
                    SqlParameter t = new SqlParameter("@y", SqlDbType.Structured)
                    {
                        TypeName = "dbo.ty_many",
                        Value    = dt
                    };
                    SqlCommand cmd = new SqlCommand("sp_insert_order", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    try
                    {
                        cmd.Parameters.AddWithValue("con", int.Parse(txt_consultation.Text));
                    }
                    catch (ArgumentException ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    cmd.Parameters.AddWithValue("@cui", class1.id);

                    cmd.Parameters.Add(t);
                    cmd.ExecuteNonQuery();

                    /* Get Data From Datagridview to DataSetForReceipt into Prescription by Chhantana */
                    receipt = new Receipt.DataSetForReceipt();
                    for (int i = 0; i < dataGridView1.Rows.Count; i++)
                    {
                        receipt.Prescripton.Rows.Add(
                            (++ord_id),
                            pro_id[i],
                            dataGridView1[0, i].Value,                                 // Product Name
                            int.Parse(dataGridView1[2, i].Value.ToString().Trim()),    // Qty
                            dataGridView1[1, i].Value,                                 // Category Name
                            double.Parse(dataGridView1[4, i].Value.ToString().Trim()), // Price
                            double.Parse(txt_consultation.Text.Trim()),                // Consulation
                            getTotal());                                               // Total
                        lastPrescription += 1;
                        this.AppendHistoryForPrescription(
                            dataGridView1[0, i].Value.ToString().Trim(),
                            int.Parse(dataGridView1[2, i].Value.ToString().Trim()),
                            dataGridView1[1, i].Value.ToString().Trim()
                            );
                    }
                    dataGridView1.Rows.Clear();
                    con.Close();
                    if (MessageBox.Show("Your data have been saved successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information) == DialogResult.OK)
                    {
                        this.Close();
                        th = new Thread(openMedicine);
                        th.SetApartmentState(ApartmentState.STA);
                        th.Start();

                        frm_History f = (frm_History)frm_History.ActiveForm;
                        f.RefreshHistoryInformation();
                    }
                }

                catch (SqlException x)
                {
                    MessageBox.Show(x.Message);
                    throw;
                }
            }
            else
            {
                return;
            }
        }