예제 #1
0
    protected void Repeater16_ItemCreated(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            DataRowView dr = (DataRowView)e.Item.DataItem;
            if (dr == null || dr.Row == null)
            {
                return;
            }
            DataRow row     = dr.Row;
            Invoice invoice = InvoiceDB.LoadAll(row);


            // get controls
            Repeater           lstCreditNotes        = (Repeater)e.Item.FindControl("lstCreditNotes");
            HtmlGenericControl div_credit_notes_list = (HtmlGenericControl)e.Item.FindControl("div_credit_notes_list");
            HtmlGenericControl span_credit_notes_trailing_space_row = (HtmlGenericControl)e.Item.FindControl("span_credit_notes_trailing_space_row");
            Label      lnkAddCreditNote       = (Label)e.Item.FindControl("lnkAddCreditNote");
            LinkButton showHideCreditNoteList = (LinkButton)e.Item.FindControl("showHideCreditNoteList");


            // get credit notes
            DataTable tblCreditNotes = CreditNoteDB.GetDataTableByInvoice(invoice.InvoiceID);
            lstCreditNotes.Visible = tblCreditNotes.Rows.Count > 0;
            span_credit_notes_trailing_space_row.Visible = tblCreditNotes.Rows.Count > 0;
            if (tblCreditNotes.Rows.Count > 0)
            {
                tblCreditNotes.Columns.Add("credit_note_url", typeof(string));
                tblCreditNotes.Columns.Add("show_status", typeof(string));
                tblCreditNotes.Columns.Add("status", typeof(string));
                tblCreditNotes.Columns.Add("show_reverse_link", typeof(string));
                tblCreditNotes.Columns.Add("show_status_column", typeof(string));
                for (int i = 0; i < tblCreditNotes.Rows.Count; i++)
                {
                    CreditNote creditNote = CreditNoteDB.Load(tblCreditNotes.Rows[i]);
                    tblCreditNotes.Rows[i]["credit_note_url"] = creditNote.GetViewPopupLinkV2();

                    tblCreditNotes.Rows[i]["show_status"]        = creditNote.IsReversed ? "1" : "0";
                    tblCreditNotes.Rows[i]["show_reverse_link"]  = !creditNote.IsReversed && !invoice.IsReversed ? "1" : "0";
                    tblCreditNotes.Rows[i]["show_status_column"] = !invoice.IsReversed ? "1" : "0";
                }

                lstCreditNotes.DataSource = tblCreditNotes;
                lstCreditNotes.DataBind();
            }

            if (!invoice.IsPaID) // can add items
            {
                lnkAddCreditNote.Text = CreditNote.GetAddCreditNotePopupLinkV2(invoice.InvoiceID, "window.location.href = window.location.href;");
            }
            else
            {
                lnkAddCreditNote.Text = tblCreditNotes.Rows.Count > 0 ? string.Empty : "No Adjustment Notes";
            }
            //span_add_credit_notes_row.Style["text-align"] = (tblCreditNotes.Rows.Count > 0) ? "center" : null;  // if have table, center add link, else left align
            lnkAddCreditNote.Visible                 = lnkAddCreditNote.Text.Length > 0;
            showHideCreditNoteList.OnClientClick     = "javascript:show_hide_byname('div_credit_notes_list_" + invoice.InvoiceID + "'); return false;";
            showHideCreditNoteList.Visible           = tblCreditNotes.Rows.Count > 0;
            div_credit_notes_list.Attributes["name"] = "div_credit_notes_list_" + invoice.InvoiceID;
        }
    }