PDA

View Full Version : حرفه ای: آموزش گزارش گیری با entity framework



firoozi90
سه شنبه 14 شهریور 1391, 09:39 صبح
سلام دوستان
از اونجایی که آموزشی در رابطه با گزارش گیری با entity framework در این سایت و سایت های های فارسی ندیدم تصمیم گرفته مقاله لاتینی در این باره که کاملا صریح گفته شده براتون بزارم که علاقمندان استفاده کنند.
در ضمن باید بگم که این مقاله منبع خاصی نداشت که بخوام منبعشو بزارم





Step 1: Create New Solution

1.Launch Visual Studio and select New Project… from the Start Page.

2.Expand the Visual C#‎ templates and click on the Web templates. Select "ASP.NET Empty Web Application" and change the name of the project to "CRForEntityFramework".

3.Click the OK button.



Step 2: Create the Database

1.Right click on the project file in the Solution Explorer and select "Add New Item…" from the pop-up menu.

2.Click the "Data" node under Visual C#‎ Items. Click on the "SQL Server Database" template and name the file "CRTest.mdf". Click the Add button. You will get a message asking if you want to add the data file to the App_Data folder. Click the Yes button.

If you don't have SQL Server Express installed you will be prompted to download the install. If you do have SQL Server Express installed then the database file will be created and you can now add a table.

3.Right click on the CRTest.mdf file in the Solution Explorer and select "Open" from the pop-up menu.

4.The database should be displayed in the Server Explorer window. Right click on the Tables node and select "Add New Table".

5.A new table will appear in design mode. Enter "UserAccountId" for the first field and set its DataType to "int" and uncheck the "Allow Nulls" box. Also change this field to an Identity field by setting the IsIdentity property to "Yes".

6.Add fields for FirstName, LastName, and EmailAddress. Make all these fields varchar(50) and do not allow nulls.

7.Click the Save button on the toolbar and change the name of the table to UserAccount.

8.Add a few records to this table by right clicking on the table in the Server Explorer and selecting "Show Table Data" from the pop-up menu. You can then just enter a few records by typing in the FirstName, LastName, and EmailAddress fields.



Step 3: Create the Entity Data Model

Now that you have the database you can create the Entity Data Model using the Entity Framework.

1.Right click on the project file in the Solution Explorer and select AddàNew Item… from the pop-up menu.

2.Click on the Data node under the Visual C#‎ templates. Click on the ADO.NET Entity Data Model template and change the name to CRTest.edmx. Now click the Add button.

3.The Entity Data Model Wizard should appear. Choose "Generate From Database" and click the Next button.

4.The "Choose Your Connection" screen should appear. Select the CRTest.mdf connection and click the Next button.

5.The next screen allows you to select the database objects you want to include in the Entity Data Model. Expand the Tables node and check the box next to the UserAccount table.

6.Click the "Finish" button. The UserAccount entity should appear in the CRTest.edmx file.


Step 4: Create the XML Schema File

There is no direct way to connect a Crystal Report file to an Entity Framework entity but you can create an XML schema file that contains the structure of the Entity and then connect that to the Crystal Report.

1.Right click on the Project in the Solution Explorer and select Add New Item…

2.Select the Data node under the Visual C#‎ Templates.

3.Select the DataSet template, name the file UserAccountSchema.xsd, and click the Add button.

4.Drag a DataTable object from the toolbox to the UserAccountSchema.xsd file.

5.Change the name of the DataTable object to UserAccountSchema.

6.Right click on the UserAccountSchema object and select AddàColumn from the pop-up menu.

7.Change the name of the column to UserAccountId and change the DataType to System.Int32. To change the DataType you can go to the property window and set it there.

8.Add the FirstName, LastName, and EmailAddress columns the same way but leave the DataType as System.String.



Step 5: Create the Crystal Report

You can now create the report using the XSD file.

1.Right click on the project and select AddàNew Item…

