本文介绍了显示屏上显示日历的同一天多个音符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有些音符/我存储在数据库中的事件显示日历。
在某些日期添加多个笔记。

I want to display calendar with some notes/events which i stored in database.In some date more than one notes are added.

现在,当页面加载我想,在我的日历控件。

Now when page is load i want that all in my calendar control.

我做到这一点,但它只能显示(第1输入)注意在日历虽然我在同一天保存多个音符。

I done that BUT It displays only one(1st entered) note in the calendar although i saved more than one notes on that same DATE.

它看起来像下面的图片..

It looks like below image..

在这个图片在日期7,我增加2注,但它只能显示...

In this Image On Date 7 i added 2 Notes but it displays only one...

我的code是如下...

My code is as below...

public partial class _Default : System.Web.UI.Page

{

    public static ArrayList MyColllection;

    //Structure

    public struct My_Date

    {

        public DateTime Cal_Date;

        public string Cal_Type;

        public string Cal_Title;

    }

    protected void Page_Load(object sender, EventArgs e)

    {

        if (!Page.IsPostBack)

        {

            MyColllection = Get_Event();

        }

    }

    public ArrayList Get_Event()

    {

        SqlConnection myCon = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);

        SqlCommand myComd = new SqlCommand("SELECT * FROM Cal_Event",myCon);

        SqlDataReader myDataReader;

        try

        {

            myCon.Open();

            myDataReader = myComd.ExecuteReader();

            MyColllection = new ArrayList();

            My_Date temp;

            //Iterate through the data reader

            while(myDataReader.Read())

            {

                temp.Cal_Title = myDataReader.GetValue(1).ToString();

                temp.Cal_Date = Convert.ToDateTime(myDataReader.GetValue(2));

                temp.Cal_Type = myDataReader.GetValue(3).ToString();

                MyColllection.Add(temp);

            }

        }

        catch

        {}

        finally

        {

            myCon.Close();

        }

        return MyColllection;

    }

    public void Calendar1_DayRender(object o, DayRenderEventArgs e)

    {

        string FontColor;

        string compDate = "01/01/1900"; // Date to compare initially

        DateTime DayVal = Convert.ToDateTime(compDate);

        bool mItemDay = false;

        bool dayTextChanged = false;

        StringBuilder strTemp = new StringBuilder();

        foreach (My_Date temp_dt in MyColllection)

        {

            if ("01/01/1900" != temp_dt.Cal_Date.ToShortDateString())

            {

                if (dayTextChanged == true)

                {

                    break;

                }

                mItemDay = false;

                DayVal = temp_dt.Cal_Date;

            }

            else

            {

                mItemDay = true;

            }

            if (e.Day.Date == Convert.ToDateTime(temp_dt.Cal_Date.ToString("d")))

            {

                switch (temp_dt.Cal_Type)

                {

                    case "1" :

                        FontColor = "Blue";

                        break;

                    case "2":

                        FontColor = "Red";

                        break;

                    default:

                        FontColor = "Black";

                        break;

                }

                if (mItemDay == false)

                {

                    strTemp = new StringBuilder();

                }

                else

                {

                    strTemp.Append("<br>");

                }

                strTemp.Append("<span style='font-family:verdana;font-size:10px;font-weight:bold;color'");

                strTemp.Append(FontColor);

                strTemp.Append("'><br>");

                strTemp.Append(temp_dt.Cal_Title.ToString());

                strTemp.Append("</span>");

                e.Cell.BackColor = System.Drawing.Color.Yellow;

                dayTextChanged = true;

            }

        }

        if (dayTextChanged == true)

        {

            e.Cell.Controls.Add(new LiteralControl(strTemp.ToString()));

        }

    }

}

所以,我需要显示在同一天多个Notes ...

So I need to display multiple Notes on same day...

所以,我该怎么做?

由于提前....

推荐答案

日历基本上日期选择器,并用它们来显示数据是最常见的错误的人做一个。用一个ListView显示数据/事件;日历中从来就这一点。

Calendars are basically date pickers and using them to display data is one of the most common mistakes people make. Use a ListView to display your data/events; calendars were never meant for that.

在某些阶段日历细胞要舒展作为事件被添加在同一天,打破了整个显示。如果你试图设置限制,那么人们会为什么其他事件列抱怨,并开始询问和他们都没有,等等。

At some stage the calendar cells are going to stretch as events are added for the same day, breaking the entire display. And if you try to set a limit, then people are going to complain and start asking why other events are listed and theirs aren't, etc.

在您的code,你基本上吞咽处理这个异常代替。注释掉的try-catch-finally程序(离开关闭()),并检查了什么错误,你得到那么:)

In your code, you're basically swallowing the exception instead of handling it. Comment out the try-catch-finally (leave the Close()) and check what error you get then :)

这篇关于显示屏上显示日历的同一天多个音符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 12:29
查看更多