using System;
using System.Collections.Generic;
using System.Data;
using QMAPP.BLL;
using QMAPP.Entity;
using QMAPP.FJC.BLL.Dict;
using QMAPP.FJC.DAL.FileCopy;
using QMAPP.FJC.Entity.FeedInManage;
using QMAPP.FJC.Entity.FileCopy;
using QMFrameWork.Data;
using QMFrameWork.Log;

namespace QMAPP.FJC.BLL.FileCopy
{
    /// <summary>
    /// 模块编号:
    /// 作    用:
    /// 作    者:王庆男
    /// 编写日期:2015年09月08日
    ///</summary>
    public class FileCopyRecordBLL : BaseBLL
    {


        #region 获取信息
        /// <summary>
        /// 获取信息
        /// </summary>
        /// <param name="">条件</param>
        /// <returns>信息</returns>
        public FileCopyRecord Get(FileCopyRecord model)
        {
            try
            {
                return new FileCopyRecordDAL().Get(model);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion


        #region 获取列表
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="condition">条件</param>
        /// <param name="page">数据页</param>
        /// <returns>数据页</returns>
        public DataPage GetList(FileCopyRecord condition, DataPage page)
        {
            try
            {
                return new FileCopyRecordDAL().GetList(condition, page);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="condition">条件</param>
        /// <param name="page">数据页</param>
        /// <returns>数据页</returns>
        public List<FileCopyRecord> GetAllList(FileCopyRecord condition)
        {
            try
            {
                return new FileCopyRecordDAL().GetList(condition);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion


        #region 信息是否重复
        /// <summary>
        /// 判断名称是否存在
        /// </summary>
        /// <param name="info"></param>
        /// <returns>true:已存在;fasel:不存在。</returns>
        public bool ExistsFileCopyRecord(FileCopyRecord model)
        {
            try
            {
                return new FileCopyRecordDAL().ExistsT_AW_FILE_COPY_RECORD(model);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }


        #endregion


        #region 插入信息
        /// <summary>
        /// 插入信息(单表)
        /// </summary>
        /// <param name="">信息</param>
        /// <returns>插入行数</returns>
        public int Insert(FileCopyRecord model)
        {
            try
            {
                //基本信息
                //model.RECORD_KEY = Guid.NewGuid().ToString();
                //model.RECORD_COPY_DATETIME = DateTime.Now;
                FileCopyRecordDAL cmdDAL = new FileCopyRecordDAL();
                if (ExistsFileCopyRecord(model) == true)
                    return -1;
                return new FileCopyRecordDAL().Insert(model);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion


        #region 更新信息
        /// <summary>
        /// 更新信息
        /// </summary>
        /// <param name=""></param>
        /// <returns>更新行数</returns>
        public int Update(FileCopyRecord model)
        {
            try
            {
                //if (ExistsFileCopyRecord(Model) == true)
                //return -1;
                //基本信息 

                return new FileCopyRecordDAL().Update(model);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }


        /// <summary>
        /// 更新信息
        /// </summary>
        /// <param name=""></param>
        /// <returns>更新行数</returns>
        public int UpdateForTime(string EQUIPMENT_INFO_KEY, string RECORD_FILENAME, string FILE_HOSTNAME, string FILE_EXPLANTTIME)
        {
            try
            {
                //if (ExistsFileCopyRecord(Model) == true)
                //return -1;
                //基本信息 

                return new FileCopyRecordDAL().Update(EQUIPMENT_INFO_KEY, RECORD_FILENAME, FILE_HOSTNAME, FILE_EXPLANTTIME);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion


        #region 删除
        /// <summary>
        /// 删除信息
        /// </summary>
        /// <param name=""></param>
        /// <returns>删除个数</returns>
        public int Delete(string strs)
        {
            int count = 0;
            string[] list = strs.Split(":".ToCharArray());
            try
            {
                foreach (string str in list)
                {
                    count += this.DeleteFileCopyRecord(new FileCopyRecord { RECORD_KEY = str });
                }
                return count;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }


        /// <summary>
        /// 删除信息
        /// </summary>
        /// <param name="">信息</param>
        /// <returns>删除个数</returns>
        public int DeleteFileCopyRecord(FileCopyRecord model)
        {
            int count = 0;
            try
            {
                count = new FileCopyRecordDAL().Delete(model);
                return count;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

           /// <summary>
        /// 获取条码
        /// </summary>
        /// <param name=""></param>
        /// <returns>获取条码</returns>
        public string GetBarcode(string tempbarcode)
        {
            return new FileCopyRecordDAL().GetBarcode(tempbarcode);
        }


        public FileCopyRecord GetLastRecord(string equipmentCode)
        {
            return new FileCopyRecordDAL().GetLastRecord(equipmentCode);
        }
    }
}