Ejemplo n.º 1
0
        protected void btnSelect_Click(object sender, EventArgs e)
        {
            try {
                ListView.Visible = true;
                cm      = new CaloriesModel();
                cm.Date = MyDate.SelectedDate;
                GetData(MyDate.SelectedDate);
                SumCalorie.Text = cr.SelectSumCalorie(cm).ToString();
                //  MyDate.SelectedDates.Clear();



                GetDataActivity(MyDate.SelectedDate);
                //  MyDate.SelectedDates.Clear();
                mm                  = new MobilitiesModel();
                mm.Date             = MyDate.SelectedDate;
                SumMobilityTxt.Text = mr.SelectSumMobility(mm).ToString();


                //dailyCalorie.Text = (Convert.ToInt32(SumCalorie.Text) - Convert.ToInt32(SumMobilityTxt.Text)).ToString();
            }
            catch (Exception ex)
            {
                le.SaveLogError(ex);
            }
        }
Ejemplo n.º 2
0
        protected void Calorie_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            cm = new CaloriesModel();
            int index = Convert.ToInt32(e.CommandArgument);

            cm.Id = Convert.ToInt32(CalorieList.Rows[index].Cells[3].Text);

            if (e.CommandName == "DeleteRow")
            {
                bool res = cr.Delete(cm);
                if (res)
                {
                    string message = "Deleting info was successfully";
                    string script  = "window.onload = function(){ alert('";
                    script += message;
                    script += "')};";
                    ClientScript.RegisterStartupScript(this.GetType(), "SuccessMessage", script, true);
                }
                else
                {
                    string message = "Deleting info was not successfully";
                    string script  = "window.onload = function(){ alert('";
                    script += message;
                    script += "')};";
                    ClientScript.RegisterStartupScript(this.GetType(), "SuccessMessage", script, true);
                }
                if (MyDate.SelectedDate != null)
                {
                    GetData(MyDate.SelectedDate);
                }
                else
                {
                    GetData(Calender.SelectedDate);
                }
            }
            if (e.CommandName == "EditRow")
            {
                MyDate.SelectedDates.Clear();
                addNew.Visible        = true;
                ShowList.Visible      = false;
                btnUpdate.Visible     = true;
                btnSave.Visible       = false;
                addNew.Visible        = true;
                Quantity.Text         = CalorieList.Rows[index].Cells[7].Text.ToString();
                Calender.SelectedDate = Convert.ToDateTime(CalorieList.Rows[index].Cells[9].Text);
                var foodGroupId = CalorieList.Rows[index].Cells[11].Text.ToString();
                FoodGroupDropDown.SelectedValue = FoodGroupDropDown.Items.FindByValue(foodGroupId).Value;
                LoadFoodDropDown(Convert.ToInt32(foodGroupId));
                var foodId = CalorieList.Rows[index].Cells[10].Text.ToString();
                FoodDropDown.SelectedValue = FoodDropDown.Items.FindByValue(foodId).Value;
                ListView.Visible           = false;
                CalorieIdTxt.Text          = CalorieList.Rows[index].Cells[3].Text.ToString();
                UsageCalorie.Text          = CalorieList.Rows[index].Cells[8].Text.ToString();
                FoodCalorieText.Text       = CalorieList.Rows[index].Cells[12].Text.ToString();
            }
        }
Ejemplo n.º 3
0
        public string SelectSumCalorie(CaloriesModel cm)
        {
            base.DataAccess();
            base.Connect();
            string Query = "select sum(Calorie) from Calories where Date='" + cm.Date + "' and UserId='" + cm.UserId + "'";
            string b     = base.ExecuteSelect(Query);

            base.DisConnect();
            return(b);
        }
Ejemplo n.º 4
0
        public DataTable SelectByDate(CaloriesModel cm)
        {
            base.DataAccess();
            base.Connect();
            string    Query = "select Calories.Id,FoodsGroup.Name as 'Food Group',Foods.Name as 'Food Name',Foods.Calorie as 'Food Calorie',Calories.Quantity,Calories.Calorie as 'Usage Calorie',Calories.Date,Calories.FoodId,Foods.FoodGroupId,Foods.Calorie from Calories,Foods,FoodsGroup where Calories.FoodId = Foods.Id and Foods.FoodGroupId =  FoodsGroup.Id and Calories.Date = '" + cm.Date + "' and Calories.UserId = '" + cm.UserId + "' order by Calories.Id desc";
            DataTable dt    = base.Select(Query);

            base.DisConnect();
            return(dt);
        }
Ejemplo n.º 5
0
        public bool Update(CaloriesModel cm)//method for update
        {
            base.DataAccess();
            base.Connect();
            string Query = "update Calories set FoodId=N'{0}',Quantity=N'{1}',Calorie=N'{2}',Date=N'{3}' where Id={4}";

            Query = string.Format(Query, cm.FoodId, cm.Quantity, cm.Calorie, cm.Date, cm.Id);
            bool res = base.DoCommand(Query);

            base.DisConnect();
            return(res);
        }
Ejemplo n.º 6
0
        public bool Delete(CaloriesModel cm)//method for delet
        {
            base.DataAccess();
            base.Connect();
            string Query = "delete from Calories where Id={0}";

            Query = string.Format(Query, cm.Id);
            bool res = base.DoCommand(Query);

            base.DisConnect();
            return(res);
        }
Ejemplo n.º 7
0
        public bool Insert(CaloriesModel cm) //method for adding item
        {
            base.DataAccess();
            base.Connect();
            string Query = "insert into Calories (UserId,FoodId,Quantity,Calorie,Date) values (N'{0}',N'{1}',N'{2}',N'{3}',N'{4}')";

            Query = string.Format(Query, cm.UserId, cm.FoodId, cm.Quantity, cm.Calorie, cm.Date);
            bool res = base.DoCommand(Query);

            base.DisConnect();
            return(res);
        }
Ejemplo n.º 8
0
 protected void btnSave_Click(object sender, EventArgs e)
 {
     try {
         if ((Calender.SelectedDate == Convert.ToDateTime("1 / 1 / 0001 12:00:00 AM")) || (FoodGroupDropDown.SelectedItem.Value == "0") || (FoodDropDown.SelectedItem.Value == "0"))
         {
             string message = "Please fill all items!";
             string script  = "window.onload = function(){ alert('";
             script += message;
             script += "')};";
             ClientScript.RegisterStartupScript(this.GetType(), "SuccessMessage", script, true);
             //Scr
         }
         else
         {
             cm          = new CaloriesModel();
             cm.FoodId   = Convert.ToInt32(FoodDropDown.SelectedItem.Value);
             cm.UserId   = Convert.ToInt32(UserIdTxt.Text);
             cm.Quantity = Quantity.Text.ToString();
             cm.Date     = Calender.SelectedDate;
             cm.Calorie  = (Convert.ToInt32(Quantity.Text.ToString())) * (Convert.ToInt32(FoodCalorieText.Text.ToString()));
             bool res = cr.Insert(cm);
             if (res)
             {
                 string message = "Saving info was successfully";
                 string script  = "window.onload = function(){ alert('";
                 script += message;
                 script += "')};";
                 ClientScript.RegisterStartupScript(this.GetType(), "SuccessMessage", script, true);
                 //ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Record Inserted Successfully')", true);
             }
             else
             {
                 string message = "Saving info was not successfully";
                 string script  = "window.onload = function(){ alert('";
                 script += message;
                 script += "')};";
                 ClientScript.RegisterStartupScript(this.GetType(), "SuccessMessage", script, true);
             }
             addNew.Visible      = false;
             ShowList.Visible    = true;
             ListView.Visible    = true;
             MyDate.SelectedDate = cm.Date;
             GetData(Calender.SelectedDate);
             GetDataActivity(Calender.SelectedDate);
             SumCalorie.Text = cr.SelectSumCalorie(cm).ToString();
             //dailyCalorie.Text = (Convert.ToInt32(SumCalorie.Text) - Convert.ToInt32(SumMobilityTxt.Text)).ToString();
         }
     }
     catch (Exception ex)
     {
         le.SaveLogError(ex);
     }
 }
Ejemplo n.º 9
0
 private void GetData(DateTime dt)
 {
     try {
         cm      = new CaloriesModel();
         cm.Date = dt;
         CalorieList.DataSource = cr.SelectByDate(cm);
         CalorieList.DataBind();
     }
     catch (Exception ex)
     {
         le.SaveLogError(ex);
     }
 }
Ejemplo n.º 10
0
 private void GetData(DateTime dt)
 {
     try {
         cm        = new CaloriesModel();
         cm.Date   = dt;
         cm.UserId = Convert.ToInt32(UserIdTxt.Text);
         CalorieList.DataSource = cr.SelectByDate(cm);
         CalorieList.DataBind();
     }
     catch (Exception ex)
     {
         le.SaveLogError(ex);
     }
 }
Ejemplo n.º 11
0
 protected void btnSelect_Click(object sender, EventArgs e)
 {
     try {
         cm               = new CaloriesModel();
         cm.Date          = MyDate.SelectedDate;
         ListView.Visible = true;
         GetData(MyDate.SelectedDate);
         SumCalorie.Text = cr.SelectSumCalorie(cm).ToString();
         //  MyDate.SelectedDates.Clear();
     }
     catch (Exception ex)
     {
         le.SaveLogError(ex);
     }
 }
Ejemplo n.º 12
0
 protected void btnUpdate_Click(object sender, EventArgs e)
 {
     try {
         cm          = new CaloriesModel();
         cm.FoodId   = Convert.ToInt32(FoodDropDown.SelectedItem.Value);
         cm.Quantity = Quantity.Text.ToString();
         cm.Date     = Calender.SelectedDate;
         cm.Calorie  = (Convert.ToInt32(Quantity.Text.ToString())) * (Convert.ToInt32(FoodCalorieText.Text.ToString()));
         cm.Id       = Convert.ToInt32(CalorieIdTxt.Text.ToString());
         bool res = cr.Update(cm);
         if (res)
         {
             string message = "Saving info was successfully";
             string script  = "window.onload = function(){ alert('";
             script += message;
             script += "')};";
             ClientScript.RegisterStartupScript(this.GetType(), "SuccessMessage", script, true);
             //ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Record Inserted Successfully')", true);
         }
         else
         {
             string message = "Saving info was not successfully";
             string script  = "window.onload = function(){ alert('";
             script += message;
             script += "')};";
             ClientScript.RegisterStartupScript(this.GetType(), "SuccessMessage", script, true);
         }
         addNew.Visible      = false;
         ShowList.Visible    = true;
         ListView.Visible    = true;
         MyDate.SelectedDate = cm.Date;
         GetData(cm.Date);
         SumCalorie.Text = cr.SelectSumCalorie(cm).ToString();
     }
     catch (Exception ex)
     {
         le.SaveLogError(ex);
     }
 }