示例#1
0
        //button1_Click belong to filenametextbox
        private void button1_Click(object sender, EventArgs e)
        {
            Anket resultanket = new Anket();

            filenametextbox.Text += ".json";
            if (File.Exists(filenametextbox.Text))
            {
                var str       = File.ReadAllText(filenametextbox.Text);
                var newobject = JsonConvert.DeserializeObject <Anket>(str);
                resultanket = newobject;
            }
            nametextBox.Text        = resultanket.Name;
            surnametextBox.Text     = resultanket.Surname;
            fathernametextBox.Text  = resultanket.FatherName;
            countrytextBox.Text     = resultanket.Country;
            citytextBox.Text        = resultanket.City;
            phonenumbertextBox.Text = resultanket.Phonenumber;
            dateTimePicker.Value    = resultanket.BirthDate;
            if (resultanket.Gender == "male")
            {
                maleradioButton.Checked = true;
            }
            else if (resultanket.Gender == "female")
            {
                femaleradiobutton.Checked = true;
            }
            foreach (var item in Controls)
            {
                if (item is TextBox tb)
                {
                    tb.ForeColor = Color.Black;
                }
            }
        }
示例#2
0
        private void buttonGetresult_Click(object sender, EventArgs e)
        {
            this.Text = dateTimePicker.Text;
            string gender = "";

            if (maleradioButton.Checked)
            {
                gender = "male";
            }
            else if (femaleradiobutton.Checked)
            {
                gender = "female";
            }
            Anket anket = new Anket(surnametextBox.Text, nametextBox.Text, surnametextBox.Text
                                    , fathernametextBox.Text, countrytextBox.Text,
                                    citytextBox.Text, phonenumbertextBox.Text, dateTimePicker.Value, gender);
            var filename = surnametextBox.Text + ".json";
            var res      = JsonConvert.SerializeObject(anket);

            File.WriteAllText(filename, res);
            foreach (var item in this.Controls)
            {
                if (item is TextBox tb)
                {
                    tb.Text = String.Empty;
                }
            }
        }