// 警告：某些程序集引用无法自动解析。这可能会导致某些部分反编译错误，
// 例如属性 getter/setter 访问。要获得最佳反编译结果，请手动将缺少的引用添加到加载的程序集列表中。
// FamousFurnitureExpo.Controllers.LoginController
using System;
using System.Collections.Specialized;
using System.Data;
using System.Text;
using System.Web;
using System.Web.Mvc;
using CommonBasic.Common;
using CommonBasic.Data;
using EfServiceCenter.Business.Person;
using FamousFurnitureExpo.Models;

public class LoginController : Controller
{
	public ActionResult SelectExhibition()
	{
		((ControllerBase)this).get_ViewData().set_Item("ExhLi", (object)Exhibition.GetList());
		return (ActionResult)(object)((Controller)this).View();
	}

	public ActionResult Login(int id)
	{
		Exhibition exhibitionByExhID = Exhibition.GetExhibitionByExhID(id);
		if (exhibitionByExhID == null)
		{
			return (ActionResult)(object)((Controller)this).RedirectToAction("SelectExhibition");
		}
		HttpContext.Current.Response.Cookies.Remove("ActorExhibition");
		HttpCookie httpCookie = new HttpCookie("ActorExhibition");
		httpCookie.Expires = DateTime.Now.AddYears(1);
		httpCookie["ExhID"] = id.ToString();
		HttpContext.Current.Response.Cookies.Add(httpCookie);
		((Controller)this).get_Session()["ExhName"] = exhibitionByExhID.ExhName;
		HttpCookie httpCookie2 = HttpContext.Current.Request.Cookies.Get("ExhibitorLoginName");
		if (httpCookie2 != null)
		{
			((ControllerBase)this).get_ViewData().set_Item("UserLoginName", (object)httpCookie2["LoginName"]);
			((ControllerBase)this).get_ViewData().set_Item("SaveLoginName", (object)"on");
		}
		((ControllerBase)this).get_ViewData().set_Item("ExhID", (object)id);
		return (ActionResult)(object)((Controller)this).View();
	}

	[HttpPost]
	public ActionResult Login(FormCollection fc)
	{
		string text = ((NameValueCollection)(object)fc).Get("LoginName").StringFilterSql();
		string loginPwd = ((NameValueCollection)(object)fc).Get("LoginPassword").StringFilterSql();
		string text2 = ((NameValueCollection)(object)fc).Get("ckbSave");
		int num = Convert.ToInt32(((NameValueCollection)(object)fc).Get("ExhID"));
		((ControllerBase)this).get_ViewData().set_Item("SaveLoginName", (object)text2);
		((ControllerBase)this).get_ViewData().set_Item("UserLoginName", (object)text);
		if (CheckLoginTime(num))
		{
			((ControllerBase)this).get_ViewData().set_Item("Message", (object)"没有在自服务开放时间内！");
		}
		else
		{
			if (CheckLogin(num, text, loginPwd))
			{
				if (text2 != null)
				{
					HttpContext.Current.Response.Cookies.Remove("ExhibitorLoginName");
					HttpCookie httpCookie = new HttpCookie("ExhibitorLoginName");
					httpCookie.Expires = DateTime.Now.AddYears(1);
					httpCookie["LoginName"] = text;
					HttpContext.Current.Response.Cookies.Add(httpCookie);
				}
				else
				{
					HttpContext.Current.Response.Cookies.Remove("ExhibitorLoginName");
					HttpCookie httpCookie2 = new HttpCookie("ExhibitorLoginName");
					httpCookie2.Expires = DateTime.Now.AddYears(-1);
					httpCookie2["LoginName"] = text;
					HttpContext.Current.Response.Cookies.Add(httpCookie2);
				}
				if (((Controller)this).get_Session()["ActorBoothType"].ToString() == "光地")
				{
					return (ActionResult)(object)((Controller)this).RedirectToAction("IndexSS", "Exhibitor");
				}
				return (ActionResult)(object)((Controller)this).RedirectToAction("Index", "Exhibitor");
			}
			((ControllerBase)this).get_ViewData().set_Item("Message", (object)"登录名或密码错误！");
		}
		((ControllerBase)this).get_ViewData().set_Item("ExhID", (object)num);
		return (ActionResult)(object)((Controller)this).View();
	}

