Пример #1
0
        private void ButtonAdd_Click(object sender, RoutedEventArgs e)
        {
            try {
                switch (comboBox.SelectedIndex)
                {
                case 2: {//Лица
                    CCreateWindow window = new CCreateWindow(null);
                    window.ShowDialog();
                    if (window.Have)
                    {
                        CIndividual individual = window.FaceWithContactID.Individual;

                        if (individual is CEntityIndividual entityIndividual)
                        {
                            SelectQuery("INSERT INTO FC_FACE (ID_TYPE, POST, FAMILY, NAME1, NAME2, NAME) " +
                                        $"VALUES({(int)ETypeFace.Entity}, \"{entityIndividual.Post}\", \"{entityIndividual.Family}\", " +
                                        $"\"{entityIndividual.Name}\",  \"{entityIndividual.Patronymic}\", \"{entityIndividual.Organization}\");");
                        }
                        else
                        {
                            SelectQuery("INSERT INTO FC_FACE (ID_TYPE, POST, FAMILY, NAME1, NAME2, NAME) " +
                                        $"VALUES({(int)ETypeFace.Individual}, \"\", \"{individual.Family}\", \"{individual.Name}\", " +
                                        $"\"{individual.Patronymic}\", \"\");");
                        }

                        DataTable dataTable = SelectQuery("select max(id) from FC_FACE;");
                        DataRow   item      = dataTable.Rows[0];
                        int       iIndex    = Convert.ToInt32(item[0].ToString());
                        foreach (CContactId contactId in window.FaceWithContactID.CContactIds)
                        {
                            SelectQuery($"INSERT INTO FC_CONTACT (ID_FC, ID_TYPE, CONTACT, DESCRIPTION) VALUES({iIndex}, " +
                                        $"{(int)contactId.Contact.GetTypeContract()}, \"{contactId.Contact.GetContact()}\", \"{contactId.Contact.Description}\"); ");
                        }
                    }

                    break;
                }

                default: {
                    throw new Exception("В данной таблице нельзя добавить запись!");
                }
                }
                Update();
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }
Пример #2
0
        private void ButtonChange_Click(object sender, RoutedEventArgs e)
        {
            try {
                if (dataGrid.SelectedIndex == -1)
                {
                    throw new Exception("Выберете строку!");
                }

                switch (comboBox.SelectedIndex)
                {
                case 0: {//Контакты
                    var            v      = GetContact();
                    CContactWindow window = new CContactWindow(GetContact());
                    window.ShowDialog();
                    if (window.Have)
                    {
                        DataRowView item   = (DataRowView)dataGrid.SelectedItem;
                        string      id     = item.Row.ItemArray[0].ToString();
                        string      idFace = item.Row.ItemArray[1].ToString();

                        CContact pContact    = window.Contact;
                        string   sContact    = pContact.GetContact();
                        string   description = pContact.Description;

                        switch (pContact.GetTypeContract())
                        {
                        case ETypeContract.Phone: {
                            SelectQuery($"UPDATE FC_CONTACT SET ID_FC = {idFace}, ID_TYPE = \"{(int)ETypeContract.Phone}\", " +
                                        $"CONTACT = \"{sContact}\", DESCRIPTION = \"{description}\" WHERE ID = {id};");
                            break;
                        }

                        case ETypeContract.Address: {
                            SelectQuery($"UPDATE FC_CONTACT SET ID_FC = {idFace}, ID_TYPE = \"{(int)ETypeContract.Address}\", " +
                                        $"CONTACT = \"{sContact}\", DESCRIPTION = \"{description}\" WHERE ID = {id};");
                            break;
                        }

                        case ETypeContract.Email: {
                            SelectQuery($"UPDATE FC_CONTACT SET ID_FC = {idFace}, ID_TYPE = \"{(int)ETypeContract.Email}\", " +
                                        $"CONTACT = \"{sContact}\", DESCRIPTION = \"{description}\" WHERE ID = {id};");
                            break;
                        }
                        }
                    }

                    break;
                }

                case 2: {//Лица
                    CCreateWindow      window          = new CCreateWindow(GetFaceWithContact());
                    CFaceWithContactID faceWithContact = GetFaceWithContact();
                    window.ShowDialog();
                    if (window.Have)
                    {
                        CIndividual individual = window.FaceWithContactID.Individual;
                        DataRowView item       = (DataRowView)dataGrid.SelectedItem;
                        string      id         = item.Row.ItemArray[0].ToString();

                        if (individual is CEntityIndividual entityIndividual)
                        {
                            SelectQuery($"UPDATE FC_FACE SET ID_TYPE = {(int)ETypeFace.Entity}, POST = \"{entityIndividual.Post}\", " +
                                        $"FAMILY = \"{entityIndividual.Family}\", NAME1 = \"{entityIndividual.Name}\", NAME2 = \"{entityIndividual.Patronymic}\"" +
                                        $", NAME = \"{entityIndividual.Organization}\" WHERE ID = {id};");
                        }
                        else
                        {
                            SelectQuery($"UPDATE FC_FACE SET ID_TYPE = {(int)ETypeFace.Individual}, POST = \"\", " +
                                        $"FAMILY = \"{individual.Family}\", NAME1 = \"{individual.Name}\", NAME2 = \"{individual.Patronymic}\"" +
                                        $", NAME = \"\" WHERE ID = {id};");
                        }

                        DataTable dataTable = SelectQuery("select max(id) from FC_FACE;");
                        DataRow   row       = dataTable.Rows[0];
                        int       iCounter  = 0;

                        foreach (CContactId contactId in faceWithContact.CContactIds)
                        {
                            bool flagOnDelete = true;
                            iCounter++;

                            foreach (CContactId windowContactId in window.FaceWithContactID.CContactIds)
                            {
                                if (contactId.ID == windowContactId.ID)
                                {
                                    SelectQuery($"UPDATE FC_CONTACT SET ID_TYPE = \"{(int)windowContactId.Contact.GetTypeContract()}\", " +
                                                $"CONTACT = \"{windowContactId.Contact.GetContact()}\", DESCRIPTION = \"{windowContactId.Contact.Description}\" " +
                                                $"WHERE FC_CONTACT.ID = {windowContactId.ID} AND FC_CONTACT.ID_FC = {id};");//Изменение контактов
                                    flagOnDelete = false;
                                    break;
                                }
                            }

                            if (flagOnDelete)
                            {
                                SelectQuery($"DELETE FROM FC_CONTACT WHERE FC_CONTACT.ID = {contactId.ID}");//Удаление контактов
                                iCounter--;
                            }
                        }

                        for (int iIndex = iCounter; iIndex < window.FaceWithContactID.CContactIds.Count; iIndex++)
                        {
                            CContactId windowContactId = window.FaceWithContactID.CContactIds[iIndex];
                            SelectQuery($"INSERT INTO FC_CONTACT (ID_FC, ID_TYPE, CONTACT, DESCRIPTION) VALUES({id}, " +
                                        $"{(int)windowContactId.Contact.GetTypeContract()}, \"{windowContactId.Contact.GetContact()}\", " +
                                        $"\"{windowContactId.Contact.Description}\"); ");//Добавление контактов
                        }
                    }

                    break;
                }

                default: {
                    throw new Exception("В данной таблице нельзя изменить запись!");
                }
                }
                Update();
            } catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }