Beispiel #1
0
 public ActionResult DeleteConfirmed(int id)
 {
     try
     {
         FormSaleDetail formSaleDetail = db.FormSaleDetails.Find(id);
         db.Entry(formSaleDetail).State = EntityState.Modified;
         formSaleDetail.IsReceived      = "No";
         formSaleDetail.ReceiveDate     = null;
         db.SaveChanges();
         ViewBag.MessageType = "success";
         ViewBag.Message     = "Record has been removed successfully.";
     }
     catch (DbUpdateException ex)
     {
         ViewBag.MessageType = "error";
         ViewBag.Message     = ex.Message;
         ModelState.AddModelError(string.Empty, ex.Message);
     }
     model.FormSaleDetails        = db.FormSaleDetails.Where(f => f.IsReceived == "Yes").OrderByDescending(a => a.FormID).ToList();
     model.SelectedFormSaleDetail = null;
     model.DisplayMode            = "WriteOnly";
     ViewBag.IsActive             = new SelectList(db.Options, "OptionDesc", "OptionDesc");
     ViewBag.IsReceived           = new SelectList(db.Options, "OptionDesc", "OptionDesc");
     ViewBag.FormTypeID           = new SelectList(db.FormTypes, "FormTypeID", "FormTypeName");
     ViewBag.DepositTypeID        = new SelectList(db.DepositTypes, "DepositTypeID", "DepositTypeName");
     ViewBag.BatchProgramID       = new SelectList(db.GetBatchProgramNameConcat("", 0), "ID", "Name");
     ViewBag.AccountID            = new SelectList(dbFinance.Bank_Account, "Account_ID", "Account_No");
     return(View("Index", model));
 }
Beispiel #2
0
        public ActionResult Update(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            FormSaleDetail formSaleDetail = db.FormSaleDetails.Find(id);

            if (formSaleDetail == null)
            {
                return(HttpNotFound());
            }

            model.FormSaleDetails        = db.FormSaleDetails.Where(f => f.IsReceived == "Yes").OrderByDescending(a => a.FormID).ToList();
            model.SelectedFormSaleDetail = formSaleDetail;
            model.DisplayMode            = "ReadWrite";
            ViewBag.IsActive             = new SelectList(db.Options, "OptionDesc", "OptionDesc", formSaleDetail.IsActive);
            ViewBag.FormTypeID           = new SelectList(db.FormTypes, "FormTypeID", "FormTypeName", formSaleDetail.FormTypeID);
            ViewBag.DepositTypeID        = new SelectList(db.DepositTypes, "DepositTypeID", "DepositTypeName", formSaleDetail.DepositTypeID);
            ViewBag.BatchProgramID       = new SelectList(db.GetBatchProgramNameConcat("", 0), "ID", "Name", formSaleDetail.BatchProgramID);
            ViewBag.AccountID            = new SelectList(dbFinance.Bank_Account, "Account_ID", "Account_No", formSaleDetail.AccountID);
            ViewBag.MessageType          = "";
            ViewBag.Message = "";
            return(View("Index", model));
        }
