雙gridview聯(lián)動(dòng)模塊

主要是控制指針實(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
    }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末昵济,一起剝皮案震驚了整個(gè)濱河市拨齐,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌壹罚,老刑警劉巖,帶你破解...
    沈念sama閱讀 219,427評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異整袁,居然都是意外死亡账忘,警方通過查閱死者的電腦和手機(jī)志膀,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,551評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來鳖擒,“玉大人溉浙,你說我怎么就攤上這事〗裕” “怎么了戳稽?”我有些...
    開封第一講書人閱讀 165,747評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)期升。 經(jīng)常有香客問我惊奇,道長(zhǎng)互躬,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,939評(píng)論 1 295
  • 正文 為了忘掉前任颂郎,我火速辦了婚禮吼渡,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘乓序。我一直安慰自己寺酪,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,955評(píng)論 6 392
  • 文/花漫 我一把揭開白布竭缝。 她就那樣靜靜地躺著房维,像睡著了一般。 火紅的嫁衣襯著肌膚如雪抬纸。 梳的紋絲不亂的頭發(fā)上咙俩,一...
    開封第一講書人閱讀 51,737評(píng)論 1 305
  • 那天,我揣著相機(jī)與錄音湿故,去河邊找鬼阿趁。 笑死,一個(gè)胖子當(dāng)著我的面吹牛坛猪,可吹牛的內(nèi)容都是我干的脖阵。 我是一名探鬼主播,決...
    沈念sama閱讀 40,448評(píng)論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼墅茉,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼命黔!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起就斤,我...
    開封第一講書人閱讀 39,352評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤悍募,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后洋机,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體坠宴,經(jīng)...
    沈念sama閱讀 45,834評(píng)論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,992評(píng)論 3 338
  • 正文 我和宋清朗相戀三年绷旗,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了喜鼓。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,133評(píng)論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡衔肢,死狀恐怖庄岖,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情膀懈,我是刑警寧澤顿锰,帶...
    沈念sama閱讀 35,815評(píng)論 5 346
  • 正文 年R本政府宣布,位于F島的核電站,受9級(jí)特大地震影響硼控,放射性物質(zhì)發(fā)生泄漏刘陶。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,477評(píng)論 3 331
  • 文/蒙蒙 一牢撼、第九天 我趴在偏房一處隱蔽的房頂上張望匙隔。 院中可真熱鬧,春花似錦熏版、人聲如沸纷责。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,022評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)再膳。三九已至,卻和暖如春曲横,著一層夾襖步出監(jiān)牢的瞬間喂柒,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,147評(píng)論 1 272
  • 我被黑心中介騙來泰國(guó)打工禾嫉, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留灾杰,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,398評(píng)論 3 373
  • 正文 我出身青樓熙参,卻偏偏與公主長(zhǎng)得像艳吠,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子孽椰,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,077評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 172,185評(píng)論 25 707
  • 用兩張圖告訴你昭娩,為什么你的 App 會(huì)卡頓? - Android - 掘金 Cover 有什么料? 從這篇文章中你...
    hw1212閱讀 12,732評(píng)論 2 59
  • Swift1> Swift和OC的區(qū)別1.1> Swift沒有地址/指針的概念1.2> 泛型1.3> 類型嚴(yán)謹(jǐn) 對(duì)...
    cosWriter閱讀 11,105評(píng)論 1 32
  • 一個(gè)獨(dú)自住在湖邊木房子里的老頭,每天釣魚削彬、回憶往事全庸、煮魚……日子過得簡(jiǎn)單而平靜。有一天當(dāng)一輛汽車駛來融痛,留下三個(gè)人:...
    王琰嘿嘿閱讀 595評(píng)論 0 0
  • 巳三雁刷、至夜後分速悎悟等(分三科)午一覆劈、徵 【云何至夜後分速疾覺寤,經(jīng)行宴坐從順障法淨(jìng)修其心?】 這是第三科「至夜後...
    德虔閱讀 523評(píng)論 0 1