partial void DeletetblServer(tblServer instance);
 partial void InserttblServer(tblServer instance);
 partial void UpdatetblServer(tblServer instance);
        protected void buttonServerSnimiPostavke_Click(object sender, EventArgs e)
        {
            SemaforiDataContext db = new SemaforiDataContext();
            SimplerAES saes = new SimplerAES();

            if (Convert.ToInt32(labelServerID.Text) > 0) {                  // ako imamo ID, znači da mijenjamo postojeći
                tblServer server = (from tblServer in db.tblServers where tblServer.id == Convert.ToInt32(labelServerID.Text) select tblServer).Single();

                server.naziv = textBoxServerNaziv.Text;
                server.serverString = textBoxServerServerString.Text;

                db.SubmitChanges();

                tblDB dbase = (from tblDB in db.tblDBs where tblDB.serverid == server.id select tblDB).Single();

                dbase.naziv = textBoxServerDatabaseName.Text;
                dbase.serverid = server.id;
                dbase.integratedAuth = checkBoxServerDatabaseIntegratedAuth.Checked;
                dbase.korisnik = textBoxServerDatabaseKorisnik.Text;
                dbase.dbAttachString = textBoxServerDatabaseAttachString.Text;

                // kriptiramo lozinku da je baš ne spremimo u clear text u bazu

                 // ako nešto piše u TXt, to je nova lozinka. Spremi u H atribut
                if (textBoxServerDatabaseLozinka.Text.Length>0) {
                    textBoxServerDatabaseLozinka.Attributes["h"] = saes.Encrypt(textBoxServerDatabaseLozinka.Text);
                }

                dbase.lozinka = textBoxServerDatabaseLozinka.Attributes["h"];

                db.SubmitChanges();

                (sender as Button).Enabled = false;
                labelServerProvjeraStringa.Text = "";

            }
            else {      //nemamo ID, upisujemo novi

                tblServer server = new tblServer();
                tblDB dbase = new tblDB();

                server.naziv = textBoxServerNaziv.Text;
                server.serverString = textBoxServerServerString.Text;

                db.tblServers.InsertOnSubmit(server);
                db.SubmitChanges();

                dbase.naziv = textBoxServerDatabaseName.Text;
                dbase.serverid = server.id;
                dbase.integratedAuth = checkBoxServerDatabaseIntegratedAuth.Checked;
                dbase.korisnik = textBoxServerDatabaseKorisnik.Text;
                dbase.dbAttachString = textBoxServerDatabaseAttachString.Text;

                // kriptiramo password prije nego ga upišemo u bazu

                textBoxServerDatabaseLozinka.Attributes["h"] = saes.Encrypt(textBoxServerDatabaseLozinka.Text);
                dbase.lozinka = saes.Encrypt(textBoxServerDatabaseLozinka.Text);

                db.tblDBs.InsertOnSubmit(dbase);
                db.SubmitChanges();

                (sender as Button).Enabled = false;
                labelServerProvjeraStringa.Text = "";

            }

            ListViewServeri.DataBind();
            menuUpdatePanel.Update();
        }