Esempio n. 1
0
        private void bSave_Click(object sender, RoutedEventArgs e)
        {
            MyItem m = (MyItem)listView.SelectedItem;


            if (m.P.Id != -1)
            {
                //TODO edit pupil
                string firstname, lastname, grade, classP;

                firstname = tbPupilFirstname.Text;
                lastname  = tbPupilLastName.Text;
                grade     = tbPupilGrade.Text;
                classP    = tbPupilClass.Text;
                //comment = tbPupilComment.Text;

                if (!(firstname.Equals("") || lastname.Equals("") || classP.Equals("")) && (grade.Equals("7") || grade.Equals("8") || grade.Equals("9")))
                {
                    Console.WriteLine(firstname + "," + lastname + ", " + grade + ", " + classP);


                    bool commentCheck = false;


                    m.P.Firstname = firstname;
                    m.P.Lastname  = lastname;
                    m.P.Grade     = grade;
                    m.P.Class     = classP;
                    // m.P.Comment = comment;

                    sql.UpdatePupil(m.P, commentCheck);


                    m.P = sql.getPupil(m.P.Id);
                }
            }
            if (m.L.Id != -1)
            {
                m.L.Status = cbStatus.SelectedIndex;
                sql.updateLocker(m.L);
            }

            if (m.C.Id != -1)
            {
                m.C.Model      = tbPCModel.Text;
                m.C.Brand      = tbPCBrand.Text;
                m.C.Smartwater = tbPCSmartwater.Text;
                //m.C.Comment = tbPCComment.Text;
                m.C.Status  = cbPCStatus.SelectedIndex;
                m.C.Buy_out = cbPCBuyOut.SelectedIndex;


                sql.updateComputer(m.C);
            }
            ICollectionView view = CollectionViewSource.GetDefaultView(listView.ItemsSource);

            view.Refresh();
            listView.UpdateLayout();

            bSave.IsEnabled = false;
        }
Esempio n. 2
0
File: SQL.cs Progetto: RH90/KeyList
        public List <MyItem> getAllLockers(String search, string grade, string classP, string floor, string status)
        {
            List <MyItem> list = new List <MyItem>();

            string lockerQuery = "";

            if (floor != "" || status != "")
            {
                lockerQuery += " where ";
            }

            bool addAND = false;;

            if (floor != "")
            {
                lockerQuery += " floor=\"" + floor + "\" ";
                addAND       = true;
            }

            if (status != "")
            {
                if (addAND)
                {
                    lockerQuery += " and ";
                }
                addAND = true;

                lockerQuery += " status=" + status + " ";
            }
            //if (grade != "")
            //{
            //    if (addAND)
            //        lockerQuery += " and ";
            //    addAND = true;
            //    lockerQuery += " grade=\"" + grade + "\"";
            //}
            //if (classP != "")
            //{
            //    if (addAND)
            //        lockerQuery += " and ";
            //    addAND = true;
            //    lockerQuery += " classP=\"" + classP + "\" ";
            //}

            string query = "SELECT * from locker " + lockerQuery;

            Console.WriteLine(query);
            using (SQLiteCommand cmd = new SQLiteCommand(
                       query, con))
            {
                SQLiteDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    int owner;

                    if (!int.TryParse(reader.GetValue(reader.GetOrdinal("owner_id")) + "", out owner))
                    {
                        owner = -1;
                    }

                    int            id        = reader.GetInt32(reader.GetOrdinal("id"));
                    List <History> histories = GetHistory(1, id);

                    string comment = getHistoryShort(histories, 2);

                    Pupil  p = null;
                    Locker l = new Locker(
                        id,
                        reader.GetInt32(reader.GetOrdinal("number")),
                        reader.GetInt32(reader.GetOrdinal("keys")),
                        reader.GetString(reader.GetOrdinal("floor")),
                        reader.GetInt32(reader.GetOrdinal("status")),
                        owner,
                        comment);

                    // Console.WriteLine(l.Owner_id);
                    Computer c = new MyItem().C;
                    if (owner == -1)
                    {
                        p = new Pupil(-1, "", "", "", "", "", "");
                    }
                    else
                    {
                        p = getPupil(owner);

                        Computer cTmp = getComputerByOwner(owner);

                        if (cTmp != null)
                        {
                            c = cTmp;
                        }
                    }

                    //Console.WriteLine(reader.GetOrdinal("locker.owner_id"));
                    search = search.ToLower();

                    string[] parts = search.Split(' ');

                    bool check = true;
                    int  tmp;
                    for (int i = 0; i < parts.Length; i++)
                    {
                        if (int.TryParse(parts[i], out tmp))
                        {
                            if (!l.Number.ToString().Equals(parts[i]))
                            {
                                check = false;
                            }
                        }
                        else if (!p.HistoryShort.ToLower().Contains(parts[i]) && !p.Firstname.ToLower().Contains(parts[i]) && !p.Lastname.ToLower().Contains(parts[i]))
                        {
                            check = false;
                        }
                    }
                    if (classP != "" && !classP.Equals(p.Class))
                    {
                        check = false;
                    }

                    // Console.WriteLine(grade + "  " + p.Grade);
                    if (grade != "" && !grade.Equals(p.Grade))
                    {
                        check = false;
                    }

                    if ((search == "" && grade == "" && classP == "") || check)
                    {
                        list.Add(new MyItem
                        {
                            P = p,
                            L = l,
                            C = c
                        });
                    }
                }
            }
            return(list);
        }