コード例 #1
0
        private void addApmokejimas_Click(object sender, EventArgs e)
        {
            try
            {
                Apmokejimas ap     = new Apmokejimas();
                DateTime    apData = DateTime.Parse(addApmokejimasApData.Text);
                ap.saskaitos_Nr    = addApmokejimasSasNr.Text;
                ap.apmokejimo_Suma = int.Parse(addApmokejimasApmokSuma.Text);
                ap.nuomos_Nr       = int.Parse(addApmokejimasNuomosNr.Text);
                ap.apmok_data      = apData.Date;

                Apmokejimas inserted = apmokRep.InsertApmokejimas(ap);

                addApmokejimasApData.Clear();
                addApmokejimasSasNr.Clear();
                addApmokejimasApmokSuma.Clear();
                addApmokejimasNuomosNr.Clear();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            MessageBox.Show("Succesfully inserted");
            getApmokejimasDisplay();
        }
コード例 #2
0
        public async Task <IActionResult> Edit(int id, [Bind("ApmokejimasId,Data,Suma,arApmoketas,KelioneId")] Apmokejimas apmokejimas)
        {
            if (id != apmokejimas.ApmokejimasId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(apmokejimas);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ApmokejimasExists(apmokejimas.ApmokejimasId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["KelioneId"] = new SelectList(_context.Kelione, "KelioneId", "KelioneId", apmokejimas.KelioneId);
            return(View(apmokejimas));
        }
コード例 #3
0
        public async Task <IActionResult> Create([Bind("ApmokejimasId,Data,Suma,arApmoketas,KelioneId")] Apmokejimas apmokejimas)
        {
            if (ModelState.IsValid)
            {
                _context.Add(apmokejimas);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["KelioneId"] = new SelectList(_context.Kelione, "KelioneId", "KelioneId", apmokejimas.KelioneId);
            return(View(apmokejimas));
        }
コード例 #4
0
        public async Task <IActionResult> Apmoketi(int?id)
        {
            var motyvuoti_DviratininkaiContext = _context.Kelione.Where(d => d.KelioneId == id).Include(k => k.Dviratis).Include(k => k.Klientas).First();
            // var motyvuoti_DviratininkaiContext = _context.Apmokejimas.Where(a => a.KelioneId == id).Include(a => a.Kelione).ThenInclude(a => a.Dviratis).First();
            var Apmokejimas = new Apmokejimas
            {
                arApmoketas = false,
                Data        = motyvuoti_DviratininkaiContext.kelionesPabaiga,
                KelioneId   = motyvuoti_DviratininkaiContext.KelioneId,
                Suma        = float.Parse(motyvuoti_DviratininkaiContext.kelionesPabaiga.Subtract(motyvuoti_DviratininkaiContext.kelionesPradzia).Multiply(motyvuoti_DviratininkaiContext.Dviratis.nuomosKaina).TotalHours.ToString().Substring(0, 4).Replace(':', ',')),
            };

            _context.Add(Apmokejimas);
            await _context.SaveChangesAsync();

            return(View(motyvuoti_DviratininkaiContext));
        }
コード例 #5
0
        private void deleteApmokejimas_Click(object sender, EventArgs e)
        {
            try
            {
                Apmokejimas gl = new Apmokejimas();
                gl.apmok_Id = int.Parse(deleteApmokejimasApmokNr.Text);
                apmokRep.DeleteApmokejimas(gl);

                deleteApmokejimasApmokNr.Clear();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            MessageBox.Show("Deleted succesfully");
            getApmokejimasDisplay();
        }
コード例 #6
0
        //REGISTER STUDENT
        public Apmokejimas InsertApmokejimas(Apmokejimas apmokejimas)//provide transportas object when calling this function
        {
            try
            {
                bool nuomaYra = false;

                //setting new SqlConnection, providing connectionString
                cnn = new MySqlConnection(connectionString);
                cnn.Open();//open database

                //check if transportas exist
                MySqlCommand cmd = new MySqlCommand("Select * from nuoma where Nuomos_nr=@Nuomos_nr", cnn);
                cmd.Parameters.AddWithValue("@Nuomos_nr", apmokejimas.nuomos_Nr);

                MySqlDataReader dataReader = cmd.ExecuteReader();//sends SQLCommand.CommandText to the SQLCommand.Connection and builds SqlDataReader
                if ((dataReader.Read() == true))
                {
                    nuomaYra = true;
                }
                else
                {
                    Console.WriteLine("Tiekejo nera. Galima pridet");
                    return(null);
                }
                dataReader.Close();//close data reader when it finishes work

                if (nuomaYra == true)
                {
                    MySqlCommand cmd2 = new MySqlCommand("Insert into apmokejimas (Saskaitos_nr,Apmokejimo_suma,Nuomos_nr,Apmok_data) VALUES(@Saskaitos_nr,@Apmokejimo_suma,@Nuomos_nr,@Apmok_data)", cnn);
                    cmd2.Parameters.AddWithValue("@Saskaitos_nr", apmokejimas.saskaitos_Nr);
                    cmd2.Parameters.AddWithValue("@Apmokejimo_suma", apmokejimas.apmokejimo_Suma);
                    cmd2.Parameters.AddWithValue("@Nuomos_nr", apmokejimas.nuomos_Nr);
                    cmd2.Parameters.AddWithValue("@Apmok_data", apmokejimas.apmok_data);
                    cmd2.ExecuteNonQuery();

                    cnn.Close();
                }
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc);
            }
            return(apmokejimas);//return
        }
コード例 #7
0
        public void UpdateApmokejimas(Apmokejimas apmokejimas)
        {
            try
            {
                //setting new SqlConnection, providing connectionString
                cnn = new MySqlConnection(connectionString);

                //check if user exist
                MySqlCommand cmd = new MySqlCommand("Update apmokejimas SET Apmok_data=@Apmok_data WHERE apmok_nr=@apmok_nr", cnn);//to check if username exist we have to select all items with username
                cmd.Parameters.AddWithValue("@Apmok_data", apmokejimas.apmok_data);
                cmd.Parameters.AddWithValue("@apmok_nr", apmokejimas.apmok_Id);
                cnn.Open();
                cmd.ExecuteNonQuery();
                cnn.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
コード例 #8
0
        public void DeleteApmokejimas(Apmokejimas apmokejima)
        {
            try
            {
                cnn = new MySqlConnection(connectionString);

                string newSql = ("Delete from apmokejimas where apmokejimas.apmok_nr=@id;");

                cnn.Open();                                       //open connection. we use the Open method of the cnn variable to open a connection to the database.
                MySqlCommand cmd = new MySqlCommand(newSql, cnn); //select all from newTestTable
                cmd.Parameters.AddWithValue("@id", apmokejima.apmok_Id);
                cmd.ExecuteNonQuery();                            //execute function

                cnn.Close();
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc);
            }
        }
コード例 #9
0
        private void updateApmokejimas_Click(object sender, EventArgs e)
        {
            try
            {
                Apmokejimas ap     = new Apmokejimas();
                DateTime    apData = DateTime.Parse(updateApmokejimasApData.Text);
                ap.apmok_data = apData.Date;
                ap.apmok_Id   = int.Parse(updateApmokejimasApmokNr.Text);

                apmokRep.UpdateApmokejimas(ap);

                updateApmokejimasApData.Clear();
                updateApmokejimasApmokNr.Clear();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            MessageBox.Show("Succesfully updated");
            getApmokejimasDisplay();
        }