Example #1
0
        /// <summary>
        /// Удаление контрагента
        /// </summary>
        private void GridAgents_DelBtn_Click(object sender, System.EventArgs e)
        {
            Agent delAgent             = (Agent)this.GridAgents.Grid.SelectedRows[0].DataBoundItem;
            int   countRecordWithAgent = 0;

            foreach (Record record in RR.Records())
            {
                if (record.Agents != null)
                {
                    foreach (Agent agent in record.Agents)
                    {
                        if (agent.GUID == delAgent.GUID)
                        {
                            countRecordWithAgent++;
                        }
                    }
                }
            }

            if (countRecordWithAgent > 0)
            {
                MessageBox.Show($"Данного контрагента нельзя удалить из справочника т.к. он используется в {countRecordWithAgent} записях(си).", "Внимание!");
            }
            else
            {
                RA.Delete(delAgent.GUID);
                RA.Save();

                this.GridAgents.Grid.DataSource = RA.Agents();
                this.GridAgents.Grid.Refresh();
            }
        }
Example #2
0
        /// <summary>
        /// Конструктор списковой формы контрагентов
        /// </summary>
        /// <param name="RA">Репозиторий справочника контрагентов</param>
        /// <param name="RR">Репозиторий справочника записи</param>
        public AgentsListForm(RepositoryRecords RR, ref RepositoryAgents RA)
        {
            InitializeComponent();
            this.GridAgents.VisibleColumns = new Dictionary <string, string>
            {
                { "GUID", "ИД" },
                { "FirstName", "Имя" },
                { "LastName", "Фамилия" },
                { "MidName", "Отчество" },
                { "Phone", "Телефон" },
                { "BirthDay", "День рождения" },
                { "EMail", "EMail" }
            };

            if (!this.DesignMode)
            {
                this.GridAgents.Grid.DataSource = RA.Agents();
                this.RA = RA;
                this.RR = RR;
                this.GridAgents.AddBtn.Click  += new System.EventHandler(GridAgents_AddBtn_Click);
                this.GridAgents.EditBtn.Click += new System.EventHandler(GridAgents_EditBtn_Click);
                this.GridAgents.DelBtn.Click  += new System.EventHandler(GridAgents_DelBtn_Click);
            }
        }