Example #1
0
 private void Count_ValueChanged(object sender, EventArgs e)
 {
     NumericUpDown temp = sender as NumericUpDown;
     int value = System.Convert.ToInt32(temp.Value);
     int type = ContCount.Controls.IndexOf(temp);
     if (ContCount.Controls.IndexOf(temp) == -1) type = ContCount.Controls.Count;
     if (LightCount.Controls.IndexOf(temp) == -1 && type >= ContCount.Controls.Count) type += LightCount.Controls.Count;
     if (LightCount.Controls.IndexOf(temp) != -1 && type >= ContCount.Controls.Count) type += LightCount.Controls.IndexOf(temp);
     if (PowAmp.Controls.IndexOf(temp) != -1) type += PowAmpCollection.Items.IndexOf(PowAmpList.Items[PowAmp.Controls.IndexOf(temp)]);
     int prim = (int)Main.Stats.Items[type].Type;
     if (Main.Stats.Items[type].Id >= 4000) prim = 3;
     //Panel[]
     int last = currRoom.LastIndex(type);
     int first = currRoom.FirstIndex(type);
     int count = last - first + 1;
     Random r = new Random();
     double maxDN = EL4Ref.DNHighest;
     double minDN = EL4Ref.DNLowest;
     double maxDt = EL4Ref.DTHighest;
     double minDt = EL4Ref.DTLowest;
     if (value < count)
     {
         DialogResult dialogResult = MessageBox.Show("По този начин ще изтриете вече въведени съоръжения. Сигурни ли сте, че искате да продължите?", "Изтриване на съоръжения", MessageBoxButtons.YesNo);
         if (dialogResult == DialogResult.Yes)
         {
             for (int i = first + value; i <= last; i++)
             {
                 currRoom.RemoveAt(first + value);
                 ImpBindingSource.RemoveAt(first + value);
                 CurrProg.DataSource = ImpBindingSource;
             }
         }
     }
     else
     {
         Installation_El_4 tempInst = new Installation_El_4();
         Control ContainerCount = new Control(), ContainerType = new Control(), ContainerAmp = new Control();
         if (prim == 0) { ContainerCount = ContCount; ContainerAmp = ContAmp; }
         if (prim == 1) { ContainerCount = LightCount; ContainerAmp = LightAmp; }
         if (prim == 2) { ContainerCount = PowAmp; ContainerAmp = PowAmperage; }
         if (prim == 3) { ContainerCount = Rows; ContainerAmp = LumAmp; }
         int typeThis = ContainerCount.Controls.IndexOf(temp);
         if (last == -1)
         {
             for (int i = 0; i < value; i++)
             {
                 tempInst.Item = Main.Stats.Items[type];
                 tempInst.DN = r.NextDouble() * (maxDN - minDN) + minDN;
                 tempInst.DT = r.NextDouble() * (maxDt - minDt) + minDt;
                 tempInst.MaxDN = EL4Ref.maxDN;
                 tempInst.MaxDT = EL4Ref.maxDT;
                 tempInst.FollowsRequirements = (tempInst.DN < tempInst.MaxDN) && (tempInst.DT < tempInst.MaxDT);
                 tempInst.NumberIn = i + 1;
                 tempInst.TypeProtector = (ContainerAmp.Controls[typeThis] as ComboBox).SelectedIndex;
                 tempInst.Id = currRoom.ListOfInstallations.Count;
                 tempInst.InstallationName = Main.Stats.Items[type].Name + " №" + tempInst.NumberIn.ToString();
                 currRoom.ListOfInstallations.Add(tempInst);
                 ImpBindingSource.Add(tempInst);
                 CurrProg.DataSource = ImpBindingSource;
                 CurrProg.Columns[0].DataPropertyName = "InstallationName";
                 CurrProg.Columns[1].DataPropertyName = "DT";
                 CurrProg.Columns[2].DataPropertyName = "DN";
                 CurrProg.Columns[3].DataPropertyName = "MaxDN";
                 CurrProg.Columns[4].DataPropertyName = "MaxDT";
                 CurrProg.Update();
                 CurrProg.Refresh();
                 for (int j = 0; j < CurrProg.Rows.Count; j++)
                 {
                     (CurrProg.Rows[j].Cells[5] as DataGridViewComboBoxCell).Items.Clear();
                     foreach(Protectors p in Main.Stats.Protectors)(CurrProg.Rows[j].Cells[5] as DataGridViewComboBoxCell).Items.Add(p.Name);
                 }
                 //Prot.ValueMember = "Main.Stats.Protectors[]"; CurrProg.Columns[5].DataPropertyName = "TypeProtector";
             }
         }
         else
         {
             for (int i = 0; i < value - count; i++)
             {
                 tempInst.Item = Main.Stats.Items[type];
                 tempInst.DN = r.NextDouble() * (maxDN - minDN) + minDN;
                 tempInst.DT = r.NextDouble() * (maxDt - minDt) + minDt;
                 tempInst.MaxDN = EL4Ref.maxDN;
                 tempInst.MaxDT = EL4Ref.maxDT;
                 tempInst.FollowsRequirements = (tempInst.DN < tempInst.MaxDN) && (tempInst.DT < tempInst.MaxDT);
                 tempInst.NumberIn = i + 1 + currRoom.ListOfInstallations.ElementAt(last).NumberIn;
                 tempInst.TypeProtector = (ContainerAmp.Controls[typeThis] as ComboBox).SelectedIndex;
                 tempInst.Id = currRoom.ListOfInstallations.Count;
                 tempInst.InstallationName = Main.Stats.Items[type].Name + " №" + tempInst.NumberIn.ToString();
                 currRoom.Insert(last + i + 1, tempInst);
                 ImpBindingSource.Insert(last + i + 1, tempInst);
                 CurrProg.DataSource = ImpBindingSource;
                 CurrProg.Update();
                 CurrProg.Refresh();
                 for (int j = 0; j < CurrProg.Rows.Count; j++)
                 {
                     (CurrProg.Rows[j].Cells[5] as DataGridViewComboBoxCell).Items.Clear();
                     foreach (Protectors p in Main.Stats.Protectors) (CurrProg.Rows[j].Cells[5] as DataGridViewComboBoxCell).Items.Add(p.Name);
                 }
             }
         }
     }
     CurrProg.Update();
     CurrProg.Refresh();
 }
