Sayfayı Yazdır | Pencereyi Kapat

Sqlite ile fotoğraf bağlantısı

Nereden Yazdırıldığı: Clomosy | Forum
Kategori: Genel Programlama
Forum Adı: Genel İşlemler
Forum Tanımlaması: TRObject dili ile programlama yaparken karşılaşılan genel işlemler
URL: https://forum.clomosy.com.tr/forum_posts.asp?TID=850
Tarih: 08 Ocak 2025 Saat 20:07
Program Versiyonu: Web Wiz Forums 12.07 - https://www.webwizforums.com


Konu: Sqlite ile fotoğraf bağlantısı
Mesajı Yazan: Furblood
Konu: Sqlite ile fotoğraf bağlantısı
Mesaj Tarihi: 08 Ağustos 2024 Saat 15:35
var
MyprofileForm : TclForm;
labelID, labelUsername, labelName, labelSurname, labelAge, labelWeight, labelHeight, labelBMI, labelPhone, labelPassword, labelCity, labelGender, labelTitle, labelSidetitle1, labelSidetitle2, labelSidetitle3: TClProLabel;
Scroll: TCLVertScrollBox;
panelTop,panelBottom : TclProPanel;

Qry : TclSQLiteQuery;

BMI:Real;
bmiResultLabel: TClProLabel;

photoList : TCLProListView;
DesignerPanel : TClListViewDesignerPanel;
taskImg,userPhoto  : TclProImage;
taskName : TClProLabel;


    void SqLiteConnection;
      {
        try
          Clomosy.DBSQLiteConnect(Clomosy.AppFilesPath + 'GYM2.db3', ''); 
        except
         ShowMessage('Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
        }
      }

    void InsertPhotoIntoDatabase(photoUrl: String);
    {
      try
        Clomosy.DBSQLiteQuery.Sql.Text = 'UPDATE Users SET PROFILEPHOTO = ' + QuotedStr(photoUrl) + ' WHERE USERNAME = ' + QuotedStr(Clomosy.GlobalVariableString);
        Clomosy.DBSQLiteQuery.OpenOrExecute;
        
        // Immediately update the user photo on the form to reflect the new photo
        userPhoto.clProSettings.PictureSource = photoUrl;
        userPhoto.SetclProSettings(userPhoto.clProSettings);
        ShowMessage('Photo updated successfully!');
      except
        ShowMessage('Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
      }
    }


    void KullaniciVerileri;
    var photoUrl : String;
    {
      try
        Qry = Clomosy.DBSQLiteQueryWith('SELECT * FROM users WHERE USERNAME=' + QuotedStr(Clomosy.GlobalVariableString));
        Qry.OpenOrExecute;
        
        // Set the user photo based on the retrieved PROFILEPHOTO field
        photoUrl = Qry.FieldByName('PROFILEPHOTO').AsString;
        if (photoUrl <> (''))
        {
          userPhoto.clProSettings.PictureSource = photoUrl;
          userPhoto.SetclProSettings(userPhoto.clProSettings);
        }
        else
        {
          // Set a default photo if no PROFILEPHOTO is available
          userPhoto.clProSettings.PictureSource = 'https://i.imgur.com/38uoXIt.png';
          userPhoto.SetclProSettings(userPhoto.clProSettings);
        }
      except
        ShowMessage('Exception Class: ' + LastExceptionClassName + ' Exception Message: ' + LastExceptionMessage);
      }  
    }


    

void CreateListView
{
  photoList = MyprofileForm.AddNewProListView(MyprofileForm,'photoList');
  photoList.Align = alRight;
  photoList.Height = 300;
  photoList.Width = 150;
  photoList.Margins.Bottom = 20;
  photoList.Margins.Top = 100;
  photoList.clProSettings.ViewType = lvIcon; //(lvList, lvIcon, lvWaterFall)
  photoList.clProSettings.ColCount = 1;
  photoList.clProSettings.ItemHeight = 100;
  photoList.clProSettings.ItemSpace = 10;
  photoList.clProSettings.BackgroundColor = clAlphaColor.clHexToColor('#FFFCFF');
  photoList.clProSettings.BorderColor = clAlphaColor.clHexToColor('#66FF7F');
  photoList.clProSettings.BorderWidth = 2;
  photoList.clProSettings.RoundHeight = 5;
  photoList.clProSettings.RoundWidth = 5;
  photoList.SetclProSettings(photoList.clProSettings);
  MyprofileForm.AddNewEvent(photoList,tbeOnItemClick,'TaskClick');
  photoList.Visible = false;
}

void CreateDesignerPanel
{
  DesignerPanel = MyprofileForm.AddNewProListViewDesignerPanel(photoList, 'DesignerPanel');
  DesignerPanel.Height = 100;
  DesignerPanel.Width = 100;
  DesignerPanel.clProSettings.BackgroundColor = clAlphaColor.clHexToColor('#B3FCE5');
  DesignerPanel.clProSettings.BorderColor = clAlphaColor.clHexToColor('#16FF8C');
  DesignerPanel.clProSettings.BorderWidth = 2;
  DesignerPanel.clProSettings.RoundHeight = 20;
  DesignerPanel.clProSettings.RoundWidth = 20;
  DesignerPanel.SetclProSettings(DesignerPanel.clProSettings);
}

void CreateData;
{
  taskImg = MyprofileForm.AddNewProImage(DesignerPanel, 'taskImg');
  taskImg.Align = AlLeft;
  taskImg.Margins.Top = 10;
  taskImg.Margins.Bottom = 10;
  DesignerPanel.AddPanelObject(taskImg, clText2);
  photoList.SetDesignerPanel(DesignerPanel);
}

void AddDataToListView;
{
  photoList.clLoadProListViewDataFromDataset(Clomosy.ClDataSetFromJSON('
  {"taskImg" : "https://i.imgur.com/m5V9b4x.png"},
  {"taskImg" : "https://i.imgur.com/LQ4J4dh.png"},
  {"taskImg" : "https://i.imgur.com/w9lmYul.png"},
  {"taskImg" : "https://i.imgur.com/b9jWqJK.png"},
  {"taskImg" : "https://i.imgur.com/KUMAPMj.png"},
  {"taskImg" : "https://i.imgur.com/4k2JH97.png"}
  '));
}

void listAyarla;
{
  AddDataToListview;
  photoList.Visible = not photoList.Visible;
}

void TaskClick(item);
var 
  selectedPhotoUrl : string;
{
  selectedPhotoUrl = photoList.clSelectedItemData(clText2);
  userPhoto.clProSettings.PictureSource = selectedPhotoUrl;
  userPhoto.SetclProSettings(userPhoto.clProSettings);
  photoList.Visible = false;

  // Now, you can use the selectedPhotoUrl to insert into the database
  InsertPhotoIntoDatabase(selectedPhotoUrl);
  
}



function BMIHesapla(weightR: Real; heightR: Real):Real;
var 
  heightM:Real;
{
  heightM = heightR / 100;
  BMI = weightR / Sqr(heightM);
  BMI = Trunc(BMI*100)/100;
}
function bmiResult(BMI:Real):String;
{
  if(BMI < 18.5)
    bmiResultLabel.Text = '(Underweight)';
  else if(18.5 <= BMI && BMI < 25 )
    bmiResultLabel.Text = '(Normal weight)';
  else if(25 <= BMI && BMI < 30)
    bmiResultLabel.Text = '(Overweight)';
  else
    bmiResultLabel.Text = '(Obesity)';
}


{
  MyprofileForm = TclForm.Create(Self);
  SqLiteConnection;
  KullaniciVerileri;


  
  panelTop = MyprofileForm.AddNewProPanel(MyprofileForm,'panelTop');
  panelTop.Align = alMostTop;
  panelTop.Height = 100;
  panelTop.clProSettings.BackgroundColor = clAlphaColor.clHextoColor('#ffffff');
  panelTop.SetclProSettings(panelTop.clProSettings);
  
  labelTitle = MyprofileForm.AddNewProLabel(panelTop, 'labelTitle', 'MY PROFILE');
  labelTitle.Align = alCenter;
  labelTitle.Width = 200;
  labelTitle.clProSettings.FontColor = clAlphaColor.clHextoColor('#6482AD');
  labelTitle.clProSettings.FontSize = 20;
  labelTitle.SetclProSettings(labelTitle.clProSettings);
  
  
  userPhoto = MyprofileForm.AddNewProImage(MyprofileForm,'userPhoto');
  userPhoto.Align = alCenter;
  userPhoto.Height = 100;
  userPhoto.Margins.Bottom = 500;
  userPhoto.clProSettings.PictureSource = 'https://i.imgur.com/38uoXIt.png';
  userPhoto.SetclProSettings(userPhoto.clProSettings);
  
  
  
  CreateListView;
  CreateDesignerPanel;
  CreateData;
  MyprofileForm.AddNewEvent(userPhoto,tbeOnClick,'listAyarla');
  
  
  panelBottom = MyprofileForm.AddNewProPanel(MyprofileForm,'panelBottom');
  panelBottom.Align = AlLeft;
  panelBottom.Margins.Left = 20;
  panelBottom.Margins.Top = 20;
  panelBottom.Width = 200;
  panelBottom.clProSettings.BackgroundColor = clAlphaColor.clHextoColor('#ffffff');
  panelBottom.SetclProSettings(panelBottom.clProSettings);
  
  Scroll = MyprofileForm.AddNewVertScrollBox(panelBottom,'Scroll');
  Scroll.Height = panelBottom.height;
  Scroll.Align = alMostTop;
  
    labelSidetitle1 = MyprofileForm.AddNewProLabel(Scroll, 'labelSidetitle1', 'Personal Information');
    labelSidetitle1.Align = alCenter;
    labelSidetitle1.Margins.Bottom = 800;
    labelSidetitle1.Width = 300;
    labelSidetitle1.clProSettings.FontColor = clAlphaColor.clHextoColor('#000000');
    labelSidetitle1.clProSettings.FontSize = 18;
    labelSidetitle1.clProSettings.TextSettings.Font.Style = [fsBold];
    labelSidetitle1.SetclProSettings(labelSidetitle1.clProSettings);
  
  labelID = MyprofileForm.AddNewProLabel(Scroll, 'labelID', 'User ID:  '+ Qry.FieldByName('userID').AsString);
  labelID.Align = alCenter;
  labelID.Margins.Bottom = 700;
  labelID.Width = 300;
  labelID.clProSettings.FontColor = clAlphaColor.clHextoColor('#6482AD');
  labelID.clProSettings.FontSize = 14;
  labelID.SetclProSettings(labelID.clProSettings);
  
  labelUsername = MyprofileForm.AddNewProLabel(Scroll, 'labelUsername', 'Username:  '+ Qry.FieldByName('USERNAME').AsString);
  labelUsername.Align = alCenter;
  labelUsername.Margins.Bottom = 600;
  labelUsername.Width = 300;
  labelUsername.clProSettings.FontColor = clAlphaColor.clHextoColor('#6482AD');
  labelUsername.clProSettings.FontSize = 14;
  labelUsername.SetclProSettings(labelUsername.clProSettings);
  
  labelName = MyprofileForm.AddNewProLabel(Scroll, 'labelName', 'Name:  ' + Qry.FieldByName('NAME').AsString);
  labelName.Align = alCenter;
  labelName.Margins.Bottom = 500;
  labelName.Width = 300;
  labelName.clProSettings.FontColor = clAlphaColor.clHextoColor('#6482AD');
  labelName.clProSettings.FontSize = 14;
  labelName.SetclProSettings(labelName.clProSettings);
  
  labelSurname = MyprofileForm.AddNewProLabel(Scroll, 'labelSurname', 'Surname:  '+ Qry.FieldByName('SURNAME').AsString);
  labelSurname.Align = alCenter;
  labelSurname.Margins.Bottom = 400;
  labelSurname.Width = 300;
  labelSurname.clProSettings.FontColor = clAlphaColor.clHextoColor('#6482AD');
  labelSurname.clProSettings.FontSize = 14;
  labelSurname.SetclProSettings(labelSurname.clProSettings);
  
  labelAge = MyprofileForm.AddNewProLabel(Scroll, 'labelAge', 'Age:  ' +Qry.FieldByName('AGE').AsString);
  labelAge.Align = alCenter;
  labelAge.Margins.Bottom = 300;
  labelAge.Width = 300;
  labelAge.clProSettings.FontColor = clAlphaColor.clHextoColor('#6482AD');
  labelAge.clProSettings.FontSize = 14;
  labelAge.SetclProSettings(labelAge.clProSettings);
  
  labelWeight = MyprofileForm.AddNewProLabel(Scroll, 'labelWeight', 'Weight: '+Qry.FieldByName('WEIGHT').AsString + ' kg');
  labelWeight.Align = alCenter;
  labelWeight.Margins.Bottom = 200;
  labelWeight.Width = 300;
  labelWeight.clProSettings.FontColor = clAlphaColor.clHextoColor('#6482AD');
  labelWeight.clProSettings.FontSize = 14;
  labelWeight.SetclProSettings(labelWeight.clProSettings);
  
  labelHeight = MyprofileForm.AddNewProLabel(Scroll, 'labelHeight', 'Height:  '+Qry.FieldByName('HEIGHT').AsString + ' cm');
  labelHeight.Align = alCenter;
  labelHeight.Margins.Bottom = 100;
  labelHeight.Width = 300;
  labelHeight.clProSettings.FontColor = clAlphaColor.clHextoColor('#6482AD');
  labelHeight.clProSettings.FontSize = 14;
  labelHeight.SetclProSettings(labelHeight.clProSettings);
  
  BMIHesapla(StrToFloat(Qry.FieldByName('WEIGHT').AsString),StrToFloat(Qry.FieldByName('HEIGHT').AsString));
  labelBMI = MyprofileForm.AddNewProLabel(Scroll, 'labelBMI', 'BMI:  '+ FloatToStr(BMI));
  labelBMI.Align = alCenter;
  labelBMI.Margins.Bottom = 0;
  labelBMI.Width = 300;
  labelBMI.clProSettings.FontColor = clAlphaColor.clHextoColor('#6482AD');
  labelBMI.clProSettings.FontSize = 14;
  labelBMI.SetclProSettings(labelBMI.clProSettings);
  
  bmiResultLabel = MyprofileForm.AddNewProLabel(Scroll, 'bmiResultLabel', '');
  bmiResultLabel.Align = alCenter;
  bmiResultLabel.Margins.Bottom = 0;
  bmiResultLabel.Margins.Left = 150;
  bmiResultLabel.Width = 300;
  bmiResultLabel.clProSettings.FontColor = clAlphaColor.clHextoColor('#6482AD');
  bmiResultLabel.clProSettings.FontSize = 14;
  bmiResultLabel.SetclProSettings(bmiResultLabel.clProSettings);
  
  labelGender = MyprofileForm.AddNewProLabel(Scroll, 'labelGender', 'Gender:  '+Qry.FieldByName('GENDER').AsString);
  labelGender.Align = alCenter;
  labelGender.Margins.Bottom = -100;
  labelGender.Width = 300;
  labelGender.clProSettings.FontColor = clAlphaColor.clHextoColor('#6482AD');
  labelGender.clProSettings.FontSize = 14;
  labelGender.SetclProSettings(labelGender.clProSettings);
  
  labelPassword = MyprofileForm.AddNewProLabel(Scroll, 'labelPassword', 'Password:  '+Qry.FieldByName('PASSWORD').AsString);
  labelPassword.Align = alCenter;
  labelPassword.Margins.Bottom = -200;
  labelPassword.Width = 300;
  labelPassword.clProSettings.FontColor = clAlphaColor.clHextoColor('#6482AD');
  labelPassword.clProSettings.FontSize = 14;
  labelPassword.SetclProSettings(labelPassword.clProSettings);
  
  
    labelSidetitle2 = MyprofileForm.AddNewProLabel(Scroll, 'labelSidetitle2', 'Contact Information');
    labelSidetitle2.Align = alCenter;
    labelSidetitle2.Margins.Bottom = -300;
    labelSidetitle2.Width = 300;
    labelSidetitle2.clProSettings.FontColor = clAlphaColor.clHextoColor('#000000');
    labelSidetitle2.clProSettings.FontSize = 18;
    labelSidetitle2.clProSettings.TextSettings.Font.Style = [fsBold];
    labelSidetitle2.SetclProSettings(labelSidetitle2.clProSettings);
  
  labelPhone = MyprofileForm.AddNewProLabel(Scroll, 'labelPhone', 'Phone:  '+Qry.FieldByName('PHONE').AsString);
  labelPhone.Align = alCenter;
  labelPhone.Margins.Bottom = -400;
  labelPhone.Width = 300;
  labelPhone.clProSettings.FontColor = clAlphaColor.clHextoColor('#6482AD');
  labelPhone.clProSettings.FontSize = 14;
  labelPhone.SetclProSettings(labelPhone.clProSettings);
  
    labelSidetitle3 = MyprofileForm.AddNewProLabel(Scroll, 'labelSidetitle3', 'Location');
    labelSidetitle3.Align = alCenter;
    labelSidetitle3.Margins.Bottom = -500;
    labelSidetitle3.Width = 300;
    labelSidetitle3.clProSettings.FontColor = clAlphaColor.clHextoColor('#000000');
    labelSidetitle3.clProSettings.FontSize = 18;
    labelSidetitle3.clProSettings.TextSettings.Font.Style = [fsBold];
    labelSidetitle3.SetclProSettings(labelSidetitle3.clProSettings);
  
  labelCity = MyprofileForm.AddNewProLabel(Scroll, 'labelCity', 'City:  '+Qry.FieldByName('CITY').AsString);
  labelCity.Align = alCenter;
  labelCity.Margins.Bottom = -600;
  labelCity.Width = 300;
  labelCity.clProSettings.FontColor = clAlphaColor.clHextoColor('#6482AD');
  labelCity.clProSettings.FontSize = 14;
  labelCity.SetclProSettings(labelCity.clProSettings);
  
  bmiResult(BMI);


  MyprofileForm.Run;
}


Kullanıcı profil fotoğrafı seçip geri gittiğinde fotoğrafın kalmasını istiyorum çünkü daha sonra bu fotoğrafı başka yerde kullanacağım. Sqlite ile fotoğrafı update etmeyi denedim fakat olmadıCry. Hata almıyorum ama uygulama açılmıyor.  Cry



-------------
furkanfidan



Cevaplar:
Mesajı Yazan: Developer
Mesaj Tarihi: 08 Ağustos 2024 Saat 16:32
Merhaba Furkan,
Oncellikle bir insert gormedim Insert islemini nerde yaptin?
Oncellikle verinin gelip gelmedigini kontrol etmen gerekiyor daha sonrasinda fieldByName yapabilirsin.
 Qry = Clomosy.DBSQLiteQueryWith('SELECT * from StudentExamInformation');
      Qry.OpenOrExecute;
      
      if (Qry.Found)
      {
        for i = 0 to Qry.RecordCount-1
        {
          sLabel = MyForm.AddNewLabel(vScroll,'Label'+IntToStr(i),'');
          sLabel.StyledSettings = ssFamily;
          sLabel.TextSettings.Font.Size=20;
          sLabel.Align = alTop;
          sLabel.Margins.Left= 5;
          sLabel.Margins.Top= 5; 
          sLabel.Height = 50;
          sLabel.Text = '* '+Qry.FieldByName('schollID').AsString + '  '+ Qry.FieldByName('name').AsString + ' '+ 
          Qry.FieldByName('surname').AsString + '  '+ Qry.FieldByName('lesson').AsString + '   '+ 
          Qry.FieldByName('v_note').AsString + '-'+ Qry.FieldByName('f_note').AsString;
          
          sLabel.AutoSize = True;
          sLabel.WordWrap = True;
          Qry.Next;
        }  
      }




Sayfayı Yazdır | Pencereyi Kapat

Forum Software by Web Wiz Forums® version 12.07 - https://www.webwizforums.com
Copyright ©2001-2024 Web Wiz Ltd. - https://www.webwiz.net