Exemplo n.º 1
0
        private void DeleteDailyInfo(bool manuallyRemoveRow = false)
        {
            string message = "Selected information will be permanently deleted. " +
                             "Are you sure you want to delete the selected information?";

            DialogResult userResponse = MessageBox.Show(message, "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (userResponse == DialogResult.No)
            {
                return;
            }

            foreach (DataGridViewRow row in MonthlyReportDataGridView.SelectedRows)
            {
                string[] date  = row.Cells[0].Value.ToString().Split(' ');
                int      day   = Convert.ToInt32(date[0]);
                int      month = _monthList.IndexOf(date[1].Replace(",", "")) + 1;
                int      year  = Convert.ToInt32(date[2]);

                string result = WebHandler.DeleteDailyInfo(day, month, year);

                if (result == "SUCCESS")
                {
                    if (manuallyRemoveRow)
                    {
                        //when we delete a row on click of delete button
                        //that doesn't automatically remove that row from dataGridView
                        //so we need to manually remove it
                        MonthlyReportDataGridView.Rows.RemoveAt(row.Index);
                    }

                    GlobalSpace.DailyInfoList.RemoveAll(
                        d => d.Day == day && d.Month == month && d.Year == year);
                }
                else
                {
                    //if the deleting doesn't succeed, the error info is returned
                    MessageBox.Show("Something went wrong! Please check your internet connection and try again.",
                                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            //monthly info should change accordingly since daily info has been modified
            MonthlyInfo.Fetch();

            UpdateTotalEarningAndExpenseLabel();
        }