示例#1
0
        private void SaveBt_Click(object sender, EventArgs e)
        {
            ContractorsLogic cl        = new ContractorsLogic(manager);
            string           lastName  = LastNameTE.Text;
            string           firstName = FirstNameTE.Text;

            if (FirstNameTE.Enabled == false)
            {
                firstName = "";
            }

            string middleName = MiddleNameE.Text;

            if (MiddleNameE.Enabled == false)
            {
                middleName = "";
            }

            string country     = CountryTE.Text;
            string region      = RegionTE.Text;
            string district    = DistrictTE.Text;
            string city        = CityTE.Text;
            string street      = StreetTE.Text;
            string building    = BuildingTE.Text;
            string flat        = FlatTE.Text;
            string phone       = PhoneTE.Text;
            string mobilePhone = MobPhoneTE.Text;
            string email       = EmailTE.Text;
            string site        = SiteTE.Text;
            string prefixName  = PrefixNameTE.Text;

            DateTime?birthDate = null;

            if (BirthDateTE.Text.Length > 0)
            {
                birthDate = BirthDateTE.DateTime;
            }
            bool?sex = null;

            if (SexRG.SelectedIndex == 0)
            {
                //чоловік
                sex = true;
            }
            if (SexRG.SelectedIndex == 1)
            {
                //жінка
                sex = false;
            }
            bool?person = null;

            switch (PersonRG.SelectedIndex)
            {
            case 0:
            {
                person = false;         //фізична особа
                break;
            }

            case 1:
            {
                person = true;         //фізична особа
                break;
            }
            }
            string newCardCode = CardCodeTB.Text.Trim();

            //List<DevExpress.XtraEditors.Repository.RepositoryItemCheckedComboBoxEdit> checkedItems;
            //checkedItems = (List<DevExpress.XtraEditors.Repository.RepositoryItemCheckedComboBoxEdit>)ContractorTypesCBE.Properties.GetCheckedItems();
            //List<ContractorType> selectedTypes = (List<ContractorType>)ContractorTypesCBE.Properties.GetCheckedItems();

            List <int> selectedTypes = new List <int>();

            foreach (DevExpress.XtraEditors.Controls.CheckedListBoxItem i in ContractorTypesCBE.Properties.Items)
            {
                if (i.CheckState == CheckState.Checked)
                {
                    selectedTypes.Add(Convert.ToInt32(i.Value));
                }
            }
            Contractor contractor = new Contractor();

            if (mode == "new")
            {
                contractor = cl.Create(prefixName, lastName, firstName, middleName,
                                       country, region, district, city, street, building, flat, phone,
                                       mobilePhone, email, site, birthDate, sex, person, selectedTypes);
            }
            if (mode == "edit")
            {
                contractor = cl.Update(Convert.ToInt32(id), prefixName, lastName, firstName, middleName,
                                       country, region, district, city, street, building, flat, phone,
                                       mobilePhone, email, site, birthDate, sex, person, selectedTypes);
            }

            cl.AddCard(contractor, newCardCode);
            manager.Save();

            this.Close();
        }