コード例 #1
0
        //Load the job numbers in the dropdown.
        private void Form1_Load(object sender, EventArgs e)
        {
            KeyPreview = true;
            SqlConnection con = new SqlConnection();

            con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["VedConnections"].ConnectionString;
            con.Open();
            try
            {
                SqlCommand cmd = new SqlCommand();
                cmd.Connection  = con;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "LoadJobNumbers";
                SqlDataReader sdr = cmd.ExecuteReader();
                //DataTable dt = new DataTable();
                //dt.Load(sdr);
                IList <string> jobList = new List <string>();
                jobList.Add("Select");

                while (sdr.Read())
                {
                    jobList.Add(sdr[0].ToString());
                }
                con.Close();
                ddlJobList.DataSource = jobList;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            // TODO: This line of code loads data into the 'cOSCDataSet.COSCREPORTS' table. You can move, or remove it, as needed.
            this.cOSCREPORTSTableAdapter1.Fill(this.cOSCDataSet.COSCREPORTS);
            CoscDAL   objCoscDAL = new CoscDAL();
            DataTable dtJobs     = objCoscDAL.getJobs();

            cmbJobNo.Enabled    = true;
            cmbJobNo.DataSource = dtJobs;
            //cmbJobNo.Items.Add("---Select Job---");

            cmbJobNo.ValueMember   = "jobno";
            cmbJobNo.DisplayMember = "jobno";
            //for job details in inventory
            cmbJobNoInventory.DataSource    = dtJobs;
            cmbJobNoInventory.ValueMember   = "jobno";
            cmbJobNoInventory.DisplayMember = "jobno";

            cmbJobNo.Enabled = true;


            //Data from Scanner to txtBarcodeID

            //SerialPort _serialPort = new SerialPort("COM1");
            //_serialPort.BaudRate = 9600;
            //_serialPort.Parity = Parity.None;
            //_serialPort.StopBits = StopBits.One;
            //_serialPort.DataBits = 8;
            //_serialPort.Handshake = Handshake.None;
            //_serialPort.RtsEnable = true;

            //_serialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);

            //_serialPort.Open();
        }
コード例 #2
0
        //this is for searching the product with the barcode id
        private void FillData(string barcodeID)
        {
            //  dictionary.Add(Convert.ToInt32(barcodeID), i);
            try
            {
                if (barcodeID == string.Empty)
                {
                    barcodeID = txtBarcodeId.Text;
                }
                //load data into the gridview
                if (barcodeID != string.Empty || gdvProductdetails.Rows.Count == 0)
                {
                    SqlConnection connProductDetails = new SqlConnection(coscConnectionString);
                    connProductDetails.Open();
                    SqlCommand commProductDetails = new SqlCommand("getProductDetails", connProductDetails);
                    commProductDetails.CommandType = CommandType.StoredProcedure;
                    commProductDetails.Parameters.AddWithValue("@barcodeId", barcodeID);
                    commProductDetails.Parameters.AddWithValue("@JobNo", cmbJobNo.Text);
                    commProductDetails.Parameters.Add("@isDataExists", SqlDbType.Bit).Direction = ParameterDirection.Output;
                    commProductDetails.ExecuteNonQuery();
                    int isDataExists = Convert.ToInt32(commProductDetails.Parameters["@isDataExists"].Value);
                    if (isDataExists == 1)
                    {
                        //tableFillSpecificDetails.Clear();
                        incrementNoOfScans = true;
                        SqlDataAdapter dataAdapterFillSpecificDetails = new SqlDataAdapter();
                        dataAdapterFillSpecificDetails.SelectCommand = commProductDetails;
                        dataAdapterFillSpecificDetails.Fill(tableFillSpecificDetails);

                        //The data set is empty : for a job there is no product matching with the barcode id - Throw a error message
                        if (tableFillSpecificDetails.Rows.Count == 0)
                        {
                            MessageBox.Show("Sorry! No matching details found. Please check the Jobno and barcode id.");
                            firstScan--;
                        }
                        // the scan when it contains job number other than selected job number

                        //else if (Convert.ToString(tableFillSpecificDetails.Rows[noOfScans][1])!=cmbJobNo.Text)
                        //{
                        //    MessageBox.Show("Current Job is currently being scanned");
                        //}
                        else
                        {
                            if (firstScan < 2 || gdvProductdetails.RowCount == 0)
                            {
                                gdvProductdetails.Columns.Add("barcodeid", "Id");
                                gdvProductdetails.Columns.Add("jobno", "Job");
                                gdvProductdetails.Columns.Add("projectname", "Project");
                                gdvProductdetails.Columns.Add("customer", "Customer");
                                gdvProductdetails.Columns.Add("area", "Area");
                                gdvProductdetails.Columns.Add("serialno", "S.No");
                                gdvProductdetails.Columns.Add("itemdescription", "Description");
                                gdvProductdetails.Columns.Add("w", "Width");
                                gdvProductdetails.Columns.Add("h", "Height");
                                gdvProductdetails.Columns.Add("w1", "Width1");
                                gdvProductdetails.Columns.Add("h1", "Height1");
                                gdvProductdetails.Columns.Add("length", "Length");
                                gdvProductdetails.Columns.Add("numberofunits", "No.units");
                                gdvProductdetails.Columns.Add("gauge", "Gauge");
                                gdvProductdetails.Columns.Add("uom", "Uom");
                                gdvProductdetails.Columns.Add("unitquantity", "UnitQuantity");
                                gdvProductdetails.Columns.Add("totalquantity", "TotalQuantity");
                                gdvProductdetails.Columns.Add("inventory", "inventory");

                                tableforReports.Columns.Add("reportnumber", typeof(String));
                                tableforReports.Columns.Add("vehiclenumber", typeof(String));
                                tableforReports.Columns.Add("reportdate", typeof(DateTime));
                                tableforReports.Columns.Add("barcodeid", typeof(Int32));
                                tableforReports.Columns.Add("jobno", typeof(String));
                                tableforReports.Columns.Add("projectname", typeof(String));
                                tableforReports.Columns.Add("customer", typeof(String));
                                tableforReports.Columns.Add("area", typeof(String));
                                tableforReports.Columns.Add("serialno", typeof(String));
                                tableforReports.Columns.Add("itemdescription", typeof(String));
                                tableforReports.Columns.Add("w", typeof(Int32));
                                tableforReports.Columns.Add("h", typeof(Int32));
                                tableforReports.Columns.Add("w1", typeof(Int32));
                                tableforReports.Columns.Add("h1", typeof(Int32));
                                tableforReports.Columns.Add("length", typeof(Int32));
                                tableforReports.Columns.Add("numberofunits", typeof(Int32));
                                tableforReports.Columns.Add("gauge", typeof(Int32));
                                tableforReports.Columns.Add("uom", typeof(String));
                                tableforReports.Columns.Add("unitquantity", typeof(Double));
                                tableforReports.Columns.Add("totalquantity", typeof(Double));
                                tableforReports.Columns.Add("seqno", typeof(Int32));
                            }


                            if (oldBarcodeID != "" && barcodeID != oldBarcodeID || !dictionary.ContainsKey(Convert.ToInt32(barcodeID)))
                            {
                                if (!dictionary.ContainsKey(Convert.ToInt32(barcodeID)))
                                {
                                    DataRow dr = tableFillSpecificDetails.Rows[noOfScans];
                                    dictionary.Add(Convert.ToInt32(barcodeID), rowC);
                                    rowC = rowC + 1;
                                    {
                                        //if (barcodeID != oldBarcodeID)
                                        {
                                            gdvProductdetails.Rows.Add(
                                                dr[0].ToString(),
                                                dr[1].ToString(),
                                                dr[2].ToString(),
                                                dr[3].ToString(),
                                                dr[4].ToString(),
                                                dr[5].ToString(),
                                                dr[6].ToString(),
                                                dr[7].ToString(),
                                                dr[8].ToString(),
                                                dr[9].ToString(),
                                                dr[10].ToString(),
                                                dr[11].ToString(),
                                                dr[12].ToString(),
                                                dr[13].ToString(),
                                                dr[14].ToString(),
                                                dr[15].ToString(),
                                                dr[16].ToString(),
                                                dr[17].ToString()

                                                );

                                            CoscDAL _coscDal = new CoscDAL();
                                            int     maxNo    = _coscDal.getMaxReportNumber();

                                            //generate Number

                                            reportNumber = "COSC" + maxNo + "RPT";

                                            string   vehicleNumber = txtVehicleNo.Text;
                                            DateTime dateNow       = DateTime.Now.Date;
                                            tableforReports.Rows.Add(
                                                reportNumber,
                                                vehicleNumber,
                                                dateNow,
                                                Convert.ToString(dr[0]),
                                                Convert.ToString(dr[1]),
                                                Convert.ToString(dr[2]),
                                                Convert.ToString(dr[3]),
                                                Convert.ToString(dr[4]),
                                                Convert.ToString(dr[5]),
                                                Convert.ToString(dr[6]),
                                                Convert.ToString(dr[7]) == string.Empty ? 0 : Convert.ToInt32(dr[7]),
                                                Convert.ToString(dr[8]) == string.Empty ? 0 : Convert.ToInt32(dr[8]),
                                                Convert.ToString(dr[9]) == string.Empty ? 0 : Convert.ToInt32(dr[9]),
                                                Convert.ToString(dr[10]) == string.Empty ? 0 : Convert.ToInt32(dr[10]),
                                                Convert.ToString(dr[11]) == string.Empty ? 0 : Convert.ToInt32(dr[11]),
                                                Convert.ToString(dr[12]) == string.Empty ? 0 : Convert.ToInt32(dr[12]),
                                                Convert.ToString(dr[13]) == string.Empty ? 0 : Convert.ToInt32(dr[13]),
                                                Convert.ToString(dr[14]),
                                                Convert.ToString(dr[15]),
                                                Convert.ToString(dr[16]), maxNo);
                                            tableforReports.AcceptChanges();

                                            int columnCount = gdvProductdetails.Columns.Count;

                                            for (int j = 0; j < columnCount; j++)
                                            {
                                                gdvProductdetails.Columns[j].ReadOnly = true;
                                            }
                                            gdvProductdetails.Columns[0].Visible = false;

                                            //resize the data grid after loading the data
                                            gdvProductdetails.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
                                        }
                                    }
                                }
                                else
                                {
                                    int value1;
                                    dictionary.TryGetValue(Convert.ToInt32(barcodeID), out value1);
                                    incrementQuantity(value1);
                                }
                            }
                            else
                            {
                                int value;
                                dictionary.TryGetValue(Convert.ToInt32(barcodeID), out value);
                                incrementQuantity(value);
                            }
                        }
                    }
                    else
                    {
                        incrementNoOfScans = false;
                    }
                    if (incrementNoOfScans == true)
                    {
                        noOfScans += 1;
                    }
                    else
                    {
                        MessageBox.Show("Current job in progress");
                    }
                }
                else
                {
                    MessageBox.Show("Please check and re-enter the barcode");
                    firstScan--;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
            oldBarcodeID      = txtBarcodeId.Text;
            txtBarcodeId.Text = string.Empty;
        }