منشئ الاكواد
#11
تقريبا انتهيت من البرنامج ولكن اريد اي فكرة لاضيفها في البرنامج ليضيفها في الكود

سيعجبكم البرنامج ان شاء الله وهذه المرة هو مبرمج بالدلفي بالكامل

[صورة مرفقة: 3c5595de0b6be79.jpg]


[صورة مرفقة: d470d5e08333785.jpg]





كود :
// Author: delphi4arab
// Homepage: http://www.delphi4arab.net
// Date: 2018-05-08


// Insert New Record By Execute SqL Query
// First Definition of a numeric variable For maxId Query
Var Int :Integer;

// Create a query to fetch the largest number

With QryMaxID Do
begin
 .Close;
 .Sql.clear;
 .Sql.Add('Select Max(id) as MaxId from Emplyee;
 .Open;
  Int := .FieldByName('MaxId').Asintegre + 1;
 .Close;
End;


// The command prompt to create a query add the required record
Try
With QryEmplyee Do
begin
 .Close;
 .SQL.Clear;
 .SQL.Add('Insert Into Emplyee(ID,FirstNmame,LastName,Age,City,Phone,Address) Values (:ID,:FirstNmame,:LastName,:Age,:City,:Phone,:Address)');
// Add Parameters to Query Control
 .ParamByName('ID').Value:= Int;
 .ParamByName('FirstNmame').Value:= Trim(TxtFirstNmame.Text);
 .ParamByName('LastName').Value:= Trim(TxtLastName.Text);
 .ParamByName('Age').Value:= Trim(TxtAge.Text);
 .ParamByName('City').Value:= Trim(TxtCity.Text);
 .ParamByName('Phone').Value:= Trim(TxtPhone.Text);
 .ParamByName('Address').Value:= Trim(TxtAddress.Text);
 .ExecSQL;
 ShowMessage('Ok File is Added');
except on E: Exception do
 ShowMessage('Error');
end;
end;

// Other Way
// Insert New Record Directly By Table

// Definition of a numeric variable For maxId Query
Var Int :Integer;

// Create a query to fetch the largest number
With QryMaxID Do
begin
 .Close;
 .Sql.clear;
 .Sql.Add('Select Max(id) as MaxId from Emplyee;
 .Open;
  Int := .FieldByName('MaxId').Asintegre + 1;
 .Close;
End;

// The command prompt to create a query add the required record
Try
With TblEmplyee Do
begin
 .Append;
 .FieldByName('ID').Value:= Int;
 .FieldByName('FirstNmame').Value:= Trim(TxtFirstNmame.Text);
 .FieldByName('LastName').Value:= Trim(TxtLastName.Text);
 .FieldByName('Age').Value:= Trim(TxtAge.Text);
 .FieldByName('City').Value:= Trim(TxtCity.Text);
 .FieldByName('Phone').Value:= Trim(TxtPhone.Text);
 .FieldByName('Address').Value:= Trim(TxtAddress.Text);
 .Post;
 ShowMessage('Ok File is Added');
except on E: Exception do
 ShowMessage('Error');
end;
end;


// The command prompt to create a Update query the required record
Try
With QryEmplyee Do
begin
 .Close;
 .SQL.Clear;
 .SQL.Add('Update Emplyee Set(ID=:ID,FirstNmame=:FirstNmame,LastName=:LastName,Age=:Age,City=:City,Phone=:Phone,Address=:Address))';
// Add Parameters to Query Control
 .ParamByName('ID').Value:= Int;
 .ParamByName('FirstNmame').Value:= Trim(TxtFirstNmame.Text);
 .ParamByName('LastName').Value:= Trim(TxtLastName.Text);
 .ParamByName('Age').Value:= Trim(TxtAge.Text);
 .ParamByName('City').Value:= Trim(TxtCity.Text);
 .ParamByName('Phone').Value:= Trim(TxtPhone.Text);
 .ParamByName('Address').Value:= Trim(TxtAddress.Text);
 .ExecSQL;
 ShowMessage('Ok File is Updated');
except on E: Exception do
 ShowMessage('Error');
end;
end;

// Other Way
// Update New Record Directly By Table

// Definition of a numeric variable For maxId Query
Var Int :Integer;

// Create a query to fetch the largest number
With QryMaxID Do
begin
 .Close;
 .Sql.clear;
 .Sql.Add('Select Max(id) as MaxId from Emplyee;
 .Open;
  Int := .FieldByName('MaxId').Asintegre + 1;
 .Close;
End;

// The command prompt to create a query add the required record
Try
With TblEmplyee Do
begin
 .Edit;
 .FieldByName('ID').Value:= Int;
 .FieldByName('FirstNmame').Value:= Trim(TxtFirstNmame.Text);
 .FieldByName('LastName').Value:= Trim(TxtLastName.Text);
 .FieldByName('Age').Value:= Trim(TxtAge.Text);
 .FieldByName('City').Value:= Trim(TxtCity.Text);
 .FieldByName('Phone').Value:= Trim(TxtPhone.Text);
 .FieldByName('Address').Value:= Trim(TxtAddress.Text);
 .Post;
 ShowMessage('Ok File is Updated');
except on E: Exception do
 ShowMessage('Error');
end;
end;

// Query for Delete

Try
With QryEmplyee Do
begin
 .Close;
 .Sql.clear;
 .Sql.Add('Delete * From Emplyee where ID=:ID');
 .ExecSQL;
 .Close;
End;
 ShowMessage('Ok File is Deleted');
except on E: Exception do
 ShowMessage('Error');
end;
end;

// Directly bt Table
TblEmplyee.Delete;

// Sql Insert Statement
Insert Into Emplyee(ID,FirstNmame,LastName,Age,City,Phone,Address) Values (:ID,:FirstNmame,:LastName,:Age,:City,:Phone,:Address)');

// Sql Update Statement
Update Emplyee Set(ID=:ID,FirstNmame=:FirstNmame,LastName=:LastName,Age=:Age,City=:City,Phone=:Phone,Address=:Address))';

// Sql Delete Statement
Delete * From Emplyee where ID=:ID

الكود الاخير هو ما يكتبه ، اشعر انه قليل ربما يمكن هناك ما نضيفه أليه
فائدة رمضان تتجلى الان فحافظوا على ما كنتم عليه من الطاعات
[-] كل من 2 users say قال شكرا ل Delphi4Us على المشاركة المفيدة
  • bassem_43, zouaidahmed
الرد


التنقل السريع :


مستخدمين يتصفحوا هذا الموضوع: 1 ضيف