コード例 #1
0
    //פעולה הרצה כל פעם ששורש בגריד ויו נוצרת
    protected void Basket_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        //חישוב המחיר הכללי של כל המוצרים
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            int amountRequired = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "AmountRequired"));
            totalPrice += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Price")) * amountRequired;
        }

        //הוספת קונטרולים לפוטר כדי שיהיה אפשר להמיר בין סוגי מטבעות שונים
        else if (e.Row.RowType == DataControlRowType.Footer)
        {
            status.Visible = false;
            //יצירת כפתור של המרה לשקל
            LinkButton shekelButton = new LinkButton();
            shekelButton.Font.Underline = false;
            shekelButton.Text           = "₪";
            shekelButton.ForeColor      = Color.Gold;
            shekelButton.ID             = "shekelButton";

            //יצירת פעולה שתתרחש כאשר כפתור ההמרה לשקל ילחץ
            shekelButton.Click += (object _sender, EventArgs _e) =>
            {
                status.Visible       = false;
                Session["convertTo"] = 1.0;
                Session["Currency"]  = "₪";
                updateVariables();
                e.Row.Cells[0].Text      = "סך הכל:";
                e.Row.Cells[0].Font.Bold = true;
                e.Row.Cells[1].Text      = (totalPrice * convertTo).ToString() + " " + currency;
                e.Row.Cells[1].Font.Bold = true;
            };

            //יצירת כפתור המרה לדולר
            LinkButton dollarButton = new LinkButton();
            dollarButton.Font.Underline = false;
            dollarButton.Text           = "$";
            dollarButton.ForeColor      = Color.Gold;
            dollarButton.ID             = "dollarButton";

            //יצירת פעולה שתתרחש כאשר כפתור ההמרה לדולר יילחץ
            dollarButton.Click += (object _sender, EventArgs _e) =>
            {
                try
                {
                    CurrencyConvertorWS.CurrencyConvertorWS client = new CurrencyConvertorWS.CurrencyConvertorWS();
                    double ConversionRate = client.GetConversionRate(CurrencyConvertorWS.Currency.USD);
                    Session["convertTo"] = ConversionRate;
                    Session["Currency"]  = "$";
                    updateVariables();
                    e.Row.Cells[0].Text      = "סך הכל:";
                    e.Row.Cells[0].Font.Bold = true;
                    e.Row.Cells[1].Text      = (totalPrice * convertTo).ToString() + " " + currency;
                    e.Row.Cells[1].Font.Bold = true;
                }
                catch (Exception ex)
                {
                    status.Text    = ".שירות ההמרה למטבעות שונים אינו זמין כעת";
                    status.Visible = true;
                }
            };

            //יצירת כפתור המרה לאירו
            LinkButton euroButton = new LinkButton();
            euroButton.Font.Underline = false;
            euroButton.Text           = "€";
            euroButton.ForeColor      = Color.Gold;
            euroButton.ID             = "euroButton";

            //יצירת פעולה שתתרחש כאשר כפתור ההמרה לאירו יילחץ
            euroButton.Click += (object _sender, EventArgs _e) =>
            {
                try
                {
                    CurrencyConvertorWS.CurrencyConvertorWS client = new CurrencyConvertorWS.CurrencyConvertorWS();
                    double ConversionRate = client.GetConversionRate(CurrencyConvertorWS.Currency.EUR);
                    Session["convertTo"] = ConversionRate;
                    Session["Currency"]  = "€";
                    updateVariables();
                    e.Row.Cells[0].Text      = "סך הכל:";
                    e.Row.Cells[0].Font.Bold = true;
                    e.Row.Cells[1].Text      = (totalPrice * convertTo).ToString() + " " + currency;
                    e.Row.Cells[1].Font.Bold = true;
                }
                catch (Exception ex)
                {
                    status.Text    = ".שירות ההמרה למטבעות שונים אינו זמין כעת";
                    status.Visible = true;
                }
            };

            //לייבלים שמטרתם לשמש כ"קישוט"
            Label l = new Label();
            l.Text = " | ";
            Label l1 = new Label();
            l1.Text = " | ";

            //הוספת כל הקונטרולים שנוצרו לפוטר
            e.Row.Cells[2].Controls.Add(shekelButton);
            e.Row.Cells[2].Controls.Add(l);
            e.Row.Cells[2].Controls.Add(euroButton);
            e.Row.Cells[2].Controls.Add(l1);
            e.Row.Cells[2].Controls.Add(dollarButton);
            e.Row.Cells[0].Text      = "סך הכל:";
            e.Row.Cells[0].Font.Bold = true;
            e.Row.Cells[1].Text      = (totalPrice * convertTo).ToString() + " " + currency;
            e.Row.Cells[1].Font.Bold = true;
        }
    }
