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.GOODS
{
public partial class GOODS_EDIT : AvalonDock.DocumentContent
{
string fileName = string.Empty;
public GOODS_EDIT(int GOODS_TYPE_ID)
{
InitializeComponent();
this.tvwGoodsClass.U_ItemSelectedChanged += new UC.ucTreeView.U_ItemSelectedChangedHandler
((treeViewItem) =>
{
this.grpGoods.Header = string.Format(this.grpGoods.Tag.ToString(), treeViewItem.Header.ToString());
this.GOODS_Bind(Convert.ToInt32(treeViewItem.Tag));
}
);
this.ucQueryGoods.U_Query += new UC.ucQuickQuery.U_QueryEventHandler
((QueryWhere) =>
{
this.GOODS_Bind(QueryWhere);
}
);
}
private void DocumentContent_Loaded(object sender, RoutedEventArgs e)
{
this.InitQueryControl();
this.GoodsClass_Bind();
}
///
/// 初始化查询控件
///
private void InitQueryControl()
{
this.ucQueryGoods.U_WindowName = this.GetType().Name;
this.ucQueryGoods.U_XmlTableName = "GOODS_MAIN";
this.ucQueryGoods.U_InitControl();
}
///
/// 加载物料类别
///
private void GoodsClass_Bind()
{
this.tvwGoodsClass.U_Header = "物料类别";
this.tvwGoodsClass.U_AllowCheck = false;
this.tvwGoodsClass.U_LoadTreeViewItems("物料类别",0, "GOODS_CLASS", "GOODS_CLASS_NAME AS HEADER", "GOODS_CLASS_ID", "GOODS_CLASS_PARENT_ID", "0", "", "GOODS_CLASS_ORDER");
}
///
/// 加载物料信息
///
private void GOODS_Bind(int GOODS_CLASS_ID)
{
try
{
this.gridGoods.U_Clear();
this.gridGoods.U_WindowName = this.GetType().Name;
this.gridGoods.U_TableName = "GOODS_MAIN";
this.gridGoods.U_XmlTableName = "GOODS_MAIN";
this.gridGoods.U_Where = string.Format("GOODS_CLASS_ID={0}", GOODS_CLASS_ID);
this.gridGoods.U_AllowOperatData = true;
if (MainApp._USER.USER_ID != 0)
this.gridGoods.U_AllowDelete = System.Windows.Visibility.Collapsed;
this.gridGoods.U_AllowChecked = false;
this.gridGoods.U_AllowPage = true;
//设置默认值
if (GOODS_CLASS_ID > 0)
{
this.gridGoods.U_DefaultRowValues.Add("GOODS_CLASS_ID", GOODS_CLASS_ID.ToString());
}
this.gridGoods.U_InitControl();
}
catch (Exception ex)
{
MainApp._MessageDialog.ShowException(ex);
}
finally
{
MainWindow.mainWin.Cursor = Cursors.Arrow;
}
}
///
/// 按条件加载物料信息
///
private void GOODS_Bind(string QueryWhere)
{
try
{
this.gridGoods.U_WindowName = this.GetType().Name;
this.gridGoods.U_TableName = "GOODS_MAIN";
this.gridGoods.U_XmlTableName = "GOODS_MAIN";
this.gridGoods.U_Where = string.Format("GOODS_CLASS_ID!=1 and {0}", string.IsNullOrEmpty(QueryWhere) ? "1=1" : QueryWhere);
this.gridGoods.U_AllowOperatData = true;
if( MainApp._USER.USER_ID != 0)
this.gridGoods.U_AllowDelete = System.Windows.Visibility.Collapsed;
this.gridGoods.U_AllowChecked = false;
this.gridGoods.U_AllowPage = true;
this.gridGoods.U_InitControl();
}
catch (Exception ex)
{
MainApp._MessageDialog.ShowException(ex);
}
}
///
/// 点击上下文菜单
///
private void ContextMenu_Click(object sender, RoutedEventArgs e)
{
if (this.tvwGoodsClass.tvwList.SelectedItem == null)
return;
TreeViewItem itemSelected = this.tvwGoodsClass.tvwList.SelectedItem as TreeViewItem;
if (itemSelected.Tag != null)
{
MenuItem menuItem = e.OriginalSource as MenuItem;
if (menuItem != null)
{
switch (menuItem.Name)
{
case "menuItemImportGoods":
//new SiaSun.LMS.WPFClient.Dialog.ImportExcelDialog(true, "GOODS_MAIN_IMPORT").ShowDialog();
if (MainApp._MessageDialog.ShowDialog(string.Format("确认导入类别[{0}]的物料?", itemSelected.Header.ToString())) == Sid.Windows.Controls.TaskDialogResult.Cancel)
{
return;
}
this.ImportGoodsFromFile(Convert.ToInt32(itemSelected.Tag.ToString()));
break;
case "menuItemUpdate":
this.Update();
break;
}
}
}
}
///
/// 从文件导入物料
///
private void ImportGoodsFromFile(int GOODS_CLASS_ID)
{
try
{
using (System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog())
{
//openFileDialog.Filter = "Excel 2007文件|*.xlsx|Excel 2003|*.xls";
if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.fileName = openFileDialog.FileName;
ImportFile(GOODS_CLASS_ID);
}
}
}
catch (Exception ex)
{
MainApp._MessageDialog.ShowException(ex);
}
}
private void ImportFile(int GOODS_CLASS_ID)
{
bool bResult = true;
string sResult = string.Empty;
if (string.IsNullOrEmpty(this.fileName))
{
MainApp._MessageDialog.ShowDialog("请选择Excel文件");
return;
}
using (DataTable tableExcel = new SiaSun.LMS.Common.Excel().ImportToDataTable(this.fileName, true))
{
if (tableExcel.Rows.Count == 0)
{
MainApp._MessageDialog.Show(false, "不存在导入的数据源");
return;
}
tableExcel.TableName = "ExcelImport";
bResult = MainApp._I_BaseService.Invoke("PlanImport", "GoodsCreate", new object[] { tableExcel, GOODS_CLASS_ID }, out sResult);
if (bResult)
{
this.gridGoods.U_Update();
}
MainApp._MessageDialog.Show(bResult, sResult);
}
}
///
/// 刷新,重新加载物料类别
///
private void Update()
{
//设置空数据源
this.gridGoods.U_DataSource = null;
//重新加载
this.GoodsClass_Bind();
}
private void sycinfo_Click(object sender, RoutedEventArgs e)
{
bool bResult = true;
string sResult = "";
string ssResult = "";
//原料送检 只给琥菘
bResult = MainApp._I_BaseService.Invoke("S_ERPService", "GoodsDataToBaili",
new object[] { "原材料" },
out sResult);
if (bResult)
{
}
//原料送检 只给琥菘
bResult = MainApp._I_BaseService.Invoke("S_ERPService", "GoodsDataToHusong",
new object[] { "原材料" },
out ssResult);
if (bResult)
{
}
sResult += ssResult;
///*无论成功与否,都需要删除本条记录,重发失败会向重发表中插入新的记录*/
//MainApp._I_BaseService.Invoke("S_ERPService", "DeleteRetryRecord", new object[] { Convert.ToInt32(rowView["ID"].ToString()) }, out sResult);
if (bResult)
{
MainApp._MessageDialog.ShowException("成功");
}
else
{
MainApp._MessageDialog.ShowException(sResult);
}
}
}
}