Exemplo n.º 1
0
        public void finilizeSale()
        {
            int saleId = db.getSaleId();

            DataManager.sale saleData = new DataManager.sale();
            saleData.total    = float.Parse(textBox2.Text);
            saleData.discount = Int32.Parse(numericUpDown1.Value.ToString());
            saleData.gtotal   = float.Parse(textBox4.Text);
            saleData.id       = saleId;
            saleData.date     = DateTime.Now;
            if (radioButton1.Checked)
            {
                saleData.payment = "cash";
            }
            else
            {
                saleData.payment = "card";
            }

            List <DataManager.saleDetails> details = new List <DataManager.saleDetails>();

            foreach (ListViewItem lvi in listView1.Items)
            {
                int tempId = Int32.Parse(lvi.SubItems[0].Text.ToString());
                int tempQu = Int32.Parse(lvi.SubItems[3].Text.ToString());
                DataManager.saleDetails tempdet = new DataManager.saleDetails();
                tempdet.itemId = tempId;
                tempdet.qun    = tempQu;
                details.Add(tempdet);
            }
            saleData.det = details;
            db.addNewSale(saleData);
        }
Exemplo n.º 2
0
        public List <DataManager.sale> getAllSales()
        {
            List <DataManager.sale> retVal = new List <DataManager.sale>();

            conn.Open();
            string           sql       = "SELECT * FROM sale";
            SQLiteCommand    sqCommand = new SQLiteCommand(sql, conn);
            SQLiteDataReader sqReader  = sqCommand.ExecuteReader();

            while (sqReader.Read())
            {
                DataManager.sale temp = new DataManager.sale();
                temp.id       = sqReader.GetInt32(0);
                temp.date     = DateTime.Parse(sqReader.GetString(1));
                temp.payment  = sqReader.GetString(2);
                temp.total    = sqReader.GetFloat(3);
                temp.discount = sqReader.GetInt32(4);
                temp.gtotal   = sqReader.GetFloat(5);
                retVal.Add(temp);
            }


            for (int i = 0; i < retVal.Count; i++)
            {
                sql       = "SELECT * FROM saleDet WHERE saleid='" + retVal[i].id + "'";
                sqCommand = new SQLiteCommand(sql, conn);
                sqReader  = sqCommand.ExecuteReader();
                List <DataManager.saleDetails> addToRetVal = new List <DataManager.saleDetails>();
                while (sqReader.Read())
                {
                    DataManager.saleDetails tmp = new DataManager.saleDetails();
                    tmp.itemId = sqReader.GetInt32(1);
                    tmp.qun    = sqReader.GetInt32(2);
                    addToRetVal.Add(tmp);
                }
                retVal[i].det = addToRetVal;
            }

            sqReader.Close();
            conn.Close();
            return(retVal);
        }