コード例 #2
0
    //מעדכן את הfooter של הטבלה
    protected void updateFooter()
    {
        status.Visible = false;
        //יצירת כפתור המרה לשקל
        LinkButton shekelButton = new LinkButton();

        shekelButton.Font.Underline = false;
        shekelButton.Text           = "₪";
        shekelButton.ForeColor      = Color.Gold;
        shekelButton.ID             = "shekelButton";

        //יצירת פעולה שתתרחש כאשר כפתור ההמרה לשקל יילחץ
        shekelButton.Click += (object _sender, EventArgs _e) =>
        {
            status.Visible       = false;
            Session["convertTo"] = 1.0;
            Session["Currency"]  = "₪";
            updateVariables();
            Basket.FooterRow.Cells[0].Text      = "סך הכל:";
            Basket.FooterRow.Cells[0].Font.Bold = true;
            Basket.FooterRow.Cells[1].Text      = (totalPrice * convertTo).ToString() + " " + currency;
            Basket.FooterRow.Cells[1].Font.Bold = true;
        };

        //יצירת כפתור המרה לדולר
        LinkButton dollarButton = new LinkButton();

        dollarButton.Font.Underline = false;
        dollarButton.Text           = "$";
        dollarButton.ForeColor      = Color.Gold;
        dollarButton.ID             = "dollarButton";

        //יצירת פעולה שתתרחש כאשר כפתור ההמרה לדולר יילחץ
        dollarButton.Click += (object _sender, EventArgs _e) =>
        {
            try
            {
                CurrencyConvertorWS.CurrencyConvertorWS client = new CurrencyConvertorWS.CurrencyConvertorWS();
                double ConversionRate = client.GetConversionRate(CurrencyConvertorWS.Currency.USD);
                Session["convertTo"] = ConversionRate;
                Session["Currency"]  = "$";
                updateVariables();
                Basket.FooterRow.Cells[0].Text      = "סך הכל:";
                Basket.FooterRow.Cells[0].Font.Bold = true;
                Basket.FooterRow.Cells[1].Text      = (totalPrice * convertTo).ToString() + " " + currency;
                Basket.FooterRow.Cells[1].Font.Bold = true;
            }
            catch (Exception ex)
            {
                status.Text    = ".שירות ההמרה למטבעות שונים אינו זמין כעת";
                status.Visible = true;
            }
        };

        //יצירת כפתור המרה לאירו
        LinkButton euroButton = new LinkButton();

        euroButton.Font.Underline = false;
        euroButton.Text           = "€";
        euroButton.ForeColor      = Color.Gold;
        euroButton.ID             = "euroButton";

        //יצירת פעולה שתתרחש כאשר כפתור ההמרה לאירו יילחץ
        euroButton.Click += (object _sender, EventArgs _e) =>
        {
            try
            {
                CurrencyConvertorWS.CurrencyConvertorWS client = new CurrencyConvertorWS.CurrencyConvertorWS();
                double ConversionRate = client.GetConversionRate(CurrencyConvertorWS.Currency.EUR);
                Session["convertTo"] = ConversionRate;
                Session["Currency"]  = "€";
                updateVariables();
                Basket.FooterRow.Cells[0].Text      = "סך הכל:";
                Basket.FooterRow.Cells[0].Font.Bold = true;
                Basket.FooterRow.Cells[1].Text      = (totalPrice * convertTo).ToString() + " " + currency;
                Basket.FooterRow.Cells[1].Font.Bold = true;
            }

            catch (Exception ex)
            {
                status.Text    = ".שירות ההמרה למטבעות שונים אינו זמין כעת";
                status.Visible = true;
            }
        };

        //לייבלים שמטרתם לשמש כ"קישוט"
        Label l = new Label();

        l.Text = " | ";
        Label l1 = new Label();

        l1.Text = " | ";

        //הוספת כל הcontrols שנוצרו לfooter
        Basket.FooterRow.Cells[2].Controls.Add(shekelButton);
        Basket.FooterRow.Cells[2].Controls.Add(l);
        Basket.FooterRow.Cells[2].Controls.Add(euroButton);
        Basket.FooterRow.Cells[2].Controls.Add(l1);
        Basket.FooterRow.Cells[2].Controls.Add(dollarButton);
        Basket.FooterRow.Cells[0].Text      = "סך הכל:";
        Basket.FooterRow.Cells[0].Font.Bold = true;
        Basket.FooterRow.Cells[1].Text      = (totalPrice * convertTo).ToString() + " " + currency;
        Basket.FooterRow.Cells[1].Font.Bold = true;
    }