普通模塊犀勒,主要記錄各種按鈕功能的實現(xiàn)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Bizcent.Client.Common;
using Bizcent.IManager.MDM;
using Bizcent.IManager.Common;
using Bizcent.Model.MDM;
using XtraMessageBox = Bizcent.Client.Common.XtraMessageBox;
using Bizcent.Common.OptReturn;
using Bizcent.Model.Common;
using System.Collections;
using Bizcent.IManager.SMS;
using System.IO;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using System.Text.RegularExpressions;
using DevExpress.XtraGrid;
namespace Bizcent.Client.MDM
{
public partial class FrmGoodsRetraCtrlListMainte : BaseForm
{
#region 接口和變量
private IManagerGoodsRetraceMaintenceList GoodsRetraceMaintenceListManager_OMP { get; set; }
private IManagerAssociate AssociateManager { get; set; }
private IDictionary<string, string> dicHanye = null;
private GridAssociate associateSupplierCode;
private GridAssociate associateSupplierName;
private GridAssociate associateGoodsCode;
private GridAssociate associateGoodsName;
private NodeInfo dbNode = CurrentLogin.Node;
private NodeInfo OrderCenterNode = CurrentLogin.OrderCenter;
FormatMaster _PrintTemp = null;
private IManagerIO IOManager { get; set; }
private IManagerGoods GoodsManager { get; set; }
private IManagerSupplier SupplierManager { get; set; }
private IManagerUser UserManager { get; set; }
string fileName = string.Empty;
string userCode = CurrentLogin.CurrentUser.Employee.EmployeeCode;
string userName = CurrentLogin.CurrentUser.Employee.EmployeeName;
#endregion
#region 私有方法
/// <summary>
/// 讀取導(dǎo)入模板
/// </summary>
private void LoadImportTemp()
{
IList types = IOManager.LoadIOFormatFrm(dbNode, this.Name);
if (types != null && types.Count != 0)
{
FormatMaster fm = types[0] as FormatMaster;
this.bsTencil.DataSource = types;
bsTencil.ResetBindings(true);
_PrintTemp = fm;
this.btnImportTencil.EditValue = fm.FormatCode;
}
}
/// <summary>
/// 權(quán)限
/// </summary>
/// <returns></returns>
private bool SetPurview()
{
bool allow = true;
IList purviewList = null;
try
{
purviewList = UserManager.LoadUserModulePurviews(dbNode, CurrentLogin.CurrentUser.Employee.EmployeeCode, this.Tag.ToString());
}
catch (Exception ex)
{
XtraMessageBox.Show(ex);
allow = false;
return allow;
}
if (!purviewList.Contains(OperateInfo.Browse))
{
allow = false;
return allow;
}
if (!purviewList.Contains(OperateInfo.Maintain))
{
btnAdd.Enabled = false;
btnDelete.Enabled = false;
btnSave.Enabled = false;
btnImportTencil.Enabled = false;
btnImport.Enabled = false;
btnQuery.Enabled = false;
gvMaintenanceList.OptionsBehavior.Editable = false;
allow = false;
return allow;
}
return allow;
}
#endregion
#region 按鈕事件
//增行
private void btnAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
try
{
GoodsRetraceMaintenceListInfo currentrow = bsMaintenceList.Current as GoodsRetraceMaintenceListInfo;
if (currentrow != null)
{
if ((currentrow.GoodsCode == null || currentrow.GoodsCode == ""))
{
XtraMessageBox.ShowErrorMessage("請聯(lián)想商品信息");
return;
}
if ((currentrow.GoodsName == null || currentrow.GoodsName == ""))
{
XtraMessageBox.ShowErrorMessage("請聯(lián)想商品信息");
return;
}
if ((currentrow.SupplierCode == null || currentrow.SupplierCode == ""))
{
XtraMessageBox.ShowErrorMessage("請聯(lián)想供應(yīng)商信息");
return;
}
if ((currentrow.SupplierName == null || currentrow.SupplierName == ""))
{
XtraMessageBox.ShowErrorMessage("請聯(lián)想供應(yīng)商信息");
return;
}
if (currentrow.RemainDDays == null)
{
XtraMessageBox.ShowErrorMessage("請?zhí)顚憴n期提醒天數(shù)");
return;
}
}
gvMaintenanceList.CloseEditor();
GoodsRetraceMaintenceListInfo MaintenceInfo = new GoodsRetraceMaintenceListInfo();
MaintenceInfo.IsNew = true;
bsMaintenceList.Add(MaintenceInfo);
bsMaintenceList.ResetBindings(false);
this.gvMaintenanceList.FocusedRowHandle = this.gvMaintenanceList.DataRowCount - 1;
gvMaintenanceList.FocusedColumn = gcolSupplierCode;
gvMaintenanceList.Columns[1].OptionsColumn.AllowEdit = true;
gvMaintenanceList.Columns[2].OptionsColumn.AllowEdit = true;
gvMaintenanceList.Columns[3].OptionsColumn.AllowEdit = true;
gvMaintenanceList.Columns[4].OptionsColumn.AllowEdit = true;
gvMaintenanceList.Columns[5].OptionsColumn.AllowEdit = true;
gvMaintenanceList.ShowEditor();
}
catch (Exception ex)
{
XtraMessageBox.Show(ex);
}
}
//刪除
private void btnDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
try
{
labelControl1.Focus();
string LogTime = CurrentLogin.SysParam.GetCurrentDate().ToString("yyyyMMddHHmmss");
IList<GoodsRetraceMaintenceListInfo> AllItem = bsMaintenceList.List as IList<GoodsRetraceMaintenceListInfo>;
int allItemNum = AllItem.Count;
if (allItemNum > 0)
{
if (XtraMessageBox.Show("確認(rèn)刪除?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
{
IList<GoodsRetraceMaintenceListInfo> deleteItem = new List<GoodsRetraceMaintenceListInfo>();
for (int i = 0; i < allItemNum; i++)
{
if (AllItem[i].IsChoosen == true)
{
deleteItem.Add(AllItem[i]);
if (AllItem[i].IsNew == false)
{
#region 記錄刪除日志
AllItem[i].OperatorTime = LogTime;
AllItem[i].OperatorCode = userCode;
AllItem[i].OperatorName = userName;
AllItem[i].OperatorType = 1;
AllItem[i].OperateContent = "刪除供應(yīng)商編碼為" + AllItem[i].SupplierCode.ToString() + "商品編碼為"
+ AllItem[i].GoodsCode.ToString() + "檔期提醒天數(shù)為" + AllItem[i].RemainDDays.ToString();
#endregion
}
}
}
if (deleteItem.Count == 0)
{
XtraMessageBox.ShowWarningMessage("未勾選要刪除的數(shù)據(jù)");
return;
}
OperateReturnInfo Msg = GoodsRetraceMaintenceListManager_OMP.DeleteGoodsRetrace(OrderCenterNode, deleteItem);
if (Msg.ReturnCode == OperateCodeEnum.Success)
{
foreach (GoodsRetraceMaintenceListInfo item in deleteItem)
{
bsMaintenceList.Remove(item);
}
}
else
{
foreach (GoodsRetraceMaintenceListInfo item in deleteItem)
{
if (item.IsNew == true)
bsMaintenceList.Remove(item);
}
}
bsMaintenceList.ResetBindings(false);
}
}
}
catch (Exception ex)
{
XtraMessageBox.Show(ex);
}
}
//查詢
private void btnQuery_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
try
{
string ConditionGoodsCode = string.Empty;
if (!string.IsNullOrEmpty(txtGoodsCode.Text.ToString().Trim()))
{
ConditionGoodsCode = txtGoodsCode.Text.ToString().Trim();
}
string ConditionSupplierCode = string.Empty;
if (!string.IsNullOrEmpty(txtSupplierCode.Text.ToString().Trim()))
{
ConditionSupplierCode = txtSupplierCode.Text.ToString().Trim();
}
bsMaintenceList.Clear();
IList<GoodsRetraceMaintenceListInfo> TempList = GoodsRetraceMaintenceListManager_OMP.LoadGoodsRetraceMaintenceList(OrderCenterNode, ConditionGoodsCode, ConditionSupplierCode);
if (TempList.Count == 0) { return; }
IList<GoodsRetraceMaintenceListInfo> QueryList = GoodsRetraceMaintenceListManager_OMP.LoadGoodsNameAndSupplierName(OrderCenterNode, TempList);
if (QueryList.Count != 0)
{
bsMaintenceList.DataSource = QueryList;
bsMaintenceList.ResetBindings(false);
}
}
catch (Exception ex)
{
XtraMessageBox.Show(ex);
}
}
//保存
private void btnSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
try
{
gvMaintenanceList.CloseEditor();
string LogTime = CurrentLogin.SysParam.GetCurrentDate().ToString("yyyyMMddHHmmss");
IList<GoodsRetraceMaintenceListInfo> ListToSave = new List<GoodsRetraceMaintenceListInfo>();
IList<GoodsRetraceMaintenceListInfo> AllItem = bsMaintenceList.List as IList<GoodsRetraceMaintenceListInfo>;
for (int i = 0; i < AllItem.Count; i++)
{
if (AllItem[i].IsNew == true && !string.IsNullOrEmpty(AllItem[i].GoodsCode) && !string.IsNullOrEmpty(AllItem[i].SupplierCode) && !string.IsNullOrEmpty(AllItem[i].GoodsName)
&& !string.IsNullOrEmpty(AllItem[i].SupplierName) && !string.IsNullOrEmpty(AllItem[i].RemainDDays.ToString()))
{
AllItem[i].IsNew = false;
#region 記錄增行日志
AllItem[i].OperatorTime = LogTime;
AllItem[i].OperatorCode = userCode;
AllItem[i].OperatorName = userName;
AllItem[i].OperatorType = 0;
AllItem[i].OperateContent = "增加供應(yīng)商編碼為" + AllItem[i].SupplierCode.ToString() + "商品編碼為"
+ AllItem[i].GoodsCode.ToString() + "檔期提醒天數(shù)為" + AllItem[i].RemainDDays.ToString();
ListToSave.Add(AllItem[i]);
#endregion
}
else if (AllItem[i].IsNew == true && (!string.IsNullOrEmpty(AllItem[i].GoodsCode) || !string.IsNullOrEmpty(AllItem[i].SupplierCode) || !string.IsNullOrEmpty(AllItem[i].GoodsName)
|| !string.IsNullOrEmpty(AllItem[i].SupplierName) || !string.IsNullOrEmpty(AllItem[i].RemainDDays.ToString())))
{
XtraMessageBox.ShowWarningMessage("請完善第" + (i + 1) + "行數(shù)據(jù)后再保存!");
return;
}
}
if (ListToSave.Count == 0) { XtraMessageBox.Show("沒有可保存的數(shù)據(jù)"); return; }
OperateReturnInfo Msg = GoodsRetraceMaintenceListManager_OMP.SaveGoodsRetraceMaintenceList(OrderCenterNode, ListToSave);
if (Msg.ReturnCode == OperateCodeEnum.Success)
bsMaintenceList.Clear();
XtraMessageBox.Show(Msg);
}
catch (Exception ex)
{
XtraMessageBox.Show(ex);
}
}
//導(dǎo)入
private void btnImport_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
try
{
if (bsMaintenceList.Count > 0)
{
GoodsRetraceMaintenceListInfo currentrow = bsMaintenceList.List[bsMaintenceList.Count - 1] as GoodsRetraceMaintenceListInfo;
if (currentrow != null)
{
if ((currentrow.GoodsCode == null || currentrow.GoodsCode == "") && (currentrow.SupplierCode == null || currentrow.SupplierCode == ""))
{
bsMaintenceList.RemoveAt(bsMaintenceList.Count - 1);
}
else
{
if ((currentrow.GoodsCode == null || currentrow.GoodsCode == ""))
{
XtraMessageBox.ShowErrorMessage("請聯(lián)想商品信息");
return;
}
if ((currentrow.GoodsName == null || currentrow.GoodsName == ""))
{
XtraMessageBox.ShowErrorMessage("請聯(lián)想商品信息");
return;
}
if ((currentrow.SupplierCode == null || currentrow.SupplierCode == ""))
{
XtraMessageBox.ShowErrorMessage("請聯(lián)想供應(yīng)商信息");
return;
}
if ((currentrow.SupplierName == null || currentrow.SupplierName == ""))
{
XtraMessageBox.ShowErrorMessage("請聯(lián)想供應(yīng)商信息");
return;
}
if (currentrow.RemainDDays == null)
{
XtraMessageBox.ShowErrorMessage("請?zhí)顚憴n期提醒天數(shù)");
return;
}
}
}
}
if (_PrintTemp == null)
{
XtraMessageBox.ShowWarningMessage("無導(dǎo)入模板!");
return;
}
if (bsMaintenceList.List.Count > 0)
{
if (XtraMessageBox.ShowQuestionMessage("是否清空界面數(shù)據(jù)?") == DialogResult.OK)
{
bsMaintenceList.Clear();
}
}
FormatMaster fm = IOManager.LoadIOFormat(dbNode, this.btnImportTencil.EditValue.ToString());
DataTable dt = new EasyImporter(IOManager).File2DataTable(fm.FormatCode);
if (dt == null || dt.Rows.Count == 0) return;
int ImportNumber = dt.Rows.Count;//導(dǎo)入的文件中數(shù)據(jù)的條數(shù)
if (!dt.Columns.Contains("GoodsCode") || !dt.Columns.Contains("SupplierCode"))
{
XtraMessageBox.ShowErrorMessage("導(dǎo)入必須包含字段:商品編碼,供應(yīng)商編碼!");
return;
}
List<string> errorInfos = new List<string>();
IList<GoodsRetraceMaintenceListInfo> resultList = new List<GoodsRetraceMaintenceListInfo>();
for (int i = 0; i < dt.Rows.Count; i++)
{
DataRow dr = dt.Rows[i];
if (dr == null) continue;
#region 驗證數(shù)據(jù)有效性
if (!string.IsNullOrEmpty(dr["GoodsCode"].ToString()))
{
GoodsInfo goods = GoodsManager.LoadGoods(OrderCenterNode, dr["GoodsCode"].ToString(), new ArrayList());
if (goods == null || string.IsNullOrEmpty(goods.GoodsCode))
{
errorInfos.Add("第" + (i + 1) + "行" + "商品編碼不存在!");
continue;
}
}
if (!string.IsNullOrEmpty(dr["SupplierCode"].ToString()))
{
SupplierInfo supplier = SupplierManager.LoadSupplier(OrderCenterNode, dr["SupplierCode"].ToString());
if (supplier == null || string.IsNullOrEmpty(supplier.SupplierCode))
{
errorInfos.Add("第" + (i + 1) + "行" + "供應(yīng)商編碼不存在!");
continue;
}
}
if (!string.IsNullOrEmpty(dr["Remainddays"].ToString()))
{
string remainday = dr["Remainddays"].ToString();
string pattern = "^[1-9]\\d*$|0$";
if (!Regex.IsMatch(remainday, pattern))
{
errorInfos.Add("第" + (i + 1) + "行" + "檔案提醒天數(shù)只能輸入非負(fù)整數(shù)!");
continue;
}
}
#endregion
resultList.Add(new GoodsRetraceMaintenceListInfo()
{
IsNew = true,
GoodsCode = dr["GoodsCode"].ToString(),
SupplierCode = dr["SupplierCode"].ToString(),
RemainDDays = int.Parse(dr["RemainDDays"].ToString()),
});
}
for (int i = 0; i < resultList.Count; i++)
{
string errorInfo = (GoodsRetraceMaintenceListManager_OMP.CheckIsExsited(OrderCenterNode, resultList[i]));
if (errorInfo != "")
{
errorInfos.Add("供應(yīng)商編碼為" + resultList[i].SupplierCode + "商品編碼為" + resultList[i].GoodsCode + errorInfo);
resultList.Remove(resultList[i]);
}
}
#region 導(dǎo)入數(shù)據(jù)自身去重
for (int i = 0; i < resultList.Count; i++)
{
int CopyNumber = 0;
for (int j = 0; j < resultList.Count; j++)
{
if (resultList[i].GoodsCode == resultList[j].GoodsCode && resultList[i].SupplierCode == resultList[j].SupplierCode)
{
if (i != j)
{
CopyNumber++;
errorInfos.Add("第" + (i + 1) + "行與第" + (j + 1) + "行重復(fù)");
}
}
}
if (CopyNumber > 0)
{
resultList.Remove(resultList[i]);
}
}
#endregion
resultList = GoodsRetraceMaintenceListManager_OMP.LoadGoodsNameAndSupplierName(OrderCenterNode, resultList);//填補/修正 商品名稱和供應(yīng)商名稱信息
#region 界面原有數(shù)據(jù)和導(dǎo)入數(shù)據(jù)去重
IList<GoodsRetraceMaintenceListInfo> ExistedData = bsMaintenceList.List as IList<GoodsRetraceMaintenceListInfo>;
//IList<GoodsRetraceMaintenceListInfo> preImport = new List<GoodsRetraceMaintenceListInfo>();
int ExistedNumber = ExistedData.Count;//原先界面數(shù)據(jù)的條數(shù)
if (ExistedData != null && ExistedData.Count != 0 && resultList.Count != 0 && resultList != null)
{
for (int i = 0; i < resultList.Count; i++)
{
ExistedData.Add(resultList[i]);
}
for (int i = 0; i < ExistedData.Count; i++)
{
int sameNum = 0;
for (int j = i + 1; j < ExistedData.Count; j++)
{
if (ExistedData[i].GoodsCode == ExistedData[j].GoodsCode && ExistedData[j].SupplierCode == ExistedData[i].SupplierCode)
{
sameNum++;
}
}
if (sameNum > 0)
{
errorInfos.Add("商品編碼為" + ExistedData[i].GoodsCode + "供應(yīng)商編碼為" + ExistedData[i].SupplierCode + "的數(shù)據(jù)界面上已存在!");
ExistedData.RemoveAt(i);
}
}
//for (int i = 0; i < ExistedData.Count; i++)
//{
// for (int j = 0; j < resultList.Count; j++)
// {
// if (resultList[j].GoodsCode != ExistedData[i].GoodsCode || resultList[j].SupplierCode != ExistedData[i].SupplierCode)
// {
// errorInfos.Add("商品編碼為" + resultList[j].GoodsCode + "供應(yīng)商編碼為" + resultList[j].SupplierCode + "的數(shù)據(jù)界面上已存在!");
// continue;
// }
// else
// {
// preImport.Add(resultList[j]);
// }
// }
//}
//if (preImport.Count > 0)
//{
// foreach (GoodsRetraceMaintenceListInfo ImportItem in preImport)
// {
// ExistedData.Add(ImportItem);
// }
//}
}
else
{
foreach (GoodsRetraceMaintenceListInfo ImportItem in resultList)
{
ExistedData.Add(ImportItem);
}
}
#endregion
StringBuilder sb = new StringBuilder();
sb.Append("導(dǎo)入成功[" + (ExistedData.Count - ExistedNumber) + "]行\(zhòng)r\n導(dǎo)入失敗[" + (ImportNumber - (ExistedData.Count - ExistedNumber)) + "]行" + "\r\n");//ExistedData.Count為導(dǎo)入完成后界面的數(shù)據(jù)總條數(shù)
if (errorInfos.Count > 0)
{
sb.Append("以下數(shù)據(jù)驗證失敵濉:" + "\r\n");
foreach (var error in errorInfos)
{
sb.Append(error + "\r\n");
}
XtraMessageBox.Show(new OperateReturnInfo() { ReturnCode = OperateCodeEnum.Failed, ReturnInfo = sb.ToString() });
return;
}
else
{ XtraMessageBox.Show("已成功導(dǎo)入" + (ExistedData.Count - ExistedNumber) + "行"); }
bsMaintenceList.ResetBindings(false);
}
catch (Exception ex)
{
XtraMessageBox.Show(ex);
}
}
//導(dǎo)出
private void btnExport_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
try
{
if ((this.gvMaintenanceList != null))
{
if (this.bsMaintenceList.Count == 0) { return; }
FrmExport2CSV frm = new FrmExport2CSV(this.gvMaintenanceList);
frm.ShowDialog();
}
}
catch (Exception ex)
{
XtraMessageBox.Show(ex);
}
}
//全清
private void btnAllClear_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
try
{
if (bsMaintenceList.List.Count > 0)
{
if (XtraMessageBox.Show("將清除所有商品追溯控制清單數(shù)據(jù)是否繼續(xù)?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
{
bsMaintenceList.Clear();
txtGoodsCode.Text = string.Empty;
txtSupplierCode.Text = string.Empty;
btnQuery_ItemClick(null, null);
bsMaintenceList.ResetBindings(false);
#region 記錄全清日志
string LogTime = CurrentLogin.SysParam.GetCurrentDate().ToString("yyyyMMddHHmmss");
IList<GoodsRetraceMaintenceListInfo> allItemList = GoodsRetraceMaintenceListManager_OMP.LoadGoodsRetraceMaintenceList(OrderCenterNode, "", "");
foreach (GoodsRetraceMaintenceListInfo item in allItemList)
{
item.OperatorTime = LogTime;
item.OperatorCode = userCode;
item.OperatorName = userName;
item.OperatorType = 2;
string operateContent = string.Empty;
item.OperateContent = "全清" + "供應(yīng)商編碼為" + item.SupplierCode + "商品編碼為" + item.GoodsCode + "檔期提醒天數(shù)" + item.RemainDDays;
}
#endregion
OperateReturnInfo Msg = GoodsRetraceMaintenceListManager_OMP.DeleteAll(OrderCenterNode, allItemList);
if (Msg.ReturnCode == OperateCodeEnum.Success)
{
bsMaintenceList.Clear();
XtraMessageBox.Show("數(shù)據(jù)庫數(shù)據(jù)已全部清空");
}
}
}
}
catch (Exception ex)
{
XtraMessageBox.Show(ex);
}
}
//退出
private void btnExit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
try
{
int newItem = 0;
foreach (GoodsRetraceMaintenceListInfo item in bsMaintenceList.List)
{
if (item.IsNew) { newItem++; }
if (newItem > 0) { break; }
}
if (newItem > 0)
{
if (XtraMessageBox.Show("放棄已有數(shù)據(jù)?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.Cancel)
{
return;
}
}
this.Close();
}
catch (Exception ex)
{
XtraMessageBox.Show(ex);
}
}
private void bbiChooseall_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
try
{
foreach (GoodsRetraceMaintenceListInfo item in bsMaintenceList.List)
{
item.IsChoosen = true;
}
bsMaintenceList.ResetBindings(false);
}
catch (Exception ex)
{
XtraMessageBox.Show(ex);
}
}
private void bbiChoosenone_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
try
{
foreach (GoodsRetraceMaintenceListInfo item in bsMaintenceList.List)
{
item.IsChoosen = false;
}
bsMaintenceList.ResetBindings(false);
}
catch (Exception ex)
{
XtraMessageBox.Show(ex);
}
}
private void bbiChooseinverse_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
try
{
foreach (GoodsRetraceMaintenceListInfo item in bsMaintenceList.List)
{
item.IsChoosen = !item.IsChoosen;
}
bsMaintenceList.ResetBindings(false);
}
catch (Exception ex)
{
XtraMessageBox.Show(ex);
}
}
#endregion
#region 窗體加載
public FrmGoodsRetraCtrlListMainte()
{
InitializeComponent();
}
private void FrmGoodsRetraCtrlListMainte_Shown(object sender, EventArgs e)
{
try
{
if (!SetPurview())
{
Close();
return;
}
LoadImportTemp();
AssociateGoodsInitGoodsCode();
AssociateSuppInitGoodsCode();
btnAllClear.Enabled = false;
this.kdStripToolStripMenuItem.Click += new System.EventHandler(this.kdStripToolStripMenuItem_Click);
#region 創(chuàng)建日志文件
//string CurrentDate = CurrentLogin.SysParam.GetCurrentDate().ToString("yyyyMMdd");
//string Path = "D:\\";
//string fileName = Path + CurrentDate + ".txt";
//if (!File.Exists(fileName))
//{
// StreamWriter sw = File.CreateText(fileName);
// sw.WriteLine("/*商品追溯控制清單維護(hù)日志*/ ");
// sw.WriteLine("/操作人編碼/操作人名稱/操作時間/操作類型/供應(yīng)商編碼/商品編碼/檔案提醒天數(shù)");
// sw.Flush();
// sw.Close();
//}
#endregion
}
catch (Exception ex)
{
XtraMessageBox.Show(ex);
}
}
#endregion
#region 聯(lián)想
private void AssociateGoodsInitGoodsCode()
{
associateGoodsCode = new GridAssociate(OrderCenterNode, "Code", AssociateManager, AssociateModeEnum.GoodsCode, null);
associateGoodsCode.BaseAssociate.Associated += new AssociateBase.AssociateEventHandler(BaseAssociate_Associated);
gcolGoodsCode.ColumnEdit = associateGoodsCode;
associateGoodsName = new GridAssociate(OrderCenterNode, "Name", AssociateManager, AssociateModeEnum.GoodsName, null);
associateGoodsName.BaseAssociate.Associated += new AssociateBase.AssociateEventHandler(BaseAssociate_Associated);
gcolGoodsName.ColumnEdit = associateGoodsName;
}
void BaseAssociate_Associated(Bizcent.Client.Common.AssociateControl.AssociateEventArgs e)
{
try
{
if (e.CurrentState == AssociateStateEnum.Normal)
{
gvMaintenanceList.CloseEditor();
DataRow dr = e.CurrentDataRow;
GoodsRetraceMaintenceListInfo MaintenceInfo = bsMaintenceList.Current as GoodsRetraceMaintenceListInfo;
GoodsRetraceMaintenceListInfo item = new GoodsRetraceMaintenceListInfo();
if (MaintenceInfo == null) { return; }
if (MaintenceInfo.IsNew == false)
{
XtraMessageBox.ShowWarningMessage("已有數(shù)據(jù)不允許修改");
return;
}
if (dr[0].ToString() != "" && MaintenceInfo.SupplierCode != "")
{
item.SupplierCode = MaintenceInfo.SupplierCode;
item.GoodsCode = dr[0].ToString();
string errorInfo = GoodsRetraceMaintenceListManager_OMP.CheckIsExsited(OrderCenterNode, item);
if (errorInfo != "")
{
XtraMessageBox.ShowErrorMessage(errorInfo);
return;
}
}
IList<GoodsRetraceMaintenceListInfo> allItemList = bsMaintenceList.List as IList<GoodsRetraceMaintenceListInfo>;
int sameNum = 0;
foreach (GoodsRetraceMaintenceListInfo grmi in allItemList)
{
if (!string.IsNullOrEmpty(grmi.GoodsCode.ToString()) && !string.IsNullOrEmpty(grmi.SupplierCode.ToString()))
{
if (MaintenceInfo.SupplierCode == grmi.SupplierCode && dr[0].ToString() == grmi.GoodsCode && dr[1].ToString() == grmi.GoodsName && MaintenceInfo.SupplierName == grmi.SupplierName)
{
sameNum++;
}
}
}
if (sameNum > 0)
{
XtraMessageBox.ShowErrorMessage("無法輸入重復(fù)數(shù)據(jù)!");
return;
}
MaintenceInfo.GoodsCode = dr[0].ToString();
MaintenceInfo.GoodsName = dr[1].ToString();
associateGoodsCode.CurrentValue = dr[0].ToString();
associateGoodsName.CurrentValue = dr[1].ToString();
bsMaintenceList.ResetBindings(false);
gvMaintenanceList.FocusedColumn = gcolRemainDDays;
gvMaintenanceList.ShowEditor();
}
}
catch (Exception ex)
{ Bizcent.Client.Common.XtraMessageBox.Show(ex); }
}
private void AssociateSuppInitGoodsCode()
{
associateSupplierCode = new GridAssociate(OrderCenterNode, "Code", AssociateManager, AssociateModeEnum.SuppCode, null);
associateSupplierCode.BaseAssociate.Associated += new AssociateBase.AssociateEventHandler(SuppBaseAssociate_Associated);
gcolSupplierCode.ColumnEdit = associateSupplierCode;
associateSupplierName = new GridAssociate(OrderCenterNode, "Name", AssociateManager, AssociateModeEnum.SuppName, null);
associateSupplierName.BaseAssociate.Associated += new AssociateBase.AssociateEventHandler(SuppBaseAssociate_Associated);
gcolSupplierName.ColumnEdit = associateSupplierName;
}
void SuppBaseAssociate_Associated(Bizcent.Client.Common.AssociateControl.AssociateEventArgs e)
{
try
{
gvMaintenanceList.CloseEditor();
if (e.CurrentState == AssociateStateEnum.Normal)
{
DataRow dr = e.CurrentDataRow;
GoodsRetraceMaintenceListInfo MaintenceInfo = bsMaintenceList.Current as GoodsRetraceMaintenceListInfo;
GoodsRetraceMaintenceListInfo item = new GoodsRetraceMaintenceListInfo();
if (MaintenceInfo == null) { return; }
if (MaintenceInfo.IsNew == false)
{
XtraMessageBox.ShowWarningMessage("已有數(shù)據(jù)不允許修改");
return;
}
if (dr[0].ToString() != "" && MaintenceInfo.GoodsCode != "")
{
item.SupplierCode = dr[0].ToString();
item.GoodsCode = MaintenceInfo.GoodsCode;
string errorInfo = GoodsRetraceMaintenceListManager_OMP.CheckIsExsited(OrderCenterNode, item);
if (errorInfo != "")
{
XtraMessageBox.ShowErrorMessage(errorInfo);
return;
}
}
IList<GoodsRetraceMaintenceListInfo> allItemList = bsMaintenceList.List as IList<GoodsRetraceMaintenceListInfo>;
int sameNum = 0;
foreach (GoodsRetraceMaintenceListInfo grmi in allItemList)
{
if (!string.IsNullOrEmpty(grmi.GoodsCode.ToString()) && !string.IsNullOrEmpty(grmi.SupplierCode.ToString()))
{
if (dr[0].ToString() == grmi.SupplierCode && MaintenceInfo.GoodsCode == grmi.GoodsCode && dr[1].ToString() == grmi.SupplierName && MaintenceInfo.GoodsName == grmi.GoodsName)
{
sameNum++;
}
}
}
if (sameNum > 0)
{
XtraMessageBox.ShowErrorMessage("無法輸入重復(fù)數(shù)據(jù)!");
return;
}
MaintenceInfo.SupplierCode = dr[0].ToString();
MaintenceInfo.SupplierName = dr[1].ToString();
associateSupplierCode.CurrentValue = dr[0].ToString();
associateSupplierName.CurrentValue = dr[1].ToString();
bsMaintenceList.ResetBindings(false);
gvMaintenanceList.FocusedColumn = gcolGoodsCode;
gvMaintenanceList.ShowEditor();
}
}
catch (Exception ex)
{ Bizcent.Client.Common.XtraMessageBox.Show(ex); }
}
#endregion
#region 窗體和表格事件
private void gvMaintenanceList_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
{
try
{
if (this.gvMaintenanceList.FocusedRowHandle < this.bsMaintenceList.Count - 1)
{
int gvMaintenanceListCount = bsMaintenceList.Count;
IList<GoodsRetraceMaintenceListInfo> List = bsMaintenceList.List as IList<GoodsRetraceMaintenceListInfo>;
if (List.Count != 0)
{
if ((List[gvMaintenanceListCount - 1].GoodsCode == null || List[gvMaintenanceListCount - 1].SupplierCode == ""))
{
bsMaintenceList.Remove(List[gvMaintenanceListCount - 1]);
}
gvMaintenanceList.CloseEditor();
GoodsRetraceMaintenceListInfo currentRow = bsMaintenceList.Current as GoodsRetraceMaintenceListInfo;
if (currentRow.IsNew == false)
{
gvMaintenanceList.Columns[1].OptionsColumn.AllowEdit = false;
gvMaintenanceList.Columns[2].OptionsColumn.AllowEdit = false;
gvMaintenanceList.Columns[3].OptionsColumn.AllowEdit = false;
gvMaintenanceList.Columns[4].OptionsColumn.AllowEdit = false;
gvMaintenanceList.Columns[5].OptionsColumn.AllowEdit = false;
}
else
{
gvMaintenanceList.Columns[1].OptionsColumn.AllowEdit = true;
gvMaintenanceList.Columns[2].OptionsColumn.AllowEdit = true;
gvMaintenanceList.Columns[3].OptionsColumn.AllowEdit = true;
gvMaintenanceList.Columns[4].OptionsColumn.AllowEdit = true;
gvMaintenanceList.Columns[5].OptionsColumn.AllowEdit = true;
}
}
GoodsRetraceMaintenceListInfo preRow = new GoodsRetraceMaintenceListInfo();
if (e.PrevFocusedRowHandle != GridControl.InvalidRowHandle && bsMaintenceList.Current != null
&& bsMaintenceList.Count != 0 && bsMaintenceList.Count > e.PrevFocusedRowHandle)
{
preRow = bsMaintenceList[e.PrevFocusedRowHandle] as GoodsRetraceMaintenceListInfo;
}
else
{ return; }
if (string.IsNullOrEmpty(preRow.GoodsCode))
{
XtraMessageBox.ShowWarningMessage("商品信息不能為空!");
this.gvMaintenanceList.FocusedColumn = this.gcolGoodsCode;
this.gvMaintenanceList.FocusedRowHandle = e.PrevFocusedRowHandle;
return;
}
if (string.IsNullOrEmpty(preRow.GoodsName))
{
XtraMessageBox.ShowWarningMessage("商品信息不能為空!");
this.gvMaintenanceList.FocusedColumn = this.gcolGoodsCode;
this.gvMaintenanceList.FocusedRowHandle = e.PrevFocusedRowHandle;
return;
}
if (string.IsNullOrEmpty(preRow.SupplierCode))
{
XtraMessageBox.ShowWarningMessage("供應(yīng)商信息不能為空!");
this.gvMaintenanceList.FocusedColumn = this.gcolSupplierCode;
this.gvMaintenanceList.FocusedRowHandle = e.PrevFocusedRowHandle;
return;
}
if (string.IsNullOrEmpty(preRow.SupplierName))
{
XtraMessageBox.ShowWarningMessage("供應(yīng)商信息不能為空!");
this.gvMaintenanceList.FocusedColumn = this.gcolSupplierCode;
this.gvMaintenanceList.FocusedRowHandle = e.PrevFocusedRowHandle;
return;
}
if (string.IsNullOrEmpty(preRow.RemainDDays.ToString()))
{
XtraMessageBox.ShowWarningMessage("檔期提醒天數(shù)信息不能為空!");
this.gvMaintenanceList.FocusedColumn = this.gcolRemainDDays;
this.gvMaintenanceList.FocusedRowHandle = e.PrevFocusedRowHandle;
return;
}
}
else
{
gvMaintenanceList.CloseEditor();
GoodsRetraceMaintenceListInfo currentRow = bsMaintenceList.Current as GoodsRetraceMaintenceListInfo;
if (currentRow.IsNew == false)
{
gvMaintenanceList.Columns[1].OptionsColumn.AllowEdit = false;
gvMaintenanceList.Columns[2].OptionsColumn.AllowEdit = false;
gvMaintenanceList.Columns[3].OptionsColumn.AllowEdit = false;
gvMaintenanceList.Columns[4].OptionsColumn.AllowEdit = false;
gvMaintenanceList.Columns[5].OptionsColumn.AllowEdit = false;
}
else
{
gvMaintenanceList.Columns[1].OptionsColumn.AllowEdit = true;
gvMaintenanceList.Columns[2].OptionsColumn.AllowEdit = true;
gvMaintenanceList.Columns[3].OptionsColumn.AllowEdit = true;
gvMaintenanceList.Columns[4].OptionsColumn.AllowEdit = true;
gvMaintenanceList.Columns[5].OptionsColumn.AllowEdit = true;
}
}
}
catch (Exception ex)
{
XtraMessageBox.Show(ex);
}
}
private void repositoryItemCheckEdit1_EditValueChanged(object sender, EventArgs e)
{
try
{
CheckEdit check = sender as CheckEdit;
GoodsRetraceMaintenceListInfo CurrentRow = bsMaintenceList.Current as GoodsRetraceMaintenceListInfo;
if (CurrentRow == null) return;
CurrentRow.IsChoosen = !CurrentRow.IsChoosen;
bsMaintenceList.ResetBindings(false);
}
catch (Exception ex)
{
XtraMessageBox.Show(ex);
}
}
private void gvMaintenanceList_MouseUp(object sender, MouseEventArgs e)
{
try
{
gvMaintenanceList.CloseEditor();
GridHitInfo hInfo = gvMaintenanceList.CalcHitInfo(new Point(e.X, e.Y));
if (hInfo.HitTest.ToString() == "EmptyRow")
{
btnAdd_ItemClick(null, null);
}
gvMaintenanceList.ShowEditor();
}
catch (Exception ex)
{
XtraMessageBox.Show(ex);
}
}
private void gvMaintenanceList_KeyDown(object sender, KeyEventArgs e)
{
try
{
if (e.KeyCode == Keys.Enter)
{
switch (gvMaintenanceList.FocusedColumn.Name)
{
case "gcolRemainDDays":
if (gvMaintenanceList.FocusedRowHandle == bsMaintenceList.Count - 1)
{
GoodsRetraceMaintenceListInfo CurrentRow = bsMaintenceList.Current as GoodsRetraceMaintenceListInfo;
if (CurrentRow.RemainDDays != 0)
{ btnAdd_ItemClick(null, null); }
}
break;
default:
break;
}
}
else if (e.KeyCode == Keys.Down)
{
if (gvMaintenanceList.FocusedRowHandle == bsMaintenceList.Count - 1)
{
btnAdd_ItemClick(null, null);
}
}
}
catch (Exception ex)
{
XtraMessageBox.Show(ex);
}
}
private void kdStripToolStripMenuItem_Click(object sender, EventArgs e)
{
btnAllClear.Enabled = true;
}
private void bbiOption_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
CustomColumnSelectForm f = new CustomColumnSelectForm(this.gvMaintenanceList);
f.ShowDialog();
}
//protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
//{
// if (keyData == (Keys.Control | Keys.F12))
// {
// btnAllClear.Enabled = true;
// return true;
// }
// return base.ProcessCmdKey(ref msg, keyData);
//}
#endregion
}
}