Example #1
0
        // GET: /AdvancePayment/Delete/<id>
        public ActionResult Delete(
            Int32?AdvancePaymentID
            )
        {
            if (
                AdvancePaymentID == null
                )
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            dtCompany = AdvancePayment_CompanyData.SelectAll();
            dtClient  = AdvancePayment_ClientData.SelectAll();
            dtProject = AdvancePayment_ProjectData.SelectAll();

            AdvancePayment AdvancePayment = new AdvancePayment();

            AdvancePayment.AdvancePaymentID = System.Convert.ToInt32(AdvancePaymentID);
            AdvancePayment         = AdvancePaymentData.Select_Record(AdvancePayment);
            AdvancePayment.Company = new Company()
            {
                CompanyID     = (Int32)AdvancePayment.CompanyID
                , CompanyName = (from DataRow rowCompany in dtCompany.Rows
                                 where AdvancePayment.CompanyID == (int)rowCompany["CompanyID"]
                                 select(String) rowCompany["CompanyName"]).FirstOrDefault()
            };
            AdvancePayment.Client = new Client()
            {
                ClientID     = (Int32)AdvancePayment.ClientID
                , ClientName = (from DataRow rowClient in dtClient.Rows
                                where AdvancePayment.ClientID == (int)rowClient["ClientID"]
                                select(String) rowClient["ClientName"]).FirstOrDefault()
            };
            AdvancePayment.Project = new Project()
            {
                ProjectID     = (Int32)AdvancePayment.ProjectID
                , ProjectName = (from DataRow rowProject in dtProject.Rows
                                 where AdvancePayment.ProjectID == (int)rowProject["ProjectID"]
                                 select(String) rowProject["ProjectName"]).FirstOrDefault()
            };

            if (AdvancePayment == null)
            {
                return(HttpNotFound());
            }
            return(View(AdvancePayment));
        }
