谁占用了CRIS

某模块代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Bizcent.Client.Common;
using Bizcent.IManager.MDM;
using Bizcent.IManager.Common;
using Bizcent.Model.MDM;
using XtraMessageBox = Bizcent.Client.Common.XtraMessageBox;
using Bizcent.Common.OptReturn;
using Bizcent.Model.Common;
using System.Collections;
using Bizcent.IManager.SMS;
using System.IO;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using System.Text.RegularExpressions;
using DevExpress.XtraGrid;

namespace Bizcent.Client.MDM
{
    public partial class FrmGoodsRetraCtrlListMainte : BaseForm
    {
        #region 接口和变量
        private IManagerGoodsRetraceMaintenceList GoodsRetraceMaintenceListManager_OMP { get; set; }
        private IManagerAssociate AssociateManager { get; set; }
        private IDictionary<string, string> dicHanye = null;
        private GridAssociate associateSupplierCode;
        private GridAssociate associateSupplierName;
        private GridAssociate associateGoodsCode;
        private GridAssociate associateGoodsName;
        private NodeInfo dbNode = CurrentLogin.Node;
        private NodeInfo OrderCenterNode = CurrentLogin.OrderCenter;
        FormatMaster _PrintTemp = null;
        private IManagerIO IOManager { get; set; }
        private IManagerGoods GoodsManager { get; set; }
        private IManagerSupplier SupplierManager { get; set; }
        private IManagerUser UserManager { get; set; }
        string fileName = string.Empty;
        string userCode = CurrentLogin.CurrentUser.Employee.EmployeeCode;
        string userName = CurrentLogin.CurrentUser.Employee.EmployeeName;
        #endregion

        #region 私有方法
        /// <summary>
        /// 读取导入模板
        /// </summary>
        private void LoadImportTemp()
        {
            IList types = IOManager.LoadIOFormatFrm(dbNode, this.Name);
            if (types != null && types.Count != 0)
            {
                FormatMaster fm = types[0] as FormatMaster;
                this.bsTencil.DataSource = types;
                bsTencil.ResetBindings(true);
                _PrintTemp = fm;
                this.btnImportTencil.EditValue = fm.FormatCode;
            }
        }

        /// <summary>
        /// 权限
        /// </summary>
        /// <returns></returns>
        private bool SetPurview()
        {
            bool allow = true;
            IList purviewList = null;
            try
            {
                purviewList = UserManager.LoadUserModulePurviews(dbNode, CurrentLogin.CurrentUser.Employee.EmployeeCode, this.Tag.ToString());
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex);
                allow = false;
                return allow;
            }
            if (!purviewList.Contains(OperateInfo.Browse))
            {
                allow = false;
                return allow;
            }
            if (!purviewList.Contains(OperateInfo.Maintain))
            {
                btnAdd.Enabled = false;
                btnDelete.Enabled = false;
                btnSave.Enabled = false;
                btnImportTencil.Enabled = false;
                btnImport.Enabled = false;
                btnQuery.Enabled = false;
                gvMaintenanceList.OptionsBehavior.Editable = false;
                allow = false;
                return allow;
            }
            return allow;
        }
        #endregion

        #region 按钮事件

