using CallCenter.Utility;
using CallCenterApi.Interface.Controllers.Base;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace CallCenterApi.Interface.Controllers.visit_dx
{
    public class VisFileController : BaseController
    {
        //获取列表
        public ActionResult GetList(int? type,int? typegroup)
        {
                string sql = "";
                DataTable dt = new DataTable();
                string userid = CurrentUser.UserData.F_UserId.ToString();
                if (userid.Trim() != "")
                {
                    sql += " and F_InputUserID=" + userid.Trim();

                }
                if (typegroup != null)
                {
                    sql += " and F_TypeGroup=" + typegroup;
                }
                if (type != null)
                {
                    sql += " and F_FileType=" + type;
                }
                string strpageindex = RequestString.GetQueryString("page");
                int pageindex = 1;
                string strpagesize = RequestString.GetQueryString("pagesize");
                int pagesize = 10;
                if (strpageindex.Trim() != "")
                {
                    pageindex = Convert.ToInt32(strpageindex);
                }

                if (strpagesize.Trim() != "")
                {
                    pagesize = Convert.ToInt32(strpagesize);
                }
                int recordCount = 0;

                dt = BLL.PagerBLL.GetListPager(
                    "T_Vis_Files",
                    "F_FileID",
                    "*",
                    " " + sql,
                    "ORDER BY F_FileID desc",
                    pagesize,
                    pageindex,
                    true,
                    out recordCount);

                var obj = new
                {
                    rows = dt,
                    total = recordCount
                };

                return Content(obj.ToJson());
        }

        //删除文件
        public ActionResult DelFile(string ids)
        {
            if (ids != null && ids.Length > 0)
            {
                Model.T_Vis_Files fileModel = new BLL.T_Vis_Files().GetModel(int.Parse(ids));
                //DataTable dt = new DataTable();
                if (fileModel != null)
                {
                    if (fileModel.F_TypeGroup == 1)
                    {
                        if (fileModel.F_FileType == 0)
                        {

                            //dt = new BLL.T_Vis_DXOTelphone().GetList("F_FileID=" + Convert.ToInt32(ids)).Tables[0];
                            new BLL.T_Vis_DXOTelphone().DeleteListByFileID(ids);
                        }
                        else
                        {
                            //dt = new BLL.T_Vis_DXNTelphone().GetList("F_FileID=" + Convert.ToInt32(ids)).Tables[0];
                            new BLL.T_Vis_DXNTelphone().DeleteListByFileID(ids);
                        }
                    }

                    bool r = new BLL.T_Vis_Files().Delete(Convert.ToInt32(ids));

                    if (r)
                        return Success("删除成功");
                    else
                    {
                        return Error("删除失败");
                    }
                }
                else
                {
                    return Error("删除失败");
                }
            }
            else
            {
                return Error("获取参数失败");
            }
        }
    }
}