Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / WinForms, .Net Framework [игнор отключен] [закрыт для гостей] / Где ошибка ? / 2 сообщений из 2, страница 1 из 1
31.08.2013, 18:26
    #38383223
megazoid007
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Где ошибка ?
Подскажите пожалуйста в чем может быть причина ошибки: в общем есть DataTable с двумя полями даты (оба поля содержат DBNull), для редактирования этой таблицы я передаю BindingSourсe привязанный к ней в форму-редактор, там привязываю к этому BindingSourсe элементы управления в том числе dateTimePicker1 к одному и dateTimePicker2 ко второму полю даты, естественно что бы решить вопрос конфликта с DBNull я мастырю общую процедуру-обработчик для обеих dateTimePicker события Format, но вот косяк для dateTimePicker1 все работает замечательно, а dateTimePicker2 ведет себя как будто ничего не происходит, если комментирую подписку на событие формат у dateTimePicker1 то вылазит ошибка (см. ниже) в материнской форме на строке if (AEForm.ShowDialog() == DialogResult.OK) вот код формы редактора:
Код: c#
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Common;

namespace Agroteh
{
    public enum mode {Insrt, Edit};

    public partial class AddEmplForm : Form
    {
        mode state;
        BindingSource bsEdit;
        bool flag;
        bool flagtwo;
        public AddEmplForm(mode mode, BindingSource bsTmp)
        {
            InitializeComponent();
            this.state = mode;
            flag = false;
            flagtwo = false;
            dateTimePicker1.ValueChanged += new EventHandler(dateTimePicker1_ValueChanged);
            dateTimePicker2.ValueChanged += new EventHandler(dateTimePicker1_ValueChanged);
            comboBox1.Items.AddRange(new string[] { "м", "ж" });
            dateTimePicker1.Format = DateTimePickerFormat.Custom;
            dateTimePicker1.CustomFormat = "d MMMM yyyy";      
            bsEdit = bsTmp;
            textBox1.DataBindings.Add("Text", bsEdit, "Фамилия");
            textBox2.DataBindings.Add("Text", bsEdit, "Имя");
            textBox3.DataBindings.Add("Text", bsEdit, "Отчество");
            comboBox1.DataBindings.Add("SelectedItem", bsEdit, "Пол");
            textBox4.DataBindings.Add("Text", bsEdit, "Адрес");
            textBox5.DataBindings.Add("Text", bsEdit, "Телефон");
            Binding b = new Binding("Value", bsEdit, "Рождение");
            dateTimePicker1.DataBindings.Add(b);
            //b.Format += new ConvertEventHandler(b_Format);
            textBox6.DataBindings.Add("Text", bsEdit, "Номер паспорта");
            textBox7.DataBindings.Add("Text", bsEdit, "Личный номер");
            b = new Binding("Value", bsEdit, "Дата выдачи");
            dateTimePicker2.DataBindings.Add(b);
            b.Format += new ConvertEventHandler(b_Format);
            if (this.state == Agroteh.mode.Insrt)
            {
                comboBox1.Text = "м";
                bsEdit.AddNew();
            }
        }

        void b_Format(object sender, ConvertEventArgs e)
        {
            Binding b = sender as Binding;
            if (b != null)
            {
                DateTimePicker dtm = (b.Control as DateTimePicker);
                if (dtm != null)
                {
                    if (Convert.IsDBNull(e.Value))
                    {
                        e.Value = DateTime.Today;
                        dtm.CustomFormat = " ";
                    }
                    else
                        dtm.CustomFormat = "d MMMM yyyy";
                }
            }
        }


        void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {
            DateTimePicker dtm = sender as DateTimePicker;
            if (dtm != null)
            {
                if (dtm.Equals(dateTimePicker1))
                {
                    flag = true;
                    dtm.CustomFormat = "d MMMM yyyy";
                }
                else if (dtm.Equals(dateTimePicker2))
                {
                    flagtwo = true;
                    dtm.CustomFormat = "d MMMM yyyy";
                } 
            }
        }

        private void AddEmplForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (this.DialogResult == DialogResult.OK)
            {
                if (textBox1.Text.Trim() == "")
                {
                    MessageBox.Show(this, "Введите Фамилию", "Внимание!!!");
                    this.DialogResult = DialogResult.Cancel;
                    e.Cancel = true;
                    return;
                }

                if (textBox2.Text.Trim() == "")
                {
                    MessageBox.Show(this, "Введите Имя", "Внимание!!!");
                    this.DialogResult = DialogResult.Cancel;
                    e.Cancel = true;
                    return;
                }

                if (textBox9.Text.Trim() != "")
                {
                    if (Convert.ToInt16(textBox9.Text.Trim()) > Byte.MaxValue)
                    {
                        MessageBox.Show(this, "Превышение допустимого значения (255) в количестве иждевенцев", "Внимание!!!");
                        this.DialogResult = DialogResult.Cancel;
                        e.Cancel = true;
                    }
                }
            }

        }

        private void AddEmplForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (this.DialogResult == DialogResult.OK)
            {
                bsEdit.EndEdit();
            }
            else bsEdit.CancelEdit();
        }

        private void textBox9_KeyPress(object sender, KeyPressEventArgs e)
        {
            char ch = e.KeyChar;
            if (!Char.IsDigit(ch) && ch != 127 && ch != 8 /*&& textBox9.TextLength>3*/)
                e.Handled = true;
        }
    }
}


а вот ошибка:
...
Рейтинг: 0 / 0
31.08.2013, 19:00
    #38383234
megazoid007
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Где ошибка ?
megazoid007, извеняюсь нашел причину как можно удалить тему ?
...
Рейтинг: 0 / 0
Форумы / WinForms, .Net Framework [игнор отключен] [закрыт для гостей] / Где ошибка ? / 2 сообщений из 2, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]