Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

how to print picturebox datas upon creation in c# windows forms with sql server2008

$
0
0

Hi my name is vishal for past 20days i have been breaking my head on how to print picturebox datas upon creation in c# windows forms? I have a form named:frmDialyzer in it are 1combobox control named:cboPatientID,1 button named:btnSearch and another button named:btnAssign,1pictureBox control named:pictureBox1,enabled:true and visible:true insidepictureBox1 are 1StrokeScribe control named:barCOrg(no need to worry about barcode generation as it is irrelevant here/i have already done it),enabled:true and visible:true and 1label control named:lblPID,enabled:true and visible:true. I have another PictureBox control named:pictureBox2,enabled:true and visible:false put on/embed onpictureBox1. Given below is my c# code of frmDialyzer:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;
using System.Drawing.Printing;
using System.Runtime.InteropServices;
using System.Drawing.Imaging;
namespace DRRS_CSharp
{
    public partial class frmDialyzer : Form
    {
         int pUserID;
         public frmDialyzer()
        {
            InitializeComponent();
            this.FillDropDownList();
            SqlConnection conn = new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=DRRS;Integrated Security=true");
            if (conn.State != ConnectionState.Open)
              {
                 conn.Open();
               }
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string ManufacturerPull = ("Select distinct(ManufacturerName) from EquipmentData");
            SqlCommand mcd = new SqlCommand(ManufacturerPull);
            mcd.Connection = conn;
            mcd.CommandType = CommandType.Text;
            SqlDataReader cdr = mcd.ExecuteReader();
            while (cdr.Read())
            {
                ManufacturerPull = cdr[0].ToString();
                cboManufacturer.Items.Add(ManufacturerPull);
            }
            cdr.Close();
        }
 private void btnNext_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=DRRS;Integrated Security=true");
                    if (conn.State != ConnectionState.Open)
                    {
                        conn.Open();
                    }
                   SqlCommand cmd = new SqlCommand();
                    cmd.Connection = conn;
                    cmd.CommandType = CommandType.Text;
                    string str;
                    string value = ("Select max(agn) from dialyser");
                    cmd = new SqlCommand(value, conn);
                    str = cmd.ExecuteScalar().ToString();
                    conn.Close();
       if (str == DBNull.Value.ToString())
                    {
                        txtDID.Text = string.Format("0000"+"1");
                    }
                    else
                    {
                        txtDID.Text = string.Format("0000"+(Convert.ToInt32(str) + 1).ToString());
                    }
barCOrg.Alphabet = STROKESCRIBELib.enumAlphabet.EAN13;
                    barCOrg.CtlText = "123456789012";
btnNext.Enabled = true;
                    button1.Enabled = true;
                    txtDID.Focus();
}
private void cboPatientID_SelectedValueChanged(object sender, EventArgs e)
        {
                btnSearch.Enabled = true;
                btnAssign.Enabled = true;
                SqlConnection conn = new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=DRRS;Integrated Security=true");
                if (conn.State != ConnectionState.Open)
                {
                    conn.Open();
                }
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = conn;
                cmd.CommandType = CommandType.Text;
                cmd = new SqlCommand("Select * from patient_name where status=1 and patient_id=" + cboPatientID.GetItemText(cboPatientID.SelectedIndex) + "'", conn);
                if (txtDID.Text.Length > 5)
                {
                    txtDID.Text = txtDID.Text.Substring(5);
                }
                lblPID.Text = cboPatientID.Text;
                cmd = new SqlCommand();
                cmd.Connection = conn;
                cmd.CommandType = CommandType.Text;
                string str;
                string value = ("Select max(agn) from dialyser");
                cmd = new SqlCommand(value, conn);
                str = cmd.ExecuteScalar().ToString();
                conn.Close();
if (str == DBNull.Value.ToString())
                {
                    txtDID.Text = string.Format("0000"+"1");
                }
                else
                {
                    txtDID.Text = string.Format("0000"+(Convert.ToInt32(str) + 1).ToString());
                }
barCOrg.Alphabet = STROKESCRIBELib.enumAlphabet.CODE128;
                barCOrg.CtlText = txtDID.Text;
int rc = 0;
                rc = barCOrg.SavePicture("bar2.bmp", STROKESCRIBELib.enumFormats.BMP, barCOrg.Width, barCOrg.Height);
if (rc > 0)
                {
                    MessageBox.Show(barCOrg.ErrorDescription);
                }
                else
                {
                    btnSearch.Enabled = true;
                    btnAssign.Enabled = true;
                }
            }
public void FillDropDownList()
        {
            string Sql = "Select p.patient_id as patient_id,(n.patient_first_name+' '+n.patient_last_name) as Name from patient_id p,patient_name n where n.patient_id=p.patient_id and n.status=1 and not exists(Select * from dialyser where dialyser.deleted_status=0 and dialyser.closed_status=0 and dialyser.patient_id=p.patient_id)";
            DataTable dt = new DataTable();
            SqlConnection conn = new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=DRRS;Integrated Security=true");
            if (conn.State != ConnectionState.Open)
            {
                conn.Open();
            }
            SqlCommand cmd = new SqlCommand(Sql, conn);
            dt.Load(cmd.ExecuteReader());
            cboPatientID.DataSource = dt;
            cboPatientID.ValueMember = "patient_id";
            cboPatientID.DisplayMember = "Name";
            cboPatientID.SelectedValue = 0;
        }
private void button1_Click(object sender, EventArgs e)
        {
            btnNext.Enabled = true;
            button1.Enabled = true;
            txtDID.Enabled = false;
            SqlConnection conn = new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=DRRS;Integrated Security=true");
            if (conn.State != ConnectionState.Open)
            {
                conn.Open();
            }
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string str;
            string value = ("Select max(agn) from dialyser");
            cmd = new SqlCommand(value, conn);
            str = cmd.ExecuteScalar().ToString();
            conn.Close();
            if (str == DBNull.Value.ToString())
            {
                txtDID.Text = string.Format("0000"+"1");
            }
            else
            {
                txtDID.Text = (string.Format("0000" + (Convert.ToInt32(str) + 1).ToString()));
            }
 barCOrg.Alphabet = STROKESCRIBELib.enumAlphabet.CODE128;
            barCOrg.CtlText = string.Format(txtDID.Text);
int rc = 0;
            rc = barCOrg.SavePicture("bar2.bmp", STROKESCRIBELib.enumFormats.BMP, barCOrg.Width, barCOrg.Height);
            if (rc > 0)
            {
                MessageBox.Show(barCOrg.ErrorDescription);
            }
            button1.Enabled = false;
            btnNext.Enabled = true;
        }
private void btnSearch_Click(object sender, EventArgs e)
        {
            string dPatientID;
            dPatientID = Convert.ToString(cboPatientID.SelectedValue);
            frmPatient p = new frmPatient();
            p.loadPatientID(dPatientID);
            p.Show();
        }
 private void btnAssign_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=DRRS;Integrated Security=true");
            if (conn.State != ConnectionState.Open)
            {
                conn.Open();
            }
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            int autoGenId = -1;
            cmd = new SqlCommand("Insert into dialyser(dialyserID,manufacturer,mfr_ref_number,mfr_lot_number,mfr_date,exp_date,start_date,packed_volume,dialyzer_size,deleted_status,closed_status,patient_id,row_upd_date,user_id)" + "Values(@dialyserID,@manufacturer,@mfr_ref_number,@mfr_lot_number,@mfr_date,@exp_date,@start_date,@packed_volume,@dialyzer_size,@deleted_status,@closed_status,@patient_id,GetDate(),@user_id);Select @autoGenId = SCOPE_IDENTITY();", conn);
            cmd.Parameters.AddWithValue("@dialyserID", txtDID.Text.ToString());
            cmd.Parameters.AddWithValue("@manufacturer", cboManufacturer.Text.ToString());
            cmd.Parameters.AddWithValue("@mfr_ref_number", txtMFRRefNo.Text.ToString());
            cmd.Parameters.AddWithValue("@mfr_lot_number", txtMFRLotNo.Text.ToString());
            cmd.Parameters.AddWithValue("@mfr_date", dtMFRDate.Value);
            cmd.Parameters.AddWithValue("@exp_date", dtExpDate.Value);
            cmd.Parameters.AddWithValue("@start_date", dtStartDate.Value);
            cmd.Parameters.AddWithValue("@packed_volume", txtPVol.Text.ToString());
            cmd.Parameters.AddWithValue("@dialyzer_size", cboequipmentType.Text.ToString());
            cmd.Parameters.AddWithValue("@deleted_status", 0);
            cmd.Parameters.AddWithValue("@closed_status", 0);
            cmd.Parameters.AddWithValue("@patient_id", cboPatientID.SelectedValue);
            cmd.Parameters.AddWithValue("@user_id", pUserID);
            cmd.Parameters.Add("@autoGenId", SqlDbType.Int).Direction = ParameterDirection.Output;
            cmd.ExecuteNonQuery();
            autoGenId = Convert.ToInt32(cmd.Parameters["@autoGenId"].Value);
((MDIParent1)this.MdiParent).updateUserActivities(autoGenId, 4, cboManufacturer.Text.ToString());
if (MessageBox.Show("Dialyzer detail was added successfully.Do you want to print the barcode dialyzerID?", "DRRS", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
            {
                System.Diagnostics.Process.Start("bar2.bmp");
            }
 this.Close();
}

The above code executes well with no problem at all! "bar2.bmp" is name of image created on StrokeScribe control named:barCOrg in c# windows forms with sql server2008. When i execute the above code i get created image of barcode(StrokeScribe control  named:barCOrg) only.!

But what i want is when the user Yes button from MessageBox he should get not only created image of barcode by StrokeScribe control(barCOrg) in c# windows forms with sql server2008 but also created data of label control named:lblPID which is on top of StrokeScribe control named:barCOrg.

So i have label control named:lblPID on top of StrokeScribe control(barCOrg)

StrokeScribe control named:barCOrg is just below lblPID insidepictureBox1.Both lblPID and barCOrg are insidepictureBox1. I just want to print/show only pictureBox1 datas(which hasbarCOrg and lblPID) upon creation to the user.

Can anyone tell me what should i need to do to achieve my required result? Should i need to use BitBlt function here to achieve my required result? Or Is there other ways of achieving the same required result in c# windows forms? If so please tell me/guide me/help me? Can anyone help me please? Any help/guidance in solving of this problem would be greatly appreciated!


vishal


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>