开发者

Copy From Previous Button

开发者 https://www.devze.com 2023-03-01 03:39 出处:网络
Hi Ihave a basic question related to C Sharp. I have a windows application, with some text fields, dropwown\'s and radio buttons.Now user fills in information in these fields and saves the informatio

Hi I have a basic question related to C Sharp.

I have a windows application, with some text fields, dropwown's and radio buttons.Now user fills in information in these fields and saves the information, which is stored in backend db. Once this task is done i reset all the fields.

Now what i want is when user has to save information for the next time, there should be a button like "Copy From Previous", when user clicks on it, the details in the box should be copied from previous task, instead of user having to fill in details again.

I would like to know what is the best approach to implement this in C Sharp. I was thinking of using dictionary in C Sharp. Like

Dictionary<string, string> d = new Dictionary<string, string>();
d.Add("txtKeyToSucess", "Pray to One God Alone");
d.Add("txtAdvise", "Dont associate any partners with God");
d.Add("txtResult", "You will be judged for your actions");


if 开发者_如何转开发(d.ContainsKey("txtKeyToSucess"))
    {
        String v = d["txtKeyToSucess"];
        txtKeyToSucess.text = v;
    }

Still not sure. Can you kindly advise how to do this with best possible approach. Recommended section of code if possible.

Thanks.


Why don't you store a reference to the fields in the database? So once you store it, retain the ID to the data, and then the copy button could just query the database, fill the fields, and you're all good.


Since you have a well known set of fields you could just create a class for this:

public class Settings
{
   public string KeyToSucces {get;set;}
   public string Advise {get;set;}
   public string Result {get;set;}
}

Now you can just copy the settings from your Settings instance. In general you should not mix presentation ( i.e. txtKeyToSucess) with your model (Settings in this case) if not neccessary.

0

精彩评论

暂无评论...
验证码 换一张
取 消