2.Select "Reporting" from the list of Visual C#‎ templates and select the Crystal Reports template.

3.Change the name of the file to UserAccountReport.rpt and click the Add button.

4.The Crystal Reports Gallery dialog will appear. Select "As a Blank Report" and click the OK button.

5.In the Field Explorer window, right click on the Database Fields node and select "Database Expert…" from the pop-up menu.

6.The Database Expert dialog should appear.

7.Click the plus sign next to "Create New Connection"

8.Click the plus sign next to "ADO.NET (XML)"

9.The ADO.NET (XML) dialog should appear. Click on the button with three dots to browse to the UserAccountSchema.xsd file you created in the step above.

10.Click the Finish button.

11.You should see the UserAccountSchema under the ADO.NET (XML) node. Click on this node and then click the ">" button to move this to the Selected Tables list.

12.Click the OK button.

13.In the Field Explorer window you should see the UserAccountSchema under the Databases Fields node. Click the plus sign next to the table name and the fields should appear.

14.Drag each field to the Details section of the report.

15.Click the save button.



Step 6: Create the ASP.NET Web Page to Display the Report

The last step is to create the ASP.NET Web Page that will display the report in the Crystal Reports Viewer control and bind a query using the Entity Framework to the report.

1.Right click on your project file in the Solution Explorer and select AddàNew Item from the pop-up menu.

2.Click on the "Web" node under Visual C#‎ templates and then select the "Web Form" template.

3.Change the name of the form to Default.aspx and click the Add button.

4.Drag a Crystal Report Viewer control from the toolbox to the form.

5.Double click on the form in design mode to create the Form_Load event handler.

6.Add the following lines to the using statements.

using CrystalDecisions.CrystalReports.Engine;


using CrystalDecisions.Shared

;


7.Add the following lines to the Form_Load event handler.


ReportDocument report =new ReportDocument();


report.Load(Server.MapPath("UserAccountReport.rpt"));

using (CRTestEntities db =new CRTestEntities())

{

report.SetDataSource(from u in db.UserAccounts

select new { u.UserAccountId, u.FirstName, u.LastName,

u.EmailAddress });



}

CrystalReportViewer1.ReportSource = report;





8.Right click on the Default.aspx file and select "Set As Start Page" from the pop-up menu.

9.Run the project and you should see your report.

firoozi90
سه شنبه 14 شهریور 1391, 12:11 عصر
لطفا نظراتونو در مورد این مقاله بگید.
و اینکه مباحث تکمیلی تر در این مورد بیان کنید تا دوستان استفاد کنند.
و اگر سوالی در این مورد داشتید در این تایپیک مطرح کنید

mhsmity
سه شنبه 14 شهریور 1391, 12:20 عصر
سلام
اینجا که بخش C# هستش ؟

firoozi90
سه شنبه 14 شهریور 1391, 14:28 عصر
توی بخش سی شارپ بیشتر سوال هایی که مطرح میشه در مورد ADO.NET هستش.حالا یه پست هم ما در مورد entity FrmeworK زدیم.به جایی که بر نمی خوره.
در ضمن ef با سی شارپ هم کار میشه.پس بی ربط هم نیستش

firoozi90
جمعه 17 شهریور 1391, 12:09 عصر
دوستان نظري ندارند؟
واسم عجيبه كه چرا هيچ كس به EF علاقه اي نداره.اگر مشكلي داره و بدرد نخوره كه ماهم قيدشو بزنيم.يا اينكه دوستان نمي خوان انعطاف به خرج بدن؟

homan1374
جمعه 17 شهریور 1391, 14:53 عصر
خیلی ممنون...
علاقه مندان به ef کم نیستند..

firoozi90
شنبه 18 شهریور 1391, 09:49 صبح
خیلی ممنون...
علاقه مندان به ef کم نیستند..
ما كه حدود 9 ماه هست توي اين سايت فعاليت داريم علاقمند چنداني نديديم.