Beispiel #3
0
        public ActionResult Create(FormSaleDetail formSaleDetail)
        {
            string ErrorMessage = "";
            int    count        = 0;

            try
            {
                FormSaleDetail fsd       = db.FormSaleDetails.FirstOrDefault(f => f.FormNo == formSaleDetail.FormNo);
                Applicant      applicant = db.Applicants.FirstOrDefault(f => f.FormNo == formSaleDetail.FormNo);
                if (fsd == null && applicant == null)
                {
                    formSaleDetail.CreatedBy     = Convert.ToInt32(Session["emp_id"]);
                    formSaleDetail.ModifiedBy    = null;
                    formSaleDetail.IsReceived    = "Yes";
                    formSaleDetail.PurchaseDate  = null;
                    formSaleDetail.AccountID     = null;
                    formSaleDetail.DepositSlipNo = null;
                    InsertFormDetail(formSaleDetail, ref ErrorMessage, ref count);
                }
                else if (fsd != null)
                {
                    formSaleDetail.ModifiedBy = Convert.ToInt32(Session["emp_id"]);
                    formSaleDetail.IsReceived = "Yes";
                    InsertFormDetail(formSaleDetail, ref ErrorMessage, ref count);
                }
            }
            catch (DbEntityValidationException ex)
            {
                foreach (DbEntityValidationResult validationResult in ex.EntityValidationErrors)
                {
                    string entityName = validationResult.Entry.Entity.GetType().Name;
                    foreach (DbValidationError error in validationResult.ValidationErrors)
                    {
                        ModelState.AddModelError(string.Empty, error.ErrorMessage);
                        count++;
                        ErrorMessage += count + "-" + string.Concat(error.PropertyName, " is required.") + "<br />";
                    }
                }
                ViewBag.MessageType = "error";
                ViewBag.Message     = ErrorMessage;
            }
            model.FormSaleDetails        = db.FormSaleDetails.Where(f => f.IsReceived == "Yes").OrderByDescending(a => a.FormID).ToList();
            model.SelectedFormSaleDetail = null;
            model.DisplayMode            = "WriteOnly";
            ViewBag.IsActive             = new SelectList(db.Options, "OptionDesc", "OptionDesc", formSaleDetail.IsActive);
            ViewBag.FormTypeID           = new SelectList(db.FormTypes, "FormTypeID", "FormTypeName", formSaleDetail.FormTypeID);
            ViewBag.DepositTypeID        = new SelectList(db.DepositTypes, "DepositTypeID", "DepositTypeName", formSaleDetail.DepositTypeID);
            ViewBag.BatchProgramID       = new SelectList(db.GetBatchProgramNameConcat("", 0), "ID", "Name", formSaleDetail.BatchProgramID);
            ViewBag.AccountID            = new SelectList(dbFinance.Bank_Account, "Account_ID", "Account_No", formSaleDetail.AccountID);
            return(View("Index", model));
        }
Beispiel #4
0
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            FormSaleDetail formSaleDetail = db.FormSaleDetails.Find(id);

            if (formSaleDetail == null)
            {
                return(HttpNotFound());
            }

            model.FormSaleDetails        = db.FormSaleDetails.Where(f => f.IsReceived == "Yes").OrderByDescending(a => a.FormID).ToList();
            model.SelectedFormSaleDetail = formSaleDetail;
            model.DisplayMode            = "Delete";
            ViewBag.MessageType          = "";
            ViewBag.Message = "";
            return(View("Index", model));
        }
Beispiel #5
0
        public ActionResult Edit(FormSaleDetail formSaleDetail)
        {
            string ErrorMessage = "";
            int    count        = 0;

            try
            {
                formSaleDetail.ModifiedBy = Convert.ToInt32(Session["emp_id"]);
                formSaleDetail.IsReceived = "Yes";
                InsertFormDetail(formSaleDetail, ref ErrorMessage, ref count);
            }
            catch (DbEntityValidationException ex)
            {
                foreach (DbEntityValidationResult validationResult in ex.EntityValidationErrors)
                {
                    string entityName = validationResult.Entry.Entity.GetType().Name;
                    foreach (DbValidationError error in validationResult.ValidationErrors)
                    {
                        ModelState.AddModelError(string.Empty, error.ErrorMessage);
                        count++;
                        ErrorMessage += string.Concat(count, "-", error.ErrorMessage, "\n");
                    }
                }
                ViewBag.MessageType = "error";
                ViewBag.Message     = ErrorMessage;
            }
            model.FormSaleDetails        = db.FormSaleDetails.Where(f => f.IsReceived == "Yes").OrderByDescending(a => a.FormID).ToList();
            model.SelectedFormSaleDetail = null;
            model.DisplayMode            = "WriteOnly";
            ViewBag.IsActive             = new SelectList(db.Options, "OptionDesc", "OptionDesc", formSaleDetail.IsActive);
            ViewBag.FormTypeID           = new SelectList(db.FormTypes, "FormTypeID", "FormTypeName", formSaleDetail.FormTypeID);
            ViewBag.DepositTypeID        = new SelectList(db.DepositTypes, "DepositTypeID", "DepositTypeName", formSaleDetail.DepositTypeID);
            ViewBag.BatchProgramID       = new SelectList(db.GetBatchProgramNameConcat("", 0), "ID", "Name", formSaleDetail.BatchProgramID);
            ViewBag.AccountID            = new SelectList(dbFinance.Bank_Account, "Account_ID", "Account_No", formSaleDetail.AccountID);
            return(View("Index", model));
        }
