Exemplo n.º 1
0
        public string GetFoodBestSellForMonthAndYear(DateTime dateStart, DateTime dateEnd)
        {
            try
            {
                MY_DB mydb = new MY_DB();

                dateStart.ToShortDateString();
                dateEnd.ToShortDateString();

                SqlCommand command = new SqlCommand("SELECT BillInfo.idFood, COUNT(count) AS number FROM BillInfo,Bill where Bill.id = BillInfo.idBill and DateCheckOut >= '" + dateStart + "' and DateCheckOut <= '" + dateEnd + "' group by BillInfo.idFood ORDER BY number DESC ", mydb.getConnection);

                SqlDataAdapter adap  = new SqlDataAdapter(command);
                DataTable      table = new DataTable();
                adap.Fill(table);
                int            idfood   = Convert.ToInt32(table.Rows[0][0].ToString());
                SqlCommand     command1 = new SqlCommand("SELECT name FROM Food where id=" + idfood, mydb.getConnection);
                SqlDataAdapter adap1    = new SqlDataAdapter(command1);
                DataTable      table1   = new DataTable();
                adap1.Fill(table1);
                string namefood = table1.Rows[0][0].ToString();
                return(namefood);
            }
            catch
            {
                string a = "false";
                return(a);
            }
        }
Exemplo n.º 2
0
        public string GetFoodBestSellForDate(DateTime date)
        {
            try
            {
                MY_DB mydb = new MY_DB();

                //string ngay =
                date.ToShortDateString();

                SqlCommand command = new SqlCommand("SELECT BillInfo.idFood, COUNT(count) AS number FROM BillInfo,Bill where Bill.id = BillInfo.idBill and DateCheckOut = '" + date + "' group by BillInfo.idFood ORDER BY number DESC ", mydb.getConnection);
                //command.Parameters.Add("@date", SqlDbType.NVarChar).Value = ngay;

                SqlDataAdapter adap  = new SqlDataAdapter(command);
                DataTable      table = new DataTable();
                adap.Fill(table);
                int            idfood   = Convert.ToInt32(table.Rows[0][0].ToString());
                SqlCommand     command1 = new SqlCommand("SELECT name FROM Food where id=" + idfood, mydb.getConnection);
                SqlDataAdapter adap1    = new SqlDataAdapter(command1);
                DataTable      table1   = new DataTable();
                adap1.Fill(table1);
                string namefood = table1.Rows[0][0].ToString();
                return(namefood);
            }
            catch
            {
                string a = "false";
                return(a);
            }
        }