Example #2
0
        private void rows_TextChanged(object sender, EventArgs e)
        {
            TextBox temp = sender as TextBox;
            if (temp.Text.IndexOf("\r\n") == -1 || temp.Text == "") return;
            temp.Text = temp.Text.Replace("\r\n", "");
            temp.Text = temp.Text.Replace(" ", "");
            int type = Rows.Controls.IndexOf(temp);
            string[] sp = temp.Text.Split(',');
            Installation_El_4 lum = new Installation_El_4();
            double maxDN = EL4Ref.DNHighest;
            double minDN = EL4Ref.DNLowest;
            double maxDt = EL4Ref.DTHighest;
            double minDt = EL4Ref.DNLowest;
            Random r = new Random();
            try
            {
                foreach (Installation_El_4 inst in currRoom.ListOfInstallations)
                {
                    if (inst.Item.Id > 4000) currRoom.ListOfInstallations.Remove(inst);
                }
                foreach (string s in sp)
                {
                    currRoom.ListOfInstallations.Add(new Installation_El_4());
                    for (int i = 0; i < System.Convert.ToInt32(s); i++)
                    {
                        lum.Item = Main.Stats.Items[type];
                        lum.DN = r.NextDouble() * (maxDN - minDN) + minDN;
                        lum.DT = r.NextDouble() * (maxDt - minDt) + minDt;
                        lum.MaxDN = EL4Ref.maxDN;
                        lum.MaxDT = EL4Ref.maxDT;
                        lum.FollowsRequirements = (lum.DN < lum.MaxDN) && (lum.DT < lum.MaxDT);
                        lum.NumberIn = i + 1;
                        lum.TypeProtector = (ContAmp.Controls[type] as ComboBox).SelectedIndex;
                        lum.Id = currRoom.ListOfInstallations.Count;
                        lum.InstallationName = Main.Stats.Items[type].Name + " №" + lum.NumberIn.ToString();
                        lum.Id = currRoom.ListOfInstallations.Count;
                        lum.InstallationName = Main.Stats.Items[type + ContCount.Controls.Count + LightCount.Controls.Count + PowAmpCollection.Controls.Count].Name + " №" + lum.NumberIn.ToString();
                        lum.Item = Main.Stats.Items[type + ContCount.Controls.Count + LightCount.Controls.Count + PowAmpCollection.Controls.Count];
                        currRoom.ListOfInstallations.Add(lum);
                    }

                }
            }
            catch
            {
                MessageBox.Show("Грешно въведени данни за редовете. Използвайте числа, разделени със запетаи!");
                temp.Text = "";
            }
        }