简体   繁体   English

C# 将所有用户输入保存到某种数据库或 smth

[英]C# Saving all Users input into some kind of database or smth

I have just started programming C# codes and I'm enjoying typing my own little windows form app.我刚刚开始编写 C# 代码,我很享受输入我自己的小窗口窗体应用程序。

Screenshots:截图:

四个选项卡之一

四个选项卡之一

Its written in C#.它是用 C# 编写的。 It basically takes an user Input, called "Kassenbestand", - "Ausgaben" + "Einnahmen" and gives out an calculated € value at "End Bestand".它基本上需要一个用户输入,称为“Kassenbestand”,-“Ausgaben”+“Einnahmen”,并在“End Bestand”处给出计算出的 € 值。 So very simple.所以非常简单。

I have got two questions:我有两个问题:

First:第一的:

I would like to create a button to save ALL the input he does, so he can save and open it afterwords, in case he forgot something.我想创建一个按钮来保存他所做的所有输入,这样他就可以保存并打开它,以防他忘记了什么。

As i wrote, I'm very new, so what do i have to do.正如我所写,我很新,所以我必须做什么。 I saw a lot of stuff with database etc. but maybe one of you professionals can support me better and explain me ?我在数据库等方面看到了很多东西,但也许你们中的一位专业人士可以更好地支持我并解释我? :) :)

Second question:第二个问题:

I wrote an saving function, to make an screenshot so he can print out all the stuff he wants.我写了一个保存功能,制作一个截图,这样他就可以打印出他想要的所有东西。 But he needs to cut off useless borders etc. Is there a smoother way to capture the Form and print it out?但是他需要切断无用的边框等。有没有更流畅的方法来捕获表单并打印出来? I read a lot of PrintDocument function etc. Any tips ?我阅读了很多PrintDocument函数等。有什么提示吗?

To save your user inputs I would suggest to save them in a .csv-file.为了保存您的用户输入,我建议将它们保存在 .csv 文件中。

Writing a csv file:写一个csv文件:

        StreamWriter sw = File.AppendText(@"C:\Test\kassenbestand.csv");
        string header = "Datum;Kassenbestand;Ausgaben;Einnahmen";
        sw.WriteLine(header);
        //Write your Data
        string line = string.Format("{0};{1};{2};{3}", DateTime.Today.ToShortDateString(), 550, 400, 600);
        //...
        //...
        //...
        sw.Close();

Reading a csv file:读取 csv 文件:

        StreamReader sr = new StreamReader(@"C:\Test\kassenbestand.csv");
        sr.ReadLine();//skip the header
        while (sr.Peek() != -1)
        {
            string line1 = sr.ReadLine();
            string[] splitted = line1.Split(';');
            // splitted[0] Datum
            // splitted[1] Kassenbestand
            // ...
        }
        sr.Close();

For taking a screenshot of your window you can use this function:要截取窗口的屏幕截图,您可以使用此功能:

    private System.Drawing.Bitmap TakeScreenshot()
    {
        int StartX, StartY;
        int Width, Height;
        StartX = 0;
        StartY = 0;
        Width = Convert.ToInt32(this.Width);
        Height = Convert.ToInt32(this.Height);
        System.Drawing.Bitmap Screenshot = new System.Drawing.Bitmap(Width, Height);
        System.Drawing.Graphics G = System.Drawing.Graphics.FromImage(Screenshot);
        G.CopyFromScreen(StartX, StartY, 0, 0, new System.Drawing.Size(Width, Height));
        G.Dispose();
        return Screenshot;
    }

To save it you only need to save your bitmap:要保存它,您只需要保存您的位图:

       System.Drawing.Bitmap bitmap = TakeScreenshot();
       bitmap.Save(@"C:\Test\screenshot.png");
       bitmap.Dispose();

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

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