private void LoadGrid()
        {
            int       clientId  = 0;
            DateTime  startDate = DateTime.MinValue;
            DateTime  endDate   = DateTime.MinValue;
            eJobState jobState  = new eJobState();

            Facade.IOrganisation  facOrg = new Facade.Organisation();
            Entities.Organisation enOrg  = new Entities.Organisation();

            // Client
            if (cboClient.Text != "")
            {
                clientId          = Convert.ToInt32(cboClient.SelectedValue);
                pnlFilter.Visible = true;
            }

            if (cboClient.SelectedValue != "")
            {
                clientId          = Convert.ToInt32(cboClient.SelectedValue);
                enOrg             = facOrg.GetForIdentityId(Convert.ToInt32(cboClient.SelectedValue));
                cboClient.Text    = enOrg.OrganisationName;
                pnlFilter.Visible = true;
            }
            //else
            //    pnlFilter.Visible = false;

            // Date Range
            if (dteStartDate.SelectedDate != DateTime.MinValue)
            {
                startDate = dteStartDate.SelectedDate.Value;
                startDate = startDate.Subtract(startDate.TimeOfDay);
            }

            if (dteEndDate.SelectedDate != DateTime.MinValue)
            {
                endDate = dteEndDate.SelectedDate.Value;
                endDate = endDate.Subtract(endDate.TimeOfDay);
                endDate = endDate.Add(new TimeSpan(23, 59, 59));
            }

            // Get Jobs to Invoice
            Facade.IInvoice facInvoice = new Facade.Invoice();
            DataSet         dsInvoicing;

            bool posted = false;

            if (startDate != DateTime.MinValue || endDate != DateTime.MinValue)
            {
                dsInvoicing = facInvoice.GetJobsToInvoiceWithParamsAndDate(clientId, jobState, posted, startDate, endDate);
            }
            else
            {
                if (clientId == 0)
                {
                    dsInvoicing = facInvoice.GetAllJobsToInvoice();
                }
                else
                {
                    dsInvoicing = facInvoice.GetJobsToInvoiceWithParams(clientId, jobState, posted);
                }
            }

            // Check whether account is on hold
            if (dsInvoicing.Tables[0].Rows.Count > 0)
            {
                if (Convert.ToInt32(dsInvoicing.Tables[0].Rows[0]["OnHold"]) == 1)
                {
                    dlJob.Enabled = false;

                    if (string.IsNullOrEmpty(cboClient.Text))
                    {
                        lblOnHold.Visible = true;
                        lblOnHold.Text    = "Client accounts are on hold, please update their on-hold status in order to raise invoices.</A>";
                    }
                    else
                    {
                        lblOnHold.Visible = true;
                        lblOnHold.Text    = cboClient.Text + "'s account has been put on hold, please go to <A HREF=../Organisation/addupdateorganisation.aspx?IdentityId=" + Convert.ToInt32(cboClient.SelectedValue) + ">" + cboClient.Text + "'s details to change.</A>";
                    }
                }
                else
                {
                    lblOnHold.Visible = false;
                }

                dlJob.Visible = true;
            }
            else
            {
                lblOnHold.Visible = true;
                lblOnHold.Text    = "With the given parameters no jobs have been found.";
                dlJob.Visible     = false;
            }

            DataView dvInvoice = new DataView(dsInvoicing.Tables[0]);

            // Sort By
            foreach (ListItem sortField in rdoSortType.Items)
            {
                if (sortField.Selected)
                {
                    dvInvoice.Sort = sortField.Text.Replace(" ", "");
                }
            }

            // Load List
            dlJob.DataSource = dvInvoice;

            dlJob.DataBind();

            lblJobCount.Text = "There are " + dlJob.Items.Count.ToString() + " jobs ready to invoice.";

            pnlNormalJob.Visible = true;
            btnFilter.Visible    = true;
            btnFilter1.Visible   = true;
            btnClear.Visible     = true;
            btnClear1.Visible    = true;
            pnlSort.Visible      = true;
            lblJobCount.Visible  = true;
        }
