namespace BLL
{
    using Model;
    using System.Collections.Generic;
    using System.Linq;
    public static class Base_DetectionRateService
    {
        /// 
        ///获取探伤比例信息
        /// 
        /// 
        public static Model.Base_DetectionRate GetDetectionRateByDetectionRateId(string detectionRateId)
        {
            return Funs.DB.Base_DetectionRate.FirstOrDefault(e => e.DetectionRateId == detectionRateId);
        }
        /// 
        /// 增加探伤比例信息
        /// 
        /// 
        public static void AddDetectionRate(Model.Base_DetectionRate detectionRate)
        {
            Model.SGGLDB db = Funs.DB;
            Model.Base_DetectionRate newDetectionRate = new Base_DetectionRate
            {
                DetectionRateId = detectionRate.DetectionRateId,
                DetectionRateCode = detectionRate.DetectionRateCode,
                DetectionRateValue = detectionRate.DetectionRateValue,
                Remark = detectionRate.Remark,
            };
            db.Base_DetectionRate.InsertOnSubmit(newDetectionRate);
            db.SubmitChanges();
        }
        /// 
        /// 修改探伤比例信息 
        /// 
        /// 
        public static void UpdateDetectionRate(Model.Base_DetectionRate detectionRate)
        {
            Model.SGGLDB db = Funs.DB;
            Model.Base_DetectionRate newDetectionRate = db.Base_DetectionRate.FirstOrDefault(e => e.DetectionRateId == detectionRate.DetectionRateId);
            if (newDetectionRate != null)
            {
                newDetectionRate.DetectionRateCode = detectionRate.DetectionRateCode;
                newDetectionRate.DetectionRateValue = detectionRate.DetectionRateValue;
                newDetectionRate.Remark = detectionRate.Remark;
                db.SubmitChanges();
            }
        }
        /// 
        /// 根据探伤比例Id删除一个探伤比例信息
        /// 
        /// 
        public static void DeleteDetectionRateByDetectionRateId(string detectionRateId)
        {
            Model.SGGLDB db = Funs.DB;
            Model.Base_DetectionRate delDetectionRate = db.Base_DetectionRate.FirstOrDefault(e => e.DetectionRateId == detectionRateId);
            if (delDetectionRate != null)
            {
                db.Base_DetectionRate.DeleteOnSubmit(delDetectionRate);
                db.SubmitChanges();
            }
        }
        /// 
        /// 按类型获取探伤比例项
        /// 
        /// 
        /// 
        public static List GetDetectionRateList()
        {
            var list = (from x in Funs.DB.Base_DetectionRate
                        orderby x.DetectionRateCode
                        select x).ToList();
            return list;
        }
        #region 探伤比例下拉项
        /// 
        /// 探伤比例下拉项
        /// 
        /// 下拉框名称
        /// 是否显示请选择
        /// 耗材类型
        public static void InitDetectionRateDropDownList(FineUIPro.DropDownList dropName, bool isShowPlease)
        {
            dropName.DataValueField = "DetectionRateId";
            dropName.DataTextField = "DetectionRateCode";
            dropName.DataSource = GetDetectionRateList();
            dropName.DataBind();
            if (isShowPlease)
            {
                Funs.FineUIPleaseSelect(dropName);
            }
        }
        #endregion
    }
}