Esempio n. 1
0
        /// <summary>
        /// Обработка нажатия кнопки создания
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Of_b_createComp_Click(object sender, EventArgs e)
        {
            newComponet = new Component();
            CEdit f = new CEdit(newComponet, true);

            if (f.ShowDialog() == DialogResult.OK)
            {
                Comp.Add(newComponet);
                of_cb_components.Items.Add(newComponet.Title);

                int n = 0;
                foreach (string title in of_cb_components.Items)
                {
                    if (title == newComponet.Title)
                    {
                        break;
                    }
                    n++;
                }
                of_cb_components.SelectedIndex = n;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Обработка нажатия кнопки редактировать
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Of_b_edit_Click(object sender, EventArgs e)
        {
            int index = of_cb_components.SelectedIndex; //позиция выбранного компонента
            int n = 0; int jj;                          //счетчики

            int[]  j        = new int[1];
            string oldTitle = of_cb_components.SelectedItem.ToString();
            string newTitle = "";
            bool   isEdit   = false; //флаг было ли редактирование

            foreach (Component item in Comp)
            {
                if (item.Title == oldTitle)
                {
                    CEdit f = new CEdit(item, false);
                    if (f.ShowDialog() == DialogResult.OK)
                    {
                        //изменение компонента в выпадающем списке
                        of_cb_components.Items.RemoveAt(index);
                        of_cb_components.Items.Insert(index, item.Title);

                        //изменение компонента в обще списке
                        Comp.RemoveAt(n);
                        Comp.Insert(n, item);

                        newTitle = item.Title;

                        of_cb_components.SelectedIndex = -1;
                        of_b_add.Enabled  = false;
                        of_b_edit.Enabled = false;
                        of_rtb_characteristics.Clear();
                        of_rtb_description.Clear();
                        of_tb_price.Clear();

                        isEdit = true;
                    }

                    break;
                }
                n++;
            }
            n  = 0;
            jj = 1;
            //Если изменения были
            if (isEdit)
            {
                //В случае если компонент был добавлен изменение в списке

                foreach (string title in of_lb_selectedComp.Items)
                {
                    if (title == oldTitle)
                    {
                        Array.Resize(ref j, jj);

                        j[jj - 1] = n;
                        jj++;
                    }
                    n++;
                }
                // Изменение в списке добавленных компонентов
                ChangeListItem(j, newTitle);

                //Пересчет общей цены
                SetTotalPrice();
            }
        }