大连融科 WMS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

254 lines
7.9 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data;
namespace SiaSun.LMS.WPFClient.Dialog
{
/// <summary>
/// ImportWindow.xaml 的交互逻辑
/// </summary>
public partial class ImportGoodsDialog : Window
{
ImportType emImportType = ImportType.Excel;
bool _IsCommit = true; //是否提交保存
string _tableConverterCode = null;
DataSet dsImport = null;
/// <summary>
/// 导入文件类型
/// </summary>
public ImportType U_ImportType
{
set { emImportType = value; }
}
/// <summary>
/// 导入的数据集集合
/// </summary>
public DataSet U_ImportDataSet
{
get { return dsImport; }
set { dsImport = value; }
}
#region ------构造函数
/// <summary>
/// 构造函数
/// </summary>
public ImportGoodsDialog(bool IsCommit)
{
InitializeComponent();
this._IsCommit = IsCommit;
}
/// <summary>
/// 构造函数
/// </summary>
public ImportGoodsDialog(bool IsCommit, string TableConverterCode)
: this(IsCommit)
{
this._tableConverterCode = TableConverterCode;
this.cmbTemplateName.IsEnabled = false;
}
#endregion
/// <summary>
/// 加载窗体
/// </summary>
private void Window_Loaded(object sender, RoutedEventArgs e)
{
//加载所有模板
this.LoadTemplate();
}
/// <summary>
/// 加载所有模板
/// </summary>
private void LoadTemplate()
{
try
{
this.cmbTemplateName.DisplayMemberPath = "TABLE_CONVERTER_NAME";
this.cmbTemplateName.SelectedValuePath = "TABLE_CONVERTER_CODE";
this.cmbTemplateName.ItemsSource = MainApp._I_SystemService.TABLE_CONVERTER_GetList();
//设置默认值
if (!string.IsNullOrEmpty(this._tableConverterCode))
{
this.cmbTemplateName.SelectedValue = this._tableConverterCode;
}
}
catch (Exception ex)
{
MainApp._MessageDialog.ShowException(ex);
}
}
/// <summary>
/// 按钮事件
/// </summary>
private void WrapPanel_Click(object sender, RoutedEventArgs e)
{
Button btn = e.OriginalSource as Button;
if (btn != null)
{
switch (btn.Name)
{
case "btnOpen":
this.OpenFile();
break;
case "btnImport":
this.ImportFile();
break;
case "btnClose":
this.Close();
break;
}
}
}
/// <summary>
/// 选择导入文件
/// </summary>
private void OpenFile()
{
System.Windows.Forms.OpenFileDialog opDig = new System.Windows.Forms.OpenFileDialog();
//判断导入文件类型
switch (emImportType)
{
case ImportType.Excel:
break;
case ImportType.Xml:
this.ImportXml();
break;
}
if (opDig.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.txtFileName.Text = opDig.FileName;
}
}
/// <summary>
/// 导入文件
/// </summary>
private void ImportFile()
{
if (string.IsNullOrEmpty(this.txtFileName.Text) || this.cmbTemplateName.SelectedValue == null)
{
MainApp._MessageDialog.ShowDialog(string.Format("检查空值{0}", string.Format("[{0}/{1}]", this.lblTemplateName.Text, this.lblFileName.Text)));
return;
}
//判断导入文件类型
switch (emImportType)
{
case ImportType.Excel:
this.ImportExcel();
break;
case ImportType.Xml:
this.ImportXml();
break;
}
}
/// <summary>
/// 导入EXCEL文件
/// </summary>
private void ImportExcel()
{
try
{
//获得Excel数据源
using (DataTable tableExcel = new SiaSun.LMS.Common.Excel().ImportToDataTable(this.txtFileName.Text, true))
{
if (tableExcel.Rows.Count > 0)
{
tableExcel.TableName = "ExcelImport";
//获得转换信息实例
Model.SYS_TABLE_CONVERTER mTABLE_CONVERTER = this.cmbTemplateName.SelectedItem as Model.SYS_TABLE_CONVERTER;
if (mTABLE_CONVERTER != null)
{
//向父级表和子级表中导入数据
string strResult = string.Empty;
this.dsImport = MainApp._I_SystemService.SYS_TABLE_CONVERTER_Import(this.cmbTemplateName.SelectedValue.ToString(), tableExcel, out strResult);
//是否提交导入数据
if (string.IsNullOrEmpty(strResult))
{
if (this._IsCommit)
{
int intAffect = MainApp._I_SystemService.TABLE_CONVERTER_Save(mTABLE_CONVERTER, dsImport, out strResult);
if (intAffect == 0)
{
MainApp._MessageDialog.ShowDialog("操作影响行数为0");
}
else
{
MainApp._MessageDialog.Show(true,"成功");
}
return;
}
}
else
{
MainApp._MessageDialog.Show(false, strResult);
}
this.DialogResult = true;
return;
}
}
}
}
catch (Exception ex)
{
MainApp._MessageDialog.ShowException(ex);
}
}
/// <summary>
/// 导入XML文件
/// </summary>
private void ImportXml()
{
if (this.dsImport != null)
{
this.dsImport.ReadXml(this.txtFileName.Text);
//判断是否提交保存
if (this._IsCommit)
{
int intAffect = MainApp._I_BaseService.Save(dsImport.Tables[0], dsImport.Tables[0].TableName);
if (intAffect == 0)
{
MainApp._MessageDialog.ShowDialog("操作影响行数为0");
}
else
{
MainApp._MessageDialog.Show(true,"成功");
}
return;
}
this.DialogResult = true;
return;
}
}
}
}