某模塊

普通模塊犀勒,主要記錄各種按鈕功能的實現(xiàn)

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

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

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

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

        #region 按鈕事件

        //增行
        private void btnAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                GoodsRetraceMaintenceListInfo currentrow = bsMaintenceList.Current as GoodsRetraceMaintenceListInfo;
                if (currentrow != null)
                {
                    if ((currentrow.GoodsCode == null || currentrow.GoodsCode == ""))
                    {
                        XtraMessageBox.ShowErrorMessage("請聯(lián)想商品信息");
                        return;
                    }
                    if ((currentrow.GoodsName == null || currentrow.GoodsName == ""))
                    {
                        XtraMessageBox.ShowErrorMessage("請聯(lián)想商品信息");
                        return;
                    }
                    if ((currentrow.SupplierCode == null || currentrow.SupplierCode == ""))
                    {
                        XtraMessageBox.ShowErrorMessage("請聯(lián)想供應(yīng)商信息");
                        return;
                    }
                    if ((currentrow.SupplierName == null || currentrow.SupplierName == ""))
                    {
                        XtraMessageBox.ShowErrorMessage("請聯(lián)想供應(yīng)商信息");
                        return;
                    }
                    if (currentrow.RemainDDays == null)
                    {
                        XtraMessageBox.ShowErrorMessage("請?zhí)顚憴n期提醒天數(shù)");
                        return;
                    }
                }
                gvMaintenanceList.CloseEditor();
                GoodsRetraceMaintenceListInfo MaintenceInfo = new GoodsRetraceMaintenceListInfo();
                MaintenceInfo.IsNew = true;
                bsMaintenceList.Add(MaintenceInfo);
                bsMaintenceList.ResetBindings(false);
                this.gvMaintenanceList.FocusedRowHandle = this.gvMaintenanceList.DataRowCount - 1;
                gvMaintenanceList.FocusedColumn = gcolSupplierCode;
                gvMaintenanceList.Columns[1].OptionsColumn.AllowEdit = true;
                gvMaintenanceList.Columns[2].OptionsColumn.AllowEdit = true;
                gvMaintenanceList.Columns[3].OptionsColumn.AllowEdit = true;
                gvMaintenanceList.Columns[4].OptionsColumn.AllowEdit = true;
                gvMaintenanceList.Columns[5].OptionsColumn.AllowEdit = true;
                gvMaintenanceList.ShowEditor();
            }
            catch (Exception ex)
            {

                XtraMessageBox.Show(ex);
            }
        }

        //刪除
        private void btnDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                labelControl1.Focus();
                string LogTime = CurrentLogin.SysParam.GetCurrentDate().ToString("yyyyMMddHHmmss");
                IList<GoodsRetraceMaintenceListInfo> AllItem = bsMaintenceList.List as IList<GoodsRetraceMaintenceListInfo>;
                int allItemNum = AllItem.Count;
                if (allItemNum > 0)
                {
                    if (XtraMessageBox.Show("確認(rèn)刪除?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                    {
                        IList<GoodsRetraceMaintenceListInfo> deleteItem = new List<GoodsRetraceMaintenceListInfo>();
                        for (int i = 0; i < allItemNum; i++)
                        {
                            if (AllItem[i].IsChoosen == true)
                            {
                                deleteItem.Add(AllItem[i]);
                                if (AllItem[i].IsNew == false)
                                {
                                    #region 記錄刪除日志
                                    AllItem[i].OperatorTime = LogTime;
                                    AllItem[i].OperatorCode = userCode;
                                    AllItem[i].OperatorName = userName;
                                    AllItem[i].OperatorType = 1;
                                    AllItem[i].OperateContent = "刪除供應(yīng)商編碼為" + AllItem[i].SupplierCode.ToString() + "商品編碼為"
                                        + AllItem[i].GoodsCode.ToString() + "檔期提醒天數(shù)為" + AllItem[i].RemainDDays.ToString();
                                    #endregion
                                }
                            }
                        }
                        if (deleteItem.Count == 0)
                        {
                            XtraMessageBox.ShowWarningMessage("未勾選要刪除的數(shù)據(jù)");
                            return;
                        }
                        OperateReturnInfo Msg = GoodsRetraceMaintenceListManager_OMP.DeleteGoodsRetrace(OrderCenterNode, deleteItem);
                        if (Msg.ReturnCode == OperateCodeEnum.Success)
                        {
                            foreach (GoodsRetraceMaintenceListInfo item in deleteItem)
                            {
                                bsMaintenceList.Remove(item);
                            }
                        }
                        else
                        {
                            foreach (GoodsRetraceMaintenceListInfo item in deleteItem)
                            {
                                if (item.IsNew == true)
                                    bsMaintenceList.Remove(item);
                            }
                        }
                        bsMaintenceList.ResetBindings(false);
                    }
                }
            }
            catch (Exception ex)
            {

                XtraMessageBox.Show(ex);
            }
        }

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

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

                XtraMessageBox.Show(ex);
            }

        }

        //保存
        private void btnSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                gvMaintenanceList.CloseEditor();
                string LogTime = CurrentLogin.SysParam.GetCurrentDate().ToString("yyyyMMddHHmmss");
                IList<GoodsRetraceMaintenceListInfo> ListToSave = new List<GoodsRetraceMaintenceListInfo>();
                IList<GoodsRetraceMaintenceListInfo> AllItem = bsMaintenceList.List as IList<GoodsRetraceMaintenceListInfo>;
                for (int i = 0; i < AllItem.Count; i++)
                {
                    if (AllItem[i].IsNew == true && !string.IsNullOrEmpty(AllItem[i].GoodsCode) && !string.IsNullOrEmpty(AllItem[i].SupplierCode) && !string.IsNullOrEmpty(AllItem[i].GoodsName) 
                        && !string.IsNullOrEmpty(AllItem[i].SupplierName) && !string.IsNullOrEmpty(AllItem[i].RemainDDays.ToString()))
                    {
                        AllItem[i].IsNew = false;
                        #region 記錄增行日志
                        AllItem[i].OperatorTime = LogTime;
                        AllItem[i].OperatorCode = userCode;
                        AllItem[i].OperatorName = userName;
                        AllItem[i].OperatorType = 0;
                        AllItem[i].OperateContent = "增加供應(yīng)商編碼為" + AllItem[i].SupplierCode.ToString() + "商品編碼為"
    + AllItem[i].GoodsCode.ToString() + "檔期提醒天數(shù)為" + AllItem[i].RemainDDays.ToString();
                        ListToSave.Add(AllItem[i]);
                        #endregion
                    }
                    else if (AllItem[i].IsNew == true && (!string.IsNullOrEmpty(AllItem[i].GoodsCode) || !string.IsNullOrEmpty(AllItem[i].SupplierCode) || !string.IsNullOrEmpty(AllItem[i].GoodsName) 
                        || !string.IsNullOrEmpty(AllItem[i].SupplierName) || !string.IsNullOrEmpty(AllItem[i].RemainDDays.ToString())))
                    {
                        XtraMessageBox.ShowWarningMessage("請完善第" + (i + 1) + "行數(shù)據(jù)后再保存!");
                        return;
                    }
                }
                if (ListToSave.Count == 0) { XtraMessageBox.Show("沒有可保存的數(shù)據(jù)"); return; }
                OperateReturnInfo Msg = GoodsRetraceMaintenceListManager_OMP.SaveGoodsRetraceMaintenceList(OrderCenterNode, ListToSave);
                if (Msg.ReturnCode == OperateCodeEnum.Success)
                    bsMaintenceList.Clear();
                XtraMessageBox.Show(Msg);
            }
            catch (Exception ex)
            {

                XtraMessageBox.Show(ex);
            }

        }

        //導(dǎo)入
        private void btnImport_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                if (bsMaintenceList.Count > 0)
                {
                    GoodsRetraceMaintenceListInfo currentrow = bsMaintenceList.List[bsMaintenceList.Count - 1] as GoodsRetraceMaintenceListInfo;
                    if (currentrow != null)
                    {
                        if ((currentrow.GoodsCode == null || currentrow.GoodsCode == "") && (currentrow.SupplierCode == null || currentrow.SupplierCode == ""))
                        {
                            bsMaintenceList.RemoveAt(bsMaintenceList.Count - 1);
                        }
                        else
                        {
                            if ((currentrow.GoodsCode == null || currentrow.GoodsCode == ""))
                            {
                                XtraMessageBox.ShowErrorMessage("請聯(lián)想商品信息");
                                return;
                            }
                            if ((currentrow.GoodsName == null || currentrow.GoodsName == ""))
                            {
                                XtraMessageBox.ShowErrorMessage("請聯(lián)想商品信息");
                                return;
                            }
                            if ((currentrow.SupplierCode == null || currentrow.SupplierCode == ""))
                            {
                                XtraMessageBox.ShowErrorMessage("請聯(lián)想供應(yīng)商信息");
                                return;
                            }
                            if ((currentrow.SupplierName == null || currentrow.SupplierName == ""))
                            {
                                XtraMessageBox.ShowErrorMessage("請聯(lián)想供應(yīng)商信息");
                                return;
                            }
                            if (currentrow.RemainDDays == null)
                            {
                                XtraMessageBox.ShowErrorMessage("請?zhí)顚憴n期提醒天數(shù)");
                                return;
                            }
                        }
                    }
                }

                if (_PrintTemp == null)
                {
                    XtraMessageBox.ShowWarningMessage("無導(dǎo)入模板!");
                    return;
                }
                if (bsMaintenceList.List.Count > 0)
                {
                    if (XtraMessageBox.ShowQuestionMessage("是否清空界面數(shù)據(jù)?") == DialogResult.OK)
                    {
                        bsMaintenceList.Clear();
                    }
                }

                FormatMaster fm = IOManager.LoadIOFormat(dbNode, this.btnImportTencil.EditValue.ToString());
                DataTable dt = new EasyImporter(IOManager).File2DataTable(fm.FormatCode);
                if (dt == null || dt.Rows.Count == 0) return;
                int ImportNumber = dt.Rows.Count;//導(dǎo)入的文件中數(shù)據(jù)的條數(shù)
                if (!dt.Columns.Contains("GoodsCode") || !dt.Columns.Contains("SupplierCode"))
                {
                    XtraMessageBox.ShowErrorMessage("導(dǎo)入必須包含字段:商品編碼,供應(yīng)商編碼!");
                    return;
                }
                List<string> errorInfos = new List<string>();
                IList<GoodsRetraceMaintenceListInfo> resultList = new List<GoodsRetraceMaintenceListInfo>();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataRow dr = dt.Rows[i];
                    if (dr == null) continue;

                    #region 驗證數(shù)據(jù)有效性

                    if (!string.IsNullOrEmpty(dr["GoodsCode"].ToString()))
                    {
                        GoodsInfo goods = GoodsManager.LoadGoods(OrderCenterNode, dr["GoodsCode"].ToString(), new ArrayList());
                        if (goods == null || string.IsNullOrEmpty(goods.GoodsCode))
                        {
                            errorInfos.Add("第" + (i + 1) + "行" + "商品編碼不存在!");
                            continue;
                        }
                    }
                    if (!string.IsNullOrEmpty(dr["SupplierCode"].ToString()))
                    {
                        SupplierInfo supplier = SupplierManager.LoadSupplier(OrderCenterNode, dr["SupplierCode"].ToString());
                        if (supplier == null || string.IsNullOrEmpty(supplier.SupplierCode))
                        {
                            errorInfos.Add("第" + (i + 1) + "行" + "供應(yīng)商編碼不存在!");
                            continue;
                        }
                    }
                    if (!string.IsNullOrEmpty(dr["Remainddays"].ToString()))
                    {
                        string remainday = dr["Remainddays"].ToString();
                        string pattern = "^[1-9]\\d*$|0$";
                        if (!Regex.IsMatch(remainday, pattern))
                        {
                            errorInfos.Add("第" + (i + 1) + "行" + "檔案提醒天數(shù)只能輸入非負(fù)整數(shù)!");
                            continue;
                        }
                    }
                    #endregion

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

                }

                for (int i = 0; i < resultList.Count; i++)
                {
                    string errorInfo = (GoodsRetraceMaintenceListManager_OMP.CheckIsExsited(OrderCenterNode, resultList[i]));
                    if (errorInfo != "")
                    {
                        errorInfos.Add("供應(yīng)商編碼為" + resultList[i].SupplierCode + "商品編碼為" + resultList[i].GoodsCode + errorInfo);
                        resultList.Remove(resultList[i]);
                    }
                }

                #region 導(dǎo)入數(shù)據(jù)自身去重
                for (int i = 0; i < resultList.Count; i++)
                {
                    int CopyNumber = 0;
                    for (int j = 0; j < resultList.Count; j++)
                    {
                        if (resultList[i].GoodsCode == resultList[j].GoodsCode && resultList[i].SupplierCode == resultList[j].SupplierCode)
                        {
                            if (i != j)
                            {
                                CopyNumber++;
                                errorInfos.Add("第" + (i + 1) + "行與第" + (j + 1) + "行重復(fù)");
                            }
                        }
                    }
                    if (CopyNumber > 0)
                    {
                        resultList.Remove(resultList[i]);
                    }
                }
                #endregion

                resultList = GoodsRetraceMaintenceListManager_OMP.LoadGoodsNameAndSupplierName(OrderCenterNode, resultList);//填補/修正 商品名稱和供應(yīng)商名稱信息

                #region 界面原有數(shù)據(jù)和導(dǎo)入數(shù)據(jù)去重
                IList<GoodsRetraceMaintenceListInfo> ExistedData = bsMaintenceList.List as IList<GoodsRetraceMaintenceListInfo>;
                //IList<GoodsRetraceMaintenceListInfo> preImport = new List<GoodsRetraceMaintenceListInfo>();
                int ExistedNumber = ExistedData.Count;//原先界面數(shù)據(jù)的條數(shù)
                if (ExistedData != null && ExistedData.Count != 0 && resultList.Count != 0 && resultList != null)
                {
                    for (int i = 0; i < resultList.Count; i++)
                    {
                        ExistedData.Add(resultList[i]);
                    }
                    for (int i = 0; i < ExistedData.Count; i++)
                    {
                        int sameNum = 0;
                        for (int j = i + 1; j < ExistedData.Count; j++)
                        {
                            if (ExistedData[i].GoodsCode == ExistedData[j].GoodsCode && ExistedData[j].SupplierCode == ExistedData[i].SupplierCode)
                            {
                                sameNum++;
                            }
                        }
                        if (sameNum > 0)
                        {
                            errorInfos.Add("商品編碼為" + ExistedData[i].GoodsCode + "供應(yīng)商編碼為" + ExistedData[i].SupplierCode + "的數(shù)據(jù)界面上已存在!");
                            ExistedData.RemoveAt(i);
                        }
                    }
                    //for (int i = 0; i < ExistedData.Count; i++)
                    //{
                    //    for (int j = 0; j < resultList.Count; j++)
                    //    {
                    //        if (resultList[j].GoodsCode != ExistedData[i].GoodsCode || resultList[j].SupplierCode != ExistedData[i].SupplierCode)
                    //        {
                    //            errorInfos.Add("商品編碼為" + resultList[j].GoodsCode + "供應(yīng)商編碼為" + resultList[j].SupplierCode + "的數(shù)據(jù)界面上已存在!");
                    //            continue;
                    //        }
                    //        else
                    //        {
                    //            preImport.Add(resultList[j]);
                    //        }
                    //    }
                    //}
                    //if (preImport.Count > 0)
                    //{
                    //    foreach (GoodsRetraceMaintenceListInfo ImportItem in preImport)
                    //    {
                    //        ExistedData.Add(ImportItem);
                    //    }
                    //}
                }
                else
                {
                    foreach (GoodsRetraceMaintenceListInfo ImportItem in resultList)
                    {
                        ExistedData.Add(ImportItem);
                    }
                }
                #endregion

                StringBuilder sb = new StringBuilder();
                sb.Append("導(dǎo)入成功[" + (ExistedData.Count - ExistedNumber) + "]行\(zhòng)r\n導(dǎo)入失敗[" + (ImportNumber - (ExistedData.Count - ExistedNumber)) + "]行" + "\r\n");//ExistedData.Count為導(dǎo)入完成后界面的數(shù)據(jù)總條數(shù)
                if (errorInfos.Count > 0)
                {
                    sb.Append("以下數(shù)據(jù)驗證失敵濉:" + "\r\n");
                    foreach (var error in errorInfos)
                    {
                        sb.Append(error + "\r\n");
                    }
                    XtraMessageBox.Show(new OperateReturnInfo() { ReturnCode = OperateCodeEnum.Failed, ReturnInfo = sb.ToString() });
                    return;
                }
                else
                { XtraMessageBox.Show("已成功導(dǎo)入" + (ExistedData.Count - ExistedNumber) + "行"); }
                bsMaintenceList.ResetBindings(false);
            }
            catch (Exception ex)
            {

                XtraMessageBox.Show(ex);
            }

        }

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

                XtraMessageBox.Show(ex);
            }
        }

        //全清
        private void btnAllClear_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                if (bsMaintenceList.List.Count > 0)
                {
                    if (XtraMessageBox.Show("將清除所有商品追溯控制清單數(shù)據(jù)是否繼續(xù)?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                    {
                        bsMaintenceList.Clear();
                        txtGoodsCode.Text = string.Empty;
                        txtSupplierCode.Text = string.Empty;
                        btnQuery_ItemClick(null, null);
                        bsMaintenceList.ResetBindings(false);

                        #region 記錄全清日志
                        string LogTime = CurrentLogin.SysParam.GetCurrentDate().ToString("yyyyMMddHHmmss");
                        IList<GoodsRetraceMaintenceListInfo> allItemList = GoodsRetraceMaintenceListManager_OMP.LoadGoodsRetraceMaintenceList(OrderCenterNode, "", "");
                        foreach (GoodsRetraceMaintenceListInfo item in allItemList)
                        {
                            item.OperatorTime = LogTime;
                            item.OperatorCode = userCode;
                            item.OperatorName = userName;
                            item.OperatorType = 2;
                            string operateContent = string.Empty;
                            item.OperateContent = "全清" + "供應(yīng)商編碼為" + item.SupplierCode + "商品編碼為" + item.GoodsCode + "檔期提醒天數(shù)" + item.RemainDDays;
                        }
                        #endregion
                        OperateReturnInfo Msg = GoodsRetraceMaintenceListManager_OMP.DeleteAll(OrderCenterNode, allItemList);
                        if (Msg.ReturnCode == OperateCodeEnum.Success)
                        {
                            bsMaintenceList.Clear();
                            XtraMessageBox.Show("數(shù)據(jù)庫數(shù)據(jù)已全部清空");
                        }

                    }
                }
            }
            catch (Exception ex)
            {

                XtraMessageBox.Show(ex);
            }
        }

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

                XtraMessageBox.Show(ex);
            }
        }

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

                XtraMessageBox.Show(ex);
            }
        }

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

                XtraMessageBox.Show(ex);
            }
        }

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

                XtraMessageBox.Show(ex);
            }
        }
        #endregion

        #region 窗體加載
        public FrmGoodsRetraCtrlListMainte()
        {
            InitializeComponent();
        }
        private void FrmGoodsRetraCtrlListMainte_Shown(object sender, EventArgs e)
        {
            try
            {
                if (!SetPurview())
                {
                    Close();
                    return;
                }
                LoadImportTemp();
                AssociateGoodsInitGoodsCode();
                AssociateSuppInitGoodsCode();
                btnAllClear.Enabled = false;
                this.kdStripToolStripMenuItem.Click += new System.EventHandler(this.kdStripToolStripMenuItem_Click);
                #region 創(chuàng)建日志文件
                //string CurrentDate = CurrentLogin.SysParam.GetCurrentDate().ToString("yyyyMMdd");
                //string Path = "D:\\";
                //string fileName = Path + CurrentDate + ".txt";
                //if (!File.Exists(fileName))
                //{
                //    StreamWriter sw = File.CreateText(fileName);
                //    sw.WriteLine("/*商品追溯控制清單維護(hù)日志*/ ");
                //    sw.WriteLine("/操作人編碼/操作人名稱/操作時間/操作類型/供應(yīng)商編碼/商品編碼/檔案提醒天數(shù)");
                //    sw.Flush();
                //    sw.Close();
                //}
                #endregion
            }
            catch (Exception ex)
            {

                XtraMessageBox.Show(ex);
            }
        }
        #endregion

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

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

                    IList<GoodsRetraceMaintenceListInfo> allItemList = bsMaintenceList.List as IList<GoodsRetraceMaintenceListInfo>;
                    int sameNum = 0;
                    foreach (GoodsRetraceMaintenceListInfo grmi in allItemList)
                    {
                        if (!string.IsNullOrEmpty(grmi.GoodsCode.ToString()) && !string.IsNullOrEmpty(grmi.SupplierCode.ToString()))
                        {
                            if (MaintenceInfo.SupplierCode == grmi.SupplierCode && dr[0].ToString() == grmi.GoodsCode && dr[1].ToString() == grmi.GoodsName && MaintenceInfo.SupplierName == grmi.SupplierName)
                            {
                                sameNum++;
                            }
                        }
                    }
                    if (sameNum > 0)
                    {
                        XtraMessageBox.ShowErrorMessage("無法輸入重復(fù)數(shù)據(jù)!");
                        return;
                    }
                    MaintenceInfo.GoodsCode = dr[0].ToString();
                    MaintenceInfo.GoodsName = dr[1].ToString();

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

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

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

                    IList<GoodsRetraceMaintenceListInfo> allItemList = bsMaintenceList.List as IList<GoodsRetraceMaintenceListInfo>;
                    int sameNum = 0;
                    foreach (GoodsRetraceMaintenceListInfo grmi in allItemList)
                    {
                        if (!string.IsNullOrEmpty(grmi.GoodsCode.ToString()) && !string.IsNullOrEmpty(grmi.SupplierCode.ToString()))
                        {
                            if (dr[0].ToString() == grmi.SupplierCode && MaintenceInfo.GoodsCode == grmi.GoodsCode && dr[1].ToString() == grmi.SupplierName && MaintenceInfo.GoodsName == grmi.GoodsName)
                            {
                                sameNum++;
                            }
                        }
                    }
                    if (sameNum > 0)
                    {
                        XtraMessageBox.ShowErrorMessage("無法輸入重復(fù)數(shù)據(jù)!");
                        return;
                    }
                    MaintenceInfo.SupplierCode = dr[0].ToString();
                    MaintenceInfo.SupplierName = dr[1].ToString();

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

        #region 窗體和表格事件

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

                XtraMessageBox.Show(ex);
            }
        }

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

                XtraMessageBox.Show(ex);
            }
        }

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

                XtraMessageBox.Show(ex);
            }

        }

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

                XtraMessageBox.Show(ex);
            }
        }

        private void kdStripToolStripMenuItem_Click(object sender, EventArgs e)
        {

            btnAllClear.Enabled = true;

        }

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

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

        #endregion

    }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市洛搀,隨后出現(xiàn)的幾起案子倘潜,更是在濱河造成了極大的恐慌格遭,老刑警劉巖愚铡,帶你破解...
    沈念sama閱讀 211,376評論 6 491
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異幔摸,居然都是意外死亡摸柄,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,126評論 2 385
  • 文/潘曉璐 我一進(jìn)店門既忆,熙熙樓的掌柜王于貴愁眉苦臉地迎上來驱负,“玉大人,你說我怎么就攤上這事患雇≡炯梗” “怎么了?”我有些...
    開封第一講書人閱讀 156,966評論 0 347
  • 文/不壞的土叔 我叫張陵苛吱,是天一觀的道長匾乓。 經(jīng)常有香客問我,道長又谋,這世上最難降的妖魔是什么拼缝? 我笑而不...
    開封第一講書人閱讀 56,432評論 1 283
  • 正文 為了忘掉前任,我火速辦了婚禮彰亥,結(jié)果婚禮上咧七,老公的妹妹穿的比我還像新娘。我一直安慰自己任斋,他們只是感情好继阻,可當(dāng)我...
    茶點故事閱讀 65,519評論 6 385
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著废酷,像睡著了一般瘟檩。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上澈蟆,一...
    開封第一講書人閱讀 49,792評論 1 290
  • 那天墨辛,我揣著相機與錄音,去河邊找鬼趴俘。 笑死睹簇,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的寥闪。 我是一名探鬼主播太惠,決...
    沈念sama閱讀 38,933評論 3 406
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼疲憋!你這毒婦竟也來了凿渊?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,701評論 0 266
  • 序言:老撾萬榮一對情侶失蹤缚柳,失蹤者是張志新(化名)和其女友劉穎埃脏,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體喂击,經(jīng)...
    沈念sama閱讀 44,143評論 1 303
  • 正文 獨居荒郊野嶺守林人離奇死亡剂癌,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,488評論 2 327
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了翰绊。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片佩谷。...
    茶點故事閱讀 38,626評論 1 340
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖监嗜,靈堂內(nèi)的尸體忽然破棺而出谐檀,到底是詐尸還是另有隱情,我是刑警寧澤裁奇,帶...
    沈念sama閱讀 34,292評論 4 329
  • 正文 年R本政府宣布桐猬,位于F島的核電站,受9級特大地震影響刽肠,放射性物質(zhì)發(fā)生泄漏溃肪。R本人自食惡果不足惜免胃,卻給世界環(huán)境...
    茶點故事閱讀 39,896評論 3 313
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望惫撰。 院中可真熱鬧羔沙,春花似錦、人聲如沸厨钻。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,742評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽夯膀。三九已至诗充,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間诱建,已是汗流浹背蝴蜓。 一陣腳步聲響...
    開封第一講書人閱讀 31,977評論 1 265
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留涂佃,地道東北人励翼。 一個月前我還...
    沈念sama閱讀 46,324評論 2 360
  • 正文 我出身青樓,卻偏偏與公主長得像辜荠,于是被迫代替她去往敵國和親汽抚。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 43,494評論 2 348