Beispiel #6
0
        private void InsertFormDetail(FormSaleDetail formSaleDetail, ref string ErrorMessage, ref int count)
        {
            DepositType dt           = db.DepositTypes.FirstOrDefault(d => d.DepositTypeID == formSaleDetail.DepositTypeID);
            string      depositeType = "";

            if (dt != null)
            {
                depositeType = dt.DepositTypeName;
            }
            if (depositeType.ToLower() == "cash")
            {
                formSaleDetail.AccountID     = null;
                formSaleDetail.DepositSlipNo = null;
            }
            else if (depositeType.ToLower() == "bank")
            {
                if (formSaleDetail.AccountID == null || formSaleDetail.AccountID == 0)
                {
                    ModelState.AddModelError(string.Empty, "Please select Bank Account.");
                    count++;
                    ErrorMessage       += count + "-Please select Bank Account.<br />";
                    ViewBag.MessageType = "error";
                }

                if (string.IsNullOrEmpty(formSaleDetail.DepositSlipNo))
                {
                    ModelState.AddModelError(string.Empty, "Please enter Deposit Slip #.");
                    count++;
                    ErrorMessage       += count + "-Please enter Deposit Slip #.<br />";
                    ViewBag.MessageType = "error";
                }
            }

            if (formSaleDetail.ReceiveDate == null)
            {
                ModelState.AddModelError(string.Empty, "Receive Date is required.");
                count++;
                ErrorMessage       += count + "-Receive Date is required.<br />";
                ViewBag.MessageType = "error";
            }

            if (string.IsNullOrEmpty(ErrorMessage))
            {
                try
                {
                    db.InsertFormSaleDetail(formSaleDetail.FormID, formSaleDetail.FormNo
                                            , formSaleDetail.FormTypeID, formSaleDetail.FormPrice
                                            , formSaleDetail.FormDescription, formSaleDetail.DepositTypeID
                                            , formSaleDetail.BatchProgramID, formSaleDetail.ApplicantName
                                            , formSaleDetail.FatherName, formSaleDetail.PhoneNo, formSaleDetail.CNIC
                                            , formSaleDetail.DepositSlipNo, formSaleDetail.PurchaseDate
                                            , formSaleDetail.AccountID, formSaleDetail.CreatedBy, formSaleDetail.IsActive
                                            , formSaleDetail.ModifiedBy, formSaleDetail.IsReceived, formSaleDetail.ReceiveDate);
                    ViewBag.MessageType = "success";
                    ViewBag.Message     = "Data has been saved successfully.";
                }
                catch (EntityCommandExecutionException ex)
                {
                    ViewBag.MessageType = "error";
                    ViewBag.Message     = ex.Message;
                    ModelState.AddModelError(string.Empty, ex.Message);
                }
            }
            else
            {
                ViewBag.MessageType = "error";
                ViewBag.Message     = ErrorMessage;
            }
        }