        //增行
        private void btnAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                GoodsRetraceMaintenceListInfo currentrow = bsMaintenceList.Current as GoodsRetraceMaintenceListInfo;
                if (currentrow != null)
                {
                    if ((currentrow.GoodsCode == null || currentrow.GoodsCode == ""))
                    {
                        XtraMessageBox.ShowErrorMessage("请联想商品信息");
                        return;
                    }
                    if ((currentrow.GoodsName == null || currentrow.GoodsName == ""))
                    {
                        XtraMessageBox.ShowErrorMessage("请联想商品信息");
                        return;
                    }
                    if ((currentrow.SupplierCode == null || currentrow.SupplierCode == ""))
                    {
                        XtraMessageBox.ShowErrorMessage("请联想供应商信息");
                        return;
                    }
                    if ((currentrow.SupplierName == null || currentrow.SupplierName == ""))
                    {
                        XtraMessageBox.ShowErrorMessage("请联想供应商信息");
                        return;
                    }
                    if (currentrow.RemainDDays == null)
                    {
                        XtraMessageBox.ShowErrorMessage("请填写档期提醒天数");
                        return;
                    }
                }
                gvMaintenanceList.CloseEditor();
                GoodsRetraceMaintenceListInfo MaintenceInfo = new GoodsRetraceMaintenceListInfo();
                MaintenceInfo.IsNew = true;
                bsMaintenceList.Add(MaintenceInfo);
                bsMaintenceList.ResetBindings(false);
                this.gvMaintenanceList.FocusedRowHandle = this.gvMaintenanceList.DataRowCount - 1;
                gvMaintenanceList.FocusedColumn = gcolSupplierCode;
                gvMaintenanceList.Columns[1].OptionsColumn.AllowEdit = true;
                gvMaintenanceList.Columns[2].OptionsColumn.AllowEdit = true;
                gvMaintenanceList.Columns[3].OptionsColumn.AllowEdit = true;
                gvMaintenanceList.Columns[4].OptionsColumn.AllowEdit = true;
                gvMaintenanceList.Columns[5].OptionsColumn.AllowEdit = true;
                gvMaintenanceList.ShowEditor();
            }
            catch (Exception ex)
            {

                XtraMessageBox.Show(ex);
            }
        }

        //删除
        private void btnDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                labelControl1.Focus();
                string LogTime = CurrentLogin.SysParam.GetCurrentDate().ToString("yyyyMMddHHmmss");
                IList<GoodsRetraceMaintenceListInfo> AllItem = bsMaintenceList.List as IList<GoodsRetraceMaintenceListInfo>;
                int allItemNum = AllItem.Count;
                if (allItemNum > 0)
                {
                    if (XtraMessageBox.Show("确认删除?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                    {
                        IList<GoodsRetraceMaintenceListInfo> deleteItem = new List<GoodsRetraceMaintenceListInfo>();
                        for (int i = 0; i < allItemNum; i++)
                        {
                            if (AllItem[i].IsChoosen == true)
                            {
                                deleteItem.Add(AllItem[i]);
                                if (AllItem[i].IsNew == false)
                                {
                                    #region 记录删除日志
                                    AllItem[i].OperatorTime = LogTime;
                                    AllItem[i].OperatorCode = userCode;
                                    AllItem[i].OperatorName = userName;
                                    AllItem[i].OperatorType = 1;
                                    AllItem[i].OperateContent = "删除供应商编码为" + AllItem[i].SupplierCode.ToString() + "商品编码为"
                                        + AllItem[i].GoodsCode.ToString() + "档期提醒天数为" + AllItem[i].RemainDDays.ToString();
                                    #endregion
                                }
                            }
                        }
                        if (deleteItem.Count == 0)
                        {
                            XtraMessageBox.ShowWarningMessage("未勾选要删除的数据");
                            return;
                        }
                        OperateReturnInfo Msg = GoodsRetraceMaintenceListManager_OMP.DeleteGoodsRetrace(OrderCenterNode, deleteItem);
                        if (Msg.ReturnCode == OperateCodeEnum.Success)
                        {
                            foreach (GoodsRetraceMaintenceListInfo item in deleteItem)
                            {
                                bsMaintenceList.Remove(item);
                            }
                        }
                        else
                        {
                            foreach (GoodsRetraceMaintenceListInfo item in deleteItem)
                            {
                                if (item.IsNew == true)
                                    bsMaintenceList.Remove(item);
                            }
                        }
                        bsMaintenceList.ResetBindings(false);
                    }
                }
            }
            catch (Exception ex)
            {

                XtraMessageBox.Show(ex);
            }
        }

        //查询
        private void btnQuery_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                string ConditionGoodsCode = string.Empty;
                if (!string.IsNullOrEmpty(txtGoodsCode.Text.ToString().Trim()))
                {
                    ConditionGoodsCode = txtGoodsCode.Text.ToString().Trim();
                }
                string ConditionSupplierCode = string.Empty;
                if (!string.IsNullOrEmpty(txtSupplierCode.Text.ToString().Trim()))
                {
                    ConditionSupplierCode = txtSupplierCode.Text.ToString().Trim();
                }

                bsMaintenceList.Clear();
                IList<GoodsRetraceMaintenceListInfo> TempList = GoodsRetraceMaintenceListManager_OMP.LoadGoodsRetraceMaintenceList(OrderCenterNode, ConditionGoodsCode, ConditionSupplierCode);
                if (TempList.Count == 0) { return; }
                IList<GoodsRetraceMaintenceListInfo> QueryList = GoodsRetraceMaintenceListManager_OMP.LoadGoodsNameAndSupplierName(OrderCenterNode, TempList);
                if (QueryList.Count != 0)
                {
                    bsMaintenceList.DataSource = QueryList;
                    bsMaintenceList.ResetBindings(false);
                }
            }
            catch (Exception ex)
            {

                XtraMessageBox.Show(ex);
            }

        }

        //保存
        private void btnSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                gvMaintenanceList.CloseEditor();
                string LogTime = CurrentLogin.SysParam.GetCurrentDate().ToString("yyyyMMddHHmmss");
                IList<GoodsRetraceMaintenceListInfo> ListToSave = new List<GoodsRetraceMaintenceListInfo>();
                IList<GoodsRetraceMaintenceListInfo> AllItem = bsMaintenceList.List as IList<GoodsRetraceMaintenceListInfo>;
                for (int i = 0; i < AllItem.Count; i++)
                {
                    if (AllItem[i].IsNew == true && !string.IsNullOrEmpty(AllItem[i].GoodsCode) && !string.IsNullOrEmpty(AllItem[i].SupplierCode) && !string.IsNullOrEmpty(AllItem[i].GoodsName) 
                        && !string.IsNullOrEmpty(AllItem[i].SupplierName) && !string.IsNullOrEmpty(AllItem[i].RemainDDays.ToString()))
                    {
                        AllItem[i].IsNew = false;
                        #region 记录增行日志
                        AllItem[i].OperatorTime = LogTime;
                        AllItem[i].OperatorCode = userCode;
                        AllItem[i].OperatorName = userName;
                        AllItem[i].OperatorType = 0;
                        AllItem[i].OperateContent = "增加供应商编码为" + AllItem[i].SupplierCode.ToString() + "商品编码为"
    + AllItem[i].GoodsCode.ToString() + "档期提醒天数为" + AllItem[i].RemainDDays.ToString();
                        ListToSave.Add(AllItem[i]);
                        #endregion
                    }
                    else if (AllItem[i].IsNew == true && (!string.IsNullOrEmpty(AllItem[i].GoodsCode) || !string.IsNullOrEmpty(AllItem[i].SupplierCode) || !string.IsNullOrEmpty(AllItem[i].GoodsName) 
                        || !string.IsNullOrEmpty(AllItem[i].SupplierName) || !string.IsNullOrEmpty(AllItem[i].RemainDDays.ToString())))
                    {
                        XtraMessageBox.ShowWarningMessage("请完善第" + (i + 1) + "行数据后再保存!");
                        return;
                    }
                }
                if (ListToSave.Count == 0) { XtraMessageBox.Show("没有可保存的数据"); return; }
                OperateReturnInfo Msg = GoodsRetraceMaintenceListManager_OMP.SaveGoodsRetraceMaintenceList(OrderCenterNode, ListToSave);
                if (Msg.ReturnCode == OperateCodeEnum.Success)
                    bsMaintenceList.Clear();
                XtraMessageBox.Show(Msg);
            }
            catch (Exception ex)
            {

                XtraMessageBox.Show(ex);
            }

        }

        //导入
        private void btnImport_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                if (bsMaintenceList.Count > 0)
                {
                    GoodsRetraceMaintenceListInfo currentrow = bsMaintenceList.List[bsMaintenceList.Count - 1] as GoodsRetraceMaintenceListInfo;
                    if (currentrow != null)
                    {
                        if ((currentrow.GoodsCode == null || currentrow.GoodsCode == "") && (currentrow.SupplierCode == null || currentrow.SupplierCode == ""))
                        {
                            bsMaintenceList.RemoveAt(bsMaintenceList.Count - 1);
                        }
                        else
                        {
                            if ((currentrow.GoodsCode == null || currentrow.GoodsCode == ""))
                            {
                                XtraMessageBox.ShowErrorMessage("请联想商品信息");
                                return;
                            }
                            if ((currentrow.GoodsName == null || currentrow.GoodsName == ""))
                            {
                                XtraMessageBox.ShowErrorMessage("请联想商品信息");
                                return;
                            }
                            if ((currentrow.SupplierCode == null || currentrow.SupplierCode == ""))
                            {
                                XtraMessageBox.ShowErrorMessage("请联想供应商信息");
                                return;
                            }
                            if ((currentrow.SupplierName == null || currentrow.SupplierName == ""))
                            {
                                XtraMessageBox.ShowErrorMessage("请联想供应商信息");
                                return;
                            }
                            if (currentrow.RemainDDays == null)
                            {
                                XtraMessageBox.ShowErrorMessage("请填写档期提醒天数");
                                return;
                            }
                        }
                    }
                }

                if (_PrintTemp == null)
                {
                    XtraMessageBox.ShowWarningMessage("无导入模板!");
                    return;
                }
                if (bsMaintenceList.List.Count > 0)
                {
                    if (XtraMessageBox.ShowQuestionMessage("是否清空界面数据?") == DialogResult.OK)
                    {
                        bsMaintenceList.Clear();
                    }
                }

                FormatMaster fm = IOManager.LoadIOFormat(dbNode, this.btnImportTencil.EditValue.ToString());
                DataTable dt = new EasyImporter(IOManager).File2DataTable(fm.FormatCode);
                if (dt == null || dt.Rows.Count == 0) return;
                int ImportNumber = dt.Rows.Count;//导入的文件中数据的条数
                if (!dt.Columns.Contains("GoodsCode") || !dt.Columns.Contains("SupplierCode"))
                {
                    XtraMessageBox.ShowErrorMessage("导入必须包含字段:商品编码,供应商编码!");
                    return;
                }
                List<string> errorInfos = new List<string>();
                IList<GoodsRetraceMaintenceListInfo> resultList = new List<GoodsRetraceMaintenceListInfo>();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataRow dr = dt.Rows[i];
                    if (dr == null) continue;

                    #region 验证数据有效性

                    if (!string.IsNullOrEmpty(dr["GoodsCode"].ToString()))
                    {
                        GoodsInfo goods = GoodsManager.LoadGoods(OrderCenterNode, dr["GoodsCode"].ToString(), new ArrayList());
                        if (goods == null || string.IsNullOrEmpty(goods.GoodsCode))
                        {
                            errorInfos.Add("" + (i + 1) + "" + "商品编码不存在!");
                            continue;
                        }
                    }
                    if (!string.IsNullOrEmpty(dr["SupplierCode"].ToString()))
                    {
                        SupplierInfo supplier = SupplierManager.LoadSupplier(OrderCenterNode, dr["SupplierCode"].ToString());
                        if (supplier == null || string.IsNullOrEmpty(supplier.SupplierCode))
                        {
                            errorInfos.Add("" + (i + 1) + "" + "供应商编码不存在!");
                            continue;
                        }
                    }
                    if (!string.IsNullOrEmpty(dr["Remainddays"].ToString()))
                    {
                        string remainday = dr["Remainddays"].ToString();
                        string pattern = "^[1-9]\\d*$|0$";
                        if (!Regex.IsMatch(remainday, pattern))
                        {
                            errorInfos.Add("" + (i + 1) + "" + "档案提醒天数只能输入非负整数!");
                            continue;
                        }
                    }
                    #endregion

                    resultList.Add(new GoodsRetraceMaintenceListInfo()
                    {
                        IsNew = true,
                        GoodsCode = dr["GoodsCode"].ToString(),
                        SupplierCode = dr["SupplierCode"].ToString(),
                        RemainDDays = int.Parse(dr["RemainDDays"].ToString()),
                    });

                }

                for (int i = 0; i < resultList.Count; i++)
                {
                    string errorInfo = (GoodsRetraceMaintenceListManager_OMP.CheckIsExsited(OrderCenterNode, resultList[i]));
                    if (errorInfo != "")
                    {
                        errorInfos.Add("供应商编码为" + resultList[i].SupplierCode + "商品编码为" + resultList[i].GoodsCode + errorInfo);
                        resultList.Remove(resultList[i]);
                    }
                }

                #region 导入数据自身去重
                for (int i = 0; i < resultList.Count; i++)
                {
                    int CopyNumber = 0;
                    for (int j = 0; j < resultList.Count; j++)
                    {
                        if (resultList[i].GoodsCode == resultList[j].GoodsCode && resultList[i].SupplierCode == resultList[j].SupplierCode)
                        {
                            if (i != j)
                            {
                                CopyNumber++;
                                errorInfos.Add("" + (i + 1) + "行与第" + (j + 1) + "行重复");
                            }
                        }
                    }
                    if (CopyNumber > 0)
                    {
                        resultList.Remove(resultList[i]);
                    }
                }
                #endregion

                resultList = GoodsRetraceMaintenceListManager_OMP.LoadGoodsNameAndSupplierName(OrderCenterNode, resultList);//填补/修正 商品名称和供应商名称信息

                #region 界面原有数据和导入数据去重
                IList<GoodsRetraceMaintenceListInfo> ExistedData = bsMaintenceList.List as IList<GoodsRetraceMaintenceListInfo>;
                //IList<GoodsRetraceMaintenceListInfo> preImport = new List<GoodsRetraceMaintenceListInfo>();
                int ExistedNumber = ExistedData.Count;//原先界面数据的条数
                if (ExistedData != null && ExistedData.Count != 0 && resultList.Count != 0 && resultList != null)
                {
                    for (int i = 0; i < resultList.Count; i++)
                    {
                        ExistedData.Add(resultList[i]);
                    }
                    for (int i = 0; i < ExistedData.Count; i++)
                    {
                        int sameNum = 0;
                        for (int j = i + 1; j < ExistedData.Count; j++)
                        {
                            if (ExistedData[i].GoodsCode == ExistedData[j].GoodsCode && ExistedData[j].SupplierCode == ExistedData[i].SupplierCode)
                            {
                                sameNum++;
                            }
                        }
                        if (sameNum > 0)
                        {
                            errorInfos.Add("商品编码为" + ExistedData[i].GoodsCode + "供应商编码为" + ExistedData[i].SupplierCode + "的数据界面上已存在!");
                            ExistedData.RemoveAt(i);
                        }
                    }
                    //for (int i = 0; i < ExistedData.Count; i++)
                    //{
                    //    for (int j = 0; j < resultList.Count; j++)
                    //    {
                    //        if (resultList[j].GoodsCode != ExistedData[i].GoodsCode || resultList[j].SupplierCode != ExistedData[i].SupplierCode)
                    //        {
                    //            errorInfos.Add("商品编码为" + resultList[j].GoodsCode + "供应商编码为" + resultList[j].SupplierCode + "的数据界面上已存在!");
                    //            continue;
                    //        }
                    //        else
                    //        {
                    //            preImport.Add(resultList[j]);
                    //        }
                    //    }
                    //}
                    //if (preImport.Count > 0)
                    //{
                    //    foreach (GoodsRetraceMaintenceListInfo ImportItem in preImport)
                    //    {
                    //        ExistedData.Add(ImportItem);
                    //    }
                    //}
                }
                else
                {
                    foreach (GoodsRetraceMaintenceListInfo ImportItem in resultList)
                    {
                        ExistedData.Add(ImportItem);
                    }
                }
                #endregion

                StringBuilder sb = new StringBuilder();
                sb.Append("导入成功[" + (ExistedData.Count - ExistedNumber) + "]行\r\n导入失败[" + (ImportNumber - (ExistedData.Count - ExistedNumber)) + "]行" + "\r\n");//ExistedData.Count为导入完成后界面的数据总条数
                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("已成功导入" + (ExistedData.Count - ExistedNumber) + ""); }
                bsMaintenceList.ResetBindings(false);
            }
            catch (Exception ex)
            {

                XtraMessageBox.Show(ex);
            }

        }

        //导出
        private void btnExport_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                if ((this.gvMaintenanceList != null))
                {
                    if (this.bsMaintenceList.Count == 0) { return; }
                    FrmExport2CSV frm = new FrmExport2CSV(this.gvMaintenanceList);
                    frm.ShowDialog();
                }
            }
            catch (Exception ex)
            {

                XtraMessageBox.Show(ex);
            }
        }

        //全清
        private void btnAllClear_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                if (bsMaintenceList.List.Count > 0)
                {
                    if (XtraMessageBox.Show("将清除所有商品追溯控制清单数据是否继续?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                    {
                        bsMaintenceList.Clear();
                        txtGoodsCode.Text = string.Empty;
                        txtSupplierCode.Text = string.Empty;
                        btnQuery_ItemClick(null, null);
                        bsMaintenceList.ResetBindings(false);

                        #region 记录全清日志
                        string LogTime = CurrentLogin.SysParam.GetCurrentDate().ToString("yyyyMMddHHmmss");
                        IList<GoodsRetraceMaintenceListInfo> allItemList = GoodsRetraceMaintenceListManager_OMP.LoadGoodsRetraceMaintenceList(OrderCenterNode, "", "");
                        foreach (GoodsRetraceMaintenceListInfo item in allItemList)
                        {
                            item.OperatorTime = LogTime;
                            item.OperatorCode = userCode;
                            item.OperatorName = userName;
                            item.OperatorType = 2;
                            string operateContent = string.Empty;
                            item.OperateContent = "全清" + "供应商编码为" + item.SupplierCode + "商品编码为" + item.GoodsCode + "档期提醒天数" + item.RemainDDays;
                        }
                        #endregion
                        OperateReturnInfo Msg = GoodsRetraceMaintenceListManager_OMP.DeleteAll(OrderCenterNode, allItemList);
                        if (Msg.ReturnCode == OperateCodeEnum.Success)
                        {
                            bsMaintenceList.Clear();
                            XtraMessageBox.Show("数据库数据已全部清空");
                        }

                    }
                }
            }
            catch (Exception ex)
            {

                XtraMessageBox.Show(ex);
            }
        }

        //退出
        private void btnExit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                int newItem = 0;
                foreach (GoodsRetraceMaintenceListInfo item in bsMaintenceList.List)
                {
                    if (item.IsNew) { newItem++; }
                    if (newItem > 0) { break; }
                }
                if (newItem > 0)
                {
                    if (XtraMessageBox.Show("放弃已有数据?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.Cancel)
                    {
                        return;
                    }
                }
                this.Close();
            }
            catch (Exception ex)
            {

                XtraMessageBox.Show(ex);
            }
        }

        private void bbiChooseall_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                foreach (GoodsRetraceMaintenceListInfo item in bsMaintenceList.List)
                {
                    item.IsChoosen = true;
                }
                bsMaintenceList.ResetBindings(false);
            }
            catch (Exception ex)
            {

                XtraMessageBox.Show(ex);
            }
        }

        private void bbiChoosenone_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                foreach (GoodsRetraceMaintenceListInfo item in bsMaintenceList.List)
                {
                    item.IsChoosen = false;
                }
                bsMaintenceList.ResetBindings(false);
            }
            catch (Exception ex)
            {

                XtraMessageBox.Show(ex);
            }
        }

        private void bbiChooseinverse_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                foreach (GoodsRetraceMaintenceListInfo item in bsMaintenceList.List)
                {
                    item.IsChoosen = !item.IsChoosen;
                }
                bsMaintenceList.ResetBindings(false);
            }
            catch (Exception ex)
            {

                XtraMessageBox.Show(ex);
            }
        }
        #endregion

        #region 窗体加载
        public FrmGoodsRetraCtrlListMainte()
        {
            InitializeComponent();
        }
        private void FrmGoodsRetraCtrlListMainte_Shown(object sender, EventArgs e)
        {
            try
            {
                if (!SetPurview())
                {
                    Close();
                    return;
                }
                LoadImportTemp();
                AssociateGoodsInitGoodsCode();
                AssociateSuppInitGoodsCode();
                btnAllClear.Enabled = false;
                this.kdStripToolStripMenuItem.Click += new System.EventHandler(this.kdStripToolStripMenuItem_Click);
                #region 创建日志文件
                //string CurrentDate = CurrentLogin.SysParam.GetCurrentDate().ToString("yyyyMMdd");
                //string Path = "D:\\";
                //string fileName = Path + CurrentDate + ".txt";
                //if (!File.Exists(fileName))
                //{
                //    StreamWriter sw = File.CreateText(fileName);
                //    sw.WriteLine("/*商品追溯控制清单维护日志*/ ");
                //    sw.WriteLine("/操作人编码/操作人名称/操作时间/操作类型/供应商编码/商品编码/档案提醒天数");
                //    sw.Flush();
                //    sw.Close();
                //}
                #endregion
            }
            catch (Exception ex)
            {

                XtraMessageBox.Show(ex);
            }
        }
        #endregion

        #region 联想
        private void AssociateGoodsInitGoodsCode()
        {
            associateGoodsCode = new GridAssociate(OrderCenterNode, "Code", AssociateManager, AssociateModeEnum.GoodsCode, null);
            associateGoodsCode.BaseAssociate.Associated += new AssociateBase.AssociateEventHandler(BaseAssociate_Associated);
            gcolGoodsCode.ColumnEdit = associateGoodsCode;
            associateGoodsName = new GridAssociate(OrderCenterNode, "Name", AssociateManager, AssociateModeEnum.GoodsName, null);
            associateGoodsName.BaseAssociate.Associated += new AssociateBase.AssociateEventHandler(BaseAssociate_Associated);
            gcolGoodsName.ColumnEdit = associateGoodsName;
        }

        void BaseAssociate_Associated(Bizcent.Client.Common.AssociateControl.AssociateEventArgs e)
        {
            try
            {
                if (e.CurrentState == AssociateStateEnum.Normal)
                {
                    gvMaintenanceList.CloseEditor();
                    DataRow dr = e.CurrentDataRow;
                    GoodsRetraceMaintenceListInfo MaintenceInfo = bsMaintenceList.Current as GoodsRetraceMaintenceListInfo;
                    GoodsRetraceMaintenceListInfo item = new GoodsRetraceMaintenceListInfo();
                    if (MaintenceInfo == null) { return; }
                    if (MaintenceInfo.IsNew == false)
                    {
                        XtraMessageBox.ShowWarningMessage("已有数据不允许修改");
                        return;
                    }
                    if (dr[0].ToString() != "" && MaintenceInfo.SupplierCode != "")
                    {
                        item.SupplierCode = MaintenceInfo.SupplierCode;
                        item.GoodsCode = dr[0].ToString();
                        string errorInfo = GoodsRetraceMaintenceListManager_OMP.CheckIsExsited(OrderCenterNode, item);
                        if (errorInfo != "")
                        {
                            XtraMessageBox.ShowErrorMessage(errorInfo);
                            return;
                        }
                    }

                    IList<GoodsRetraceMaintenceListInfo> allItemList = bsMaintenceList.List as IList<GoodsRetraceMaintenceListInfo>;
                    int sameNum = 0;
                    foreach (GoodsRetraceMaintenceListInfo grmi in allItemList)
                    {
                        if (!string.IsNullOrEmpty(grmi.GoodsCode.ToString()) && !string.IsNullOrEmpty(grmi.SupplierCode.ToString()))
                        {
                            if (MaintenceInfo.SupplierCode == grmi.SupplierCode && dr[0].ToString() == grmi.GoodsCode && dr[1].ToString() == grmi.GoodsName && MaintenceInfo.SupplierName == grmi.SupplierName)
                            {
                                sameNum++;
                            }
                        }
                    }
                    if (sameNum > 0)
                    {
                        XtraMessageBox.ShowErrorMessage("无法输入重复数据!");
                        return;
                    }
                    MaintenceInfo.GoodsCode = dr[0].ToString();
                    MaintenceInfo.GoodsName = dr[1].ToString();

                    associateGoodsCode.CurrentValue = dr[0].ToString();
                    associateGoodsName.CurrentValue = dr[1].ToString();
                    bsMaintenceList.ResetBindings(false);
                    gvMaintenanceList.FocusedColumn = gcolRemainDDays;
                    gvMaintenanceList.ShowEditor();
                }
            }
            catch (Exception ex)
            { Bizcent.Client.Common.XtraMessageBox.Show(ex); }
        }

        private void AssociateSuppInitGoodsCode()
        {
            associateSupplierCode = new GridAssociate(OrderCenterNode, "Code", AssociateManager, AssociateModeEnum.SuppCode, null);
            associateSupplierCode.BaseAssociate.Associated += new AssociateBase.AssociateEventHandler(SuppBaseAssociate_Associated);
            gcolSupplierCode.ColumnEdit = associateSupplierCode;
            associateSupplierName = new GridAssociate(OrderCenterNode, "Name", AssociateManager, AssociateModeEnum.SuppName, null);
            associateSupplierName.BaseAssociate.Associated += new AssociateBase.AssociateEventHandler(SuppBaseAssociate_Associated);
            gcolSupplierName.ColumnEdit = associateSupplierName;
        }

        void SuppBaseAssociate_Associated(Bizcent.Client.Common.AssociateControl.AssociateEventArgs e)
        {
            try
            {
                gvMaintenanceList.CloseEditor();
                if (e.CurrentState == AssociateStateEnum.Normal)
                {
                    DataRow dr = e.CurrentDataRow;
                    GoodsRetraceMaintenceListInfo MaintenceInfo = bsMaintenceList.Current as GoodsRetraceMaintenceListInfo;
                    GoodsRetraceMaintenceListInfo item = new GoodsRetraceMaintenceListInfo();
                    if (MaintenceInfo == null) { return; }
                    if (MaintenceInfo.IsNew == false)
                    {
                        XtraMessageBox.ShowWarningMessage("已有数据不允许修改");
                        return;
                    }
                    if (dr[0].ToString() != "" && MaintenceInfo.GoodsCode != "")
                    {
                        item.SupplierCode = dr[0].ToString();
                        item.GoodsCode = MaintenceInfo.GoodsCode;
                        string errorInfo = GoodsRetraceMaintenceListManager_OMP.CheckIsExsited(OrderCenterNode, item);
                        if (errorInfo != "")
                        {
                            XtraMessageBox.ShowErrorMessage(errorInfo);
                            return;
                        }
                    }

                    IList<GoodsRetraceMaintenceListInfo> allItemList = bsMaintenceList.List as IList<GoodsRetraceMaintenceListInfo>;
                    int sameNum = 0;
                    foreach (GoodsRetraceMaintenceListInfo grmi in allItemList)
                    {
                        if (!string.IsNullOrEmpty(grmi.GoodsCode.ToString()) && !string.IsNullOrEmpty(grmi.SupplierCode.ToString()))
                        {
                            if (dr[0].ToString() == grmi.SupplierCode && MaintenceInfo.GoodsCode == grmi.GoodsCode && dr[1].ToString() == grmi.SupplierName && MaintenceInfo.GoodsName == grmi.GoodsName)
                            {
                                sameNum++;
                            }
                        }
                    }
                    if (sameNum > 0)
                    {
                        XtraMessageBox.ShowErrorMessage("无法输入重复数据!");
                        return;
                    }
                    MaintenceInfo.SupplierCode = dr[0].ToString();
                    MaintenceInfo.SupplierName = dr[1].ToString();

                    associateSupplierCode.CurrentValue = dr[0].ToString();
                    associateSupplierName.CurrentValue = dr[1].ToString();
                    bsMaintenceList.ResetBindings(false);
                    gvMaintenanceList.FocusedColumn = gcolGoodsCode;
                    gvMaintenanceList.ShowEditor();
                }
            }
            catch (Exception ex)
            { Bizcent.Client.Common.XtraMessageBox.Show(ex); }
        }
        #endregion

        #region 窗体和表格事件

        private void gvMaintenanceList_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            try
            {
                if (this.gvMaintenanceList.FocusedRowHandle < this.bsMaintenceList.Count - 1)
                {
                    int gvMaintenanceListCount = bsMaintenceList.Count;
                    IList<GoodsRetraceMaintenceListInfo> List = bsMaintenceList.List as IList<GoodsRetraceMaintenceListInfo>;
                    if (List.Count != 0)
                    {
                        if ((List[gvMaintenanceListCount - 1].GoodsCode == null || List[gvMaintenanceListCount - 1].SupplierCode == ""))
                        {
                            bsMaintenceList.Remove(List[gvMaintenanceListCount - 1]);
                        }
                        gvMaintenanceList.CloseEditor();
                        GoodsRetraceMaintenceListInfo currentRow = bsMaintenceList.Current as GoodsRetraceMaintenceListInfo;
                        if (currentRow.IsNew == false)
                        {
                            gvMaintenanceList.Columns[1].OptionsColumn.AllowEdit = false;
                            gvMaintenanceList.Columns[2].OptionsColumn.AllowEdit = false;
                            gvMaintenanceList.Columns[3].OptionsColumn.AllowEdit = false;
                            gvMaintenanceList.Columns[4].OptionsColumn.AllowEdit = false;
                            gvMaintenanceList.Columns[5].OptionsColumn.AllowEdit = false;
                        }
                        else
                        {
                            gvMaintenanceList.Columns[1].OptionsColumn.AllowEdit = true;
                            gvMaintenanceList.Columns[2].OptionsColumn.AllowEdit = true;
                            gvMaintenanceList.Columns[3].OptionsColumn.AllowEdit = true;
                            gvMaintenanceList.Columns[4].OptionsColumn.AllowEdit = true;
                            gvMaintenanceList.Columns[5].OptionsColumn.AllowEdit = true;
                        }
                    }
                    GoodsRetraceMaintenceListInfo preRow = new GoodsRetraceMaintenceListInfo();
                    if (e.PrevFocusedRowHandle != GridControl.InvalidRowHandle && bsMaintenceList.Current != null
                    && bsMaintenceList.Count != 0 && bsMaintenceList.Count > e.PrevFocusedRowHandle)
                    {
                        preRow = bsMaintenceList[e.PrevFocusedRowHandle] as GoodsRetraceMaintenceListInfo;
                    }
                    else
                    { return; }
                    if (string.IsNullOrEmpty(preRow.GoodsCode))
                    {
                        XtraMessageBox.ShowWarningMessage("商品信息不能为空!");
                        this.gvMaintenanceList.FocusedColumn = this.gcolGoodsCode;
                        this.gvMaintenanceList.FocusedRowHandle = e.PrevFocusedRowHandle;
                        return;
                    }
                    if (string.IsNullOrEmpty(preRow.GoodsName))
                    {
                        XtraMessageBox.ShowWarningMessage("商品信息不能为空!");
                        this.gvMaintenanceList.FocusedColumn = this.gcolGoodsCode;
                        this.gvMaintenanceList.FocusedRowHandle = e.PrevFocusedRowHandle;
                        return;
                    }
                    if (string.IsNullOrEmpty(preRow.SupplierCode))
                    {
                        XtraMessageBox.ShowWarningMessage("供应商信息不能为空!");
                        this.gvMaintenanceList.FocusedColumn = this.gcolSupplierCode;
                        this.gvMaintenanceList.FocusedRowHandle = e.PrevFocusedRowHandle;
                        return;
                    }
                    if (string.IsNullOrEmpty(preRow.SupplierName))
                    {
                        XtraMessageBox.ShowWarningMessage("供应商信息不能为空!");
                        this.gvMaintenanceList.FocusedColumn = this.gcolSupplierCode;
                        this.gvMaintenanceList.FocusedRowHandle = e.PrevFocusedRowHandle;
                        return;
                    }
                    if (string.IsNullOrEmpty(preRow.RemainDDays.ToString()))
                    {
                        XtraMessageBox.ShowWarningMessage("档期提醒天数信息不能为空!");
                        this.gvMaintenanceList.FocusedColumn = this.gcolRemainDDays;
                        this.gvMaintenanceList.FocusedRowHandle = e.PrevFocusedRowHandle;
                        return;
                    }
                }
                else
                {
                    gvMaintenanceList.CloseEditor();
                    GoodsRetraceMaintenceListInfo currentRow = bsMaintenceList.Current as GoodsRetraceMaintenceListInfo;
                    if (currentRow.IsNew == false)
                    {
                        gvMaintenanceList.Columns[1].OptionsColumn.AllowEdit = false;
                        gvMaintenanceList.Columns[2].OptionsColumn.AllowEdit = false;
                        gvMaintenanceList.Columns[3].OptionsColumn.AllowEdit = false;
                        gvMaintenanceList.Columns[4].OptionsColumn.AllowEdit = false;
                        gvMaintenanceList.Columns[5].OptionsColumn.AllowEdit = false;
                    }
                    else
                    {
                        gvMaintenanceList.Columns[1].OptionsColumn.AllowEdit = true;
                        gvMaintenanceList.Columns[2].OptionsColumn.AllowEdit = true;
                        gvMaintenanceList.Columns[3].OptionsColumn.AllowEdit = true;
                        gvMaintenanceList.Columns[4].OptionsColumn.AllowEdit = true;
                        gvMaintenanceList.Columns[5].OptionsColumn.AllowEdit = true;
                    }
                }
            }
            catch (Exception ex)
            {

                XtraMessageBox.Show(ex);
            }
        }

        private void repositoryItemCheckEdit1_EditValueChanged(object sender, EventArgs e)
        {
            try
            {
                CheckEdit check = sender as CheckEdit;
                GoodsRetraceMaintenceListInfo CurrentRow = bsMaintenceList.Current as GoodsRetraceMaintenceListInfo;
                if (CurrentRow == null) return;
                CurrentRow.IsChoosen = !CurrentRow.IsChoosen;
                bsMaintenceList.ResetBindings(false);
            }
            catch (Exception ex)
            {

                XtraMessageBox.Show(ex);
            }
        }

        private void gvMaintenanceList_MouseUp(object sender, MouseEventArgs e)
        {
            try
            {
                gvMaintenanceList.CloseEditor();
                GridHitInfo hInfo = gvMaintenanceList.CalcHitInfo(new Point(e.X, e.Y));
                if (hInfo.HitTest.ToString() == "EmptyRow")
                {
                    btnAdd_ItemClick(null, null);
                }
                gvMaintenanceList.ShowEditor();
            }
            catch (Exception ex)
            {

                XtraMessageBox.Show(ex);
            }

        }

        private void gvMaintenanceList_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                if (e.KeyCode == Keys.Enter)
                {
                    switch (gvMaintenanceList.FocusedColumn.Name)
                    {
                        case "gcolRemainDDays":
                            if (gvMaintenanceList.FocusedRowHandle == bsMaintenceList.Count - 1)
                            {
                                GoodsRetraceMaintenceListInfo CurrentRow = bsMaintenceList.Current as GoodsRetraceMaintenceListInfo;
                                if (CurrentRow.RemainDDays != 0)
                                { btnAdd_ItemClick(null, null); }
                            }
                            break;
                        default:
                            break;
                    }
                }
                else if (e.KeyCode == Keys.Down)
                {
                    if (gvMaintenanceList.FocusedRowHandle == bsMaintenceList.Count - 1)
                    {
                        btnAdd_ItemClick(null, null);
                    }
                }
            }
            catch (Exception ex)
            {

                XtraMessageBox.Show(ex);
            }
        }

        private void kdStripToolStripMenuItem_Click(object sender, EventArgs e)
        {

            btnAllClear.Enabled = true;

        }

        private void bbiOption_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            CustomColumnSelectForm f = new CustomColumnSelectForm(this.gvMaintenanceList);
            f.ShowDialog();
        }

        //protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        //{
        //    if (keyData == (Keys.Control | Keys.F12))
        //    {
        //        btnAllClear.Enabled = true;
        //        return true;
        //    }
        //    return base.ProcessCmdKey(ref msg, keyData);
        //}

        #endregion

    }
}

 

posted on 2018-07-27 14:24  谁占用了CRIS  阅读(97)  评论(0编辑  收藏  举报

导航