Exemple #1
0
        public bool AddAdjustSlip(GageAdjustSlip adjustSlip, User CurrentUser)
        {
            using (SqlConnection conn = new SqlConnection(Common.SQLHelper.Asset_strConn))
            {
                conn.Open();
                SqlTransaction sqlTransaction = conn.BeginTransaction();
                try
                {
                    Asset gage = Asset.GetBy(adjustSlip.AssetID);
                    if (gage == null)
                    {
                        throw new Exception("资产不存在");
                    }
                    if (!"在库领用".Contains(gage.Status.Substring(gage.Status.Length - 2)))
                    {
                        throw new Exception("资产未处于在库或领用状态");
                    }


                    Gage gageDetail = Gage.GetBy(gage.AssetID).First();
                    if (gageDetail.StandardAdjustType == "免校")
                    {
                        throw new Exception("无法为免校的资产做校准");
                    }
                    gageDetail.NextAdjustDate = null;


                    adjustSlip.AssetName      = gage.AssetName;
                    adjustSlip.AdjustDate     = DateTime.Now;
                    adjustSlip.TransactorName = CurrentUser.Name;


                    gage.Status                   = gage.AddStatus("在校");
                    gage.CurrentWhereSpot         = adjustSlip.Spot;
                    gage.CurrentWhereOrganization = adjustSlip.Organization;


                    gageDetail.sqlTransaction = gage.sqlTransaction = adjustSlip.sqlTransaction = sqlTransaction;
                    adjustSlip.Add();
                    gage.Update();
                    gageDetail.Update();

                    sqlTransaction.Commit();
                    return(true);
                }
                catch
                {
                    sqlTransaction.Rollback();
                    throw;
                }
            }
        }
Exemple #2
0
        public bool Update(Gage paras)
        {
            using (SqlConnection conn = new SqlConnection(Common.SQLHelper.Asset_strConn))
            {
                conn.Open();
                SqlTransaction sqlTransaction = conn.BeginTransaction();
                try
                {
                    Asset gage = Asset.GetBy(paras.AssetID);
                    if (gage == null)
                    {
                        throw new Exception("资产不存在");
                    }
                    paras.CopyTo(gage, false);


                    Gage gageDetail = Gage.GetBy(gage.AssetID).First();

                    ////填充前的检测
                    //if(!gageDetail.Status.Contains(paras.StandardAdjustType))
                    //    throw new Exception("");

                    //使用新数据填充
                    paras.CopyTo(gageDetail, false);


                    if (gageDetail.StandardAdjustType == "免校")
                    {
                        gageDetail.AdjustPeriod             = null;
                        gageDetail.NextAdjustDate           = null;
                        gageDetail.AdjustNoticeDays         = null;
                        gageDetail.DefaultAdjustRequirement = null;
                    }


                    gageDetail.sqlTransaction = gage.sqlTransaction = sqlTransaction;
                    gage.Update();
                    gageDetail.Update();

                    sqlTransaction.Commit();
                    return(true);
                }
                catch
                {
                    sqlTransaction.Rollback();
                    throw;
                }
            }
        }