	private bool checkEFormPerson()
	{
		int num = Convert.ToInt32(((Controller)this).get_Session()["ExhID"]);
		int num2 = Convert.ToInt32(((Controller)this).get_Session()["ComID"]);
		string text = $"select count(*) from PersonJoin where PsjJoinType='展商' and ','+PsjType+',' like '%,表格联系人,%' and PsjSysState='正常' and PsjPreExhID={num} and ComID={num2} ";
		int num3 = Convert.ToInt32(SqlHelper.ExecuteScalar(text));
		if (num3 > 0)
		{
			return true;
		}
		return false;
	}

	public ActionResult AddEFormPerson()
	{
		Helper.InitialConfig();
		int num = Convert.ToInt32(((Controller)this).get_Session()["AtrID"]);
		string text = $"select BthCode,AtrLogName from Actor where AtrID={num}";
		DataRow dataRow = SqlHelper.ExecuteDataset(text).Tables[0].Rows[0];
		string text2 = dataRow["BthCode"].ToString();
		string text3 = dataRow["AtrLogName"].ToString();
		((ControllerBase)this).get_ViewData().set_Item("Booth", (object)text2);
		((ControllerBase)this).get_ViewData().set_Item("LoginName", (object)text3);
		return (ActionResult)(object)((Controller)this).View();
	}

