using System;
using System. Data;
using Smobiler. Core. Controls;

namespace SMOSEC.UI.AssetsManager
{
    partial class frmReturnOrder : Smobiler. Core. Controls. MobileForm
    {
        #region 变量
        private AutofacConfig _autofacConfig = new AutofacConfig();//调用配置类
        

        #endregion

        /// <summary>
        /// 添加归还单
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAdd_Press(object sender, EventArgs e)
        {
            try
            {
                frmRtoCreate frmRtoCreate = new frmRtoCreate();
                Show(frmRtoCreate, (MobileForm sender1, object args) =>
                {
                    if (frmRtoCreate. ShowResult == ShowResult. Yes)
                    {
                        Bind();
                    }
                });
            }
            catch (Exception ex)
            {
                Toast(ex. Message);
            }
        }

        /// <summary>
        /// 按回退时关闭客户端
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FrmReturnOrder_KeyDown(object sender, KeyDownEventArgs e)
        {
            if (e.KeyCode == KeyCode. Back)
                Client. Exit();
        }

        /// <summary>
        /// 界面初始化
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FrmReturnOrder_Load(object sender, EventArgs e)
        {
            Bind();
        }

        /// <summary>
        /// 绑定数据
        /// </summary>
        private void Bind()
        {
            try
            {
                string LocationId = "";
                string UserId = Session["UserID"].ToString();
                if (Client. Session["Role"].ToString() == "SMOSECAdmin")
                {
                    var user = _autofacConfig.coreUserService. GetUserByID(UserId);
                    LocationId = user. USER_LOCATIONID;
                }
                if (Client. Session["Role"].ToString() == "SMOSECUser")
                {
                    plButton. Visible = false;
                }
                DataTable assborrowTable = _autofacConfig. AssetsService. GetRtoByUserId(Client. Session["Role"].ToString() == "SMOSECUser" ?  Client. Session["UserID"].ToString() : "",LocationId);
                ListViewCO.Rows. Clear();
                if (assborrowTable. Rows. Count > 0)
                {
                    ListViewCO.DataSource = assborrowTable;
                    ListViewCO.DataBind();
                }
            }
            catch (Exception ex)
            {
                Toast(ex. Message);
            }

        }
    }
}