using System;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.Windows.Forms;
using DevExpress.Utils.Menu;
using DevExpress.XtraEditors;
using DevExpress.XtraMap;
using DevExpress.XtraPrinting;
namespace TestProject
{
/// <summary>
/// 메인 폼
/// </summary>
public partial class MainForm : XtraForm
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 인쇄 버튼 텍스트 베이스
/// </summary>
private const string PRINT_BUTTON_TEXT_BASE = "Show ";
/// <summary>
/// 내보내기 버튼 텍스트 베이스
/// </summary>
private const string EXPORT_BUTTON_TEXT_BASE = "Export to ";
/// <summary>
/// 파일 경로 베이스
/// </summary>
private const string FILE_PATH_BASE = "Exported Map";
/// <summary>
/// 인쇄 딕셔너리
/// </summary>
private Dictionary<DXMenuItem, PrintType> printDictionary = new Dictionary<DXMenuItem, PrintType>();
/// <summary>
/// 인쇄 타입
/// </summary>
private PrintType printType = PrintType.Preview;
/// <summary>
/// 내보내기 딕셔너리
/// </summary>
private Dictionary<DXMenuItem, ExportFormat> exportDictionary = new Dictionary<DXMenuItem, ExportFormat>();
/// <summary>
/// 내보내기 포맷
/// </summary>
private ExportFormat exportFormat = ExportFormat.Image;
/// <summary>
/// 빙 맵 키
/// </summary>
private string bingKey = "INPUT YOUR BING KEY";
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary>
/// 생성자
/// </summary>
public MainForm()
{
InitializeComponent();
#region Size Mode 콤보 박스를 설정한다.
this.sizeModeComboBox.DataSource = Enum.GetValues(typeof(MapPrintSizeMode));
#endregion
#region 인쇄 DROP DOWN 버튼을 설정한다.
DXPopupMenu printPopupMenu = new DXPopupMenu();
DXMenuItem printMenuItem;
printMenuItem = new DXMenuItem("Print Preview", printMenuItem_Click);
this.printDictionary.Add(printMenuItem, PrintType.Preview);
printPopupMenu.Items.Add(printMenuItem);
printMenuItem = new DXMenuItem("Ribbon Print Preview", printMenuItem_Click);
this.printDictionary.Add(printMenuItem, PrintType.RibbonPreview);
printPopupMenu.Items.Add(printMenuItem);
printMenuItem = new DXMenuItem("Print Dialog", printMenuItem_Click);
this.printDictionary.Add(printMenuItem, PrintType.Dialog);
printPopupMenu.Items.Add(printMenuItem);
this.printDropDownButton.Text = PRINT_BUTTON_TEXT_BASE + printType.ToString();
this.printDropDownButton.DropDownControl = printPopupMenu;
#endregion
#region 내보내기 DROP DOWN 버튼을 설정한다.
DXPopupMenu exportPopupMenu = new DXPopupMenu();
DXMenuItem exportMenuItem;
exportMenuItem = new DXMenuItem(ExportFormat.Image.ToString(), exportMenuItem_Click);
this.exportDictionary.Add(exportMenuItem, ExportFormat.Image);
exportPopupMenu.Items.Add(exportMenuItem);
exportMenuItem = new DXMenuItem(ExportFormat.Mht.ToString(), exportMenuItem_Click);
this.exportDictionary.Add(exportMenuItem, ExportFormat.Mht);
exportPopupMenu.Items.Add(exportMenuItem);
exportMenuItem = new DXMenuItem(ExportFormat.Pdf.ToString(), exportMenuItem_Click);
this.exportDictionary.Add(exportMenuItem, ExportFormat.Pdf);
exportPopupMenu.Items.Add(exportMenuItem);
exportMenuItem = new DXMenuItem(ExportFormat.Xls.ToString(), exportMenuItem_Click);
this.exportDictionary.Add(exportMenuItem, ExportFormat.Xls);
exportPopupMenu.Items.Add(exportMenuItem);
exportMenuItem = new DXMenuItem(ExportFormat.Xlsx.ToString(), exportMenuItem_Click);
this.exportDictionary.Add(exportMenuItem, ExportFormat.Xlsx);
exportPopupMenu.Items.Add(exportMenuItem);
this.exportDropDownButton.Text = EXPORT_BUTTON_TEXT_BASE + exportFormat.ToString();
this.exportDropDownButton.DropDownControl = exportPopupMenu;
#endregion
#region 빙 맵 데이터 공급자를 설정한다.
this.bingMapDataProvider.BingKey = this.bingKey;
#endregion
#region 이벤트를 설정한다.
this.sizeModeComboBox.SelectedIndexChanged += sizeModeComboBox_SelectedIndexChanged;
this.printDropDownButton.Click += printDropDownButton_Click;
this.exportDropDownButton.Click += exportDropDownButton_Click;
#endregion
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
#region 크기 모드 콤보 박스 선택 인덱스 변경시 처리하기 - sizeModeComboBox_SelectedIndexChanged(sender, e)
/// <summary>
/// 크기 모드 콤보 박스 선택 인덱스 변경시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void sizeModeComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
MapPrintSizeMode sizeMode = (MapPrintSizeMode)this.sizeModeComboBox.SelectedValue;
this.mapControl.PrintOptions.SizeMode = sizeMode;
}
#endregion
#region 인쇄 DROP DOWN 버튼 클릭시 처리하기 - printDropDownButton_Click(sender, e)
/// <summary>
/// 인쇄 DROP DOWN 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void printDropDownButton_Click(object sender, EventArgs e)
{
switch(this.printType)
{
case PrintType.Preview :
this.mapControl.ShowPrintPreview();
break;
case PrintType.RibbonPreview :
this.mapControl.ShowRibbonPrintPreview();
break;
case PrintType.Dialog :
this.mapControl.ShowPrintDialog();
break;
}
}
#endregion
#region 내보내기 DROP DOWN 버튼 클릭시 처리하기 - exportDropDownButton_Click(sender, e)
/// <summary>
/// 내보내기 DROP DOWN 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void exportDropDownButton_Click(object sender, EventArgs e)
{
string filePath = FILE_PATH_BASE + this.exportFormat.ToString();
switch(exportFormat)
{
case ExportFormat.Image :
this.mapControl.ExportToImage(filePath, ImageFormat.Jpeg);
break;
case ExportFormat.Mht :
this.mapControl.ExportToMht(FILE_PATH_BASE);
break;
case ExportFormat.Pdf :
this.mapControl.ExportToPdf(FILE_PATH_BASE);
break;
case ExportFormat.Xls :
this.mapControl.ExportToXls(FILE_PATH_BASE);
break;
case ExportFormat.Xlsx :
this.mapControl.ExportToXlsx(FILE_PATH_BASE);
break;
default :
MessageBox.Show
(
"Export to a *" + this.exportFormat.ToString() + " file format is impossible.",
"Export to " + this.exportFormat.ToString()
);
return;
}
MessageBox.Show
(
"Export to a *" + this.exportFormat.ToString() + " file is done.",
"Export to " + this.exportFormat.ToString()
);
}
#endregion
#region 인쇄 메뉴 항목 클릭시 처리하기 - printMenuItem_Click(sender, e)
/// <summary>
/// 인쇄 메뉴 항목 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void printMenuItem_Click(object sender, EventArgs e)
{
DXMenuItem menuItem = sender as DXMenuItem;
this.printDropDownButton.Text = PRINT_BUTTON_TEXT_BASE + menuItem.Caption;
this.printType = (PrintType)this.printDictionary[menuItem];
}
#endregion
#region 내보내기 메뉴 항목 클릭시 처리하기 - exportMenuItem_Click(sender, e)
/// <summary>
/// 내보내기 메뉴 항목 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void exportMenuItem_Click(object sender, EventArgs e)
{
DXMenuItem menuItem = sender as DXMenuItem;
this.exportDropDownButton.Text = EXPORT_BUTTON_TEXT_BASE + menuItem.Caption;
exportFormat = (ExportFormat)this.exportDictionary[menuItem];
}
#endregion
}
}