	[HttpPost]
	public ActionResult AddEFormPerson(FormCollection fc)
	{
		//IL_017c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0183: Expected O, but got Unknown
		//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ec: Expected O, but got Unknown
		//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d1: Expected O, but got Unknown
		//IL_0377: Unknown result type (might be due to invalid IL or missing references)
		//IL_037e: Expected O, but got Unknown
		//IL_03d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03de: Expected O, but got Unknown
		Helper.InitialConfig();
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.Append(" if not exists (select * from Dict where DctType='联系人类别' and DctName='表格联系人') ");
		stringBuilder.Append(" begin ");
		stringBuilder.Append(" insert into Dict(DctType,DctName,DctCode,DctValue,DctSort,DctOwnerID,DctRemarks,DctBigType,DctIfShow,DctCraeteTime) ");
		stringBuilder.Append(" values ('联系人类别','表格联系人','表格联系人','1','99','-','','公共字典','1',getdate()) ");
		stringBuilder.Append(" end ");
		SqlHelper.ExecuteSQL(stringBuilder.ToString());
		int num = Convert.ToInt32(((Controller)this).get_Session()["ExhID"]);
		int num2 = Convert.ToInt32(((Controller)this).get_Session()["ComID"]);
		int num3 = Convert.ToInt32(((Controller)this).get_Session()["AtrID"]);
		string arg = ((NameValueCollection)(object)fc).Get("Password").StringFilterSql();
		string text = $"update Actor set AtrPwd='{arg}' where AtrID={num3}";
		SqlHelper.ExecuteSQL(text);
		string text2 = ((NameValueCollection)(object)fc).Get("Name").StringFilterSql();
		string text3 = ((NameValueCollection)(object)fc).Get("Email").StringFilterSql();
		string text4 = ((NameValueCollection)(object)fc).Get("Rank").StringFilterSql();
		string text5 = ((NameValueCollection)(object)fc).Get("CountryStr").StringFilterSql();
		string text6 = ((NameValueCollection)(object)fc).Get("Country").StringFilterSql();
		string text7 = ((NameValueCollection)(object)fc).Get("Tel").StringFilterSql();
		string text8 = ((NameValueCollection)(object)fc).Get("Fax").StringFilterSql();
		int num4 = 0;
		int num5 = 0;
		string text9 = $"select PsnID from Person where ComID={num2} and PsnName='{text2}' and PsnSysState='正常'";
		string text10 = SqlHelper.ExecuteScalar(text9);
		if (text10 == "")
		{
			TPerson val = new TPerson();
			val.PsnName = text2;
			val.PsnEmail = text3;
			val.PsnRank = text4;
			val.PsnCountry = text5;
			val.PsnCountryCode = text6;
			val.PsnTel1 = text7;
			val.PsnFax1 = text8;
			val.PsnSysState = "正常";
			val.ComID = num2.ToString();
			num4 = ((Entity)val).Insert();
			TPersonJoin val2 = new TPersonJoin();
			val2.PsjName = text2;
			val2.PsjEmail = text3;
			val2.PsjRank = text4;
			val2.PsjCountry = text5;
			val2.PsjCountryCode = text6;
			val2.PsjTel1 = text7;
			val2.PsjFax1 = text8;
			val2.PsjJoinType = "展商";
			val2.PsjType = "联系人,表格联系人";
			val2.PsjSysState = "正常";
			val2.PsnID = num4.ToString();
			val2.ComID = num2.ToString();
			val2.PsjPreExhID = num.ToString();
			num5 = ((Entity)val2).Insert();
		}
		else
		{
			num4 = Convert.ToInt32(text10);
			string text11 = $"select PsjID from PersonJoin where PsjPreExhID={num} and PsnID={num4} and PsjJoinType='展商' and PsjSysState='正常'";
			string text12 = SqlHelper.ExecuteScalar(text11);
			if (text12 == "")
			{
				TPersonJoin val3 = new TPersonJoin();
				val3.PsjName = text2;
				val3.PsjEmail = text3;
				val3.PsjRank = text4;
				val3.PsjCountry = text5;
				val3.PsjCountryCode = text6;
				val3.PsjTel1 = text7;
				val3.PsjFax1 = text8;
				val3.PsjJoinType = "展商";
				val3.PsjType = "联系人,表格联系人";
				val3.PsjSysState = "正常";
				val3.PsnID = num4.ToString();
				val3.ComID = num2.ToString();
				val3.PsjPreExhID = num.ToString();
				num5 = ((Entity)val3).Insert();
			}
			else
			{
				num5 = Convert.ToInt32(text12);
				TPersonJoin val4 = new TPersonJoin();
				val4.PsjID = num5.ToString();
				val4.PsjName = text2;
				val4.PsjEmail = text3;
				val4.PsjRank = text4;
				val4.PsjCountry = text5;
				val4.PsjCountryCode = text6;
				val4.PsjTel1 = text7;
				val4.PsjFax1 = text8;
				val4.PsjJoinType = "展商";
				TPersonJoin val5 = new TPersonJoin();
				val5.PsjID = num5.ToString();
				val5.GetOne();
				string psjType = val5.PsjType;
				string text13 = "";
				text13 = (val4.PsjType = ((psjType == null || psjType == "") ? "联系人,表格联系人" : ((("," + psjType + ",").IndexOf(",表格联系人,") >= 0) ? psjType : (val5.PsjType + ",表格联系人"))));
				val4.PsjSysState = "正常";
				val4.PsnID = num4.ToString();
				val4.ComID = num2.ToString();
				val4.PsjPreExhID = num.ToString();
				((Entity)val4).Update();
			}
		}
		PersonJoinProject.Add(num, num4, 3);
		return (ActionResult)(object)((Controller)this).RedirectToAction("Index", "Exhibitor");
	}

	public ActionResult LoginOut()
	{
		if (((Controller)this).get_Session()["ExhID"] != null)
		{
			int id = Convert.ToInt32(((Controller)this).get_Session()["ExhID"]);
			((Controller)this).get_Session().RemoveAll();
			((Controller)this).get_Session().Abandon();
			return (ActionResult)(object)((Controller)this).RedirectToAction("Login", (object)new { id });
		}
		HttpCookie httpCookie = HttpContext.Current.Request.Cookies.Get("ActorExhibition");
		string text = httpCookie["ExhID"];
		if (text != null && text != "")
		{
			int id2 = Convert.ToInt32(text);
			return (ActionResult)(object)((Controller)this).RedirectToAction("Login", (object)new
			{
				id = id2
			});
		}
		return (ActionResult)(object)((Controller)this).RedirectToAction("SelectExhibition");
	}