Example #2
0
        // GET: /AdvancePayment/
        public ActionResult Index(string sortOrder,
                                  String SearchField,
                                  String SearchCondition,
                                  String SearchText,
                                  String Export,
                                  int?PageSize,
                                  int?page,
                                  string command)
        {
            if (command == "Show All")
            {
                SearchField                = null;
                SearchCondition            = null;
                SearchText                 = null;
                Session["SearchField"]     = null;
                Session["SearchCondition"] = null;
                Session["SearchText"]      = null;
            }
            else if (command == "Add New Record")
            {
                return(RedirectToAction("Create"));
            }
            else if (command == "Export")
            {
                Session["Export"] = Export;
            }
            else if (command == "Search" | command == "Page Size")
            {
                if (!string.IsNullOrEmpty(SearchText))
                {
                    Session["SearchField"]     = SearchField;
                    Session["SearchCondition"] = SearchCondition;
                    Session["SearchText"]      = SearchText;
                }
            }
            if (command == "Page Size")
            {
                Session["PageSize"] = PageSize;
            }

            ViewData["SearchFields"]     = GetFields((Session["SearchField"] == null ? "Advance Payment I D" : Convert.ToString(Session["SearchField"])));
            ViewData["SearchConditions"] = Library.GetConditions((Session["SearchCondition"] == null ? "Contains" : Convert.ToString(Session["SearchCondition"])));
            ViewData["SearchText"]       = Session["SearchText"];
            ViewData["Exports"]          = Library.GetExports((Session["Export"] == null ? "Pdf" : Convert.ToString(Session["Export"])));
            ViewData["PageSizes"]        = Library.GetPageSizes();

            ViewData["CurrentSort"] = sortOrder;
            ViewData["AdvancePaymentIDSortParm"] = sortOrder == "AdvancePaymentID_asc" ? "AdvancePaymentID_desc" : "AdvancePaymentID_asc";
            ViewData["PaymentDateSortParm"]      = sortOrder == "PaymentDate_asc" ? "PaymentDate_desc" : "PaymentDate_asc";
            ViewData["CompanyIDSortParm"]        = sortOrder == "CompanyID_asc" ? "CompanyID_desc" : "CompanyID_asc";
            ViewData["ClientIDSortParm"]         = sortOrder == "ClientID_asc" ? "ClientID_desc" : "ClientID_asc";
            ViewData["ProjectIDSortParm"]        = sortOrder == "ProjectID_asc" ? "ProjectID_desc" : "ProjectID_asc";
            ViewData["GrossAmountSortParm"]      = sortOrder == "GrossAmount_asc" ? "GrossAmount_desc" : "GrossAmount_asc";
            ViewData["TDSRateSortParm"]          = sortOrder == "TDSRate_asc" ? "TDSRate_desc" : "TDSRate_asc";
            ViewData["CGSTRateSortParm"]         = sortOrder == "CGSTRate_asc" ? "CGSTRate_desc" : "CGSTRate_asc";
            ViewData["SGSTRateSortParm"]         = sortOrder == "SGSTRate_asc" ? "SGSTRate_desc" : "SGSTRate_asc";
            ViewData["IGSTRateSortParm"]         = sortOrder == "IGSTRate_asc" ? "IGSTRate_desc" : "IGSTRate_asc";
            ViewData["RemarksSortParm"]          = sortOrder == "Remarks_asc" ? "Remarks_desc" : "Remarks_asc";

            dtAdvancePayment = AdvancePaymentData.SelectAll();
            dtCompany        = AdvancePayment_CompanyData.SelectAll();
            dtClient         = AdvancePayment_ClientData.SelectAll();
            dtProject        = AdvancePayment_ProjectData.SelectAll();

            try
            {
                if (!string.IsNullOrEmpty(Convert.ToString(Session["SearchField"])) & !string.IsNullOrEmpty(Convert.ToString(Session["SearchCondition"])) & !string.IsNullOrEmpty(Convert.ToString(Session["SearchText"])))
                {
                    dtAdvancePayment = AdvancePaymentData.Search(Convert.ToString(Session["SearchField"]), Convert.ToString(Session["SearchCondition"]), Convert.ToString(Session["SearchText"]));
                }
            }
            catch { }

            var Query = from rowAdvancePayment in dtAdvancePayment.AsEnumerable()
                        join rowCompany in dtCompany.AsEnumerable() on rowAdvancePayment.Field <Int32>("CompanyID") equals rowCompany.Field <Int32>("CompanyID")
                        join rowClient in dtClient.AsEnumerable() on rowAdvancePayment.Field <Int32>("ClientID") equals rowClient.Field <Int32>("ClientID")
                        join rowProject in dtProject.AsEnumerable() on rowAdvancePayment.Field <Int32>("ProjectID") equals rowProject.Field <Int32>("ProjectID")
                        select new AdvancePayment()
            {
                AdvancePaymentID = rowAdvancePayment.Field <Int32>("AdvancePaymentID")
                , PaymentDate    = rowAdvancePayment.Field <DateTime>("PaymentDate")
                ,
                Company = new Company()
                {
                    CompanyID     = rowCompany.Field <Int32>("CompanyID")
                    , CompanyName = rowCompany.Field <String>("CompanyName")
                }
                ,
                Client = new Client()
                {
                    ClientID     = rowClient.Field <Int32>("ClientID")
                    , ClientName = rowClient.Field <String>("ClientName")
                }
                ,
                Project = new Project()
                {
                    ProjectID     = rowProject.Field <Int32>("ProjectID")
                    , ProjectName = rowProject.Field <String>("ProjectName")
                }
                , GrossAmount = rowAdvancePayment.Field <Decimal>("GrossAmount")
                , TDSRate     = rowAdvancePayment.Field <Decimal>("TDSRate")
                , CGSTRate    = rowAdvancePayment.Field <Decimal>("CGSTRate")
                , SGSTRate    = rowAdvancePayment.Field <Decimal>("SGSTRate")
                , IGSTRate    = rowAdvancePayment.Field <Decimal>("IGSTRate")
                , Remarks     = rowAdvancePayment.Field <String>("Remarks")
            };

            switch (sortOrder)
            {
            case "AdvancePaymentID_desc":
                Query = Query.OrderByDescending(s => s.AdvancePaymentID);
                break;

            case "AdvancePaymentID_asc":
                Query = Query.OrderBy(s => s.AdvancePaymentID);
                break;

            case "PaymentDate_desc":
                Query = Query.OrderByDescending(s => s.PaymentDate);
                break;

            case "PaymentDate_asc":
                Query = Query.OrderBy(s => s.PaymentDate);
                break;

            case "CompanyID_desc":
                Query = Query.OrderByDescending(s => s.Company.CompanyName);
                break;

            case "CompanyID_asc":
                Query = Query.OrderBy(s => s.Company.CompanyName);
                break;

            case "ClientID_desc":
                Query = Query.OrderByDescending(s => s.Client.ClientName);
                break;

            case "ClientID_asc":
                Query = Query.OrderBy(s => s.Client.ClientName);
                break;

            case "ProjectID_desc":
                Query = Query.OrderByDescending(s => s.Project.ProjectName);
                break;

            case "ProjectID_asc":
                Query = Query.OrderBy(s => s.Project.ProjectName);
                break;

            case "GrossAmount_desc":
                Query = Query.OrderByDescending(s => s.GrossAmount);
                break;

            case "GrossAmount_asc":
                Query = Query.OrderBy(s => s.GrossAmount);
                break;

            case "TDSRate_desc":
                Query = Query.OrderByDescending(s => s.TDSRate);
                break;

            case "TDSRate_asc":
                Query = Query.OrderBy(s => s.TDSRate);
                break;

            case "CGSTRate_desc":
                Query = Query.OrderByDescending(s => s.CGSTRate);
                break;

            case "CGSTRate_asc":
                Query = Query.OrderBy(s => s.CGSTRate);
                break;

            case "SGSTRate_desc":
                Query = Query.OrderByDescending(s => s.SGSTRate);
                break;

            case "SGSTRate_asc":
                Query = Query.OrderBy(s => s.SGSTRate);
                break;

            case "IGSTRate_desc":
                Query = Query.OrderByDescending(s => s.IGSTRate);
                break;

            case "IGSTRate_asc":
                Query = Query.OrderBy(s => s.IGSTRate);
                break;

            case "Remarks_desc":
                Query = Query.OrderByDescending(s => s.Remarks);
                break;

            case "Remarks_asc":
                Query = Query.OrderBy(s => s.Remarks);
                break;

            default:      // Name ascending
                Query = Query.OrderBy(s => s.AdvancePaymentID);
                break;
            }

            if (command == "Export")
            {
                GridView  gv = new GridView();
                DataTable dt = new DataTable();
                dt.Columns.Add("Advance Payment I D", typeof(string));
                dt.Columns.Add("Payment Date", typeof(string));
                dt.Columns.Add("Company I D", typeof(string));
                dt.Columns.Add("Client I D", typeof(string));
                dt.Columns.Add("Project I D", typeof(string));
                dt.Columns.Add("Gross Amount", typeof(string));
                dt.Columns.Add("T D S Rate", typeof(string));
                dt.Columns.Add("C G S T Rate", typeof(string));
                dt.Columns.Add("S G S T Rate", typeof(string));
                dt.Columns.Add("I G S T Rate", typeof(string));
                dt.Columns.Add("Remarks", typeof(string));
                foreach (var item in Query)
                {
                    dt.Rows.Add(
                        item.AdvancePaymentID
                        , item.PaymentDate
                        , item.Company.CompanyName
                        , item.Client.ClientName
                        , item.Project.ProjectName
                        , item.GrossAmount
                        , item.TDSRate
                        , item.CGSTRate
                        , item.SGSTRate
                        , item.IGSTRate
                        , item.Remarks
                        );
                }
                gv.DataSource = dt;
                gv.DataBind();
                ExportData(Export, gv, dt);
            }

            int pageNumber = (page ?? 1);
            int?pageSZ     = (Convert.ToInt32(Session["PageSize"]) == 0 ? 5 : Convert.ToInt32(Session["PageSize"]));

            return(View(Query.ToPagedList(pageNumber, (pageSZ ?? 5))));
        }