/// <summary>
        /// 添加映射表信息
        /// </summary>
        /// <param name="bomMapping">要添加的信息</param>
        /// <returns>返回是否成功的标志</returns>
        public bool AddBomMapping(P_ProductBomMapping bomMapping)
        {
            try
            {
                DepotManagementDataContext dataContxt = CommentParameter.DepotDataContext;

                dataContxt.P_ProductBomMapping.InsertOnSubmit(bomMapping);
                dataContxt.SubmitChanges(System.Data.Linq.ConflictMode.ContinueOnConflict);

                return(true);
            }
            catch (System.Data.Linq.ChangeConflictException)
            {
                DepotManagementDataContext dataContxt = CommentParameter.DepotDataContext;

                foreach (System.Data.Linq.ObjectChangeConflict occ in dataContxt.ChangeConflicts)
                {
                    // 使用Linq缓存中实体对象的值,覆盖当前数据库中的值
                    occ.Resolve(System.Data.Linq.RefreshMode.KeepCurrentValues);
                }

                dataContxt.SubmitChanges();
                return(true);
            }
            catch (Exception err)
            {
                DepotManagementDataContext dataContxt = CommentParameter.DepotDataContext;

                try
                {
                    string error = err.Message;

                    dataContxt.Dispose();

                    dataContxt = CommentParameter.DepotDataContext;
                    dataContxt.P_ProductBomMapping.InsertOnSubmit(bomMapping);

                    dataContxt.SubmitChanges();

                    return(true);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows == null)
            {
                MessageDialog.ShowPromptMessage("请选择需要删除的记录后再进行此操作!");
                return;
            }

            if (!CheckData())
            {
                return;
            }

            try
            {
                P_ProductBomMapping bomMapping = new P_ProductBomMapping();

                bomMapping.ProductName       = txtProductName.Text;
                bomMapping.ParentCode        = txtParentCode.Text;
                bomMapping.ParentName        = txtParentName.Text;
                bomMapping.PartCode          = txtCode.Text;
                bomMapping.PartName          = txtName.Text;
                bomMapping.Spec              = txtSpec.Text;
                bomMapping.PartCounts        = Convert.ToInt32(numBasicCount.Value);
                bomMapping.FittingParentName = cmbAssemblyParentName.Text;
                bomMapping.FittingCounts     = Convert.ToInt32(numAssemblyCount.Value);
                bomMapping.Date              = ServerModule.ServerTime.Time;
                bomMapping.UserCode          = BasicInfo.LoginID;
                bomMapping.Workbench         = cmbWorkBench.Text;
                bomMapping.NeedToClean       = cmbCleanout.SelectedIndex > 0;
                bomMapping.Remarks           = txtAssemblyRemark.Text;

                m_bomMappingServer.UpdateBomMapping(Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["序号"].Value), bomMapping);
                RefreshDataGridView(txtProductName.Text);
                PositioningRecord(bomMapping.ParentCode, bomMapping.PartCode);
            }
            catch (Exception err)
            {
                MessageDialog.ShowErrorMessage(err.Message);
            }
        }
        /// <summary>
        /// 更新映射表中某一产品名称
        /// </summary>
        /// <param name="oldProductName">老产品名称</param>
        /// <param name="newProductName">新产品名称</param>
        /// <returns>返回是否成功更新BomMapping中某一版本的版本号</returns>
        public bool UpdateProductName(string oldProductName, string newProductName)
        {
            DepotManagementDataContext dataContxt = CommentParameter.DepotDataContext;

            var result = from r in dataContxt.P_ProductBomMapping
                         where r.ProductName == oldProductName
                         select r;

            try
            {
                if (result.Count() == 0)
                {
                    throw new Exception("没有找到要更新的记录无法进行此操作!");
                }

                foreach (var record in result)
                {
                    P_ProductBomMapping updateRecord = record;

                    updateRecord.ProductName = newProductName;
                }

                dataContxt.SubmitChanges(System.Data.Linq.ConflictMode.ContinueOnConflict);
                return(true);
            }
            catch (System.Data.Linq.ChangeConflictException)
            {
                foreach (System.Data.Linq.ObjectChangeConflict occ in dataContxt.ChangeConflicts)
                {
                    // 使用Linq缓存中实体对象的值,覆盖当前数据库中的值
                    occ.Resolve(System.Data.Linq.RefreshMode.KeepCurrentValues);
                }

                dataContxt.SubmitChanges();
                return(true);
            }
            catch (Exception err)
            {
                try
                {
                    string error = err.Message;

                    dataContxt.Dispose();
                    dataContxt = CommentParameter.DepotDataContext;

                    foreach (var record in result)
                    {
                        P_ProductBomMapping updateRecord = record;

                        updateRecord.ProductName = newProductName;
                        dataContxt.P_ProductBomMapping.Attach(updateRecord);
                    }

                    dataContxt.SubmitChanges();
                    return(true);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
        }
        /// <summary>
        /// 修改指定映射表信息
        /// </summary>
        /// <param name="id">要更新的数据 ID</param>
        /// <param name="bomMapping">修改后的值</param>
        /// <returns>返回是否成功的标志</returns>
        public bool UpdateBomMapping(int id, P_ProductBomMapping bomMapping)
        {
            try
            {
                DepotManagementDataContext dataContxt = CommentParameter.DepotDataContext;

                var result = from r in dataContxt.P_ProductBomMapping
                             where r.ID == id
                             select r;

                if (result.Count() == 0)
                {
                    throw new Exception("没有找到要更新的记录无法进行此操作!");
                }

                P_ProductBomMapping updateRecord = result.Single();

                updateRecord.ProductName       = bomMapping.ProductName;
                updateRecord.ParentCode        = bomMapping.ParentCode;
                updateRecord.ParentName        = bomMapping.ParentName;
                updateRecord.PartCode          = bomMapping.PartCode;
                updateRecord.PartName          = bomMapping.PartName;
                updateRecord.Spec              = bomMapping.Spec;
                updateRecord.PartCounts        = bomMapping.PartCounts;
                updateRecord.FittingParentName = bomMapping.FittingParentName;
                updateRecord.FittingCounts     = bomMapping.FittingCounts;
                updateRecord.Workbench         = bomMapping.Workbench;
                updateRecord.NeedToClean       = bomMapping.NeedToClean;
                updateRecord.UserCode          = bomMapping.UserCode;
                updateRecord.Date              = bomMapping.Date;
                updateRecord.Remarks           = bomMapping.Remarks;

                dataContxt.SubmitChanges(System.Data.Linq.ConflictMode.ContinueOnConflict);
                return(true);
            }
            catch (System.Data.Linq.ChangeConflictException)
            {
                DepotManagementDataContext dataContxt = CommentParameter.DepotDataContext;

                foreach (System.Data.Linq.ObjectChangeConflict occ in dataContxt.ChangeConflicts)
                {
                    // 使用Linq缓存中实体对象的值,覆盖当前数据库中的值
                    occ.Resolve(System.Data.Linq.RefreshMode.KeepCurrentValues);
                }

                dataContxt.SubmitChanges();
                return(true);
            }
            catch (Exception err)
            {
                try
                {
                    DepotManagementDataContext dataContxt = CommentParameter.DepotDataContext;
                    string error = err.Message;

                    dataContxt.Dispose();

                    dataContxt = CommentParameter.DepotDataContext;
                    dataContxt.P_ProductBomMapping.Attach(bomMapping);
                    dataContxt.SubmitChanges();

                    return(true);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
        }