	public bool CheckLogin(int exhID, string loginName, string loginPwd)
	{
		if (loginName.Trim() == "" || loginPwd.Trim() == "")
		{
			return false;
		}
		string text = $"select AtrID,AtrName,ComID,ExhID,AtrFiStatus,isnull(AtrGroup,'') as AtrGroup from Actor where ExhID={exhID} and AtrLogName='{loginName}' and AtrPwd='{loginPwd}' and AtrFiStatus in('潜在展商','预订展商','签约展商','全部付款','部分付款')";
		DataSet dataSet = SqlHelper.ExecuteDataset(text);
		if (dataSet != null)
		{
			DataTable dataTable = dataSet.Tables[0];
			if (dataTable.Rows.Count > 0)
			{
				DataRow dataRow = dataTable.Rows[0];
				int num = Convert.ToInt32(dataRow["AtrID"]);
				string value = dataRow["AtrName"].ToString();
				int num2 = Convert.ToInt32(dataRow["ComID"]);
				((Controller)this).get_Session()["AtrID"] = num;
				((Controller)this).get_Session()["AtrName"] = value;
				((Controller)this).get_Session()["ComID"] = num2;
				((Controller)this).get_Session()["ExhID"] = exhID;
				((Controller)this).get_Session()["AtrFiStatus"] = dataRow["AtrFiStatus"].ToString();
				((Controller)this).get_Session()["AtrGroup"] = dataRow["AtrGroup"].ToString();
				Exhibition exhibitionByExhID = Exhibition.GetExhibitionByExhID(exhID);
				((Controller)this).get_Session()["ExhName"] = exhibitionByExhID.ExhName;
				((Controller)this).get_Session()["ExhBTime"] = exhibitionByExhID.ExhBTime;
				((Controller)this).get_Session()["ExhETime"] = exhibitionByExhID.ExhETime;
				((Controller)this).get_Session()["SrmID"] = 1;
				string text2 = $"select BthType from Booth where ExhID={exhID} and AtrID={num}";
				DataTable dataTable2 = SqlHelper.ExecuteDataset(text2).Tables[0];
				bool flag = false;
				bool flag2 = false;
				foreach (DataRow row in dataTable2.Rows)
				{
					string text3 = row["BthType"].ToString();
					if (text3.IndexOf("光地") >= 0 || text3.ToLower().IndexOf("raw space") >= 0)
					{
						flag = true;
					}
					if (text3.IndexOf("标摊") >= 0 || text3.ToLower().IndexOf("shell schemes") >= 0)
					{
						flag2 = true;
					}
				}
				string value2 = "";
				if (flag && flag2)
				{
					value2 = "";
				}
				else if (flag)
				{
					value2 = "光地";
				}
				else if (flag2)
				{
					value2 = "标摊";
				}
				((Controller)this).get_Session()["ActorBoothType"] = value2;
				return true;
			}
		}
		return false;
	}

	public bool CheckLoginTime(int exhID)
	{
		string text = string.Format("select bTime=(select SetValue from Setting where ExhID={0} and SetKey='自服务开始时间' and SetType='自服务设置'),eTime=(select SetValue from Setting where ExhID={0} and SetKey='自服务结束时间' and SetType='自服务设置')", exhID);
		DataSet dataSet = SqlHelper.ExecuteDataset(text);
		DataRow dataRow = dataSet.Tables[0].Rows[0];
		try
		{
			DateTime dateTime = Convert.ToDateTime(dataRow["bTime"]);
			DateTime dateTime2 = Convert.ToDateTime(dataRow["eTime"]);
			if (dateTime < DateTime.Now && DateTime.Now < dateTime2.AddDays(1.0))
			{
				((Controller)this).get_Session()["ServerBTime"] = dateTime;
				((Controller)this).get_Session()["ServerETime"] = dateTime2;
				return true;
			}
			return false;
		}
		catch (Exception)
		{
			return false;
		}
	}
}
