protected void InsertButton_Click(object sender, EventArgs e)
        {
            try
            {
                using (TopCareDataContext db = new TopCareDataContext())
                {
                    MemberSubscriptionsPaid _tempMemberSubscriptionsPaid = new MemberSubscriptionsPaid();
                    _tempMemberSubscriptionsPaid.MemberID = Convert.ToInt32(Request.QueryString["mid"]);
                    _tempMemberSubscriptionsPaid.AmountPaid = Convert.ToDecimal(AmountPaidTextBox.Text.Trim());
                   // _tempMemberSubscriptionsPaid.CreatedBy = Session["CurrentUser"].ToString();
                    _tempMemberSubscriptionsPaid.CreatedDate = DateTime.Now;
                    _tempMemberSubscriptionsPaid.ExpiryDate = Convert.ToDateTime(PaymentDateTextBox.Text.Trim()).AddYears(1).AddDays(-1);
                    _tempMemberSubscriptionsPaid.PaymentDate = Convert.ToDateTime(PaymentDateTextBox.Text.Trim());
                   // _tempMemberSubscriptionsPaid.PaymentRecievedBy = Session["CurrentUser"].ToString();

                    db.MemberSubscriptionsPaids.InsertOnSubmit(_tempMemberSubscriptionsPaid);
                    db.SubmitChanges();

                    GridView1.DataBind();

                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //GridView1.Rows
            try
            {
                MemberAttendance tempMA;
                using (TopCareDataContext db = new TopCareDataContext())
                {
                    foreach (GridViewRow item in GridView1.Rows)
                    {
                        if (item.RowType == DataControlRowType.DataRow)
                        {
                            CheckBox chkBox = item.FindControl("CheckBox1") as CheckBox;
                            UserControls.AttendanceWebUserControl usrControl = item.FindControl("AttendanceWebUserControl1") as UserControls.AttendanceWebUserControl;
                            UserControls.SubscriptionFeeWebUserControl usrControl2 = item.FindControl("SubscriptionFeeWebUserControl1") as UserControls.SubscriptionFeeWebUserControl;

                            decimal d = usrControl.PaidAmount;
                            tempMA = db.MemberAttendances.FirstOrDefault(m => m.MemberID == usrControl.MemberID && m.ScheduleID == usrControl.ScheduleID);

                            //if payment for subscription is made, save it in the database
                            if (usrControl2.PaidAmount > 0)
                            {
                                MemberSubscriptionsPaid _memberSubscriptionsPaid = new MemberSubscriptionsPaid();
                                _memberSubscriptionsPaid.AmountPaid = usrControl2.PaidAmount;
                                _memberSubscriptionsPaid.CreatedBy = HttpContext.Current.User.Identity.Name;
                                _memberSubscriptionsPaid.CreatedDate = DateTime.Now;
                                _memberSubscriptionsPaid.ExpiryDate = DateTime.Today.AddYears(1).AddDays(-1);
                                _memberSubscriptionsPaid.IsWaived = usrControl2.IsWaived;
                                _memberSubscriptionsPaid.MemberID = usrControl2.MemberID;
                                _memberSubscriptionsPaid.PaymentDate = DateTime.Now;
                                _memberSubscriptionsPaid.PaymentRecievedBy = HttpContext.Current.User.Identity.Name;
                                db.MemberSubscriptionsPaids.InsertOnSubmit(_memberSubscriptionsPaid);
                            }

                            if (tempMA != null)
                            {
                                tempMA.HasAttended = chkBox.Checked;
                                tempMA.IsFeeWaived = usrControl.IsWaived;
                                tempMA.AmountPaid = usrControl.PaidAmount;
                                //db.SubmitChanges();
                            }
                            else
                            {
                                tempMA = new MemberAttendance();
                                tempMA.HasAttended = chkBox.Checked;
                                tempMA.IsFeeWaived = usrControl.IsWaived;
                                tempMA.PaymentDate = DateTime.Now;
                                tempMA.AmountPaid = usrControl.PaidAmount;
                                tempMA.MemberID = usrControl.MemberID;
                                tempMA.ScheduleID = usrControl.ScheduleID;
                                tempMA.PaymentRecievedBy = HttpContext.Current.User.Identity.Name;
                                db.MemberAttendances.InsertOnSubmit(tempMA);
                            }
                            db.SubmitChanges();
                        }
                    }
                }

                //Response.Redirect("ScheduleList_MultiView.aspx");
                Response.Redirect("~/topcare/ReportPages/SchAttendanceSummary.aspx?sID=" + Request.QueryString["sID"]);
            }
            catch (Exception)
            {
                throw;
            }
        }