Pages

Tuesday, June 29, 2010

Generate RDLC dynamically - Table

Generate RDLC dynamically - Table

Generate RDLC at run-time based on user-specified options. Download C# version or VB versionVB translation contributed by Willem van den Broek.


Report viewer Print without preview

เวลาที่ทำโปรแกรมสักอย่างจะต้องมีรายงานอาจจะมากหรือน้อยก็แล้วแต่ว่า user ต้องการ ปกติผมจะใช้ Report viewer ในการสร้างรายงาน เช่น ใบสั่งซื้อ ใบรายการสินค้าต่าง ๆ

ปกติถ้าเราใช้ Report viewer จะต้องลาง control มาว่างใน form แต่ทีนี้ผมต้องการแบบไม่ใช้ control วางใน form ให้สามารถกดปุ่มพิมพ์แล้วพิมพ์ได้เลยโดยไม่ต้องแสดง report viewer ก็

สำหรับวิธีการทำ

Tools ที่ผมใช้
  1. Visual Studio 2008
  2. MS SqlServer 2008
  3. Report viewer 2008 (ตัวนี้จะต้องตาม vs ที่เราใช้นะครับ)
  4. คอม - -" (ไม่ใช้คอมจะทำไงวะเนี่ย)
มาเริ่มกันเลย

  1. สร้าง Form ขึ้นมาสักอัน
  2. สร้าง dataset
  3. สร้าง Report.rdlc พร้อมทั้ง fomat ของข้อมูลที่ต้องการแสดง
  4. หลังจากที่เราได้ครบแล้วก็มาเขียน code กันเลย

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

ReportViewer ReportViewer1 = new ReportViewer();
byte[] bytes = null;
private void button1_Click(object sender, EventArgs e)
{
//this.dataSet11.Customers.WriteXml("data1.xml");
Run();
}

private void Form1_Load(object sender, EventArgs e)
{
customersTableAdapter1.Fill(this.dataSet1.Customers);
this.dataSet1.Customers.WriteXml("data1.xml");
}

private int m_currentPageIndex;

private IList m_streams;

private DataTable LoadSalesData()
{
DataSet dataSet = new DataSet();
dataSet.ReadXml("data1.xml");
return dataSet.Tables[0];
}

private Stream CreateStream(string name, string fileNameExtension, Encoding encoding,
string mimeType, bool willSeek)
{
Stream stream = new FileStream(name + "." + fileNameExtension, FileMode.Create);
m_streams.Add(stream);
return stream;
}

private void Export(LocalReport report)
{
string deviceInfo =
"" +
" EMF" +
" 8.5in" +
" 11in" +
" 0.25in" +
" 0.25in" +
" 0.25in" +
" 0.25in" +
"";
Warning[] warnings;
m_streams = new List();
//report.Render("Image", deviceInfo, CreateStream, out warnings);
//Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string extension;

bytes = ReportViewer1.LocalReport.Render(
"PDF", null, out mimeType, out encoding,
out extension,
out streamids, out warnings);

FileStream fs = new FileStream(@"D:\output.PDF",
FileMode.Create);
fs.Write(bytes, 0, bytes.Length);
fs.Close();


foreach (Stream stream in m_streams)
stream.Position = 0;
}