예제 #2
0
        private void LoadGrid()
        {
            int       clientId  = 0;
            DateTime  startDate = DateTime.MinValue;
            DateTime  endDate   = DateTime.MinValue;
            eJobState jobState  = new eJobState();

            // Client
            if (cboClient.Text != "")
            {
                clientId = Convert.ToInt32(cboClient.SelectedValue);
            }

            // Job State
            if (cboJobState.SelectedValue != string.Empty)
            {
                jobState = (eJobState)Enum.Parse(typeof(eJobState), cboJobState.SelectedValue.Replace(" ", ""));
            }

            // Date Range
            if (dteStartDate.SelectedDate != DateTime.MinValue)
            {
                startDate = dteStartDate.SelectedDate.Value;
                startDate = startDate.Subtract(startDate.TimeOfDay);
            }

            if (dteEndDate.SelectedDate != DateTime.MinValue)
            {
                endDate = dteEndDate.SelectedDate.Value;
                endDate = endDate.Subtract(endDate.TimeOfDay);
                endDate = endDate.Add(new TimeSpan(23, 59, 59));
            }

            // Get Jobs to Invoice
            Facade.IInvoice facInvoice = new Facade.Invoice();
            DataSet         dsInvoicing;

            bool posted = false;

            if (startDate != DateTime.MinValue || endDate != DateTime.MinValue)
            {
                dsInvoicing = facInvoice.GetJobsToInvoiceWithParamsAndDate(clientId, jobState, posted, startDate, endDate);
            }
            else
            {
                if (clientId == 0)
                {
                    dsInvoicing = facInvoice.GetAllJobsToInvoice();
                }
                else
                {
                    dsInvoicing = facInvoice.GetJobsToInvoiceWithParams(clientId, jobState, posted);
                }
            }

            // Check whether account is on hold
            if (dsInvoicing.Tables.Count > 0)
            {
                if (dsInvoicing.Tables[0].Rows.Count > 0)
                {
                    if (Convert.ToInt32(dsInvoicing.Tables[0].Rows[0]["OnHold"]) == 1)
                    {
                        dgJobs.Enabled    = false;
                        lblOnHold.Visible = true;
                        lblOnHold.Text    = cboClient.Text + "'s account has been put on hold, please go to <A HREF=../Organisation/addupdateorganisation.aspx?IdentityId=" + Convert.ToInt32(cboClient.SelectedValue) + ">" + cboClient.Text + "'s details to change.</A>";
                    }
                    else
                    {
                        lblOnHold.Visible = false;
                    }

                    dgJobs.Visible = true;
                }
                else
                {
                    lblOnHold.Visible    = true;
                    lblOnHold.Text       = "With the given parameters no jobs have been found.";
                    dgJobs.Visible       = false;
                    pnlNormalJob.Visible = false;
                    lblClient.Text       = "Client";
                    cboClient.Visible    = true;
                }

                // Put in dummy checkbox column
                dsInvoicing.Tables[0].Columns.Add("Include", typeof(Boolean));

                // Sort By
                DataView dvInvoice = new DataView(dsInvoicing.Tables[0]);

                if (chkOnlyShowTicked.Checked)
                {
                    if (m_selectedJobs.Count != 0)
                    {
                        dvInvoice.RowFilter = "jobId IN (" + hidSelectedJobs.Value + ")";
                    }
                }
                // Load List
                dgJobs.DataSource = dvInvoice;

                if (cboClient.SelectedValue == String.Empty)
                {
                    dgJobs.GroupBy = "OrganisationName";
                }
                else
                {
                    dgJobs.Levels[0].AllowGrouping = false;
                    dgJobs.Levels[0].Columns["OrganisationName"].Visible = false;
                }

                Session[C_EXPORTCSV_VS] = dvInvoice;

                dgJobs.DataBind();

                // Check All Now We Have Filtered Down
                if (dgJobs.Items.Count >= 1)
                {
                    btnExport.Visible = true;
                    ComponentArt.Web.UI.GridItem griditemMyRow;
                    decimal jobTotal = 0.0M;
                    int     jobCount = 0;

                    for (int i = 0; i <= dgJobs.Items.Count - 1; i++)
                    {
                        griditemMyRow = dgJobs.Items[i];

                        if (chkOnlyShowTicked.Checked)
                        {
                            griditemMyRow["Include"] = true;
                            jobTotal += Decimal.Parse(griditemMyRow["ChargeAmount"].ToString());
                            jobCount++;
                        }
                        else
                        {
                            int jobId = 0;

                            jobId = Convert.ToInt32(griditemMyRow["JobId"]);

                            if (m_selectedJobs.Contains(jobId.ToString()))
                            {
                                griditemMyRow["Include"] = true;
                                jobTotal += Decimal.Parse(griditemMyRow["ChargeAmount"].ToString());
                                jobCount++;
                            }
                        }
                    }

                    if (jobCount != 0)
                    {
                        lblDetails.Text   = "You have selected " + jobCount + " job(s), and the total amount is " + jobTotal.ToString("C");
                        hidJobTotal.Value = jobTotal.ToString();
                        hidJobCount.Value = jobCount.ToString();
                    }
                    else
                    {
                        hidJobTotal.Value = hidJobCount.Value = "0";
                        lblDetails.Text   = "";
                    }
                }
            }
            else
            {
                btnExport.Visible    = false;
                lblOnHold.Visible    = true;
                lblOnHold.Text       = "With the given parameters no jobs have been found.";
                dgJobs.Visible       = false;
                pnlNormalJob.Visible = false;
                lblClient.Text       = "Client";
                cboClient.Visible    = true;
            }

            if (dgJobs.Items.Count >= 1)
            {
                if (cboClient.Text != "")
                {
                    chkMarkAll.Visible = true;

                    // If these jobs ready for invoice show Create Invoice Button (ONLY FOR READY-FOR-INVOICE)
                    if (jobState == eJobState.ReadyToInvoice)
                    {
                        btnCreateInvoice.Visible = btnCreateInvoice2.Visible = true;
                    }

                    dgJobs.Levels[0].Columns[1].Visible = true;
                    btnSaveFilter.Visible = true;
                }
                else
                {
                    //TODO: dgJobs.GroupBy[2].ToString();
                    dgJobs.Levels[0].Columns[1].Visible = false;
                }
            }

            lblJobCount.Text = "There are " + dgJobs.Items.Count.ToString() + " jobs ready to invoice.";

            pnlNormalJob.Visible = true;
            btnFilter.Visible    = btnFilter2.Visible = true;
            btnClear.Visible     = btnClear2.Visible = true;
        }