﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CraneAlert.Service;
using System.Collections;

namespace CraneAlert.UnitInfoManage
{
    public partial class UnitInfoAdd : System.Web.UI.Page
    {
        private UnitInfoService service = new UnitInfoService();
        private SysArgService sysService = new SysArgService();
        protected void Page_Load(object sender, EventArgs e)
        {
            UnitInfo unitInfoObj = service.getLastUnitInfo();
            if (!Page.IsPostBack)
            {
                getSysArgCity();
                getSysArgUnit();
                if (unitInfoObj != null)
                {
                    this.unitNo.Text = Common.getConNumber(unitInfoObj.UnitNo);
                }
                else
                {
                    this.unitNo.Text = Common.getConNumber("");
                }
            }
        }

        protected void saveUnitInfo(object sender, EventArgs e)
        {
            UnitInfo unitInfo = new UnitInfo();
            UnitInfo unitInfoInfoObj = service.getLastUnitInfo();
            if (unitInfoInfoObj != null)
            {
                unitInfo.UnitNo = Common.getConNumber(unitInfoInfoObj.UnitNo);
            }
            else
            {
                unitInfo.UnitNo = Common.getConNumber("");
            }
            unitInfo.Address = address.Text;
            unitInfo.CityCode = cityCode.SelectedValue;
            unitInfo.Memo = memo.Text;
            unitInfo.PostCode = postCode.Text;
            unitInfo.RegDate = regDate.Text;
            unitInfo.Technician = technician.Text;
            unitInfo.Telephone2 = telephone2.Text;
            unitInfo.Telephone3 = telephone3.Text;
            unitInfo.UnitName = unitName.Text;
            unitInfo.UnitNo = unitNo.Text;
            unitInfo.ZhiZhaoNo = zhiZhaoNo.Text;
            unitInfo.EQManager = EQManager.Text;
            unitInfo.UnitType = unitType.SelectedValue;

            service.saveUnitInfo(unitInfo);
            Response.Write("<script>alert('添加成功');window.top.closeDialog();</script>");
        }


        public void getSysArgCity()
        {
            IList list = sysService.getSysArgByType("C");
            cityCode.DataSource = list;
            cityCode.DataBind();
            ListItem item = new ListItem("请选择", "");
            item.Selected = true;
            cityCode.Items.Insert(0, item);
        }
        public void getSysArgUnit()
        {
            IList list = sysService.getSysArgByType("U");
            unitType.DataSource = list;
            unitType.DataBind();
            ListItem item = new ListItem("请选择", "");
            item.Selected = true;
            unitType.Items.Insert(0, item);
        }
        

    }
}