Example #1
0
        /// <summary>
        /// 初始化TreeView1
        /// </summary>
        /// <param name="edition">版本号</param>
        void InitTreeView(string productCode)
        {
            IQueryable <P_ElectronFile> eRecords;
            string error;

            treeView1.Nodes.Clear();

            if (m_serverModule.GetElectronFile(productCode, out eRecords, out error))
            {
                List <string> lstParentCode = (from r in eRecords orderby r.ParentCode
                                               select r.ParentCode).Distinct().ToList();
                List <P_ElectronFile> electronWords = (from r in eRecords
                                                       where lstParentCode.Contains(r.GoodsCode) orderby r.GoodsCode
                                                       select r).ToList();
                if (electronWords.Count == 0)
                {
                    return;
                }

                P_ElectronFile root = electronWords.Find(p => p.ParentCode == "");

                TreeNode rootNode = new TreeNode();

                rootNode.Name        = root.GoodsCode;
                rootNode.Text        = root.GoodsName;
                rootNode.ToolTipText = root.GoodsName + "," + root.GoodsCode + "," + root.Spec;
                rootNode.Tag         = root;
                treeView1.Nodes.Add(rootNode);
                electronWords.Remove(root);

                for (int i = 0; i < electronWords.Count; i++)
                {
                    P_ElectronFile item       = electronWords[i];
                    TreeNode       parentNode = new TreeNode();

                    parentNode.Name        = item.GoodsCode;
                    parentNode.Text        = item.GoodsName;
                    parentNode.ToolTipText = item.GoodsName + "," + item.GoodsCode + "," + item.Spec;
                    parentNode.Tag         = item;
                    rootNode.Nodes.Add(parentNode);
                    electronWords.Remove(item);

                    i--;
                }

                List <P_ElectronFile> lstEF =
                    (from r in eRecords
                     where !lstParentCode.Contains(r.GoodsCode) orderby r.GoodsCode
                     select r).ToList();

                for (int i = 0; i < rootNode.Nodes.Count; i++)
                {
                    RecursionBuildTreeView(rootNode.Nodes[i], lstEF);
                }

                RecursionBuildTreeView(rootNode, lstEF);
            }

            treeView1.ExpandAll();
        }
