简体   繁体   English

如何在C#中创建时间表

[英]how to create Schedule in c#

I'm new into programing and still learning. 我是编程和学习的新手。 Currently I'm coding simple form for my schedule program (c#) in MS Visual Studio 2017. I already program day in month grid ( when you change date program generate gridview for it) but I have two important problem: 当前,我正在为MS Visual Studio 2017中的日程安排程序(c#)编写简单的表单。我已经对月份网格进行了编程(当您更改日期程序时,会为其生成gridview),但是我有两个重要的问题:


  1. I would like to get day number in each cell, I tried use loop while and foreach but it doesn't work.... 我想在每个单元格中获得天数,我尝试在while和foreach中使用循环,但是它不起作用。
  2. Second thing is that I would like to save my appointment in cell. 第二件事是我想将约会保存在单元格中。 If its possible I would rather not use database, and I really don't want to use solutions that I would have to pay. 如果可能的话,我宁愿不使用数据库,而且我真的不想使用我必须付费的解决方案。

Here's my code: 这是我的代码:

namespace WindowsFormsApp1
{
public partial class Kalendarz : Form
{
    public Kalendarz()
    {
        InitializeComponent();
    }



    private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
    {
        DateTime date_start = this.dateTimePicker1.Value;
        this.textBox2.Text = date_start.ToString("hh-mm-dd-MM-yyyy"); // czas startu
        this.textBox1.Text = date_start.ToString("MMMM");
        int Month = date_start.Month;
        int Year = date_start.Year;
        int NoD = DateTime.DaysInMonth(Year, Month);

        Decimal NoWD = Decimal.Divide(NoD, 7.0m);


        if (NoWD > 4.1m)
        {
            int WN = 5;
            dataGridView1.RowCount = WN;
            int n0 = 1;

           foreach(DataGridCell cell in dataGridView1)
            {

                while (n0 = NoD; n0++)

            }

        }
        else
        {
            int WN = 4;
            dataGridView1.RowCount = WN;

        }




    }

    private void checkBox1_CheckedChanged(object sender, EventArgs e)
    {
        if (checkBox1.Checked)
        {
            dataGridView1.Columns["s"].Visible = true;
            dataGridView1.Columns["st"].Visible = true;
        }
        else if (!checkBox1.Checked)
        {
            dataGridView1.Columns["s"].Visible = false;
            dataGridView1.Columns["st"].Visible = false;

        }

    }

    private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
    {

    }
}

Do you have any suggestions what can I do ? 您有什么建议我该怎么办? I found something like that but I don't have any idea how to loop it dataGridView.CurrentCell.Value = newValue.ToString (); 我发现了类似的东西,但我不知道如何将其循环dataGridView.CurrentCell.Value = newValue.ToString ();

Be careful, what you whish for ... 小心点,您希望 ...

Regarding 1st request: This code will fill a DataGridView with day numbers, starting on the set day in week and not exceeding number of days in month, provided you have enough rows an columns, filling it from left to right (as opposed to ie top-down). 关于第一个请求:如果您有足够的行,并且从左到右(从顶部到顶部)填充,那么这段代码将从日期的星期几开始,以不超过月的天数填充日期日期的DataGridView。 -下)。 I'd advice 7 columns, unless you want to have a lot of fun with calendar. 我建议您选择7栏,除非您想从日历中获得很多乐趣。 Guessing from your name, you're Polish and as far as I know week starts with Monday in Poland. 根据您的名字猜测,您是波兰人,据我所知,一周从波兰的星期一开始。 You'd need a modification to the code for week starting with Sunday. 您需要修改从星期日开始的一周的代码。

VB.NET: VB.NET:

    Dim DayCounter As Int16 = 1
    Dim DayInWeekStart As Int16 = 2   ' 1 = MON, 2 = TUE, 3 = WED, ...
    Dim DayInMonthTotal As Int16 = 31
    For ir = 0 To Me.dgv.rows.count - 1
        For ic = 0 To Me.dgv.columns.count - 1   ' you should have 7 columns for MON-SUN in your DataGridView
            If ir = 0 And (ic + 1) < DayInWeekStart And DayCounter < DayInMonthTotal Then
                ' skip / do nothing
            Else
                Me.dgv.rows(ir).cells(ic).value = DayCounter   ' set DGV cell value to the date
                DayCounter += 1   ' iterate day in month number
            End If
        Next
    Next

C# (converted): C#(转换后):

    Int16 DayCounter = 1;
    Int16 DayInWeekStart = 2;
    // 1 = MON, 2 = TUE, 3 = WED, ...
    Int16 DayInMonthTotal = 31;
    For (ir = 0; ir <= this.dgv.rows.count - 1; ir++) {
        // you should have 7 columns for MON-SUN in your DataGridView
        For (ic = 0; ic <= this.dgv.columns.count - 1; ic++) {
            If (ir == 0 & (ic + 1) < DayInWeekStart & DayCounter < DayInMonthTotal) Then {
                // skip / do nothing
            } else {
                this.dgv.rows(ir).cells(ic).value = DayCounter;
                // set DGV cell value to the date
                DayCounter += 1;
                // iterate day in month number
            }
        }
    }

As for saving, the best option would be definitely a database, even though a structured text file is doable. 至于保存,最好的选择肯定是数据库,即使结构化文本文件是可行的。 If you have a lot of time... For database, I'd use MERGE statement to UPDATE, DELETE or INSERT appointments. 如果您有很多时间...对于数据库,我将使用MERGE语句进行UPDATE,DELETE或INSERT约会。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM