Beispiel #1
0
        private DataBaseConnection()
        {
            LoginForm logf             = new LoginForm();
            string    Dir              = logf.GetHomeDirectory();
            string    connectionString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString + "Data Source ='" + @Dir + "\\DataBase.sdf'";

            connection = new SqlCeConnection(connectionString);
            connection.Open();
        }
        private void PrintStatisticTeacherRoundedButton_Click(object sender, EventArgs e)
        {
            int       columnNumber = 6;
            PdfPTable table        = new PdfPTable(columnNumber)
            {
                //actual width of table in points
                TotalWidth = 400f,
                //fix the absolute width of the table
                LockedWidth = true
            };

            //relative col widths in proportions - 1/3 and 2/3
            float[] widths = new float[] { 1f, 1f, 1f, 1f, 1f, 1f };
            table.SetWidths(widths);
            table.HorizontalAlignment = 0;
            //leave a gap before and after the table
            table.SpacingBefore = 20f;
            table.SpacingAfter  = 30f;
            PdfPCell cell = new PdfPCell(new Phrase("Ucenici"))
            {
                Colspan             = columnNumber,
                Border              = 0,
                HorizontalAlignment = 1
            };

            table.AddCell(cell);

            table.AddCell("Ime");
            table.AddCell("Prezime");
            table.AddCell("Odsustva(U)");
            table.AddCell("Odsustva(O)");
            table.AddCell("Odsustva(N)");
            table.AddCell("Prosjek");



            int    TeacherId     = CurrentTeacher.Id;
            int    DepartmentId  = DepartmentsRepository.GetIdByTeacherId(TeacherId);
            string StudentsQuery = StudentRepository.GetQuery(DepartmentId);

            SqlCeCommand    cmd    = new SqlCeCommand(StudentsQuery, Connection);
            SqlCeDataReader reader = cmd.ExecuteReader();


            try
            {
                while (reader.Read())
                {
                    int justifiedAbsents   = AbsentsRepository.GetAbsents((int)reader["Id"], 1);
                    int unJustifiedAbsents = AbsentsRepository.GetAbsents((int)reader["Id"], 0);
                    int sum = justifiedAbsents + unJustifiedAbsents;

                    string   CoursesId = CoursesRepository.GetCoursesId();
                    string[] parts     = CoursesId.Split(',');
                    int      suum      = 0;
                    for (int i = 0; i < parts.Length; i++)
                    {
                        string   marks     = MarksRepository.GetMarks((int)reader["Id"]);
                        string[] particles = marks.Split(',');
                        double   mark      = Math.Round(float.Parse(CalculateAverageGrade(particles)), MidpointRounding.AwayFromZero);

                        suum += (int)mark;
                    }

                    float average = suum / (parts.Length);

                    string averageMark = average.ToString("0.00") + "(" + Math.Round(average, MidpointRounding.AwayFromZero) + ")";

                    table.AddCell(reader["Name"].ToString());
                    table.AddCell(reader["Surname"].ToString());
                    table.AddCell(sum.ToString());
                    table.AddCell(justifiedAbsents.ToString());
                    table.AddCell(unJustifiedAbsents.ToString());
                    table.AddCell(averageMark);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            LoginForm logf = new LoginForm();
            string    Dir  = logf.GetHomeDirectory();

            FileStream fs = new FileStream("report.pdf", FileMode.Create);

            Document  doc       = new Document(PageSize.A4);
            PdfWriter pdfWriter = PdfWriter.GetInstance(doc, fs);

            doc.Open();
            doc.Add(table);
            while (reader.Read())
            {
                doc.Add(new Paragraph(reader[0].ToString() + reader[1].ToString() + reader[2].ToString()));
            }

            pdfWriter.CloseStream = true;
            doc.Close();


            Process.Start("report.pdf");
        }
        public void  CheckLogin(TextBox Username, TextBox Password)
        {
            LoginForm logf             = new LoginForm();
            string    Dir              = logf.GetHomeDirectory();
            string    connectionString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString + "Data Source ='" + @Dir + "\\DataBase.sdf'";

            using (SqlCeConnection Connection = new SqlCeConnection())
            { if (Username.TextLength > 0 && Password.TextLength > 0)
              {
                  try
                  {
                      Connection.ConnectionString = connectionString;
                      Connection.Open();
                      SqlCeCommand logincommand = new SqlCeCommand(@"SELECT Id,UserName,Password FROM Users
                                        WHERE UserName=@uname and  Password=@pass", Connection);
                      logincommand.Parameters.AddWithValue("@uname", Username.Text);
                      logincommand.Parameters.AddWithValue("@pass", Password.Text);
                      SqlCeDataReader loginReader = logincommand.ExecuteReader();

                      if (loginReader.Read() &&
                          loginReader["UserName"].ToString() == Username.Text &&
                          loginReader["Password"].ToString() == Password.Text)
                      {
                          SqlCeCommand admincommand = new SqlCeCommand(@"SELECT Name,Surname,UsersId FROM Administration
                                                             WHERE UsersId =@LoggedId", Connection);
                          admincommand.Parameters.AddWithValue("@LoggedId", loginReader["Id"]);
                          SqlCeDataReader adminReader = admincommand.ExecuteReader();   //ADMIN

                          SqlCeCommand teachercommand = new SqlCeCommand(@"SELECT Name,Surname,UsersId FROM Teachers
                                                             WHERE UsersId =@LoggedId", Connection);
                          teachercommand.Parameters.AddWithValue("@LoggedId", loginReader["Id"]);
                          SqlCeDataReader teacherReader = teachercommand.ExecuteReader();   //TEACHER

                          SqlCeCommand directorcommand = new SqlCeCommand(@"SELECT Name,Surname,UsersId FROM Directors
                                                             WHERE UsersId =@LoggedId", Connection);
                          directorcommand.Parameters.AddWithValue("@LoggedId", loginReader["Id"]);
                          SqlCeDataReader directorReader = directorcommand.ExecuteReader();   //DIRECTOR

                          if (adminReader.Read() && loginReader["Id"].ToString() == adminReader["UsersId"].ToString())
                          {
                              flag = true;
                              Form newform = new AdministrationForm();
                              newform.Show();
                          }
                          else if (teacherReader.Read() && loginReader["Id"].ToString() == teacherReader["UsersId"].ToString())
                          {
                              flag = true;
                              Form newform = new TeacherForm();
                              newform.Show();
                          }
                          else if (directorReader.Read() && loginReader["Id"].ToString() == directorReader["UsersId"].ToString())
                          {
                              flag = true;
                              Form newform = new DirectorForm();
                              newform.Show();
                          }
                          else
                          {
                              flag = false;
                              MessageBox.Show("Netacni podaci");
                          }
                      }
                      else
                      {
                          flag = false;
                          MessageBox.Show("Netacni podaci");
                          Username.Text = "";
                          Password.Text = "";
                      }
                  }
                  catch (Exception ex)
                  {
                      flag = false;
                      MessageBox.Show("Neočekivana greška:" + ex.Message);
                  }
              }
            }
        }