Example #2
0
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (treeView1.SelectedNode != null)
            {
                P_ElectronFile data = treeView1.SelectedNode.Tag as P_ElectronFile;

                if (!m_serverModule.GetElectronFile(m_curProductCode, data.ParentCode, data.GoodsOnlyCode,
                                                    data.GoodsCode, data.Spec, out m_allTable, out m_err))
                {
                    MessageDialog.ShowErrorMessage(m_err);
                    return;
                }

                RefreshDataGridView();
            }
        }
        /// <summary>
        /// 递归生成电子档案的树型结构
        /// </summary>
        /// <param name="parentNode">父总成节点</param>
        /// <param name="parentRecords">父总成信息列表</param>
        /// <param name="eRecords">电子档案信息</param>
        void RecursionBuildTreeView(TreeNode parentNode, List <P_ElectronFile> parentRecords, List <P_ElectronFile> eRecords)
        {
            P_ElectronFile parentInfo = parentNode.Tag as P_ElectronFile;
            bool           find       = false;

            for (int i = 0; i < eRecords.Count; i++)
            {
                if (parentInfo.GoodsName != eRecords[i].ParentName)
                {
                    continue;
                }

                #region 是否找到更匹配的父节点(父总成扫描码=父节点零件标识码)

                find = false;

                foreach (P_ElectronFile item in parentRecords)
                {
                    if (item != parentInfo && item.GoodsCode == eRecords[i].ParentCode &&
                        item.GoodsOnlyCode == eRecords[i].ParentScanCode)
                    {
                        find = true;
                    }
                }

                #endregion

                if (find)
                {
                    continue;
                }

                TreeNode node = new TreeNode();

                node.Name        = eRecords[i].GoodsCode;
                node.Text        = eRecords[i].GoodsName;
                node.ToolTipText = eRecords[i].Spec;
                node.Tag         = eRecords[i];
                parentNode.Nodes.Add(node);

                eRecords.RemoveAt(i);
                i = -1;

                RecursionBuildTreeView(node, parentRecords, eRecords);
            }
        }
        /// <summary>
        /// 更改选定treeView1内容
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (treeView1.SelectedNode != null)
            {
                P_ElectronFile data = treeView1.SelectedNode.Tag as P_ElectronFile;

                if (!m_serverModule.GetElectronFile(m_curProductCode, data.ParentCode, data.GoodsOnlyCode,
                                                    data.GoodsCode, data.Spec, out m_allTable, out m_err))
                {
                    MessageDialog.ShowErrorMessage(m_err);
                    return;
                }

                // 相同分总成数量(对于返修时整体替换分总成的情况)
                int parentCount = 0;

                foreach (P_ElectronFile item in m_parentElectronWords)
                {
                    if (data.GoodsName == item.GoodsName)
                    {
                        parentCount++;
                    }
                }

                if (m_allTable != null && treeView1.SelectedNode.Parent != null && (parentCount > 1 || parentCount == 0))
                {
                    for (int i = 0; i < m_allTable.Rows.Count; i++)
                    {
                        string parentScanCode = m_allTable.Rows[i].Field <string>("父总成扫描码");
                        string goodsOnlyCode  = m_allTable.Rows[i].Field <string>("零件标识码");

                        // parentCount > 1 表示当前选择节点是总成节点且有多个相同的总成节点(表示有总成被替换过)
                        // parentCount = 0 表示当前选择节点是零件节点
                        if ((parentCount > 1 && parentScanCode != data.GoodsOnlyCode && parentScanCode != data.GoodsCode &&
                             data.GoodsOnlyCode != goodsOnlyCode) ||
                            (parentCount == 0 && parentScanCode != data.ParentScanCode))
                        {
                            m_allTable.Rows.RemoveAt(i--);
                        }
                    }
                }

                RefreshDataGridView();
            }
        }
        /// <summary>
        /// 添加返修信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (!CheckData())
            {
                return;
            }

            P_ElectronFile ef = m_electronFileServer.CreateElectronFile(m_dataRow["产品编码"]);

            ef.ParentCode     = m_dataRow["父总成编码"];
            ef.ParentName     = m_dataRow["父总成名称"];
            ef.ParentScanCode = m_dataRow["父总成扫描码"];
            ef.GoodsCode      = txtGoodsCode.Text;
            ef.GoodsName      = txtGoodsName.Text;
            ef.GoodsOnlyCode  = txtPartID.Text;
            ef.Spec           = txtSpec.Text;
            ef.Counts         = Convert.ToInt32(numAssemblyAmount.Value);
            ef.Provider       = txtProvider.Text;
            ef.BatchNo        = txtBatchNo.Text;
            ef.CheckDatas     = txtCheckData.Text;
            ef.FactDatas      = txtResultData.Text;
            ef.AssemblingMode = m_updateMode.ToString();
            ef.Remark         = txtRemark.Text;
            ef.WorkBench      = m_dataRow["工位"];

            if (!m_electronFileServer.AddElectronFile(ef, out m_error))
            {
                MessageDialog.ShowErrorMessage(m_error);
            }
            else
            {
                MessageDialog.ShowPromptMessage("操作成功");
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }
        /// <summary>
        /// 初始化TreeView
        /// </summary>
        /// <param name="productCode">产品编号</param>
        void InitTreeView(string productCode)
        {
            IQueryable <P_ElectronFile> eRecords;
            string error;

            treeView1.Nodes.Clear();

            if (m_serverModule.GetElectronFile(productCode, out eRecords, out error))
            {
                // 在后续剔除分总成的过程中防止剔除零部件编码为空的零件,如:白锌平垫
                List <string> lstParentCode = (from r in eRecords
                                               orderby r.ParentCode
                                               where r.ParentCode != ""
                                               select r.ParentCode).Distinct().ToList();

                m_parentElectronWords = (from r in eRecords
                                         where lstParentCode.Contains(r.GoodsCode)
                                         orderby r.GoodsCode, Convert.ToDateTime(r.FittingTime)
                                         select r).ToList();

                var rootGroup = from r in eRecords
                                where r.ParentCode == ""
                                select r;

                if (rootGroup.Count() > 1)
                {
                    MessageDialog.ShowErrorMessage(string.Format("箱号为[{0}] 的变速箱存在多个根产品信息记录,请及时反馈给系统管理员",
                                                                 productCode));
                    return;
                }
                else if (rootGroup.Count() == 0)
                {
                    MessageDialog.ShowErrorMessage(string.Format("箱号为[{0}] 的变速箱没有大总成记录,无法进行此查询请使用“综合查询”,其共有 {1} 条返修记录",
                                                                 productCode, eRecords.Count()));

                    return;
                }

                P_ElectronFile root = rootGroup.First();

                TreeNode rootNode = new TreeNode();

                rootNode.Name        = root.GoodsCode;
                rootNode.Text        = root.GoodsName;
                rootNode.ToolTipText = root.GoodsName + "," + root.GoodsCode + "," + root.Spec;
                rootNode.Tag         = root;
                treeView1.Nodes.Add(rootNode);
                m_parentElectronWords.Remove(root);

                for (int i = 0; i < m_parentElectronWords.Count; i++)
                {
                    P_ElectronFile item = m_parentElectronWords[i];

                    // 剔除零部件编码为空的零件,如:白锌平垫
                    if (item.GoodsCode == "")
                    {
                        continue;
                    }

                    if (item.ParentName != root.GoodsName)
                    {
                        lstParentCode.Remove(item.GoodsCode);
                        continue;
                    }

                    TreeNode parentNode = new TreeNode();

                    parentNode.Name        = item.GoodsCode;
                    parentNode.Text        = item.GoodsName;
                    parentNode.ToolTipText = item.GoodsName + "," + item.GoodsCode + "," + item.Spec;
                    parentNode.Tag         = item;

                    rootNode.Nodes.Add(parentNode);
                }

                List <P_ElectronFile> lstEF = (from r in eRecords
                                               where !lstParentCode.Contains(r.GoodsCode)
                                               orderby r.ParentName, r.ParentScanCode, r.GoodsName, r.GoodsCode, r.GoodsOnlyCode
                                               select r).ToList();

                for (int i = 0; i < rootNode.Nodes.Count; i++)
                {
                    RecursionBuildTreeView(rootNode.Nodes[i], m_parentElectronWords, lstEF);
                }

                RecursionBuildTreeView(rootNode, m_parentElectronWords, lstEF);
            }
            else
            {
                MessageDialog.ShowErrorMessage(error);
                return;
            }

            foreach (TreeNode item in treeView1.Nodes)
            {
                if (item.Nodes.Count > 0)
                {
                    item.Expand();
                }
            }
        }
        /// <summary>
        /// 添加维修记录(不仅变更箱号还根据旧箱电子档案生成新箱电子档案)
        /// </summary>
        /// <param name="data">要添加的数据</param>
        /// <param name="error">出错时返回的错误信息</param>
        /// <returns>操作是否成功的标志</returns>
        public bool Add(DepotManagementDataContext ctx, ZPX_ConvertedCVTNumber data, out string error)
        {
            error = null;

            try
            {
                string oldCVTNumber = data.OldProductType + " " + data.OldProductNumber;
                string newCVTNumber = data.NewProductType + " " + data.NewProductNumber;

                if (!m_electronFileServer.IsExists(oldCVTNumber))
                {
                    error = "电子档案中找不到旧箱信息,检查操作是否有误,无法继续";
                    return(false);
                }

                P_AssemblingBom oldBom = m_assemblingBom.GetRootNode(data.OldProductType);
                P_AssemblingBom newBom = m_assemblingBom.GetRootNode(data.NewProductType);

                #region Modify by cjb on 2016.10.9, reason:由于LINQ无法调用存储过程ZPX_ConvertElectronFile,为保证操作在同一事务里,故用代码实现存储过程中的功能

                string OldCode = oldCVTNumber;
                string OldName = oldBom.PartName;
                string NewCode = newCVTNumber;
                string NewName = newBom.PartName;

                var varData = from a in ctx.P_ElectronFile
                              where a.ProductCode == OldCode
                              select a;

                if (varData.Count() == 0)
                {
                    throw new Exception(string.Format("箱号{0}的变速箱电子档案已经存在,无法进行此操作!", OldCode));
                }

                foreach (P_ElectronFile item in varData)
                {
                    P_ElectronFile tempFile = item;
                    string         NewType  = NewCode.Substring(NewCode.IndexOf(' ')).Trim();

                    P_ElectronFile lnqInsert = new P_ElectronFile();

                    lnqInsert.ProductCode      = NewCode;
                    lnqInsert.ParentCode       = tempFile.ParentName == OldName ? NewType : tempFile.ParentCode;
                    lnqInsert.ParentName       = tempFile.ParentName == OldName ? NewName : tempFile.ParentName;
                    lnqInsert.ParentScanCode   = tempFile.ParentScanCode == OldCode ? NewCode : tempFile.ParentScanCode;
                    lnqInsert.GoodsCode        = tempFile.GoodsName == OldName ? NewType : tempFile.GoodsCode;
                    lnqInsert.GoodsName        = tempFile.GoodsName == OldName ? NewName : tempFile.GoodsName;
                    lnqInsert.Spec             = tempFile.Spec;
                    lnqInsert.GoodsOnlyCode    = tempFile.GoodsOnlyCode == OldCode ? NewCode : tempFile.GoodsOnlyCode;
                    lnqInsert.Counts           = tempFile.Counts;
                    lnqInsert.Provider         = tempFile.Provider;
                    lnqInsert.BatchNo          = tempFile.BatchNo;
                    lnqInsert.WorkBench        = tempFile.WorkBench;
                    lnqInsert.CheckDatas       = tempFile.CheckDatas;
                    lnqInsert.FactDatas        = tempFile.FactDatas;
                    lnqInsert.FittingPersonnel = tempFile.FittingPersonnel;
                    lnqInsert.FittingTime      = ServerTime.Time.ToString("yyyy-MM-dd HH:mm:ss");
                    lnqInsert.FinishTime       = ServerTime.Time.ToString("yyyy-MM-dd HH:mm:ss");
                    lnqInsert.FillInPersonnel  = tempFile.FillInPersonnel;
                    lnqInsert.FillInDate       = tempFile.FillInDate;
                    lnqInsert.AssemblingMode   = tempFile.AssemblingMode;

                    if (lnqInsert.ParentCode == "")
                    {
                        lnqInsert.Remark = string.Format("[旧箱箱号:{0},{1}]; {2}", OldCode, ServerTime.Time.ToString("yyyy-MM-dd HH:mm:ss"), tempFile.Remark);
                    }
                    else
                    {
                        lnqInsert.Remark = string.Format("旧箱箱号:{0}; {1}", OldCode, tempFile.Remark);
                    }

                    ctx.P_ElectronFile.InsertOnSubmit(lnqInsert);
                }


                var varUpdate1 = from a in ctx.P_ElectronFile
                                 where a.ProductCode == OldCode && a.ParentCode == ""
                                 select a;

                foreach (P_ElectronFile item in varUpdate1)
                {
                    item.Remark += string.Format("[新箱箱号:{0},{1}]", NewCode, ServerTime.Time.ToString("yyyy-MM-dd HH:mm:ss"));
                }

                #endregion

                //GlobalObject.DatabaseServer.QueryInfoPro("ZPX_ConvertElectronFile", hsTable, out error);

                //ctx.ZPX_ConvertElectronFile(oldCVTNumber, oldBom.PartName, newCVTNumber, newBom.PartName);

                //IDBOperate dbOperate = CommentParameter.GetDBOperate();

                //Hashtable paramTable = new Hashtable();

                //paramTable.Add("@OldCode", oldCVTNumber);
                //paramTable.Add("@OldName", oldBom.PartName);
                //paramTable.Add("@NewCode", newCVTNumber);
                //paramTable.Add("@NewName", newBom.PartName);

                //Dictionary<OperateCMD, object> dicOperateCMD = dbOperate.RunProc_CMD("ZPX_ConvertElectronFile", paramTable);

                //if (!Convert.ToBoolean(dicOperateCMD[OperateCMD.Return_OperateResult]))
                //{
                //    error = Convert.ToString(dicOperateCMD[OperateCMD.Return_Errmsg]);
                //    return false;
                //}

                //DateTime serverTime = ServerTime.Time;

                //P_ElectronFile item = m_electronFileServer.CreateElectronFile(newCVTNumber);

                //item.GoodsCode = rootBom.PartCode;
                //item.GoodsName = rootBom.PartName;
                //item.GoodsOnlyCode = item.ProductCode;
                //item.WorkBench = rootBom.Workbench;
                //item.Remark = string.Format("旧箱箱号 {0};", oldCVTNumber);

                //m_electronFileServer.AddElectronFile(ctx, item);

                //P_ElectronFile oldRoot = m_electronFileServer.GetRootNode(ctx, oldCVTNumber);

                //oldRoot.Remark += string.Format("新箱箱号 {0};", newCVTNumber);

                ctx.ZPX_ConvertedCVTNumber.InsertOnSubmit(data);

                return(true);
            }
            catch (Exception exce)
            {
                error = exce.Message;
                return(false);
            }
        }