双gridview联动模块

主要是控制指针实现两个gridview联动

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>
        /// 读取导入模板
        /// </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>
        /// 权限
        /// </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数据完整
        /// </summary>
        private string CheckgvParent()
        {
            gvParent.CloseEditor();
            PriceChangeSKUInfo currentRow = bsParent.Current as PriceChangeSKUInfo;
            if (currentRow == null) { return null; }
            if (currentRow.CategoryCode == null || currentRow.CategoryCode == "")
            {
                return "二级品类编码不能为空!";

            }
            if (currentRow.CategoryName == null || currentRow.CategoryName == "")
            {
                return "二级品类名称不能为空!";
            }
            if (currentRow.BudgetLine == null || currentRow.BudgetLine.ToString() == "" || currentRow.BudgetLine == 0)
            {
                return "预算额度必须大于0!";
            }
            return "";
        }

        /// <summary>
        /// 查询并绑定gvChild的数据
        /// </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("请先选择档期!");
                    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("确认删除?", "提示", 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("无导入模板!");
                    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;//导入的文件中数据的条数
                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("导入必须包含字段:促销主题编码,档期编码,子档号,二级品类编码,预算额度,变价原因编码,规划SKU数量,选品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 验证数据有效性

                    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) + "行" + "子档号不存在!");
                            continue;
                        }
                    }
                    else
                    {
                        errorInfos.Add("第" + (i + 1) + "行" + "子档号不能为空!");
                        continue;
                    }
                    if (!string.IsNullOrEmpty(dr["CategoryCode"].ToString()))
                    {
                        string CategoryCode = PriceChangeSKUManager.LoadtbGoodsCategory(dbNode, dr["CategoryCode"].ToString());
                        if (string.IsNullOrEmpty(CategoryCode))
                        {
                            errorInfos.Add("第" + (i + 1) + "行" + "二级分类编码不存在!");
                            continue;
                        }
                    }
                    else
                    {
                        errorInfos.Add("第" + (i + 1) + "行" + "二级分类编码不能为空!");
                        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) + "行" + "预算额度只能输入正整数!");
                            continue;
                        }
                    }
                    else
                    {
                        errorInfos.Add("第" + (i + 1) + "行" + "预算额度不能为空!");
                        continue;
                    }
                    if (!string.IsNullOrEmpty(dr["ChangeCauseCode"].ToString()))
                    {
                        string ChangeCauseCode = PriceChangeSKUManager.LoadChangePriceCause(dbNode, dr["ChangeCauseCode"].ToString());
                        if (string.IsNullOrEmpty(ChangeCauseCode))
                        {
                            errorInfos.Add("第" + (i + 1) + "行" + "变价原因编码不存在!");
                            continue;
                        }
                    }
                    else
                    {
                        errorInfos.Add("第" + (i + 1) + "行" + "变价原因编码不能为空!");
                        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) + "行" + "规划SKU数量只能输入非负整数!");
                            continue;
                        }
                    }
                    else
                    {
                        errorInfos.Add("第" + (i + 1) + "行" + "规划SKU数量不能为空!");
                        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下限只能输入非负整数!");
                            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上限只能输入非负整数!");
                            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 导入数据自身去重
                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) + "行重复");
                            }
                        }
                    }
                }
                #endregion

                //resultList = PriceChangeSKUManager.LoadNames(dbNode, resultList);//填补/修正 名称信息
                //if (resultList.Count <= 0)
                //{
                //    XtraMessageBox.ShowErrorMessage("没有导入任何数据!");
                //    return;
                //}
                //if (opr.ReturnCode == OperateCodeEnum.Warning)
                //{
                //    XtraMessageBox.ShowErrorMessage("没有导入任何数据!");
                //    return;
                //}

                StringBuilder sb = new StringBuilder();
                sb.Append("导入成功[" + (resultList.Count) + "]行\r\n导入失败[" + (ImportNumber - resultList.Count) + "]行" + "\r\n");
                if (errorInfos.Count > 0)
                {
                    sb.Append("以下数据验证失败:" + "\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("已成功导入" + ImportNumber + "行"); }

                if (resultList.Count == 0) { return; }
                OperateReturnInfo opr = PriceChangeSKUManager.UpdatePriceChangeSKUInfo(dbNode, resultList);
                if (opr.ReturnCode == OperateCodeEnum.Failed)
                {
                    XtraMessageBox.ShowErrorMessage("导入失败!");
                    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("没有可保存的数据!");
                    return;
                }

                foreach (PriceChangeSKUInfo item in bsParent.List)
                {
                    if (item == null) { return; }
                    if (item.CategoryCode == null || item.CategoryCode == "")
                    {
                        XtraMessageBox.ShowWarningMessage("二级品类编码不能为空!");
                        return;
                    }
                    if (item.CategoryName == null || item.CategoryName == "")
                    {
                        XtraMessageBox.ShowWarningMessage("二级品类名称不能为空!");
                        return;
                    }
                    if (item.BudgetLine == null || item.BudgetLine.ToString() == "" || item.BudgetLine == 0)
                    {
                        XtraMessageBox.ShowWarningMessage("预算额度必须大于0!");
                        return;
                    }
                    foreach (PriceChangeCauseSKUInfo ob in item.PriceChangeCauseSKUList)
                    {
                        if (ob.SKULowerLimit > ob.SKUUpperLimit)
                        {
                            XtraMessageBox.ShowWarningMessage("选品SKU数量上限必须大于下限!");
                            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("没有可保存的数据!");
                    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("是否保存当前档期数据?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                {
                    btnSave_ItemClick(null, null);
                }
            }
            this.Close();
        }
        #endregion

        #region 联想
        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("请先选择档期!");
                        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("是否保存当前档期数据?", "提示", 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("二级品类编码不能为空!");
                    //    gvParent.FocusedRowHandle = e.PrevFocusedRowHandle;
                    //    return;
                    //}
                    //if (previousRow.CategoryName == null || previousRow.CategoryName == "")
                    //{
                    //    XtraMessageBox.ShowWarningMessage("二级品类名称不能为空!");
                    //    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数量上限必须大于下限!");
                    //        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数量上限必须大于下限!");
                        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
    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 202,905评论 5 476
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,140评论 2 379
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 149,791评论 0 335
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,483评论 1 273
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,476评论 5 364
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,516评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,905评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,560评论 0 256
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,778评论 1 296
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,557评论 2 319
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,635评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,338评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,925评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,898评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,142评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,818评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,347评论 2 342

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 171,376评论 25 707
  • 用两张图告诉你,为什么你的 App 会卡顿? - Android - 掘金 Cover 有什么料? 从这篇文章中你...
    hw1212阅读 12,680评论 2 59
  • Swift1> Swift和OC的区别1.1> Swift没有地址/指针的概念1.2> 泛型1.3> 类型严谨 对...
    cosWriter阅读 11,082评论 1 32
  • 一个独自住在湖边木房子里的老头,每天钓鱼、回忆往事、煮鱼……日子过得简单而平静。有一天当一辆汽车驶来,留下三个人:...
    王琰嘿嘿阅读 582评论 0 0
  • 巳三、至夜後分速悎悟等(分三科)午一、徵 【云何至夜後分速疾覺寤,經行宴坐從順障法淨修其心?】 這是第三科「至夜後...
    德虔阅读 507评论 0 1