示例#1
0
        private void buttonGenerateCode_Click(object sender, EventArgs e)
        {
            string[] newTextBoxCityNames       = textBoxCityNameMultiple.Lines;
            string[] newTextBoxEventIDMultiple = textBoxEventIDMultiple.Lines;
            string[] newTextBoxIDStates        = textBoxStateIDMultiple.Lines;
            for (int i = 0; i < newTextBoxCityNames.Length; i++)
            {
                if (newTextBoxCityNames[i] == "")
                {
                    newTextBoxCityNames[i] = "cityname" + (i + 1);
                }
            }
            for (int i = 0; i < newTextBoxEventIDMultiple.Length; i++)
            {
                if (newTextBoxEventIDMultiple[i] == "")
                {
                    newTextBoxEventIDMultiple[i] = (i + 1).ToString();
                }
            }
            for (int i = 0; i < newTextBoxIDStates.Length; i++)
            {
                if (newTextBoxIDStates[i] == "")
                {
                    newTextBoxIDStates[i] = (i + 1).ToString();
                }
            }
            textBoxCityNameMultiple.Lines = newTextBoxCityNames;
            textBoxEventIDMultiple.Lines  = newTextBoxEventIDMultiple;
            textBoxStateIDMultiple.Lines  = newTextBoxIDStates;
            var generationArray   = new List <FullGeneration>();
            var eventArray        = new List <string>();
            var onactionArray     = new List <string>();
            var statesArray       = new List <string>();
            var gfxArray          = new List <string>();
            var localisationArray = new List <string>();

            try
            {
                if (checkBoxMultipleGeneration.Checked == false)
                {
                    Event    newEvent    = new Event(Convert.ToInt32(textBoxEventID.Text), textBoxCityName.Text, checkBoxLiberation.Checked);
                    Onaction newonaction = new Onaction(Convert.ToInt32(textBoxEventID.Text), Convert.ToInt32(textBoxStateID.Text), textBoxCityName.Text.ToLower(), checkBoxLiberation.Checked);
                    if (checkBoxLiberation.Checked == true)
                    {
                        GFX newgfxCapture = new GFX(textBoxCityName.Text, true);
                        GFX newgfxLib     = new GFX(textBoxCityName.Text, false);
                        gfxArray.Add(newgfxCapture.GetCode());
                        gfxArray.Add(newgfxLib.GetCode());
                    }
                    else
                    {
                        GFX newgfxCapture = new GFX(textBoxCityName.Text, true);
                        gfxArray.Add(newgfxCapture.GetCode());
                    }
                    Localisation newLocalisation = new Localisation(Convert.ToInt32(textBoxEventID.Text), Convert.ToInt32(textBoxStateID.Text), textBoxCityName.Text, checkBoxLiberation.Checked);
                    eventArray.Add(newEvent.GetCode());
                    onactionArray.Add(newonaction.GetCode());
                    statesArray.Add(newonaction.GetCodeStateList());
                    localisationArray.Add(newLocalisation.GetCode());
                }
                else
                {
                    for (int i = 0; i < numericUpDownNumberGenerations.Value; i++)
                    {
                        Event    newEvent    = new Event(Convert.ToInt32(textBoxEventIDMultiple.Lines.GetValue(i)), textBoxCityNameMultiple.Lines.GetValue(i).ToString(), checkBoxLiberation.Checked);
                        Onaction newonaction = new Onaction(Convert.ToInt32(textBoxEventIDMultiple.Lines.GetValue(i)), Convert.ToInt32(textBoxStateIDMultiple.Lines.GetValue(i)), textBoxCityNameMultiple.Lines.GetValue(i).ToString(), checkBoxLiberation.Checked);
                        if (checkBoxLiberation.Checked == true)
                        {
                            GFX newgfxCapture = new GFX(textBoxCityNameMultiple.Lines.GetValue(i).ToString(), true);
                            GFX newgfxLib     = new GFX(textBoxCityNameMultiple.Lines.GetValue(i).ToString(), false);
                            gfxArray.Add(newgfxCapture.GetCode());
                            gfxArray.Add(newgfxLib.GetCode());
                        }
                        else
                        {
                            GFX newgfxCapture = new GFX(textBoxCityNameMultiple.Lines.GetValue(i).ToString(), true);
                            gfxArray.Add(newgfxCapture.GetCode());
                        }
                        Localisation newLocalisation = new Localisation(Convert.ToInt32(textBoxEventIDMultiple.Lines.GetValue(i)), Convert.ToInt32(textBoxStateIDMultiple.Lines.GetValue(i)), textBoxCityNameMultiple.Lines.GetValue(i).ToString(), checkBoxLiberation.Checked);
                        eventArray.Add(newEvent.GetCode());
                        onactionArray.Add(newonaction.GetCode());
                        statesArray.Add(newonaction.GetCodeStateList());
                        localisationArray.Add(newLocalisation.GetCode());
                    }
                }
                string fullEventCode        = "";
                string fullonactionCode     = "";
                string fullGFXCode          = "";
                string fullLocalisationCode = "";
                eventArray.ForEach(delegate(string code)
                {
                    fullEventCode += code;
                });
                statesArray.ForEach(delegate(string code)
                {
                    fullonactionCode += code;
                });
                fullonactionCode += "\n";
                onactionArray.ForEach(delegate(string code)
                {
                    fullonactionCode += code;
                });
                gfxArray.ForEach(delegate(string code)
                {
                    fullGFXCode += code;
                });
                localisationArray.ForEach(delegate(string code)
                {
                    fullLocalisationCode += code;
                });
                FullGeneration newGeneration = new FullGeneration(fullEventCode, fullonactionCode, fullGFXCode, fullLocalisationCode);
                generationArray.Add(newGeneration);
                labelGenerationStatus.ForeColor = Color.Green;
                labelGenerationStatus.Text      = "Generated successfully!";
                labelGenerationStatus.Enabled   = true;
                buttonSaveCode.Enabled          = true;
            }
            catch (Exception)
            {
                FullGeneration newGeneration = new FullGeneration("", "", "", "");
                generationArray.Add(newGeneration);
                labelGenerationStatus.ForeColor = Color.Red;
                labelGenerationStatus.Text      = "A problem occurred during the generation.";
            }
            finally
            {
                labelGenerationStatus.Visible = true;
                var t = new Timer();
                t.Interval = 3000; // it will Tick in 3 seconds
                t.Tick    += (s, error) =>
                {
                    labelGenerationStatus.Visible = false;
                    t.Stop();
                };
                t.Start();
                FullGeneration generationPreview = generationArray.First <FullGeneration>();
                string         showPreview       = generationPreview.GetFullCode();
                richTextBoxPreviewCode.BackColor = Color.LightSkyBlue;
                richTextBoxPreviewCode.Text      = showPreview;
            }
        }
        private void buttonGenerateonactionCode_Click(object sender, EventArgs e)
        {
            string[] newTextBoxCityNames       = textBoxCityNames.Lines;
            string[] newTextBoxEventIDMultiple = textBoxEventIDMultiple.Lines;
            string[] newTextBoxIDStates        = textBoxIDStates.Lines;
            for (int i = 0; i < newTextBoxCityNames.Length; i++)
            {
                if (newTextBoxCityNames[i] == "")
                {
                    newTextBoxCityNames[i] = "cityname" + (i + 1);
                }
            }
            for (int i = 0; i < newTextBoxEventIDMultiple.Length; i++)
            {
                if (newTextBoxEventIDMultiple[i] == "")
                {
                    newTextBoxEventIDMultiple[i] = (i + 1).ToString();
                }
            }
            for (int i = 0; i < newTextBoxIDStates.Length; i++)
            {
                if (newTextBoxIDStates[i] == "")
                {
                    newTextBoxIDStates[i] = (i + 1).ToString();
                }
            }
            textBoxCityNames.Lines       = newTextBoxCityNames;
            textBoxEventIDMultiple.Lines = newTextBoxEventIDMultiple;
            textBoxIDStates.Lines        = newTextBoxIDStates;
            var onactionArray = new List <Onaction>();

            try
            {
                if (checkBoxMultipleonaction.Checked == false)
                {
                    Onaction newonaction = new Onaction(Convert.ToInt32(textBoxEventIDOne.Text), Convert.ToInt32(textBoxIDState.Text), textBoxNameCity.Text.ToLower(), checkBoxIsCapital.Checked);
                    onactionArray.Add(newonaction);
                }
                else
                {
                    for (int i = 0; i < numericUpDownEventCount.Value; i++)
                    {
                        Onaction newonaction = new Onaction(Convert.ToInt32(textBoxEventIDMultiple.Lines.GetValue(i)), Convert.ToInt32(textBoxIDStates.Lines.GetValue(i)), (textBoxCityNames.Lines.GetValue(i)).ToString(), checkBoxIsCapital.Checked);
                        onactionArray.Add(newonaction);
                    }
                }
                labelGenerateStatus.ForeColor = Color.Green;
                labelGenerateStatus.Text      = "Generated successfully!";
                buttonSaveonaction.Enabled    = true;
            }
            catch (Exception)
            {
                labelGenerateStatus.ForeColor = Color.Red;
                labelGenerateStatus.Text      = "A problem occurred during the generation.";
            }
            finally
            {
                labelGenerateStatus.Visible = true;
                var t = new Timer();
                t.Interval = 3000; // it will Tick in 3 seconds
                t.Tick    += (s, error) =>
                {
                    labelGenerateStatus.Visible = false;
                    t.Stop();
                };
                t.Start();
                string showPreview     = "";
                string showPreviewCode = "";
                foreach (Onaction onactionCreated in onactionArray)
                {
                    showPreview     = showPreview + onactionCreated.GetCode();
                    showPreviewCode = showPreviewCode + onactionCreated.GetCodeStateList();
                }
                richTextBoxPreviewCode.BackColor          = Color.LightSkyBlue;
                richTextBoxCodePreviewStateList.BackColor = Color.LightSkyBlue;
                richTextBoxPreviewCode.Text          = showPreview;
                richTextBoxCodePreviewStateList.Text = showPreviewCode;
            }
        }