private void ExecuteFindStudentWithGRCommand(object obj)
        {
            if (String.IsNullOrEmpty(SelectedSection.Name))
            {
                WPFCustomMessageBox.CustomMessageBox.ShowOK("Please Select Any Section", "Warning", "OK");
                return;
            }

            S360Model.PromoteStudentModel student = new StudentBusinessLogic().GetStudentWithRegNoAndSection(this.CurrentChequeInwardModel.RegNo, this.SelectedSection.Section_Id);

            if (student == null)
            {
                WPFCustomMessageBox.CustomMessageBox.ShowOK("No Records Found", "Message", "OK");
                this.CurrentChequeInwardModel.RegNo = string.Empty;
                this.CurrentChequeInwardModel       = null;
            }
            else
            {
                CurrentChequeInwardModel = new ChequeInwardsModel()
                {
                    Student_ID  = student.StudentId,
                    RegNo       = student.RegNo,
                    StudentName = student.Name + " " + student.SurName + " " + student.Father,
                    Section_ID  = student.SectionId,
                    Section     = student.Section,
                    ChequeNo    = "000000",
                    ChqAmount   = 0
                };
            }
        }
        private void ExecuteFindStudent(object sender)
        {
            UC_FindStudentScreen findStuent = new UC_FindStudentScreen();

            findStuent.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
            FindStudentViewModel findStudentVM = new FindStudentViewModel();

            findStudentVM.SelectedSection = this._selectedSection;
            findStuent.DataContext        = findStudentVM;
            if (findStuent.ShowDialog() == true)
            {
                findStudentVM = findStuent.DataContext as FindStudentViewModel;
                if (findStudentVM.SelectedStudent != null && findStudentVM.SelectedStudent.StudentId > 0)
                {
                    CurrentChequeInwardModel = new ChequeInwardsModel()
                    {
                        Student_ID  = findStudentVM.SelectedStudent.StudentId,
                        RegNo       = findStudentVM.SelectedStudent.RegNo,
                        StudentName = findStudentVM.SelectedStudent.Name + " " + findStudentVM.SelectedStudent.SurName + " " + findStudentVM.SelectedStudent.Father,
                        Section_ID  = findStudentVM.SelectedStudent.SectionId,
                        Section     = findStudentVM.SelectedStudent.Section,
                        ChequeNo    = "000000",
                        ChqAmount   = 0
                    };
                }
            }
        }
        /// <summary>
        /// Converts the input ChequeMaster object to its model object type
        /// </summary>
        /// <param name="cheque"></param>
        /// <returns></returns>
        private ChequeInwardsModel ConvertToCheque(CHQ_Cheques_Master cheque, int SerialNo)
        {
            if (cheque == null)
            {
                return(new ChequeInwardsModel());
            }
            StudentBusinessLogic bussiness = new StudentBusinessLogic();

            //STUD_Students_Master student = bussiness.GetAllStudents().Where(S => S.Student_ID == cheque.Student_ID).FirstOrDefault();
            //GEN_Sections_Lookup sec = bussiness.GetAllSections().Where(S => S.Section_Id == cheque.Section_ID).FirstOrDefault();

            ChequeInwardsModel cheq = new ChequeInwardsModel();

            cheq.SerialNo     = SerialNo;
            cheq.Student_ID   = cheque.Student_ID;
            cheq.Bank         = cheque.Bank;
            cheq.ChequeNo     = cheque.ChequeNo;
            cheq.Cheque_ID    = cheque.Cheque_ID;
            cheq.ChqAmount    = cheque.ChqAmount;
            cheq.ChqStatus_ID = cheque.ChqStatus_ID;
            cheq.EnteredBy    = cheque.EnteredBy;
            cheq.EnteredOn    = cheque.EnteredOn;
            cheq.InwardDate   = cheque.InwardDate;
            cheq.IsActive     = cheque.IsActive;
            cheq.Login_ID     = cheque.Login_ID;
            cheq.Remarks      = cheque.Remarks;
            cheq.Section_ID   = cheque.Section_ID;
            cheq.RegNo        = CurrentChequeInwardModel.RegNo;
            cheq.StudentName  = CurrentChequeInwardModel.StudentName;
            cheq.Section      = CurrentChequeInwardModel.Section;

            cheq.User = LoginBusinessLogic.GetUserByID(LoginBusinessLogic.GetUserIdByLoginId((decimal)cheque.Login_ID)).Username;
            return(cheq);
        }
        /// <summary>
        /// Converts the input ChequeMaster object to its temp object type
        /// </summary>
        /// <param name="cheque"></param>
        /// <returns></returns>
        private object ConvertToCheque(object chq, bool IsTemp = false)
        {
            if (!IsTemp)
            {
                CHQ_Cheques_Master_Temp cheque = chq as CHQ_Cheques_Master_Temp;
                if (cheque == null)
                {
                    return(new ChequeInwardsModel());
                }
                StudentBusinessLogic bussiness = new StudentBusinessLogic();

                STUD_Students_Master student = bussiness.GetAllStudents().Where(S => S.Student_ID == cheque.Student_ID).FirstOrDefault();
                GEN_Sections_Lookup  sec     = bussiness.GetAllSections().Where(S => S.Section_Id == cheque.Section_ID).FirstOrDefault();

                ChequeInwardsModel cheq = new ChequeInwardsModel();
                cheq.Student_ID   = cheque.Student_ID;
                cheq.Bank         = cheque.Bank;
                cheq.ChequeNo     = cheque.ChequeNo;
                cheq.Cheque_ID    = cheque.Cheque_ID;
                cheq.ChqAmount    = cheque.ChqAmount;
                cheq.ChqStatus_ID = cheque.ChqStatus_ID;
                cheq.EnteredBy    = cheque.EnteredBy;
                cheq.EnteredOn    = cheque.EnteredOn;
                cheq.InwardDate   = cheque.InwardDate;
                cheq.IsActive     = cheque.IsActive;
                cheq.Login_ID     = cheque.Login_ID;
                cheq.Remarks      = cheque.Remarks;
                cheq.Section_ID   = cheque.Section_ID;
                cheq.RegNo        = student.RegNo;
                cheq.StudentName  = student.Name + " " + student.Surname + " " + student.FatherName;
                cheq.Section      = sec.Name;
                cheq.User         = S360Model.S360Configuration.Instance.User;
                return(cheq);
            }
            else
            {
                CHQ_Cheques_Master cheque = chq as CHQ_Cheques_Master;
                if (cheque == null)
                {
                    return(new CHQ_Cheques_Master_Temp());
                }
                CHQ_Cheques_Master_Temp cheq = new CHQ_Cheques_Master_Temp();
                cheq.Student_ID   = cheque.Student_ID;
                cheq.Bank         = cheque.Bank;
                cheq.ChequeNo     = cheque.ChequeNo;
                cheq.Cheque_ID    = cheque.Cheque_ID;
                cheq.ChqAmount    = cheque.ChqAmount;
                cheq.ChqStatus_ID = cheque.ChqStatus_ID;
                cheq.EnteredBy    = cheque.EnteredBy;
                cheq.EnteredOn    = cheque.EnteredOn;
                cheq.InwardDate   = cheque.InwardDate;
                cheq.IsActive     = cheque.IsActive;
                cheq.Login_ID     = cheque.Login_ID;
                cheq.Remarks      = cheque.Remarks;
                cheq.Section_ID   = cheque.Section_ID;
                return(cheq);
            }
        }
        private bool CanExecuteDeleteCQCommand(object sender)
        {
            ChequeInwardsModel chequeinward = this.ChequeList.Where(S => S.Student_ID == this._selectedCheque.Student_ID && S.ChequeNo == this._selectedCheque.ChequeNo).FirstOrDefault();

            if (chequeinward != null)
            {
                return(true);
            }
            return(false);
        }
        private bool CanExecuteAddChequeCommand(object sender)
        {
            if (string.IsNullOrEmpty(this.CurrentChequeInwardModel.StudentName))
            {
                return(false);
            }

            ChequeInwardsModel existingCheque = this.ChequeList.Where(S => S.Student_ID == this.CurrentChequeInwardModel.Student_ID &&
                                                                      S.ChequeNo == this.CurrentChequeInwardModel.ChequeNo).FirstOrDefault();

            if (existingCheque != null)
            {
                return(false);
            }

            return(true);
        }
        private void ExecuteSaveChqCommand(object sender)
        {
            View.Cheque.UC_ChequeEditScreen uccheque = sender as View.Cheque.UC_ChequeEditScreen;
            ChequeBusinessLogic             chequeBussiness;

            try
            {
                ControlValidationStatus status = ValidateControls.ValidateAllControls(uccheque);
                if (status != null && !status.isValid)
                {
                    WPFCustomMessageBox.CustomMessageBox.ShowOK(status.ValidationMessage, "S360 Application", "OK");
                    return;
                }
                decimal chequeNo = 0;
                decimal Amt      = 0;
                decimal.TryParse(CurrentChequeInwardModel.ChequeNo, out chequeNo);
                if (string.IsNullOrEmpty(CurrentChequeInwardModel.ChequeNo) || chequeNo <= 0)
                {
                    WPFCustomMessageBox.CustomMessageBox.ShowOK("Invalid Cq. No", "Warning", "OK");
                    S360Controlls.BasicControls.S360TextBox txt = FindVisualChildren <S360Controlls.BasicControls.S360TextBox>(uccheque).Where(S => S.Name == "txtCqNo").FirstOrDefault();
                    txt.Text = string.Empty;
                    txt.Focus();
                    return;
                }
                if (!decimal.TryParse(CurrentChequeInwardModel.ChqAmount.ToString(), out Amt))
                {
                    WPFCustomMessageBox.CustomMessageBox.ShowOK("Invalid Amount", "Warning", "OK");
                    S360Controlls.BasicControls.S360TextBox txt = FindVisualChildren <S360Controlls.BasicControls.S360TextBox>(uccheque).Where(S => S.Name == "txtAmt").FirstOrDefault();
                    txt.Text = string.Empty;
                    txt.Focus();
                    return;
                }
                if (Amt <= 0)
                {
                    WPFCustomMessageBox.CustomMessageBox.ShowOK("Invalid Amount", "Warning", "OK");
                    S360Controlls.BasicControls.S360TextBox txt = FindVisualChildren <S360Controlls.BasicControls.S360TextBox>(uccheque).Where(S => S.Name == "txtAmt").FirstOrDefault();
                    txt.Text = string.Empty;
                    txt.Focus();
                    return;
                }

                chequeBussiness = new ChequeBusinessLogic();
                CHQ_Cheques_Master model = new CHQ_Cheques_Master()
                {
                    Student_ID   = CurrentChequeInwardModel.Student_ID,
                    Bank         = CurrentChequeInwardModel.Bank,
                    ChequeNo     = CurrentChequeInwardModel.ChequeNo,
                    Cheque_ID    = CurrentChequeInwardModel.Cheque_ID,
                    ChqAmount    = CurrentChequeInwardModel.ChqAmount,
                    ChqStatus_ID = CurrentChequeInwardModel.ChqStatus_ID,
                    EnteredBy    = CurrentChequeInwardModel.EnteredBy,
                    //EnteredBy = S360Configuration.Instance.UserID,
                    EnteredOn  = CurrentChequeInwardModel.EnteredOn,
                    InwardDate = CurrentChequeInwardModel.InwardDate,
                    IsActive   = CurrentChequeInwardModel.IsActive,
                    Login_ID   = S360Configuration.Instance.LoginID,
                    Remarks    = CurrentChequeInwardModel.Remarks,
                    Section_ID = CurrentChequeInwardModel.Section_ID
                };
                chequeBussiness.UpdateCheque(model);

                CurrentChequeInwardModel = new ChequeInwardsModel()
                {
                    RegNo       = SelectedCheque.RegNo,
                    StudentName = SelectedCheque.StudentName,
                    Student_ID  = SelectedCheque.Student_ID,
                    Section     = SelectedCheque.Section,
                    Section_ID  = SelectedCheque.Section_ID
                };

                IEnumerable <CHQ_Cheques_Master> cheques = chequeBussiness.GetAllCheques().Where(C => C.Student_ID == CurrentChequeInwardModel.Student_ID &&
                                                                                                 C.ChqStatus_ID == 1 /*Cheque Recieved*/ && C.IsActive == true);

                ChequeList.Clear();
                int serialNo = 1;
                foreach (CHQ_Cheques_Master chq in cheques)
                {
                    this.ChequeList.Add(ConvertToCheque(chq, serialNo++));
                }
                this.SelectedCheque = null;
            }
            catch (Exception ex)
            {
                throw new S360Exceptions.S360Exception(ex.Message, ex.InnerException);
            }
            finally
            {
                //ExecuteClearCommand(null);
                chequeBussiness = null;
            }
        }