主要是控制指針實(shí)現(xiàn)兩個(gè)gridview聯(lián)動(dòng)
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.Model.MDM;
using XtraMessageBox = Bizcent.Client.Common.XtraMessageBox;
using Bizcent.Model.Common;
using Bizcent.IManager.Common;
using Bizcent.IManager.MDM;
using System.Text.RegularExpressions;
using Bizcent.Common.OptReturn;
using System.Collections;
using Bizcent.IManager.SMS;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
namespace Bizcent.Client.MDM
{
public partial class FrmPriceChangeSKU : BaseForm
{
#region 窗體加載
public FrmPriceChangeSKU()
{
InitializeComponent();
}
private void FrmPriceChangeSKU_Shown(object sender, EventArgs e)
{
try
{
if (!SetPurview())
{
Close();
return;
}
LoadImportTemp();
associateInitDeptCode();
PromotionPeriodList = PeriodExhSetManager.LoadPromotionPeriodBill(dbNode);
bsPromotionPeriod.DataSource = PromotionPeriodList;
bsPromotionPeriod.ResetBindings(false);
}
catch (Exception ex)
{
}
}
#endregion
#region 接口和變量
FormatMaster _PrintTemp = null;
private IManagerIO IOManager { get; set; }
NodeInfo dbNode = CurrentLogin.Node;
private IManagerPeriodExhSet PeriodExhSetManager { get; set; }
IList<PromotionPeriodInfo> PromotionPeriodList = new List<PromotionPeriodInfo>();
private IManagerPriceChangeSKU PriceChangeSKUManager { get; set; }
private IManagerUser UserManager { get; set; }
private GridAssociate associateCategoryCode;
private GridAssociate associateCategoryName;
private IManagerAssociate AssociateManager { get; set; }
#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;
_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))
{
allow = false;
return allow;
}
return allow;
}
/// <summary>
/// 檢查gvParent數(shù)據(jù)完整
/// </summary>
private string CheckgvParent()
{
gvParent.CloseEditor();
PriceChangeSKUInfo currentRow = bsParent.Current as PriceChangeSKUInfo;
if (currentRow == null) { return null; }
if (currentRow.CategoryCode == null || currentRow.CategoryCode == "")
{
return "二級(jí)品類編碼不能為空!";
}
if (currentRow.CategoryName == null || currentRow.CategoryName == "")
{
return "二級(jí)品類名稱不能為空!";
}
if (currentRow.BudgetLine == null || currentRow.BudgetLine.ToString() == "" || currentRow.BudgetLine == 0)
{
return "預(yù)算額度必須大于0!";
}
return "";
}
/// <summary>
/// 查詢并綁定gvChild的數(shù)據(jù)
/// </summary>
/// <param name="parentInfo"></param>
private void LoadandBoundChildData(PriceChangeSKUInfo parentInfo)
{
if (parentInfo.PriceChangeCauseSKUList.Count > 0)
{
bsChild.DataSource = parentInfo.PriceChangeCauseSKUList;
}
else
{
IList<PriceChangeCauseSKUInfo> childList = PriceChangeSKUManager.LoadChild(dbNode, parentInfo);
bsChild.DataSource = childList;
}
bsChild.ResetBindings(false);
}
#endregion
#region 按鈕事件
private void btnSearch_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
if (gcParent.Focused)
{
FrmFind t = new FrmFind(gcParent);
t.ShowDialog();
}
else
{
FrmFind f = new FrmFind(gcChild);
f.ShowDialog();
}
}
private void btnAddRow_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
try
{
if (luePromotionPeriod.Text == null || luePromotionPeriod.Text == "")
{
XtraMessageBox.ShowWarningMessage("請(qǐng)先選擇檔期!");
return;
}
string Msg = CheckgvParent();
if (!string.IsNullOrEmpty(Msg))
{
XtraMessageBox.Show(Msg);
return;
}
PriceChangeSKUInfo newRow = new PriceChangeSKUInfo();
bsParent.Add(newRow);
bsParent.ResetBindings(false);
gvParent.FocusedColumn = colCategoryCode;
gvParent.FocusedRowHandle = bsParent.Count - 1;
gvParent.ShowEditor();
}
catch (Exception ex)
{
XtraMessageBox.Show(ex);
}
}
private void btnDeleteRow_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
try
{
if (bsParent.Count <= 0) { return; }
if (XtraMessageBox.Show("確認(rèn)刪除?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
{
gvParent.CloseEditor();
PriceChangeSKUInfo currentRow = bsParent.Current as PriceChangeSKUInfo;
if (currentRow == null) { return; }
if (bsParent.Count > 0)
{
OperateReturnInfo opr = PriceChangeSKUManager.Delete(dbNode, currentRow);
if (opr.ReturnCode == OperateCodeEnum.Success)
{
bsParent.Remove(currentRow);
bsParent.ResetBindings(false);
if (bsParent.Count == 0)
{ bsChild.Clear(); }
else
{
PriceChangeSKUInfo anotherCurrentRow = bsParent.Current as PriceChangeSKUInfo;
if (anotherCurrentRow.PriceChangeCauseSKUList.Count <= 0)
{
IList<PriceChangeCauseSKUInfo> childList = PriceChangeSKUManager.LoadChild(dbNode, anotherCurrentRow);
anotherCurrentRow.PriceChangeCauseSKUList = childList;
bsChild.DataSource = anotherCurrentRow.PriceChangeCauseSKUList;
}
}
}
}
bsParent.ResetBindings(false);
gvParent.ShowEditor();
}
}
catch (Exception ex)
{
XtraMessageBox.Show(ex);
}
}
private void btnImport_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
try
{
if (_PrintTemp == null)
{
XtraMessageBox.ShowWarningMessage("無(wú)導(dǎo)入模板!");
return;
}
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("PromotionPeriodCode") || !dt.Columns.Contains("SubID") || !dt.Columns.Contains("CategoryCode") || !dt.Columns.Contains("BudgetLine")
|| !dt.Columns.Contains("ChangeCauseCode") || !dt.Columns.Contains("PlanSKUNum") || !dt.Columns.Contains("SKULowerLimit") || !dt.Columns.Contains("SKUUpperLimit")
|| !dt.Columns.Contains("PromotionThemeCode"))
{
XtraMessageBox.ShowErrorMessage("導(dǎo)入必須包含字段:促銷主題編碼,檔期編碼,子檔號(hào),二級(jí)品類編碼,預(yù)算額度,變價(jià)原因編碼,規(guī)劃SKU數(shù)量,選品SKU下限,選品SKU上限!");
return;
}
List<string> errorInfos = new List<string>();
IList<PriceChangeSKUInfo> resultList = new List<PriceChangeSKUInfo>();
for (int i = 0; i < dt.Rows.Count; i++)
{
DataRow dr = dt.Rows[i];
if (dr == null) continue;
#region 驗(yàn)證數(shù)據(jù)有效性
if (!string.IsNullOrEmpty(dr["PromotionThemeCode"].ToString()))
{
string PromotionThemeCode = PriceChangeSKUManager.LoadPromotionThemeCode(dbNode, dr["PromotionThemeCode"].ToString());
if (string.IsNullOrEmpty(PromotionThemeCode))
{
errorInfos.Add("第" + (i + 1) + "行" + "促銷主題編碼不存在!");
continue;
}
}
else
{
errorInfos.Add("第" + (i + 1) + "行" + "促銷主題編碼不能為空!");
continue;
}
if (!string.IsNullOrEmpty(dr["PromotionPeriodCode"].ToString()))
{
bool IsExist = false;
foreach (PromotionPeriodInfo item in PromotionPeriodList)
{
if (item.PromotionPeriodCode == dr["PromotionPeriodCode"].ToString())
{
IsExist = true;
}
}
if (!IsExist)
{
errorInfos.Add("第" + (i + 1) + "行" + "檔期編碼不存在!");
continue;
}
}
else
{
errorInfos.Add("第" + (i + 1) + "行" + "檔期編碼不能為空!");
continue;
}
if (!string.IsNullOrEmpty(dr["SubID"].ToString()))
{
bool IsExist = false;
foreach (PromotionPeriodInfo item in PromotionPeriodList)
{
if (item.SubID.ToString() == dr["SubID"].ToString())
{
IsExist = true;
}
}
if (!IsExist)
{
errorInfos.Add("第" + (i + 1) + "行" + "子檔號(hào)不存在!");
continue;
}
}
else
{
errorInfos.Add("第" + (i + 1) + "行" + "子檔號(hào)不能為空!");
continue;
}
if (!string.IsNullOrEmpty(dr["CategoryCode"].ToString()))
{
string CategoryCode = PriceChangeSKUManager.LoadtbGoodsCategory(dbNode, dr["CategoryCode"].ToString());
if (string.IsNullOrEmpty(CategoryCode))
{
errorInfos.Add("第" + (i + 1) + "行" + "二級(jí)分類編碼不存在!");
continue;
}
}
else
{
errorInfos.Add("第" + (i + 1) + "行" + "二級(jí)分類編碼不能為空!");
continue;
}
if (!string.IsNullOrEmpty(dr["BudgetLine"].ToString()))
{
string BudgetLine = dr["BudgetLine"].ToString();
string pattern = @"^[0-9]*[1-9][0-9]*$";
if (!Regex.IsMatch(BudgetLine, pattern))
{
errorInfos.Add("第" + (i + 1) + "行" + "預(yù)算額度只能輸入正整數(shù)!");
continue;
}
}
else
{
errorInfos.Add("第" + (i + 1) + "行" + "預(yù)算額度不能為空!");
continue;
}
if (!string.IsNullOrEmpty(dr["ChangeCauseCode"].ToString()))
{
string ChangeCauseCode = PriceChangeSKUManager.LoadChangePriceCause(dbNode, dr["ChangeCauseCode"].ToString());
if (string.IsNullOrEmpty(ChangeCauseCode))
{
errorInfos.Add("第" + (i + 1) + "行" + "變價(jià)原因編碼不存在!");
continue;
}
}
else
{
errorInfos.Add("第" + (i + 1) + "行" + "變價(jià)原因編碼不能為空!");
continue;
}
if (!string.IsNullOrEmpty(dr["PlanSKUNum"].ToString()))
{
string PlanSKUNum = dr["PlanSKUNum"].ToString();
string pattern = "^[1-9]\\d*$|0$";
if (!Regex.IsMatch(PlanSKUNum, pattern))
{
errorInfos.Add("第" + (i + 1) + "行" + "規(guī)劃SKU數(shù)量只能輸入非負(fù)整數(shù)!");
continue;
}
}
else
{
errorInfos.Add("第" + (i + 1) + "行" + "規(guī)劃SKU數(shù)量不能為空!");
continue;
}
if (!string.IsNullOrEmpty(dr["SKULowerLimit"].ToString()))
{
string SKULowerLimit = dr["SKULowerLimit"].ToString();
string pattern = "^[1-9]\\d*$|0$";
if (!Regex.IsMatch(SKULowerLimit, pattern))
{
errorInfos.Add("第" + (i + 1) + "行" + "選品SKU下限只能輸入非負(fù)整數(shù)!");
continue;
}
}
else
{
errorInfos.Add("第" + (i + 1) + "行" + "選品SKU下限不能為空!");
continue;
}
if (!string.IsNullOrEmpty(dr["SKUUpperLimit"].ToString()))
{
string SKUUpperLimit = dr["SKUUpperLimit"].ToString();
string pattern = "^[1-9]\\d*$|0$";
if (!Regex.IsMatch(SKUUpperLimit, pattern))
{
errorInfos.Add("第" + (i + 1) + "行" + "選品SKU上限只能輸入非負(fù)整數(shù)!");
continue;
}
}
else
{
errorInfos.Add("第" + (i + 1) + "行" + "選品SKU上限不能為空!");
continue;
}
if (!string.IsNullOrEmpty(dr["SKUUpperLimit"].ToString()) && !string.IsNullOrEmpty(dr["SKULowerLimit"].ToString()))
{
if (int.Parse(dr["SKUUpperLimit"].ToString()) < int.Parse(dr["SKULowerLimit"].ToString()))
{
errorInfos.Add("第" + (i + 1) + "行" + "選品SKU上限必須大于商品SKU下限!");
continue;
}
}
#endregion
PriceChangeCauseSKUInfo info = new PriceChangeCauseSKUInfo();
info.ChangeCauseCode = dr["ChangeCauseCode"].ToString();
info.SKULowerLimit = int.Parse(dr["SKULowerLimit"].ToString());
info.SKUUpperLimit = int.Parse(dr["SKUUpperLimit"].ToString());
info.PlanSKUNum = int.Parse(dr["PlanSKUNum"].ToString());
PriceChangeSKUInfo mainInfo = new PriceChangeSKUInfo();
mainInfo.PromotionThemeCode = dr["PromotionThemeCode"].ToString();
mainInfo.PromotionPeriodCode = dr["PromotionPeriodCode"].ToString();
mainInfo.SubID = int.Parse(dr["SubID"].ToString());
mainInfo.CategoryCode = dr["CategoryCode"].ToString();
mainInfo.BudgetLine = double.Parse(dr["BudgetLine"].ToString());
mainInfo.PriceChangeCauseSKU = CreateDeepCopy<PriceChangeCauseSKUInfo>(info);
mainInfo.PriceChangeCauseSKUList.Add(info);
resultList.Add(mainInfo);
}
#region 導(dǎo)入數(shù)據(jù)自身去重
for (int i = 0; i < resultList.Count; i++)
{
for (int j = resultList.Count - 1; j > i; j--)
{
if (
resultList[i].PromotionThemeCode == resultList[j].PromotionThemeCode
&& resultList[i].PromotionPeriodCode == resultList[j].PromotionPeriodCode
&& resultList[i].SubID == resultList[j].SubID
&& resultList[i].CategoryCode == resultList[j].CategoryCode
&& resultList[i].PriceChangeCauseSKU.ChangeCauseCode == resultList[j].PriceChangeCauseSKU.ChangeCauseCode
)
{
if (i != j)
{
resultList.Remove(resultList[j]);
errorInfos.Add("第" + (i + 1) + "行與第" + (j + 1) + "行重復(fù)");
}
}
}
}
#endregion
//resultList = PriceChangeSKUManager.LoadNames(dbNode, resultList);//填補(bǔ)/修正 名稱信息
//if (resultList.Count <= 0)
//{
// XtraMessageBox.ShowErrorMessage("沒有導(dǎo)入任何數(shù)據(jù)!");
// return;
//}
//if (opr.ReturnCode == OperateCodeEnum.Warning)
//{
// XtraMessageBox.ShowErrorMessage("沒有導(dǎo)入任何數(shù)據(jù)!");
// return;
//}
StringBuilder sb = new StringBuilder();
sb.Append("導(dǎo)入成功[" + (resultList.Count) + "]行\(zhòng)r\n導(dǎo)入失敗[" + (ImportNumber - resultList.Count) + "]行" + "\r\n");
if (errorInfos.Count > 0)
{
sb.Append("以下數(shù)據(jù)驗(yàn)證失敶虏ァ:" + "\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)入" + ImportNumber + "行"); }
if (resultList.Count == 0) { return; }
OperateReturnInfo opr = PriceChangeSKUManager.UpdatePriceChangeSKUInfo(dbNode, resultList);
if (opr.ReturnCode == OperateCodeEnum.Failed)
{
XtraMessageBox.ShowErrorMessage("導(dǎo)入失敗!");
return;
}
}
catch (Exception ex)
{
XtraMessageBox.Show(ex);
}
}
private void btnSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
try
{
gvParent.CloseEditor();
gvChild.CloseEditor();
if (bsParent.Count <= 0)
{
XtraMessageBox.ShowWarningMessage("沒有可保存的數(shù)據(jù)!");
return;
}
foreach (PriceChangeSKUInfo item in bsParent.List)
{
if (item == null) { return; }
if (item.CategoryCode == null || item.CategoryCode == "")
{
XtraMessageBox.ShowWarningMessage("二級(jí)品類編碼不能為空!");
return;
}
if (item.CategoryName == null || item.CategoryName == "")
{
XtraMessageBox.ShowWarningMessage("二級(jí)品類名稱不能為空!");
return;
}
if (item.BudgetLine == null || item.BudgetLine.ToString() == "" || item.BudgetLine == 0)
{
XtraMessageBox.ShowWarningMessage("預(yù)算額度必須大于0!");
return;
}
foreach (PriceChangeCauseSKUInfo ob in item.PriceChangeCauseSKUList)
{
if (ob.SKULowerLimit > ob.SKUUpperLimit)
{
XtraMessageBox.ShowWarningMessage("選品SKU數(shù)量上限必須大于下限!");
gvChild.FocusedColumn = colSKUUpperLimit;
gvChild.FocusedRowHandle = int.Parse(ob.ChangeCauseCode) - 1;
return;
}
}
}
IList<PriceChangeSKUInfo> PriceChangeSKUList = bsParent.List as IList<PriceChangeSKUInfo>;
OperateReturnInfo opr = PriceChangeSKUManager.UpdatePriceChangeSKUInfo(dbNode, PriceChangeSKUList);
if (opr.ReturnCode == OperateCodeEnum.Warning)
{
XtraMessageBox.ShowWarningMessage("沒有可保存的數(shù)據(jù)!");
return;
}
XtraMessageBox.Show(opr);
gvChild.ShowEditor();
gvParent.ShowEditor();
}
catch (Exception ex)
{
throw;
}
}
private void btnOption_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
if (gcParent.Focused)
{
CustomColumnSelectForm f = new CustomColumnSelectForm(this.gvParent);
f.ShowDialog();
}
else
{
CustomColumnSelectForm f = new CustomColumnSelectForm(this.gvChild);
f.ShowDialog();
}
}
private void btnExit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
if (bsParent.Count > 0)
{
if (XtraMessageBox.Show("是否保存當(dāng)前檔期數(shù)據(jù)?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
{
btnSave_ItemClick(null, null);
}
}
this.Close();
}
#endregion
#region 聯(lián)想
private void associateInitDeptCode()
{
associateCategoryCode = new GridAssociate(dbNode, "colCategoryCode", AssociateManager, AssociateModeEnum.GoodsCategoryeyCode, null);
associateCategoryCode.BaseAssociate.Associated += new AssociateBase.AssociateEventHandler(BaseAssociate_Associated);
associateCategoryCode.CurrentConditions["categoryitemcode"] = "0000";
colCategoryCode.ColumnEdit = associateCategoryCode;
associateCategoryName = new GridAssociate(dbNode, "colCategoryName", AssociateManager, AssociateModeEnum.GoodsCategoryeyName, null);
associateCategoryName.BaseAssociate.Associated += new AssociateBase.AssociateEventHandler(BaseAssociate_Associated);
associateCategoryName.CurrentConditions["categoryitemcode"] = "0000";
colCategoryName.ColumnEdit = associateCategoryName;
}
void BaseAssociate_Associated(Bizcent.Client.Common.AssociateControl.AssociateEventArgs e)
{
try
{
gvParent.CloseEditor();
if (e.CurrentState == AssociateStateEnum.Normal)
{
PromotionPeriodInfo currentPromotion = bsPromotionPeriod.List[luePromotionPeriod.ItemIndex] as PromotionPeriodInfo;
if (luePromotionPeriod.Text == null || luePromotionPeriod.Text == "")
{
XtraMessageBox.ShowWarningMessage("請(qǐng)先選擇檔期!");
return;
}
DataRow dr = e.CurrentDataRow;
PriceChangeSKUInfo currentRow = bsParent.Current as PriceChangeSKUInfo;
currentRow.PromotionThemeCode = currentPromotion.PromotionThemeCode;
currentRow.PromotionPeriodCode = currentPromotion.PromotionPeriodCode;
currentRow.SubID = currentPromotion.SubID;
currentRow.CategoryCode = dr[0].ToString();
currentRow.CategoryName = dr[1].ToString();
if (currentRow == null) { return; }
int sameNumPanel = 0;
foreach (PriceChangeSKUInfo item in bsParent.List)
{
if (item.CategoryCode == currentRow.CategoryCode)
{
sameNumPanel++;
}
}
if (sameNumPanel > 1)
{
XtraMessageBox.ShowWarningMessage("二次品類編碼已存在!");
currentRow.CategoryCode = "";
currentRow.CategoryName = "";
bsParent.ResetBindings(false);
gvParent.FocusedColumn = colCategoryCode;
return;
}
IList<PriceChangeCauseSKUInfo> childList = PriceChangeSKUManager.LoadChild(dbNode, currentRow);
currentRow.PriceChangeCauseSKUList = childList;
bsChild.DataSource = childList;
bsChild.ResetBindings(false);
associateCategoryCode.CurrentValue = dr[0].ToString();
associateCategoryName.CurrentValue = dr[1].ToString();
bsParent.ResetBindings(false);
gvParent.FocusedColumn = colBudgetLine;
gvParent.ShowEditor();
}
}
catch (Exception ex)
{ XtraMessageBox.Show(ex); }
}
#endregion
#region 表格和控件事件
private void luePromotionPeriod_EditValueChanged(object sender, EventArgs e)
{
try
{
if (bsParent.Count > 0)
{
if (XtraMessageBox.Show("是否保存當(dāng)前檔期數(shù)據(jù)?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
{
btnSave_ItemClick(null, null);
}
PromotionPeriodInfo currentRow = bsPromotionPeriod.List[luePromotionPeriod.ItemIndex] as PromotionPeriodInfo;
deStart.Text = currentRow.BeginDate;
deEnd.Text = currentRow.EndDate;
IList<PriceChangeSKUInfo> parentList = PriceChangeSKUManager.LoadCategory(dbNode, currentRow);
if (parentList.Count == 0) { bsChild.Clear(); }
foreach (PriceChangeSKUInfo item in parentList)
{
item.PromotionThemeCode = currentRow.PromotionThemeCode;
item.PromotionPeriodCode = currentRow.PromotionPeriodCode;
item.SubID = currentRow.SubID;
}
bsParent.DataSource = parentList;
bsParent.ResetBindings(false);
if (parentList.Count > 0)
{
IList<PriceChangeCauseSKUInfo> childList = PriceChangeSKUManager.LoadChild(dbNode, parentList[0]);
parentList[0].PriceChangeCauseSKUList = childList;
bsChild.DataSource = parentList[0].PriceChangeCauseSKUList;
}
}
else
{
PromotionPeriodInfo currentRow = bsPromotionPeriod.List[luePromotionPeriod.ItemIndex] as PromotionPeriodInfo;
deStart.Text = currentRow.BeginDate;
deEnd.Text = currentRow.EndDate;
IList<PriceChangeSKUInfo> parentList = PriceChangeSKUManager.LoadCategory(dbNode, currentRow);
if (parentList.Count == 0) { bsChild.Clear(); }
foreach (PriceChangeSKUInfo item in parentList)
{
item.PromotionThemeCode = currentRow.PromotionThemeCode;
item.PromotionPeriodCode = currentRow.PromotionPeriodCode;
item.SubID = currentRow.SubID;
}
bsParent.DataSource = parentList;
bsParent.ResetBindings(false);
if (parentList.Count > 0)
{
IList<PriceChangeCauseSKUInfo> childList = PriceChangeSKUManager.LoadChild(dbNode, parentList[0]);
parentList[0].PriceChangeCauseSKUList = childList;
bsChild.DataSource = parentList[0].PriceChangeCauseSKUList;
}
}
}
catch (Exception ex)
{
XtraMessageBox.Show(ex);
}
}
private void gvParent_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
{
try
{
gvParent.CloseEditor();
gvChild.CloseEditor();
PriceChangeSKUInfo currentRow = bsParent.Current as PriceChangeSKUInfo;
if (currentRow == null) { return; }
PromotionPeriodInfo PromotionPeriod = bsPromotionPeriod.List[luePromotionPeriod.ItemIndex] as PromotionPeriodInfo;
currentRow.PromotionThemeCode = PromotionPeriod.PromotionThemeCode;
currentRow.PromotionPeriodCode = PromotionPeriod.PromotionPeriodCode;
currentRow.SubID = PromotionPeriod.SubID;
if (e.PrevFocusedRowHandle != GridControl.InvalidRowHandle && bsParent.Current != null
&& bsParent.Count != 0 && bsParent.Count > e.PrevFocusedRowHandle)
{
PriceChangeSKUInfo previousRow = bsParent[e.PrevFocusedRowHandle] as PriceChangeSKUInfo;
if (previousRow == null) { return; }
if (string.IsNullOrEmpty(previousRow.CategoryCode) && string.IsNullOrEmpty(previousRow.CategoryName))
{
bsParent.Remove(previousRow);
if (currentRow.CategoryCode != "")
{
if (currentRow.PriceChangeCauseSKUList.Count <= 0)
{
IList<PriceChangeCauseSKUInfo> childList = PriceChangeSKUManager.LoadChild(dbNode, currentRow);
currentRow.PriceChangeCauseSKUList = childList;
bsChild.DataSource = currentRow.PriceChangeCauseSKUList;
}
else
{
bsChild.DataSource = currentRow.PriceChangeCauseSKUList;
}
}
}
else
{
if (currentRow.CategoryCode != "")
{
if (currentRow.PriceChangeCauseSKUList.Count <= 0)
{
IList<PriceChangeCauseSKUInfo> childList = PriceChangeSKUManager.LoadChild(dbNode, currentRow);
currentRow.PriceChangeCauseSKUList = childList;
bsChild.DataSource = currentRow.PriceChangeCauseSKUList;
}
else
{
bsChild.DataSource = currentRow.PriceChangeCauseSKUList;
}
}
else
{
bsChild.DataSource = currentRow.PriceChangeCauseSKUList;
bsChild.ResetBindings(false);
}
}
//if (previousRow.CategoryCode == null || previousRow.CategoryCode == "")
//{
// XtraMessageBox.ShowWarningMessage("二級(jí)品類編碼不能為空!");
// gvParent.FocusedRowHandle = e.PrevFocusedRowHandle;
// return;
//}
//if (previousRow.CategoryName == null || previousRow.CategoryName == "")
//{
// XtraMessageBox.ShowWarningMessage("二級(jí)品類名稱不能為空!");
// gvParent.FocusedRowHandle = e.PrevFocusedRowHandle;
// return;
//}
//IList<PriceChangeCauseSKUInfo> tempList = bsChild.List as IList<PriceChangeCauseSKUInfo>;
//if (tempList == null) { return; }
//foreach (PriceChangeCauseSKUInfo item in tempList)
//{
// if (item.SKUUpperLimit < item.SKULowerLimit)
// {
// XtraMessageBox.ShowWarningMessage("選品SKU數(shù)量上限必須大于下限!");
// gvParent.FocusedRowHandle = e.PrevFocusedRowHandle;
// return;
// }
//}
//for (int i = 0; i < tempList.Count; i++)
//{
// PriceChangeCauseSKUInfo tempInfo = new PriceChangeCauseSKUInfo();
// tempInfo = CreateDeepCopy<PriceChangeCauseSKUInfo>(tempList[i]);
// previousRow.PriceChangeCauseSKUList.Add(tempInfo);
//}
//bsParent.ResetBindings(false);
//if (currentRow.CategoryCode != "")
//{
// if (currentRow.PriceChangeCauseSKUList.Count != 0)
// {
// bsChild.DataSource = currentRow.PriceChangeCauseSKUList;
// }
// else
// {
// LoadandBoundChildData(currentRow);
// }
//}
//else
//{ bsChild.Clear(); }
}
}
catch (Exception ex)
{
XtraMessageBox.Show(ex);
}
}
private void gvParent_KeyDown(object sender, KeyEventArgs e)
{
try
{
gvParent.CloseEditor();
if (e.KeyCode == Keys.Down)
{
if (gvParent.FocusedRowHandle == bsParent.Count - 1)
{
btnAddRow_ItemClick(null, null);
}
}
else if (e.KeyCode == Keys.Enter)
{
PriceChangeSKUInfo currentRow = bsParent.Current as PriceChangeSKUInfo;
if (gvParent.FocusedColumn == colBudgetLine && currentRow.BudgetLine != 0 && currentRow.BudgetLine.ToString() != ""
&& currentRow.CategoryCode != "" && currentRow.CategoryName != "")
{
btnAddRow_ItemClick(null, null);
}
}
gvParent.ShowEditor();
}
catch (Exception ex)
{
XtraMessageBox.Show(ex);
}
}
private void gvParent_MouseDown(object sender, MouseEventArgs e)
{
try
{
gvParent.CloseEditor();
GridHitInfo hInfo = gvParent.CalcHitInfo(new Point(e.X, e.Y));
if (hInfo.HitTest.ToString() == "EmptyRow")
{
btnAddRow_ItemClick(null, null);
}
}
catch (Exception ex)
{
XtraMessageBox.Show(ex);
}
}
private void repositoryItemTextEdit4_EditValueChanged(object sender, EventArgs e)
{
}
private void gvChild_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
{
try
{
gvChild.CloseEditor();
PriceChangeCauseSKUInfo currentRow = bsChild.Current as PriceChangeCauseSKUInfo;
if (currentRow == null) { return; }
if (currentRow.SKULowerLimit.ToString() != "" && currentRow.SKUUpperLimit.ToString() != "" && currentRow.SKUUpperLimit != 0)
{
if (currentRow.SKULowerLimit > currentRow.SKUUpperLimit)
{
XtraMessageBox.ShowWarningMessage("選品SKU數(shù)量上限必須大于下限!");
return;
}
}
gvChild.ShowEditor();
}
catch (Exception ex)
{
XtraMessageBox.Show(ex);
}
}
private void gvChild_KeyDown(object sender, KeyEventArgs e)
{
gvChild.CloseEditor();
if (e.KeyCode == Keys.Enter)
{
if (gvChild.FocusedColumn == colPlanSKUNum)
{
gvChild.FocusedColumn = colSKULowerLimit;
return;
}
if (gvChild.FocusedColumn == colSKULowerLimit)
{
gvChild.FocusedColumn = colSKUUpperLimit;
return;
}
PriceChangeCauseSKUInfo currentRow = bsChild.Current as PriceChangeCauseSKUInfo;
if (gvChild.FocusedColumn == colSKUUpperLimit && currentRow.PlanSKUNum.ToString() != "" && currentRow.SKULowerLimit.ToString() != ""
&& currentRow.SKUUpperLimit.ToString() != "" && currentRow.SKUUpperLimit >= currentRow.SKULowerLimit)
{
gvChild.MoveNext();
gvChild.FocusedColumn = colPlanSKUNum;
}
}
gvChild.ShowEditor();
}
#endregion
}
}