//public  int insertToBatchItemID(classItemBatch item)
        //{
        //    string query = "insert into ItemBatchID values ( '" + item.itemid + "', '" + item.batchid + "'); ";
        //    int result = clsConnection.SendQuery(query);
        //    return result;
        //}
        public int insertToItemBatch(classBatch item)
        {
            string query  = "insert into Batch values ('" + item.itemid + "', '" + item.batchid + "', " + item.sellingprice + ", '" + item.expireDate + "', " + item.itemquantity + ", " + item.costperunit + "); ";
            int    result = clsConnection.SendQuery(query);

            return(result);
        }
        private void btnOrder_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < dgvBillView.Rows.Count; i++)
            {
                try
                {
                    string   format = dgvBillView.Rows[i].Cells[2].Value.ToString();
                    DateTime dt     = Convert.ToDateTime(format);
                    string   date   = dt.ToString("MM-d-yyyy");
                    string   IID    = dgvBillView.Rows[i].Cells[0].Value.ToString();

                    var itemBatch = new classBatch
                    {
                        itemid       = dgvBillView.Rows[i].Cells[0].Value.ToString(),
                        batchid      = dgvBillView.Rows[i].Cells[1].Value.ToString(),
                        sellingprice = float.Parse(dgvBillView.Rows[i].Cells[3].Value.ToString()),
                        expireDate   = date,
                        itemquantity = Int32.Parse(dgvBillView.Rows[i].Cells[5].Value.ToString()),
                        costperunit  = float.Parse(dgvBillView.Rows[i].Cells[4].Value.ToString())
                    };
                    int inserttoItemBatch = itemBatch.insertToItemBatch(itemBatch);
                    //int inserttoItemBatchId = itemBatch.insertToBatchItemID(itemBatch);

                    int insertopurchasedetails = classPurchaseBatch.insertpurchaseDetails(txtPurchaseId.Text, dgvBillView.Rows[i].Cells[0].Value.ToString(), dgvBillView.Rows[i].Cells[1].Value.ToString(), Int32.Parse(dgvBillView.Rows[i].Cells[5].Value.ToString()));

                    var item = new Items
                    {
                        iId       = IID,
                        iQuantity = Int32.Parse(dgvBillView.Rows[i].Cells[5].Value.ToString())
                    };
                    int updateItemQuantity = item.updateItemQuantity(item);
                }
                catch (SqlException sqle)
                {
                    clsConnection.connectionclose();
                    MessageBox.Show("Enter an Item only once", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    MessageBox.Show(sqle.Message);
                }
                catch (Exception ex)
                {
                    clsConnection.connectionclose();
                }
            }
            try
            {
                int       insertPurchase = classPurchases.insertTopurchase(txtPurchaseId.Text, lblDate.Text, float.Parse(txtAmount.Text));
                DataTable db             = classPurchases.getTopPurchaseId();
                string    purchaseId     = db.Rows[0][0].ToString();
                int       newpurchaseId  = Int32.Parse(purchaseId) + 1;
                txtPurchaseId.Text = newpurchaseId.ToString();
            }
            catch (Exception ex)
            {
                clsConnection.connectionclose();
            }
            int rowCount = dgvBillView.Rows.Count;

            for (int i = rowCount - 1; i >= 0; i--)
            {
                dgvBillView.Rows.RemoveAt(i);
            }
            dgvStockView.DataSource = Items.itemsearchall();
        }