Exemple #1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (!CheckData())
            {
                return;
            }

            ZPX_CVTRepairInfo data = new ZPX_CVTRepairInfo();

            data.ProductType = cmbProductCode.Text;

            if (cmbRepairType.SelectedIndex != 3)
            {
                data.ProductNewNumber = txtProductNumber.Text;
            }
            else
            {
                data.ProductOldNumber = txtOldProductCode.Text;
                data.ProductNewNumber = txtNewProductCode.Text;
                data.BonnetNumber     = txtBonnetCode.Text;
            }

            data.Assembler  = txtAssembler.Text.ToString();
            data.Fault      = txtFault.Text;
            data.Scheme     = txtScheme.Text.Trim();
            data.IsTest     = cbTest.Checked;
            data.Hours      = numTaskTime.Value;
            data.Recorder   = BasicInfo.LoginID;
            data.RecordTime = ServerTime.Time;
            data.Status     = "等待审核";
            data.RepairType = cmbRepairType.Text;

            if (cmbAssociateType.SelectedIndex != -1)
            {
                data.AssociateType = cmbAssociateType.Text;

                if (cmbAssociateType.SelectedIndex == 0)
                {
                    data.AssociateBillNo = txtAssociateBillNoBF.Text;
                }
                else
                {
                    data.AssociateBillNo = txtAssociaBillNoTK.Text;
                }
            }

            try
            {
                m_testServer.Insert(data);

                RefreshDataGridView(m_testServer.GetViewData(new View_ZPX_CVTRepairInfo()
                {
                    序号 = data.ID
                }));
            }
            catch (Exception exce)
            {
                MessageDialog.ShowErrorMessage(exce.Message);
            }
        }
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="data">要更新的数据</param>
        /// <returns>操作是否成功的标志</returns>
        public bool Update(View_ZPX_CVTRepairInfo data)
        {
            DepotManagementDataContext context = CommentParameter.DepotDataContext;

            var result = from r in context.ZPX_CVTRepairInfo
                         where r.ID == data.序号
                         select r;

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

            ZPX_CVTRepairInfo updateData = result.Single();

            if (updateData.Recorder != GlobalObject.BasicInfo.LoginID)
            {
                throw new Exception("不是记录创建人员不允许进行此操作");
            }

            if (updateData.Status == "已完成")
            {
                throw new Exception("返修已完成,不允许进行此操作");
            }

            View_ZPX_CVTRepairInfo old = (from r in context.View_ZPX_CVTRepairInfo
                                          where r.序号 == data.序号
                                          select r).Single();

            if (GlobalObject.StapleFunction.SimpleEqual <View_ZPX_CVTRepairInfo>(old, data))
            {
                throw new Exception("数据没有任何变化,不需要进行此操作");
            }

            updateData.ProductType      = data.产品型号;
            updateData.Assembler        = data.返修人员;
            updateData.AssociateBillNo  = data.关联单号;
            updateData.AssociateType    = data.关联单据类别;
            updateData.BonnetNumber     = data.阀块编号;
            updateData.Fault            = data.故障现象;
            updateData.Duty             = data.责任判定;
            updateData.Hours            = data.工时;
            updateData.IsTest           = data.是否需要重新跑试验 == "需要" ? true : false;
            updateData.ProductNewNumber = data.新箱号;
            updateData.ProductOldNumber = data.旧箱号;
            updateData.RepairType       = data.返修类型;
            updateData.Scheme           = data.返修方案及明细;
            updateData.Status           = data.单据状态;

            context.SubmitChanges();

            return(true);
        }
        /// <summary>
        /// 添加数据
        /// </summary>
        /// <param name="data">要添加的数据</param>
        /// <returns>操作是否成功的标志</returns>
        public bool Insert(ZPX_CVTRepairInfo data)
        {
            DepotManagementDataContext context = CommentParameter.DepotDataContext;

            var result = from r in context.ZPX_CVTRepairInfo
                         where r.ProductType == data.ProductType && r.ProductOldNumber == data.ProductOldNumber &&
                         r.RepairType == data.RepairType && r.ProductNewNumber == r.ProductNewNumber &&
                         r.Hours == data.Hours
                         select r;

            if (result.Count() > 0)
            {
                throw new Exception("已经存在此记录,不允许重复添加");
            }

            context.ZPX_CVTRepairInfo.InsertOnSubmit(data);
            context.SubmitChanges();

            return(true);
        }
        /// <summary>
        /// 质检判定
        /// </summary>
        /// <param name="dataID">要判定的数据编号</param>
        /// <param name="duty">判定内容</param>
        /// <returns>操作是否成功的标志</returns>
        public bool Auditing(int dataID, string duty)
        {
            DepotManagementDataContext context = CommentParameter.DepotDataContext;

            var result = from r in context.ZPX_CVTRepairInfo
                         where r.ID == dataID
                         select r;

            if (result.Count() == 0)
            {
                throw new Exception("找不到要审核的记录,无法进行此操作");
            }

            ZPX_CVTRepairInfo updateData = result.Single();

            updateData.Duty   = BasicInfo.LoginName + ServerTime.Time.ToString() + duty;
            updateData.Status = "已完成";

            context.SubmitChanges();

            return(true);
        }