Ejemplo n.º 1
0
        public void Auth(int userId, string username, UserType userType, AuthResponse code)
        {
            _tbUsername.Text = string.Empty;
            _tbPassword.Text = string.Empty;
            _btAuth.Enabled  = true;
            if (code == AuthResponse.AUTH_RESPONSE_UNKNOWN_USER)
            {
                _lbAuthError.Text = "Неизвестный пользователь";
                return;
            }

            if (code == AuthResponse.AUTH_RESPONSE_UNKNOWN_ERROR)
            {
                _lbAuthError.Text = "Неизвестныя ошибка...";
                return;
            }

            Form userForm = null;

            switch (userType)
            {
            case UserType.USER_TYPE_CLIENT:
                userForm = new ClientForm(userId, username);
                break;

            case UserType.USER_TYPE_DISPATCHER:
                userForm = new DispatcherForm(userId, username);
                break;

            case UserType.USER_TYPE_DRIVER:
            default:
                throw new NotSupportedException($"Not supported usertype {userType}");
            }

            Visible        = false;
            userForm.Owner = this;
            userForm.Show();
        }
Ejemplo n.º 2
0
        private void AddFromCommand(object sender, EventArgs e)
        {
            var isChange = Equals(sender, this.CommandChangeButton) && this.ViewData.CurrentRow != null;
            var id       = isChange
                ? (int)this.ViewData.CurrentRow.Cells[0].Value
                : -1;

            switch (this.activeTable)
            {
            case ActiveTable.Bus:
            {
                var form = new BusForm();
                if (isChange)
                {
                    form.SaveButton.Enabled      = true;
                    form.NumberTextBox.Text      = (string)this.ViewData.CurrentRow.Cells["№ автобуса"].Value;
                    form.ModelTextBox.Text       = (string)this.ViewData.CurrentRow.Cells["Модель автобуса"].Value;
                    form.NumberplateTextBox.Text = (string)this.ViewData.CurrentRow.Cells["Номерной знак"].Value;
                    form.SizeNumeric.Value       = (int)this.ViewData.CurrentRow.Cells["Кол-во посадочных мест"].Value;
                }

                var result = form.ShowDialog();

                string command;
                var    number      = form.NumberTextBox.Text;
                var    model       = form.ModelTextBox.Text;
                var    numberplate = form.NumberplateTextBox.Text;
                var    size        = (int)form.SizeNumeric.Value;
                switch (result)
                {
                case DialogResult.OK:
                    command = "INSERT INTO [Bus] " +
                              " ([Number], [Model], [Numberplate], [Size]) " +
                              "VALUES " +
                              $" (N'{number}', N'{model}', N'{numberplate}', {size}) ";
                    break;

                case DialogResult.Retry:
                    command = "UPDATE [Bus] " +
                              "SET " +
                              $" [Number] = N'{number}', " +
                              $" [Model] = N'{model}', " +
                              $" [Numberplate] = N'{numberplate}', " +
                              $" [Size] = {size} " +
                              $"WHERE [Id] = {id} ";
                    break;

                default:
                    return;
                }
                SqlHelper.ExecuteQuery(command);
                this.ViewBuses(sender, e);
                break;
            }

            case ActiveTable.Dispatcher:
            {
                var form = new DispatcherForm();
                if (isChange)
                {
                    form.SaveButton.Enabled    = true;
                    form.NameTextBox.Text      = (string)this.ViewData.CurrentRow.Cells["Диспетчер"].Value;
                    form.BirthDatePicker.Value = (DateTime)this.ViewData.CurrentRow.Cells["Дата рождения"].Value;
                    form.AddressTextBox.Text   = (string)this.ViewData.CurrentRow.Cells["Адрес"].Value;
                    form.PassportTextBox.Text  = (string)this.ViewData.CurrentRow.Cells["Пасспорт"].Value;
                }

                var result = form.ShowDialog();

                string command;
                var    name     = form.NameTextBox.Text;
                var    birth    = form.BirthDatePicker.Value.ToString("yyyy-MM-dd");
                var    address  = form.AddressTextBox.Text;
                var    passport = form.PassportTextBox.Text;

                switch (result)
                {
                case DialogResult.OK:
                    command = "INSERT INTO [Dispatcher] " +
                              " ([Name], [BirthDate], [Address], [Passport]) " +
                              "VALUES " +
                              $" (N'{name}', N'{birth}', N'{address}', N'{passport}') ";
                    break;

                case DialogResult.Retry:
                    command = "UPDATE [Dispatcher] " +
                              "SET " +
                              $" [Name] = N'{name}', " +
                              $" [BirthDate] = N'{birth}', " +
                              $" [Address] = N'{address}', " +
                              $" [Passport] = N'{passport}' " +
                              $"WHERE [Id] = {id} ";
                    break;

                default:
                    return;
                }
                SqlHelper.ExecuteQuery(command);
                this.ViewDispatchers(sender, e);
                break;
            }

            case ActiveTable.Driver:
            {
                var form = new DriverForm();
                if (isChange)
                {
                    form.SaveButton.Enabled    = true;
                    form.NameTextBox.Text      = (string)this.ViewData.CurrentRow.Cells["Водитель"].Value;
                    form.BirthDatePicker.Value = (DateTime)this.ViewData.CurrentRow.Cells["Дата рождения"].Value;
                    form.AddressTextBox.Text   = (string)this.ViewData.CurrentRow.Cells["Адрес"].Value;
                    form.PassportTextBox.Text  = (string)this.ViewData.CurrentRow.Cells["Пасспорт"].Value;
                }

                var result = form.ShowDialog();

                string command;
                var    name     = form.NameTextBox.Text;
                var    birth    = form.BirthDatePicker.Value.ToString("yyyy-MM-dd");
                var    address  = form.AddressTextBox.Text;
                var    passport = form.PassportTextBox.Text;
                switch (result)
                {
                case DialogResult.OK:
                    command = "INSERT INTO [Driver] " +
                              " ([Name], [BirthDate], [Address], [Passport]) " +
                              "VALUES " +
                              $" (N'{name}', N'{birth}', N'{address}', N'{passport}')";
                    break;

                case DialogResult.Retry:
                    command = "UPDATE [Driver] " +
                              "SET " +
                              $" [Name] = N'{name}', " +
                              $" [BirthDate] = N'{birth}', " +
                              $" [Address] = N'{address}', " +
                              $" [Passport] = N'{passport}' " +
                              $"WHERE [Id] = {id} ";
                    break;

                default:
                    return;
                }
                SqlHelper.ExecuteQuery(command);
                this.ViewDrivers(sender, e);
                break;
            }

            case ActiveTable.Route:
            {
                var form = new RouteForm();
                if (isChange)
                {
                    form.SaveButton.Enabled      = true;
                    form.IdTextBox.Text          = (string)this.ViewData.CurrentRow.Cells["№ маршрута"].Value;
                    form.DepartureTextBox.Text   = (string)this.ViewData.CurrentRow.Cells["Место отправления"].Value;
                    form.DestinationTextBox.Text = (string)this.ViewData.CurrentRow.Cells["Место прибытия"].Value;
                    form.DistanceNumeric.Value   = Convert.ToDecimal(this.ViewData.CurrentRow.Cells["Расстояние (км)"].Value);
                    form.BeginDatePicker.Value   = (DateTime)this.ViewData.CurrentRow.Cells["Время отправления"].Value;
                    form.EndDatePicker.Value     = (DateTime)this.ViewData.CurrentRow.Cells["Время прибытия"].Value;
                }

                var result = form.ShowDialog();

                string command;
                var    number      = form.IdTextBox.Text;
                var    departure   = form.DepartureTextBox.Text;
                var    destination = form.DestinationTextBox.Text;
                var    distance    = (int)form.DistanceNumeric.Value;
                var    begin       = form.BeginDatePicker.Value.ToString("HH:mm:ss");
                var    end         = form.EndDatePicker.Value.ToString("HH:mm:ss");
                switch (result)
                {
                case DialogResult.OK:
                    command = "INSERT INTO [Route] " +
                              " ([Number], [Departure], [Destination], [Distance], [BeginDate], [EndDate]) " +
                              "VALUES " +
                              $" (N'{number}', N'{departure}', N'{destination}', {distance}, N'{begin}', N'{end}') ";
                    break;

                case DialogResult.Retry:
                    command = "UPDATE [Route] " +
                              "SET" +
                              $" [Number] = N'{number}', " +
                              $" [Departure] = N'{departure}', " +
                              $" [Destination] = N'{destination}', " +
                              $" [Distance] = {distance}, " +
                              $" [BeginDate] = N'{begin}', " +
                              $" [EndDate] = N'{end}' " +
                              $"WHERE [Id] = {id} ";
                    break;

                default:
                    return;
                }
                SqlHelper.ExecuteQuery(command);
                this.ViewRoutes(sender, e);
                break;
            }

            case ActiveTable.Ticket:
            {
                var form = new TicketForm();
                if (isChange)
                {
                    form.SaveButton.Enabled    = true;
                    form.PriceNumeric.Value    = Convert.ToDecimal(this.ViewData.CurrentRow.Cells["Цена билета"].Value);
                    form.BuyDatePicker.Value   = (DateTime)this.ViewData.CurrentRow.Cells["Дата покупки"].Value;
                    form.PlaceNumeric.Value    = Convert.ToDecimal(this.ViewData.CurrentRow.Cells["Место пассажира"].Value);
                    form.PassengerTextBox.Text = (string)this.ViewData.CurrentRow.Cells["Пассажир"].Value;
                    form.PassportTextBox.Text  = (string)this.ViewData.CurrentRow.Cells["Пасспорт"].Value;
                    form.DiscountCheck.Checked = (bool)this.ViewData.CurrentRow.Cells["Льготы?"].Value;
                }

                var result = form.ShowDialog();

                string command;
                var    price     = (int)form.PriceNumeric.Value;
                var    buy       = form.BuyDatePicker.Value.ToString("yyyy-MM-dd HH:mm:ss");
                var    place     = (int)form.PlaceNumeric.Value;
                var    passenger = form.PassengerTextBox.Text;
                var    passport  = form.PassportTextBox.Text;
                var    discount  = form.DiscountCheck.Checked ? 1 : 0;
                switch (result)
                {
                case DialogResult.OK:
                    command = "INSERT INTO [Ticket] " +
                              " ([Price], [BuyDate], [Place], [Passenger], [Passport], [Discount]) " +
                              "VALUES " +
                              $" ({price}, N'{buy}', {place}, N'{passenger}', N'{passport}', {discount})";
                    break;

                case DialogResult.Retry:
                    command = "UPDATE [Ticket] " +
                              "SET " +
                              $" [Price] = {price}, " +
                              $" [BuyDate] = N'{buy}', " +
                              $" [Place] = {place}, " +
                              $" [Passenger] = N'{passenger}', " +
                              $" [Passport] = N'{passport}', " +
                              $" [Discount] = {discount} " +
                              $"WHERE [Id] = {id}";
                    break;

                default:
                    return;
                }
                SqlHelper.ExecuteQuery(command);
                this.ViewTickets(sender, e);
                break;
            }

            default:
                return;
            }
        }