samadblaj
شنبه 18 شهریور 1391, 10:20 صبح
سلام اتفاقا طرفدار زیاد داره یکیش که خودمم .
خوب بود ترجمه اش میکردید بعد درخواست نظر میدادید همینطور توی تاپیک دیگه تشکر این پست رو زدم.
موفق باشید

uniqueboy_ara
شنبه 18 شهریور 1391, 10:54 صبح
منم با firoozi90 موافقم!
اکثر دوستان شایدم خیلی درباره EF شنیده باشن، ولی هیچ کدوم تن به این کوچ کردن نمیدن!!!
در صورتی که استفاده ازADO.net کلاسیک نسبت به EF، مثل استفاده از Dos به جای Windows می مونه

abcd_a
شنبه 18 شهریور 1391, 11:04 صبح
سلام
ضمن تشکر
تو زمینه EF منابع فارسی کمه به خاطر همینه که خیلی ها با اون آشنای ندارند ، و همچنین تو دانشگاه هم معمولا ADO تدریس میشه و خیلی ها هم به خودشون زحمت یادگیری تکنولوژی جدید را نمی دن!.

اگه منابع یا آموزشی دارید خوشحال میشم که معرفی کنید.

uniqueboy_ara
شنبه 18 شهریور 1391, 11:17 صبح
مشکلی که اکقر ماها داریم اینهکه تمیتونیم ریسک کوچ کردن به یه تکنولوژی جدید تر رو قبول کنیم!
خو منم 9 ماه پیش که کتاب Pro.Entity Framework 4.0 از انتشارات Apress رو شروع کردم بخونم، هیچوقت فکر نمیکردم که یه روزی بی خیال ADO بشم، ولی کتابو هنوز به نصف هم نرسونده بودم که دیدم یه عمری خودمو با ADO سر کار گذاشته بودم :) ، با این روش تمام کار های زمان بر و خسته کننده ADO از جلوی پای آدم برداشته میشه و کلی کار برنامه نویس راحت تر میشه :)

واسه شروع کار میتونید از این استفاده کنید: پروژه ساخت دفترچه تلفن با استفاده از EF و LINQ (http://barnamenevis.org/showthread.php?347385-%D9%BE%D8%B1%D9%88%DA%98%D9%87-%D8%B3%D8%A7%D8%AE%D8%AA-%D8%AF%D9%81%D8%AA%D8%B1%DA%86%D9%87-%D8%AA%D9%84%D9%81%D9%86-%D8%A8%D8%A7-%D8%A7%D8%B3%D8%AA%D9%81%D8%A7%D8%AF%D9%87-%D8%A7%D8%B2-EF-%D9%88-LINQ)

samadblaj
شنبه 18 شهریور 1391, 11:24 صبح
واسه شروع کار میتونید از این استفاده کنید: پروژه ساخت دفترچه تلفن با استفاده از EF و LINQ

به نظر من منبع فقط همین تاپیک هستش من غیر از این پست حرفه ای برای این اموش ندیدم...
به اعتقاد منم منبع این اموزش بیش از حد کمه!
و از دوستان اگه کسی Pro.Entity Framework به پستشون خورد معرفی کنند ، این کتاب هم که خیلی خلاصه رد شده.
فرضا مثالهای join اینا خیلی کمه...که این اصل خودش به مانور های گسترده و متنوعی داره.
در هر صورت این نوع برنامه نویسی عالیه بهینه بودن، سرعت ، سادگی.
موفق باشید

uniqueboy_ara
شنبه 18 شهریور 1391, 11:48 صبح
اولین پست تو این زمینه رو جناب gwbasic زدن ( کارگاه عملی : ساخت پروژه ثبت سفارشات مرحله به مرحله ) که نکته های خیلی خوبی میشه ازش یاد گرفت :)
اون کتاب به نظر من خیلی عالیه، چون با یه زبان بسیار ساده همه چیو توضیح میده و باعث گیج شدن آدمای تازه کار نمیشه، بعد که اصول رو یاد گرفتی دیگه بقیه ش میشه تحقیق و جستجوی خود برنامه نویس، تا ریزه کاری ها رو هم یاد بگیریم :)
.
.
اینم یه منبع خوب واسه دستورات LINQ از جمله Join :چشمک:

samadblaj
شنبه 18 شهریور 1391, 12:06 عصر
دوست عزیز uniqueboy_ara ممنونم از لطفت افتادید تو زحمت روال کار به همین شکل با اساس و ریتم کار آشنا بشیم ادامه اش میشه تغییر و ابتکار برنامه نویس.
این مثال ها از جمله مثالهای microsoft نیست؟ Linq to sql ؟
من نظر توی دنیای رایانه (از جمله برنامه نویسی) چیزی به نام کمبود منبع معنی نداره. محدود به دلیل نویی بودن برنامه هست.
موفق باشید./

uniqueboy_ara
شنبه 18 شهریور 1391, 12:15 عصر
اینا دقیقا مثال های خود Microsoft هستن که من همشونو توی این فایل جمع آوری کردم :)

firoozi90
شنبه 18 شهریور 1391, 12:34 عصر
سلام اتفاقا طرفدار زیاد داره یکیش که خودمم .
خوب بود ترجمه اش میکردید بعد درخواست نظر میدادید همینطور توی تاپیک دیگه تشکر این پست رو زدم.
موفق باشید

به نظر من نيازي به ترجمه نداره .خيلي روان گفته شده .چون قدم به قدم هستش.اگر دوستان يه كم حوصله به خرج بدن و دوخط اولو بخونن ميفهمن كه من چي مي گم

firoozi90
شنبه 18 شهریور 1391, 12:39 عصر
دوستان علاقمند مي تونند از اين تايپيك هايي كه من قبا گذاشتم براي شروع استفاده كنند
دانلود کتاب های آموزشی LINQ (http://barnamenevis.org/showthread.php?330200-%D8%AF%D8%A7%D9%86%D9%84%D9%88%D8%AF-%DA%A9%D8%AA%D8%A7%D8%A8-%D9%87%D8%A7%DB%8C-%D8%A2%D9%85%D9%88%D8%B2%D8%B4%DB%8C-LINQ)

کد فرم login با entity framework (http://barnamenevis.org/showthread.php?329527-%DA%A9%D8%AF-%D9%81%D8%B1%D9%85-login-%D8%A8%D8%A7-entity-framework)

آموزش ویرایش اطلاعات با Entity framework (http://barnamenevis.org/showthread.php?329518-%D8%A2%D9%85%D9%88%D8%B2%D8%B4-%D9%88%DB%8C%D8%B1%D8%A7%DB%8C%D8%B4-%D8%A7%D8%B7%D9%84%D8%A7%D8%B9%D8%A7%D8%AA-%D8%A8%D8%A7-Entity-framework)

آموزش قدم به قدم اعمال اصلی با entity framework (http://barnamenevis.org/showthread.php?328861-%D8%A2%D9%85%D9%88%D8%B2%D8%B4-%D9%82%D8%AF%D9%85-%D8%A8%D9%87-%D9%82%D8%AF%D9%85-%D8%A7%D8%B9%D9%85%D8%A7%D9%84-%D8%A7%D8%B5%D9%84%DB%8C-%D8%A8%D8%A7-entity-framework)

firoozi90
چهارشنبه 29 شهریور 1391, 13:21 عصر
دوستان گرامي
اگر كسي مبحث تكميلي تر رو داره يا اينكه سايتي رو ميشناسه كه در مورد EF هستش لطفا اينجا بزاره كه علاقمندان استفاده كنند

khista
جمعه 21 تیر 1392, 16:30 عصر
عالی عزیز،ممنونم ازت خیلی تو وب گشتم تا این پست مفید شما رو پیدا کردم