Beispiel #7
0
        public ActionResult Create(FormSaleDetail formSaleDetail)
        {
            string ErrorMessage = "";
            int    count        = 0;

            try
            {
                FormSaleDetail fsd       = db.FormSaleDetails.FirstOrDefault(f => f.FormNo == formSaleDetail.FormNo);
                Applicant      applicant = db.Applicants.FirstOrDefault(f => f.FormNo == formSaleDetail.FormNo);
                if (fsd == null && applicant == null)
                {
                    DepositType dt           = db.DepositTypes.FirstOrDefault(d => d.DepositTypeID == formSaleDetail.DepositTypeID);
                    string      depositeType = "";
                    if (dt != null)
                    {
                        depositeType = dt.DepositTypeName;
                    }
                    if (depositeType.ToLower() == "cash")
                    {
                        formSaleDetail.AccountID     = null;
                        formSaleDetail.DepositSlipNo = null;
                    }
                    else if (depositeType.ToLower() == "bank")
                    {
                        if (formSaleDetail.AccountID == null || formSaleDetail.AccountID == 0)
                        {
                            ModelState.AddModelError(string.Empty, "Please select Bank Account.");
                            count++;
                            ErrorMessage       += count + "-Please select Bank Account.<br />";
                            ViewBag.MessageType = "error";
                        }

                        if (string.IsNullOrEmpty(formSaleDetail.DepositSlipNo))
                        {
                            ModelState.AddModelError(string.Empty, "Please enter Deposit Slip #.");
                            count++;
                            ErrorMessage       += count + "-Please enter Deposit Slip #.<br />";
                            ViewBag.MessageType = "error";
                        }
                    }

                    if (formSaleDetail.PurchaseDate == null)
                    {
                        ModelState.AddModelError(string.Empty, "Purchase Date is required.");
                        count++;
                        ErrorMessage       += count + "-Purchase Date is required.<br />";
                        ViewBag.MessageType = "error";
                    }

                    if (string.IsNullOrEmpty(ErrorMessage))
                    {
                        try
                        {
                            formSaleDetail.CreatedBy   = Convert.ToInt32(Session["emp_id"]);
                            formSaleDetail.ModifiedBy  = 0;
                            formSaleDetail.IsReceived  = "No";
                            formSaleDetail.ReceiveDate = null;
                            db.InsertFormSaleDetail(formSaleDetail.FormID, formSaleDetail.FormNo
                                                    , formSaleDetail.FormTypeID, formSaleDetail.FormPrice
                                                    , formSaleDetail.FormDescription, formSaleDetail.DepositTypeID
                                                    , formSaleDetail.BatchProgramID, formSaleDetail.ApplicantName
                                                    , formSaleDetail.FatherName, formSaleDetail.PhoneNo, formSaleDetail.CNIC
                                                    , formSaleDetail.DepositSlipNo, formSaleDetail.PurchaseDate
                                                    , formSaleDetail.AccountID, formSaleDetail.CreatedBy, formSaleDetail.IsActive
                                                    , formSaleDetail.ModifiedBy, formSaleDetail.IsReceived, formSaleDetail.ReceiveDate);
                            ViewBag.MessageType = "success";
                            ViewBag.Message     = "Data has been saved successfully.";
                        }
                        catch (EntityCommandExecutionException ex)
                        {
                            ViewBag.MessageType = "error";
                            ViewBag.Message     = ex.Message;
                            ModelState.AddModelError(string.Empty, ex.Message);
                        }
                    }
                    else
                    {
                        ViewBag.MessageType = "error";
                        ViewBag.Message     = ErrorMessage;
                    }
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Form # is already exists.");
                    ViewBag.MessageType = "error";
                    ViewBag.Message     = "Form # is already exists.";
                }
            }
            catch (DbEntityValidationException ex)
            {
                foreach (DbEntityValidationResult validationResult in ex.EntityValidationErrors)
                {
                    string entityName = validationResult.Entry.Entity.GetType().Name;
                    foreach (DbValidationError error in validationResult.ValidationErrors)
                    {
                        ModelState.AddModelError(string.Empty, error.ErrorMessage);
                        count++;
                        ErrorMessage += count + "-" + string.Concat(error.PropertyName, " is required.") + "<br />";
                    }
                }
                ViewBag.MessageType = "error";
                ViewBag.Message     = ErrorMessage;
            }
            model.FormSaleDetails        = db.FormSaleDetails.Where(f => f.PurchaseDate != null).OrderByDescending(a => a.FormID).ToList();
            model.SelectedFormSaleDetail = null;
            model.DisplayMode            = "WriteOnly";
            ViewBag.IsActive             = new SelectList(db.Options, "OptionDesc", "OptionDesc", formSaleDetail.IsActive);
            ViewBag.FormTypeID           = new SelectList(db.FormTypes, "FormTypeID", "FormTypeName", formSaleDetail.FormTypeID);
            ViewBag.DepositTypeID        = new SelectList(db.DepositTypes, "DepositTypeID", "DepositTypeName", formSaleDetail.DepositTypeID);
            ViewBag.BatchProgramID       = new SelectList(db.GetBatchProgramNameConcat("", 0), "ID", "Name", formSaleDetail.BatchProgramID);
            ViewBag.AccountID            = new SelectList(dbFinance.Bank_Account, "Account_ID", "Account_No", formSaleDetail.AccountID);
            return(View("Index", model));
        }