using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using ZXDT.DBUtility;
namespace ZXDT.CallCenter.DAL
{
    /// <summary>
    /// 数据访问类:T_Good_Info
    /// </summary>
    public partial class T_Good_Info
    {
        public T_Good_Info()
        { }
        #region  BasicMethod





        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(ZXDT.CallCenter.Model.T_Good_Info model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into T_Good_Info(");
            strSql.Append("F_GoodsName,F_KindsId,F_KindsName,F_PropertyId,F_PropertyName,F_PathId,F_PlaceId,F_PlaceName,F_GetDate,F_GetPersonName,F_Status,F_StatusName,F_OwerName,F_OwerPhoneNumber,F_OwerCardNumber,F_OwerCardPath,F_OwerDate,F_Remark,F_SaveDepeId,F_SaveDepeName,F_SaveUserId,F_SaveUserName,F_UserId,F_UserName,F_CreateDate,F_UpdateDate,F_EarNumber,F_GoodsImg)");
            strSql.Append(" values (");
            strSql.Append("@F_GoodsName,@F_KindsId,@F_KindsName,@F_PropertyId,@F_PropertyName,@F_PathId,@F_PlaceId,@F_PlaceName,@F_GetDate,@F_GetPersonName,@F_Status,@F_StatusName,@F_OwerName,@F_OwerPhoneNumber,@F_OwerCardNumber,@F_OwerCardPath,@F_OwerDate,@F_Remark,@F_SaveDepeId,@F_SaveDepeName,@F_SaveUserId,@F_SaveUserName,@F_UserId,@F_UserName,@F_CreateDate,@F_UpdateDate,@F_EarNumber,@F_GoodsImg)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@F_GoodsName", SqlDbType.NVarChar,50),
					new SqlParameter("@F_KindsId", SqlDbType.Int,4),
					new SqlParameter("@F_KindsName", SqlDbType.NVarChar,50),
					new SqlParameter("@F_PropertyId", SqlDbType.Int,4),
					new SqlParameter("@F_PropertyName", SqlDbType.NVarChar,50),
					new SqlParameter("@F_PathId", SqlDbType.Int,4),
					new SqlParameter("@F_PlaceId", SqlDbType.Int,4),
					new SqlParameter("@F_PlaceName", SqlDbType.NVarChar,50),
					new SqlParameter("@F_GetDate", SqlDbType.DateTime),
					new SqlParameter("@F_GetPersonName", SqlDbType.NVarChar,50),
					new SqlParameter("@F_Status", SqlDbType.Int,4),
					new SqlParameter("@F_StatusName", SqlDbType.NVarChar,50),
					new SqlParameter("@F_OwerName", SqlDbType.NVarChar,50),
					new SqlParameter("@F_OwerPhoneNumber", SqlDbType.NVarChar,50),
					new SqlParameter("@F_OwerCardNumber", SqlDbType.NVarChar,50),
					new SqlParameter("@F_OwerCardPath", SqlDbType.NVarChar,50),
					new SqlParameter("@F_OwerDate", SqlDbType.DateTime),
					new SqlParameter("@F_Remark", SqlDbType.NVarChar,4000),
					new SqlParameter("@F_SaveDepeId", SqlDbType.Int,4),
					new SqlParameter("@F_SaveDepeName", SqlDbType.NVarChar,50),
					new SqlParameter("@F_SaveUserId", SqlDbType.Int,4),
					new SqlParameter("@F_SaveUserName", SqlDbType.NVarChar,50),
					new SqlParameter("@F_UserId", SqlDbType.Int,4),
					new SqlParameter("@F_UserName", SqlDbType.NVarChar,50),
					new SqlParameter("@F_CreateDate", SqlDbType.DateTime),
					new SqlParameter("@F_UpdateDate", SqlDbType.DateTime),
					new SqlParameter("@F_EarNumber", SqlDbType.NVarChar,50),
                    new SqlParameter("@F_GoodsImg", SqlDbType.NVarChar,500)
                                        
                                        };
            parameters[0].Value = model.F_GoodsName;
            parameters[1].Value = model.F_KindsId;
            parameters[2].Value = model.F_KindsName;
            parameters[3].Value = model.F_PropertyId;
            parameters[4].Value = model.F_PropertyName;
            parameters[5].Value = model.F_PathId;
            parameters[6].Value = model.F_PlaceId;
            parameters[7].Value = model.F_PlaceName;
            parameters[8].Value = model.F_GetDate;
            parameters[9].Value = model.F_GetPersonName;
            parameters[10].Value = model.F_Status;
            parameters[11].Value = model.F_StatusName;
            parameters[12].Value = model.F_OwerName;
            parameters[13].Value = model.F_OwerPhoneNumber;
            parameters[14].Value = model.F_OwerCardNumber;
            parameters[15].Value = model.F_OwerCardPath;
            parameters[16].Value = model.F_OwerDate;
            parameters[17].Value = model.F_Remark;
            parameters[18].Value = model.F_SaveDepeId;
            parameters[19].Value = model.F_SaveDepeName;
            parameters[20].Value = model.F_SaveUserId;
            parameters[21].Value = model.F_SaveUserName;
            parameters[22].Value = model.F_UserId;
            parameters[23].Value = model.F_UserName;
            parameters[24].Value = model.F_CreateDate;
            parameters[25].Value = model.F_UpdateDate;
            parameters[26].Value = model.F_EarNumber;
            parameters[27].Value = model.F_GoodsImg;
            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(ZXDT.CallCenter.Model.T_Good_Info model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_Good_Info set ");
            strSql.Append("F_GoodsName=@F_GoodsName,");
            strSql.Append("F_KindsId=@F_KindsId,");
            strSql.Append("F_KindsName=@F_KindsName,");
            strSql.Append("F_PropertyId=@F_PropertyId,");
            strSql.Append("F_PropertyName=@F_PropertyName,");
            strSql.Append("F_GetDate=@F_GetDate,");
            strSql.Append("F_GetPersonName=@F_GetPersonName,");
            strSql.Append("F_Remark=@F_Remark,");
            strSql.Append("F_GoodsImg=@F_GoodsImg");
            strSql.Append(" where F_Id=@F_Id");
            SqlParameter[] parameters = {
					new SqlParameter("@F_GoodsName", SqlDbType.NVarChar,50),
					new SqlParameter("@F_KindsId", SqlDbType.Int,4),
					new SqlParameter("@F_KindsName", SqlDbType.NVarChar,50),
					new SqlParameter("@F_PropertyId", SqlDbType.Int,4),
					new SqlParameter("@F_PropertyName", SqlDbType.NVarChar,50),
					new SqlParameter("@F_GetDate", SqlDbType.DateTime),
					new SqlParameter("@F_GetPersonName", SqlDbType.NVarChar,50),
					new SqlParameter("@F_Remark", SqlDbType.NVarChar,4000),
					new SqlParameter("@F_GoodsImg", SqlDbType.NVarChar,500),
					new SqlParameter("@F_Id", SqlDbType.Int,4)};
            parameters[0].Value = model.F_GoodsName;
            parameters[1].Value = model.F_KindsId;
            parameters[2].Value = model.F_KindsName;
            parameters[3].Value = model.F_PropertyId;
            parameters[4].Value = model.F_PropertyName;
            parameters[5].Value = model.F_GetDate;
            parameters[6].Value = model.F_GetPersonName;
            parameters[7].Value = model.F_Remark;
            parameters[8].Value = model.F_GoodsImg;
            parameters[9].Value = model.F_Id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from T_Good_Info ");
            strSql.Append(" where F_Id=@F_Id");
            SqlParameter[] parameters = {
					new SqlParameter("@F_Id", SqlDbType.Int,4)
			};
            parameters[0].Value = id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string idlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from T_Good_Info ");
            strSql.Append(" where F_Id in (" + idlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ZXDT.CallCenter.Model.T_Good_Info GetModel(int id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 F_Id,F_GoodsName,F_KindsId,F_KindsName,F_PropertyId,F_PropertyName,F_PathId,F_PlaceId,F_PlaceName,F_GetDate,F_GetPersonName,F_Status,F_StatusName,F_OwerName,F_OwerPhoneNumber,F_OwerCardNumber,F_OwerCardPath,F_OwerDate,F_Remark,F_SaveDepeId,F_SaveDepeName,F_SaveUserId,F_SaveUserName,F_UserId,F_UserName,F_CreateDate,F_UpdateDate,F_EarNumber,F_GoodsImg,F_BackRemark from T_Good_Info ");
            strSql.Append(" where F_Id=@F_Id");
            SqlParameter[] parameters = {
					new SqlParameter("@F_Id", SqlDbType.Int,4)
			};
            parameters[0].Value = id;

            ZXDT.CallCenter.Model.T_Good_Info model = new ZXDT.CallCenter.Model.T_Good_Info();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ZXDT.CallCenter.Model.T_Good_Info DataRowToModel(DataRow row)
        {
            ZXDT.CallCenter.Model.T_Good_Info model = new ZXDT.CallCenter.Model.T_Good_Info();
            if (row != null)
            {
                if (row["F_Id"] != null && row["F_Id"].ToString() != "")
                {
                    model.F_Id = int.Parse(row["F_Id"].ToString());
                }
                if (row["F_GoodsName"] != null)
                {
                    model.F_GoodsName = row["F_GoodsName"].ToString();
                }
                if (row["F_KindsId"] != null && row["F_KindsId"].ToString() != "")
                {
                    model.F_KindsId = int.Parse(row["F_KindsId"].ToString());
                }
                if (row["F_KindsName"] != null)
                {
                    model.F_KindsName = row["F_KindsName"].ToString();
                }
                if (row["F_PropertyId"] != null && row["F_PropertyId"].ToString() != "")
                {
                    model.F_PropertyId = int.Parse(row["F_PropertyId"].ToString());
                }
                if (row["F_PropertyName"] != null)
                {
                    model.F_PropertyName = row["F_PropertyName"].ToString();
                }
                if (row["F_PathId"] != null && row["F_PathId"].ToString() != "")
                {
                    model.F_PathId = int.Parse(row["F_PathId"].ToString());
                }
                if (row["F_PlaceId"] != null && row["F_PlaceId"].ToString() != "")
                {
                    model.F_PlaceId = int.Parse(row["F_PlaceId"].ToString());
                }
                if (row["F_PlaceName"] != null)
                {
                    model.F_PlaceName = row["F_PlaceName"].ToString();
                }
                if (row["F_GetDate"] != null && row["F_GetDate"].ToString() != "")
                {
                    model.F_GetDate = DateTime.Parse(row["F_GetDate"].ToString());
                }
                if (row["F_GetPersonName"] != null)
                {
                    model.F_GetPersonName = row["F_GetPersonName"].ToString();
                }
                if (row["F_Status"] != null && row["F_Status"].ToString() != "")
                {
                    model.F_Status = int.Parse(row["F_Status"].ToString());
                }
                if (row["F_StatusName"] != null)
                {
                    model.F_StatusName = row["F_StatusName"].ToString();
                }
                if (row["F_OwerName"] != null)
                {
                    model.F_OwerName = row["F_OwerName"].ToString();
                }
                if (row["F_OwerPhoneNumber"] != null)
                {
                    model.F_OwerPhoneNumber = row["F_OwerPhoneNumber"].ToString();
                }
                if (row["F_OwerCardNumber"] != null)
                {
                    model.F_OwerCardNumber = row["F_OwerCardNumber"].ToString();
                }
                if (row["F_OwerCardPath"] != null)
                {
                    model.F_OwerCardPath = row["F_OwerCardPath"].ToString();
                }
                if (row["F_OwerDate"] != null && row["F_OwerDate"].ToString() != "")
                {
                    model.F_OwerDate = DateTime.Parse(row["F_OwerDate"].ToString());
                }
                if (row["F_Remark"] != null)
                {
                    model.F_Remark = row["F_Remark"].ToString();
                }
                if (row["F_SaveDepeId"] != null && row["F_SaveDepeId"].ToString() != "")
                {
                    model.F_SaveDepeId = int.Parse(row["F_SaveDepeId"].ToString());
                }
                if (row["F_SaveDepeName"] != null)
                {
                    model.F_SaveDepeName = row["F_SaveDepeName"].ToString();
                }
                if (row["F_SaveUserId"] != null && row["F_SaveUserId"].ToString() != "")
                {
                    model.F_SaveUserId = int.Parse(row["F_SaveUserId"].ToString());
                }
                if (row["F_SaveUserName"] != null)
                {
                    model.F_SaveUserName = row["F_SaveUserName"].ToString();
                }
                if (row["F_UserId"] != null && row["F_UserId"].ToString() != "")
                {
                    model.F_UserId = int.Parse(row["F_UserId"].ToString());
                }
                if (row["F_UserName"] != null)
                {
                    model.F_UserName = row["F_UserName"].ToString();
                }
                if (row["F_CreateDate"] != null && row["F_CreateDate"].ToString() != "")
                {
                    model.F_CreateDate = DateTime.Parse(row["F_CreateDate"].ToString());
                }
                if (row["F_UpdateDate"] != null && row["F_UpdateDate"].ToString() != "")
                {
                    model.F_UpdateDate = DateTime.Parse(row["F_UpdateDate"].ToString());
                }
                if (row["F_EarNumber"] != null)
                {
                    model.F_EarNumber = row["F_EarNumber"].ToString();
                }
                if (row["F_GoodsImg"] != null)
                {
                    model.F_GoodsImg = row["F_GoodsImg"].ToString();
                }
                if (row["F_BackRemark"] != null)
                {
                    model.F_BackRemark = row["F_BackRemark"].ToString();
                }
                
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select F_Id,F_GoodsName,F_KindsId,F_KindsName,F_PropertyId,F_PropertyName,F_PathId,F_PlaceId,F_PlaceName,F_GetDate,F_GetPersonName,F_Status,F_StatusName,F_OwerName,F_OwerPhoneNumber,F_OwerCardNumber,F_OwerCardPath,F_OwerDate,F_Remark,F_SaveDepeId,F_SaveDepeName,F_SaveUserId,F_SaveUserName,F_UserId,F_UserName,F_CreateDate,F_UpdateDate,F_EarNumber,F_GoodsImg,F_BackRemark ");
            strSql.Append(" FROM T_Good_Info ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }


        /// <summary>
        /// 归还
        /// </summary>
        public bool RebackGoods(ZXDT.CallCenter.Model.T_Good_Info model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_Good_Info set ");
            strSql.Append("F_Status=@F_Status,");
            strSql.Append("F_StatusName=@F_StatusName,");
            strSql.Append("F_OwerName=@F_OwerName,");
            strSql.Append("F_OwerPhoneNumber=@F_OwerPhoneNumber,");
            strSql.Append("F_OwerCardNumber=@F_OwerCardNumber,");
            strSql.Append("F_OwerCardPath=@F_OwerCardPath,");
            strSql.Append("F_OwerDate=@F_OwerDate,");
            strSql.Append("F_UpdateDate=@F_UpdateDate,");
            strSql.Append("F_EarNumber=@F_EarNumber,");
            strSql.Append("F_BackRemark=@F_BackRemark");
            strSql.Append(" where F_Id=@F_Id");
            SqlParameter[] parameters = {
					new SqlParameter("@F_Status", SqlDbType.Int,4),
					new SqlParameter("@F_StatusName", SqlDbType.NVarChar,50),
					new SqlParameter("@F_OwerName", SqlDbType.NVarChar,50),
					new SqlParameter("@F_OwerPhoneNumber", SqlDbType.NVarChar,50),
					new SqlParameter("@F_OwerCardNumber", SqlDbType.NVarChar,50),
					new SqlParameter("@F_OwerCardPath", SqlDbType.NVarChar,50),
					new SqlParameter("@F_OwerDate", SqlDbType.DateTime),
					new SqlParameter("@F_UpdateDate", SqlDbType.DateTime),
                    new SqlParameter("@F_EarNumber", SqlDbType.NVarChar,50),
                      new SqlParameter("@F_BackRemark", SqlDbType.NVarChar,4000),
					new SqlParameter("@F_Id", SqlDbType.Int,4)};

            parameters[0].Value = model.F_Status;
            parameters[1].Value = model.F_StatusName;
            parameters[2].Value = model.F_OwerName;
            parameters[3].Value = model.F_OwerPhoneNumber;
            parameters[4].Value = model.F_OwerCardNumber;
            parameters[5].Value = model.F_OwerCardPath;
            parameters[6].Value = DateTime.Now;
            parameters[7].Value = DateTime.Now;
            parameters[8].Value = model.F_EarNumber;
            parameters[9].Value = model.F_BackRemark;
            parameters[10].Value = model.F_Id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        #endregion  BasicMethod



        #region  失物转移发起

        public bool TransferGoodList(Model.T_Good_TransInfo model)
        {
            bool result = false;

            //事务处理
            NoSortHashtable table = new NoSortHashtable();

            if (model != null && !string.IsNullOrEmpty(model.KeyList))
            {
                string[] keyList = model.KeyList.Split(',');

                if (keyList.Length > 0)
                {
                    StringBuilder strSql = new StringBuilder();
                    foreach (string key in keyList)
                    {
                        if (model.types == 0)
                        {

                            //修改主表信息
                            strSql = new StringBuilder();
                            strSql.AppendFormat(@"------------{0} {1}", System.Guid.NewGuid().ToString(), Environment.NewLine);
                            strSql.Append("update  T_Good_Info set F_Status=@F_Status,F_StatusName=@F_StatusName ");
                            strSql.Append(" where F_Id=@F_Id");
                            SqlParameter[] parameters = {
					    new SqlParameter("@F_Status", SqlDbType.Int,4),
                    	new SqlParameter("@F_StatusName", SqlDbType.NVarChar,50),
                        new SqlParameter("@F_Id", SqlDbType.Int,4) };
                            parameters[0].Value = 1;
                            parameters[1].Value = "转移中";
                            parameters[2].Value = int.Parse(key);
                            table.Add(strSql.ToString(), parameters);

                            //插入转移信息
                            strSql = new StringBuilder();
                            strSql.AppendFormat(@"------------{0} {1}", System.Guid.NewGuid().ToString(), Environment.NewLine);
                            strSql.Append("insert into T_Good_TransInfo(");
                            strSql.Append("F_TStatus,F_TStatusName,F_RecivedDepId,F_RecivedDepName,F_CreateDate,F_GoodInfoId)");
                            strSql.Append(" values (");
                            strSql.Append("@F_TStatus,@F_TStatusName,@F_RecivedDepId,@F_RecivedDepName,@F_CreateDate,@F_GoodInfoId)");
                            SqlParameter[] parametersContent = {
					new SqlParameter("@F_TStatus", SqlDbType.Int,4),
					new SqlParameter("@F_TStatusName", SqlDbType.NVarChar,50),
					new SqlParameter("@F_RecivedDepId", SqlDbType.Int,4),
					new SqlParameter("@F_RecivedDepName", SqlDbType.NVarChar,50),
					new SqlParameter("@F_CreateDate", SqlDbType.DateTime),
					new SqlParameter("@F_GoodInfoId", SqlDbType.Int,4)};
                            parametersContent[0].Value = 0;
                            parametersContent[1].Value = "未接收";
                            parametersContent[2].Value = model.F_RecivedUserID;
                            parametersContent[3].Value = model.F_RecivedUserName;
                            parametersContent[4].Value = DateTime.Now;
                            parametersContent[5].Value = int.Parse(key);
                            table.Add(strSql.ToString(), parametersContent);
                        }
                        else
                        {

                            //修改主表信息
                            strSql = new StringBuilder();
                            strSql.AppendFormat(@"------------{0} {1}", System.Guid.NewGuid().ToString(), Environment.NewLine);
                            strSql.Append("update  T_Good_Info set F_Status=@F_Status,F_StatusName=@F_StatusName,F_SaveDepeId=@F_SaveDepeId,F_SaveDepeName=@F_SaveDepeName ");
                            strSql.Append(" where F_Id=@F_Id");
                            SqlParameter[] parameters = {
					    new SqlParameter("@F_Status", SqlDbType.Int,4),
                    	new SqlParameter("@F_StatusName", SqlDbType.NVarChar,50),
                           new SqlParameter("@F_SaveDepeId", SqlDbType.Int,4),
                    	new SqlParameter("@F_SaveDepeName", SqlDbType.NVarChar,50),
                        new SqlParameter("@F_Id", SqlDbType.Int,4) };
                            parameters[0].Value = 4;
                            parameters[1].Value = "外部单位";
                            parameters[2].Value = DBNull.Value;
                            parameters[3].Value = model.F_OtherDeptName;
                            parameters[4].Value = int.Parse(key);
                            table.Add(strSql.ToString(), parameters);

                        }
                    }
                    return DbHelperSQL.ExecuteSqlTran(table);
                }
            }

            return result;
        }

        #endregion

        #region  失物接收/退回

        public bool TransferGoodReceivedList(Model.T_Good_TransInfo model, int status)
        {
            bool result = false;

            string statusName = "";

            if (status == 1)
            {
                statusName = "已接收";
            }
            else if (status == 2)
            {

                statusName = "接收方退回";
            }
            else if (status == 3)
            {

                statusName = "发起方退回";
            }

            //事务处理
            NoSortHashtable table = new NoSortHashtable();

            if (model != null && !string.IsNullOrEmpty(model.KeyList))
            {
                string[] keyList = model.KeyList.Split(',');

                if (keyList.Length > 0)
                {
                    StringBuilder strSql = new StringBuilder();
                    foreach (string key in keyList)
                    {

                        if (status == 1)
                        {
                            //修改主表信息
                            strSql = new StringBuilder();
                            strSql.AppendFormat(@"------------{0} {1}", System.Guid.NewGuid().ToString(), Environment.NewLine);
                            strSql.Append("update  T_Good_Info set F_Status=@F_Status,F_StatusName=@F_StatusName,F_SaveDepeId=@F_SaveDepeId,F_SaveDepeName=@F_SaveDepeName");
                            strSql.Append(" where F_Id=(SELECT  f_goodinfoid FROM T_Good_TransInfo WHERE F_TStatus=0 AND F_Id=@F_Id)");
                            SqlParameter[] parameters = {
					    new SqlParameter("@F_Status", SqlDbType.Int,4),
                    	new SqlParameter("@F_StatusName", SqlDbType.NVarChar,50),
                          new SqlParameter("@F_SaveDepeId", SqlDbType.Int,4),
                    	new SqlParameter("@F_SaveDepeName", SqlDbType.NVarChar,50),
                     
                        new SqlParameter("@F_Id", SqlDbType.Int,4) };
                            parameters[0].Value = 0;
                            parameters[1].Value = "未归还";
                            parameters[2].Value = model.F_RecivedDepId;
                            parameters[3].Value = model.F_RecivedDepName;

                            parameters[4].Value = int.Parse(key);
                            table.Add(strSql.ToString(), parameters);
                        }
                        else
                        {
                            //修改主表信息
                            strSql = new StringBuilder();
                            strSql.AppendFormat(@"------------{0} {1}", System.Guid.NewGuid().ToString(), Environment.NewLine);
                            strSql.Append("update  T_Good_Info set F_Status=@F_Status,F_StatusName=@F_StatusName");
                            strSql.Append(" where F_Id=(SELECT  f_goodinfoid FROM T_Good_TransInfo WHERE F_TStatus=0 AND F_Id=@F_Id)");
                            SqlParameter[] parameters = {
					    new SqlParameter("@F_Status", SqlDbType.Int,4),
                    	new SqlParameter("@F_StatusName", SqlDbType.NVarChar,50),                     
                        new SqlParameter("@F_Id", SqlDbType.Int,4) };
                            parameters[0].Value = 0;
                            parameters[1].Value = "未归还";
                            parameters[2].Value = int.Parse(key);
                            table.Add(strSql.ToString(), parameters);
                        }

                        //插入转移信息
                        strSql = new StringBuilder();
                        strSql.AppendFormat(@"------------{0} {1}", System.Guid.NewGuid().ToString(), Environment.NewLine);
                        strSql.Append("update T_Good_TransInfo ");
                        strSql.Append(" set F_TStatus=@F_TStatus,F_TStatusName=@F_TStatusName,F_RecivedDate=@F_RecivedDate ");
                        strSql.Append(" where F_Id=@F_Id");
                        SqlParameter[] parametersContent = {
					new SqlParameter("@F_TStatus", SqlDbType.Int,4),
					new SqlParameter("@F_TStatusName", SqlDbType.NVarChar,50),
                    new SqlParameter("@F_RecivedDate", SqlDbType.DateTime),
					new SqlParameter("@F_Id", SqlDbType.Int,4)};
                        parametersContent[0].Value = status;
                        parametersContent[1].Value = statusName;
                        parametersContent[2].Value = DateTime.Now;
                        parametersContent[3].Value = int.Parse(key);
                        table.Add(strSql.ToString(), parametersContent);
                    }
                    return DbHelperSQL.ExecuteSqlTran(table);
                }
            }

            return result;
        }

        #endregion


        #region 销毁

        /// <summary>
        /// 删除
        /// </summary>
        public bool AdminDeleteGoods(string idList)
        {
            if (!string.IsNullOrEmpty(idList))
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("update T_Good_Info set ");
                strSql.Append("F_Status=@F_Status,");
                strSql.Append("F_StatusName=@F_StatusName,");
                strSql.Append("F_UpdateDate=@F_UpdateDate ");
                strSql.Append(" where F_Id in (" + idList + ")");
                SqlParameter[] parameters = {
				
					new SqlParameter("@F_Status", SqlDbType.Int,4),
					new SqlParameter("@F_StatusName", SqlDbType.NVarChar,50),
					new SqlParameter("@F_UpdateDate", SqlDbType.DateTime)};
                parameters[0].Value = 9;
                parameters[1].Value = "已删除";
                parameters[2].Value = DateTime.Now;
                int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
                if (rows > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 销毁
        /// </summary>
        public bool DeleteGoods(string idList)
        {
            if (!string.IsNullOrEmpty(idList))
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("update T_Good_Info set ");
                strSql.Append("F_Status=@F_Status,");
                strSql.Append("F_StatusName=@F_StatusName,");
                strSql.Append("F_UpdateDate=@F_UpdateDate ");
                strSql.Append(" where F_Id in (" + idList + ")");
                SqlParameter[] parameters = {
				
					new SqlParameter("@F_Status", SqlDbType.Int,4),
					new SqlParameter("@F_StatusName", SqlDbType.NVarChar,50),
					new SqlParameter("@F_UpdateDate", SqlDbType.DateTime)};
                parameters[0].Value = 3;
                parameters[1].Value = "已销毁";
                parameters[2].Value = DateTime.Now;
                int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
                if (rows > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }



        /// <summary>
        /// 自动销毁
        /// </summary>
        public void DeleteGoodsBySys()
        {

            try
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("update T_Good_Info set ");
                strSql.Append("F_Status=5,");
                strSql.Append("F_StatusName='自动销毁',");
                strSql.Append("F_UpdateDate=getdate() ");
                strSql.Append(" where  F_Status=0 and F_PropertyId=545  and F_CreateDate<='" + DateTime.Now.AddDays(-1).ToString() + "';");
                strSql.Append("update T_Good_Info set ");
                strSql.Append("F_Status=5,");
                strSql.Append("F_StatusName='自动销毁',");
                strSql.Append("F_UpdateDate=getdate() ");
                strSql.Append(" where  F_Status=1 and F_PropertyId=545  and F_CreateDate<='" + DateTime.Now.AddDays(-1).ToString() + "';");
               
                DbHelperSQL.ExecuteSql(strSql.ToString());
            }
            catch(Exception ex)
            {

            }

        }
        #endregion
    }
}