private void PrintPage(object sender, PrintPageEventArgs ev)
{
Metafile pageImage = new Metafile(m_streams[m_currentPageIndex]);
ev.Graphics.DrawImage(pageImage, ev.PageBounds);
m_currentPageIndex++;
ev.HasMorePages = (m_currentPageIndex <>
}

private void Print()
{
const string printerName = "Microsoft Office Document Image Writer";

if (m_streams == null || m_streams.Count == 0)
return;

PrintDocument printDoc = new PrintDocument();
System.Windows.Forms.PrintDialog printDialog = new System.Windows.Forms.PrintDialog();
printDialog.Document = printDoc;
if (printDialog.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
return;

printDoc.PrinterSettings.PrinterName = printDialog.PrinterSettings.PrinterName;
if (!printDoc.PrinterSettings.IsValid)
{
string msg = String.Format("Can't find printer \"{0}\".", printerName);
Console.WriteLine(msg);
return;
}
printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
printDoc.Print();
}

public void Run()
{
//LocalReport report = new LocalReport();
//report.ReportPath = "Report.rdlc";
//report.DataSources.Add(new ReportDataSource("Sales", LoadSalesData()));
//report.DataSources.Add(new ReportDataSource("Sales", LoadSalesData()));
//ReportViewer oViewer = new ReportViewer();

//this.customersTableAdapter1.Fill(this.dataSet1.Customers);
this.ReportViewer1.ProcessingMode = ProcessingMode.Local;
this.ReportViewer1.LocalReport.ReportPath =
@"Report.rdlc";
ReportViewer1.LocalReport.DataSources.Add(
new ReportDataSource("Customers", LoadSalesData()));

string deviceInfo =
"" +
" EMF" +
" 8.5in" +
" 11in" +
" 0.25in" +
" 0.25in" +
" 0.25in" +
" 0.25in" +
"";
Warning[] warnings;
//m_streams = new List();
//report.Render("Image", deviceInfo, CreateStream, out warnings);

//Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string extension;

bytes = ReportViewer1.LocalReport.Render(
"PDF", null, out mimeType, out encoding,
out extension,
out streamids, out warnings);

FileStream fs = new FileStream(@"D:\output.PDF",
FileMode.Create);
fs.Write(bytes, 0, bytes.Length);
fs.Close();


foreach (Stream stream in m_streams)
stream.Position = 0;

//Export(report);

m_currentPageIndex = 0;
Print();
}

public void Dispose()
{
if (m_streams != null)
{
foreach (Stream stream in m_streams)
stream.Close();
m_streams = null;
}
}
}

Resource : http://www.gotreportviewer.com/

Download

Monday, June 28, 2010

The CurrentContext property of the LicenseManager is currently locked and cannot be chaged

หลังจากที่ผม install add-on ของ vs2010 พอกลับมาเปิด solution ของ vs2008 กลับเจอ error แบบนี้ครับ
ปัญหาคือ ว่า add-on ที่ผมลงมันเป็นของ vs2010 มันไม่ support vs2008


วิธีแก้คือต้อง reset ค่าเดิมที่เคย setting ไว้แล้ว
ไปที่ Tools->Import and Export setting จากนั้นเลือกเป็น Reset all setting
ปัญหานี้ก็หมดไป

Print report without display c#

วันนี้พยายามที่จะสร้างใบส่งของ โดยที่เวลากดปุ่มแล้วให้มันพิมพ์รายการที่ต้องการส่ง

ปกติที่ผมเคยทำจะใช้ Reportviewer หรือไม่ก็ CrytalReport แต่ว่ามันจะต้องแสดงใน form ก็แล้วค่อยกดปริ้นทีหลัง

อีกวิธีคือ ใช้ Graphic.drawString เอาเลยแบบง่าย ๆ

แต่น่าจะมีวิธีที่ง่ายกว่านี้ก็คงต้องใช้ reportviewer ในการพิมพ์เลยแต่ไม่ต้องการให้มันแสดงใน form เนี่ยสิทำยังไงดี ก็เลยของหาใน google ไปเจอ tutorial ของ microsoftที่ http://msdn.microsoft.com/en-us/library/ms252091(VS.80).aspx แต่ก็ยังงงอยู่ดี เพราะตัว Report ที่ผมใช้เป็น version 2008 พอ build มันจะฟ้อง error

Error 2 The report definition is not valid. Details: The element 'ReportItems' in namespace 'http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition' has invalid child element 'Tablix' in namespace 'http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition'. List of possible elements expected: 'http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition:Line http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition:Rectangle http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition:Textbox http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition:Image http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition:Subreport http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition:List http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition:Matrix http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition:Table http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition:Chart http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition:CustomReportItem ##other:*'. C:\Users\wirat\Documents\Visual Studio 2008\Projects\Inventory\Inventory\Report1.rdlc Inventory

ซะเยอะเลย


Monday, June 21, 2010

Unable to create a manifest resource name

Error 1 Unable to create a manifest resource name for "frmCheckOut.resx". Could not find file 'C:\Users\wirat\Documents\Visual Studio 2008\Projects\Inventory\Inventory\frmCheckOut.cs'. Inventory


เจอแบบนี้ไปไม่เป็นเลย อุตสาห์นั่งเขียนทั้งวันหายหมด ไม่รู้จะทำยังไงดี ลองเอา error ไปหาใน google ดูก็ไม่มีวิธีแก้ไข เพราะมันเป็น bug ของ vs 2008 ตายห่าเลยตู นั่งเขียนทั้งวัน

แต่ยังดีสามารถ recovery design page กลับคืนมาได้ แต่ code ต่างหายหมด - -"

วิธีก็คือ
  1. สร้าง new form เป็น form1.cs หละกัน ก็จะได้หน้า form มาเปล่าว ๆ ยังไม่มีอะไร จะเห็นมันมีอยู่ 2 ไฟล์ คือ form1.cs กับ form1.Designer.cs
  2. ลาก button หรืออะไรก็ได้มาใส่แล้วก็ save ทีนี้จะสังเกตเห็นเพิ่มมาอีก 1 ไฟล์ คือ form1.resx
  3. close solution
  4. rename form1.cs -> xxx.cs เพราะไฟล์ที่มันหายไปคือ xxx.cs เราจะสร้างอันใหม่ขึ้นมาแทนแต่จะยังได้ designer กลับคือ (ก็ยังดีวะ)
  5. เปิด xxx.cs แล้วมันจะฟ้อง Error ช่างหัวมันให้ ignore มันเลยแล้วก็จะได้หน้า designer กลับมา

Thursday, June 10, 2010

ลองหา BPEL Tools กัน

พอดีช่วงนี้กำลังรื้อฟื้นและศึกษาเพิ่มเติมเกี่ยวกับ BPEL-WS ก็เลยลองหา tools ว่ามีตัวไหนบ้างแต่ละตัวมันมีดีมีเสียต่างกันยังไง แต่วันนี้จะลองหาดูว่ามี BPEL Tools ทั้งที่เป็น Opensource และ Commercial อยู่เยอะไหม


เท่าที่หาดูก็จะมีอยู่ไม่กี่ตัวเองครับ
- Active bpel

Monday, June 7, 2010

Create and Insert value to file using command

First open command prompt on window and then relocate to directory that you want to create example c:\ and type

copy con serial.txt
[value insert to file]


final press ctrl+z to save file

Sunday, June 6, 2010

Appserv Virtual host on Window

พอลง window ใหม่เสร็จกับเวลาสองวันในการนั่ง update window ก็ยังไม่เสร็จไหนจะติดตั้ง vs2008, vs2010, ms sqlserver และ accessories ต่าง ๆ อีกตั้งมากมาย และก็มาถึง Appserv และต้องทำ virtual host ด้วยเพื่อง่ายต่อการทำ

โดยปกติ เวลาเราใช้งาน localhost บนเครื่องเราจะใช้ http://localhost (127.0.0.1) ตามด้วย path ของ web นั้น ๆ ที่เราพัฒนาขึ้น แต่สำหรับการทำ virtual host จะเป็นการตั้งค่า apache และ dns (window)อย่างเช่นผมต้องการใช้ http://www.myserver.dev อย่างนี้เป็นต้นครับ

แล้วทีนี้ก็มาถึงขั้นตอนการทำ virtual host บน window ก่อนอื่นต้องติดตั้ง Appserv ให้เสร็จก่อนนะครับ

เราจะแก้ไขทั้งหมด 3 ไฟล์ คือ
- httpd.conf
- httpd-vhosts.conf
- hosts


แก้ไข httpd.conf
1. หลังจากที่ติดตั้งเสร็จแล้วลองเข้า http://localhost ดูถ้าเข้าได้แสดงว่า ok ไปขั้นตอนต่อไปเลย
2. ไปที่ไฟล์ C:\AppServ\Apache2.2\conf\httpd.conf (อาจไม่จำเป็นต้องอยู่ที่ C:\ ก็ได้นะครับ) และเปิดมันด้วย text editor
3. Ctrl+F เราจะค้นหา

#Include conf/extra/httpd-vhosts.conf

และทำการ enable มันด้วยเอา # ออกจะได้เป็น

Include conf/extra/httpd-vhosts.conf

และทำการ
4. ค้นหา
#LoadModule vhost_alias_module module/mod_vhost_alias.so

และ enable เช่นกันกับขั้นตอนที่ 4.5. บันทึกและปิด httpd.conof

แก้ไข httpd-vhosts.conf
1. เปิดไฟล์ C:\AppServ\Apache2.2\conf\extra\httpd-vhosts.conf
2. เพิ่มเข้าไปดังนี้

NameVirtualHost 127.0.0.1

<VirtualHost 127.0.0.1>
DocumentRoot "C:\AppServ\www"
ServerName localhost
</VirtualHotst>

<VirtualHost 127.0.0.1>
DocumentRoot "C:\AppServ\www\Site1"
ServerName site1.com
</VirtualHotst>

3. บันทึก


แก้ไขไฟล์ hosts ที่ C:\WINDOWS\System32\drivers\etc

โดยเพิ่ม


127.0.0.1    site1.com

Friday, June 4, 2010

ผักหวานบ้าน

Install new window

หลังจากเซงกับความช้ามานานมากพอ และช่วงนี้งานก็เริ่มจะเรียบร้อย ก็ได้เวลาปรับแต่งเครื่องเสียใหม่ซะดี
ก็เลยทำ System recovery laptop ซะเลย เวลาในการ recovery ก็ไม่นาน ประมาณ 40 นาทีก็เสร็จแล้วครับ แต่ว่าต้องมานั่ง update window เนี่ยสิ นานโคตร ๆ ไม่รู้สองวันจะเสร็จหรือเปล่าว คือ สองวันนี้หมายถึงการลงโปรแกรมต่าง ๆ นา ๆ ด้วยนะครับ คิดแล้วเหนื่อยเลย - -" แต่ทำไงได้เพื่อความคล่องตัว

Thursday, June 3, 2010

วิธีทำแก๊สชีวภาพ






การผสมพันธุ์เทียมปลาดุก

หลังจากที่เหนื่อยกับการทำงานเป็น programmer มาทั้งวันแล้ว ตอนดึก ๆ เลยปลีกตัวหาเวลาว่างศึกษาเกษตรพอเพียง เหตุที่ผมสนใจก็เพราะคำว่าพอเพียง ซึ่งทุกวันนี้ ก็ยังไม่แน่ใจเหมือนกันว่า ชีวิตที่เป็นอยู่ (programmer) จะพอเพียงหรือยัง

แต่เดิมผมก็เป็นเด็กบ้านนอก ที่พ่อกับแม่มีอาชีพทำนา ปีหนึ่งทำได้ครั้งเดียวใช้เวลาในการทำไม่กี่วัน เพราะมีเครื่องจักรช่วยตั้งแต่ไถ ยันขนใส่รถไปขาย ฮ่า ๆ ฟังดูแล้วการทำงานทำจริง ๆ กันไม่กี่วันเอง แล้วเวลาที่เหลือหละเอาไปทำอะไรหมด ผมก็เลยพยายามคิดหาวิธีเพิ่มรายได้ให้กับทางบ้าน และเผื่อในอนาคตผมอาจจะได้กลับไปอยู่บ้านนอก

อยู่บ้านนอก ถึงจะไม่มีรายได้ ก็สามารถอยู่ได้ ข้าวก็ปลูกเองไม่ต้องซื้อเหมือนอย่างในเมือง กับข้าวก็มีเยอะแยะ แค่เดินออกจากบ้านก็ได้แล้ว ไม่ว่าจะเป็นผักตำลึง ผักโขม ผักกะเฉด บอกได้ว่ามีแทบทุกผักเลย เดินออกไปทุ่งพร้อมกับเสียม กลับมาก็ได้ปู มาทอด หรือไม่ก็ทำแกงปูนา (อร่อยอย่าบอกใคร) หรือไม่ก็ทอดแหลงสระก็ได้ปลามากินแล้ว เห็นไหมครับว่า แทบจะไม่ได้ซื้ออะไรเลย อีกอย่าง สะอาดและปลอยภัยจากสารพิษด้วย

จะเริ่มอย่างไรดี ช่วงแรก ๆ ผมเริ่มศึกษาหาข้อมูล เช่น การเลี้ยงปลา (ปลาดุก ปลานิล) การปลูกผลไม้ ก็เช่น มะนาว เพราะว่ามะนาวแทบจะปลูกได้กับสภาพอากาศทุกพื้นที่ของเมืองไทยเลยทีเดียวครับ ผมก็ลองค้นหาในพี่ google ดูเกี่ยวกับการปลูกมะนาวก็ไปเจอ มะนาวพันธ์พิจิตร 1 ที่ได้ปรับปรุงและพัฒนาให้ทนต่อโรงแครงเกอร์ได้ดี กว่ามะนาวพันธ์พื้นเมืองทั่วไป เอ่...... แต่มะนาวราคามันก็ไม่ได้แพงอะไรน๊ะ นอกจากว่าจะสามารถบังคับใหัมันออกนอกฤดูได้ ผมก็ลองคนหาวิธีการทำมะนาวนอกฤดูอีกครับ ก็ไปเจอ การปลูกมะนาวท่อ อ่านข้อมูลดูแล้วน่าสนใจทีเดียว คือ เขาจะเอาท่าซีเมนต์เส้นผ่าศูนย์กลางประมาร 80 cm สูงประมาณ 60 cm มาวางแนวตั้งแล้วรองพื้นด้วยฝา จากนั้นก็เอาดินกับปุ๋ยคอกผมสมกันใส่ลงไป แล้วเอามะนาวมาปลูก เหอะๆ คิดได้ไง ที่ทำแบบนี้ก็เพื่อจะบังคับปริมาณน้ำ เพื่อให้มะนาวออกนอกฤดูกาลได้นั่นเองครับ สุดยอดไหมหละ

นอกจากจะหาวิธีการปลูกมะนาวแล้วผมก็ยังหาวิธีการเพาะพันธุ์เทียมปลาดุกเพิ่มอีกด้วย ลองหาใน youtube.com ดูบอกได้คำเดียว หายากมากแทบไม่มีเลยแต่ก็ไปเจออยู่ link หนึ่งที่ดีมากทีเดียว ได้เห็นภาพด้วย เพราะถ้าอ่านจากหนังสือไม่ค่อยได้เห็นภาพเท่าที่ควร

ตามไปดูกันเลยครับ


สงสัยผมจะต้องลองหาซื้อปลาตามท้องตลาดมาลองทำดูบ้างหละ ดู ๆ แล้วทำไม่ยากเลย

Wednesday, June 2, 2010

How to attachments file in web service

นั่นสิครับ เจอคำถามนี้เข้าไปผมก็เลยงง เลยครับ ปกติการส่ง data between more than 2 services like message (Soap message) แต่ถ้าผมต้องการจะแนบไฟล์ไปกับ response message หละ ทำยังไงดี - -"

เดี่ยวบ่ายนี้มีคำตอบ

Web Service Standards Listings

พอมีเวลาว่างสักหน่อยก็เป็นว่าต้องหาอะไร มาอ่านอยู่เรื่องเลย จริง ๆ เรื่องที่อ่านเนี่ย ก็พอมีความรู้อยู่บ้างนิดหน่อยแต่ก็กลัวว่าจะลืม เลยมารื้อฟื้นความรู้ซะหน่อยเกี่ยวกับ webservice เกี่ยวกับเรื่อง Web Service Standards และก็ไปเจอใน wiki บอกได้คำเดียวว่าเยอะมาก ๆ สงสัยอ่านจนตาลายแน่ ๆ ^^

Web Service Standards Listings

These sites contain documents and links about the different Web Services standards identified on this page.


XML Specification


Messaging Specification


Metadata Exchange Specification


Security Specification


Privacy


Reliable Messaging Specifications


Resource Specifications


Web Services Interoperability (WS-I) Specification

These specifications provide additional information to improve interoperability between vendor implementations.


Business Process Specifications


Transaction Specifications


Management Specifications


Presentation Oriented Specification


Draft Specifications

  • WS-Provisioning Describes the APIs and Schemas necessary to facilitate interoperability between provisioning systems in a consistent manner using Web services


Other