mardi 29 septembre 2015

How to replace product to #product?

I have this code, but when I run the program remain blocked. With this code I want to check/uncheck all items, and when this are checked in text file installer.ini to write #product=name of checkbox => product=name of checkbox and if this are unchecked in text file where I have product=name of checkboxto replace with #product=name of checkbox.

private void checkBox1_CheckedChanged_1(object sender, EventArgs e)
{
    string installerfilename = path + "installer.ini";
    string installertext = File.ReadAllText(installerfilename);
    var lin =File.ReadLines(path + "installer.ini").ToArray();

    CheckBox cb = sender as CheckBox;
    if (cb.Checked)
    {
        for (int i = 0; i < this.checkedListBox2.Items.Count; i++)
        {
            this.checkedListBox2.SetItemChecked(i, true);
            foreach (var txt in lin)
            {
                if (txt.Contains("#product="))
                {
                    var name = txt.Split('=')[1];
                    installertext = installertext.Replace("#product=", "product=" + name);

                }
                File.WriteAllText(installerfilename, installertext);
            }
        }
    }
    else if (!cb.Checked)
    {
        for (int i = 0; i < this.checkedListBox2.Items.Count; i++)
        {
            this.checkedListBox2.SetItemChecked(i, false);
            foreach (var txt in lin)
            {
                if (txt.Contains("product="))
                {
                    var name1 = txt.Split('=')[1];
                    installertext = installertext.Replace("product=", "#product=" + name1);

                }
                File.WriteAllText(installerfilename, installertext);
            }

        }
    }
}




Aucun commentaire:

Enregistrer un commentaire