コード例 #1
0
ファイル: Form1.cs プロジェクト: FrameSpark/zd
        private void DCreate_Click(object sender, EventArgs e)
        {
            try
            {
                using (New_route frm = new New_route())
                {
                    if (frm.ShowDialog() == DialogResult.OK)
                    {
                        string st1;
                        if (Convert.ToString(frm.cbStation1.Text) != "")
                        {
                            st1 = Convert.ToString(frm.cbStation1.Text);
                        }
                        else
                        {
                            st1 = Convert.ToString(frm.cbStation1.SelectedValue);
                        }

                        string st2;
                        if (Convert.ToString(frm.cbStation2.Text) != "")
                        {
                            st2 = Convert.ToString(frm.cbStation2.Text);
                        }
                        else
                        {
                            st2 = Convert.ToString(frm.cbStation2.SelectedValue);
                        }


                        if (db.newRoute(st1, st2, Convert.ToInt32(frm.tbTime.Text)) == null)
                        {
                            MessageBox.Show("Ошибка вставки. Возможно данный маршрут уже существует");
                        }
                        ;
                        dgRoutes.DataSource = vc.View_route.ToList();
                    }
                }
            }
            catch (FormatException)
            {
                MessageBox.Show("Ошибка ввода");
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: FrameSpark/zd
        private void DgRoutes_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                string station1 = Convert.ToString(dgRoutes.CurrentRow.Cells["startnamestation"].Value);
                string station2 = Convert.ToString(dgRoutes.CurrentRow.Cells["finishnamestation"].Value);
                int    min      = Convert.ToInt32(dgRoutes.CurrentRow.Cells["routetime"].Value);
                int    id       = Convert.ToInt32(dgRoutes.CurrentRow.Cells["idroute"].Value);
                if (e.ColumnIndex == 5)
                {
                    string message = "Вы действительно хотите удалить маршрут ";
                    string caption = "Подтверждение выбора";
                    var    result  = MessageBox.Show(message, caption, MessageBoxButtons.YesNo,
                                                     MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        if (db.deleteRoute(id))
                        {
                            MessageBox.Show("Маршрут удален");
                            db.checkAllRoute();
                        }
                        else
                        {
                            MessageBox.Show("Не удалось удалить");
                        }
                    }
                    dgRoutes.DataSource = vc.View_route.ToList();
                }

                if (e.ColumnIndex == 4)
                {
                    using (New_route frm = new New_route(station1, station2, min))
                    {
                        if (frm.ShowDialog() == DialogResult.OK)
                        {
                            string st1;
                            if (Convert.ToString(frm.cbStation1.Text) != "")
                            {
                                st1 = Convert.ToString(frm.cbStation1.Text);
                            }
                            else
                            {
                                st1 = Convert.ToString(frm.cbStation1.SelectedValue);
                            }

                            string st2;
                            if (Convert.ToString(frm.cbStation2.Text) != "")
                            {
                                st2 = Convert.ToString(frm.cbStation2.Text);
                            }
                            else
                            {
                                st2 = Convert.ToString(frm.cbStation2.SelectedValue);
                            }

                            if (!db.UpdateRoute(id, st1, st2, Convert.ToInt32(frm.tbTime.Text)))
                            {
                                MessageBox.Show("Ошибка вставки");
                            }
                            ;
                            db.checkAllRoute();
                            dgRoutes.DataSource = vc.View_route.ToList();
                        }
                    }
                }
            }
            catch (FormatException)
            {
                MessageBox.Show("Ошибка ввода");
            }
        }