198 lines
7.8 KiB
C#
198 lines
7.8 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.Linq;
|
||
using System.Web.UI;
|
||
using System.Web.UI.WebControls;
|
||
using SuperMap.RealEstate.CoreFrameWork;
|
||
using SuperMap.RealEstate.ServiceModel;
|
||
using SuperMap.RealEstate.Utility;
|
||
using SuperMap.RealEstate.Web.UI;
|
||
using SuperMap.RealEstate.Web.UI.WebControls;
|
||
using SuperMap.RealEstate.Web.Utility;
|
||
using HWSB = SuperMap.RealEstate.HighWay.Storage.Business;
|
||
//using Business = SuperMap.RealEstate.HighWay.Storage.Business;
|
||
|
||
namespace SuperMap.RealEstate.MainTenance.Storage.Modules.ServerPartMaterial
|
||
{
|
||
/// <summary>
|
||
/// T_MATERIAL_固定资产 的WebUserControl
|
||
/// <summary>
|
||
public partial class MATERIAL : UserControl<Business.MATERIAL>
|
||
{
|
||
protected void Page_Load(object sender, EventArgs e)
|
||
{
|
||
if (IsPostBack)
|
||
return;
|
||
|
||
if (CurrObject.PropertyObject != null && CurrObject.SERVERPART_ID != null)
|
||
{
|
||
HighWay.Storage.Business.SERVERPART _SERVERPART = new HighWay.Storage.Business.SERVERPART(Transaction);
|
||
_SERVERPART.SERVERPART_ID_Encrypt = CurrObject.SERVERPART_ID.ToEncrypt();
|
||
if (_SERVERPART.Select())
|
||
{
|
||
SERVERPART_NAME.Text = _SERVERPART.SERVERPART_NAME;
|
||
BindRegion();
|
||
}
|
||
}
|
||
STAFF_NAME.Text = Page.PassportInfo.Name;
|
||
OPERATE_DATE.Text = DateTime.Now.ToShortDateString();
|
||
}
|
||
|
||
//在此加入界面的数据初始化(Page_Load之前),如DropDownList的数据源绑定等
|
||
public override void InitializeWebControl()
|
||
{
|
||
//服务区区域
|
||
SHOPREGION.Clear();
|
||
SHOPREGION.Items.Add(new ListItemEx());
|
||
DictionaryHelper.BindingDropDownList("SHOPREGION", SHOPREGION.Items, this.Transaction);
|
||
//资产类别
|
||
MATERIAL_TYPE.Clear();
|
||
DictionaryHelper.BindingDropDownList("FIXED_TYPE", MATERIAL_TYPE.Items, this.Transaction);
|
||
|
||
MATERIAL_ADDTYPE.Clear();
|
||
DictionaryHelper.BindingDropDownList("MATERIAL_ADDTYPE", MATERIAL_ADDTYPE.Items, this.Transaction);
|
||
}
|
||
|
||
//载入数据
|
||
public override bool LoadData()
|
||
{
|
||
SERVERPART_ID.Text = Request["SERVERPART_ID"].ToDecrypt();
|
||
if (!string.IsNullOrWhiteSpace(Request["SERVERPART_ID"]))
|
||
{
|
||
HWSB.SERVERPART _SERVERPART = new HWSB.SERVERPART(Transaction);
|
||
_SERVERPART.SERVERPART_ID_Encrypt = Request["SERVERPART_ID"];
|
||
if (_SERVERPART.Select())
|
||
{
|
||
SERVERPART_ID.Text = _SERVERPART.SERVERPART_ID.ToString();
|
||
SERVERPART_NAME.Text = _SERVERPART.SERVERPART_NAME;
|
||
BindRegion();
|
||
}
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(Request["SHOPREGION"]))
|
||
{
|
||
SHOPREGION.SelectedValue = Request["SHOPREGION"].ToDecrypt();
|
||
}
|
||
|
||
|
||
if (Request["SHOPREGION"] != null)
|
||
SHOPREGION.SelectedValue = Request["SHOPREGION"].ToDecrypt();
|
||
//如果是工作流组件请自行修改载入的逻辑,以下是功能模块的默认代码
|
||
if (!String.IsNullOrEmpty(Request["ID"]))
|
||
{
|
||
CurrObject.MATERIAL_ID_Encrypt = Request["ID"];
|
||
return this.Select();
|
||
}
|
||
//默认返回值,工作流组件返回True,功能模块返回False。
|
||
return (WorkFlowPage != null);
|
||
}
|
||
|
||
public void BindRegion()
|
||
{
|
||
string region = "";
|
||
string sqlRegion = @"
|
||
SELECT
|
||
WM_CONCAT(DISTINCT A.SHOPREGION) AS SHOPREGIONS
|
||
FROM
|
||
HIGHWAY_STORAGE.T_SERVERPARTSHOP A
|
||
WHERE
|
||
A.SERVERPART_ID = " + SERVERPART_ID.Text;
|
||
DataTable dt = new HWSB.SERVERPARTSHOP(this.Transaction).ExecuteDataTable(sqlRegion);
|
||
if (dt.Rows.Count > 0)
|
||
{
|
||
region = dt.Rows[0]["SHOPREGIONS"].ToString();
|
||
}
|
||
string[] regions = region.Split(",");
|
||
SHOPREGION.Clear();
|
||
foreach (var item in regions)
|
||
{
|
||
ListItemEx _ListItemEx = new ListItemEx();
|
||
_ListItemEx.Text = DictionaryHelper.GetFieldEnumName("SHOPREGION", item, this.Transaction);
|
||
_ListItemEx.Value = item;
|
||
if (regions.Length == 1)
|
||
{
|
||
_ListItemEx.Selected = true;
|
||
}
|
||
SHOPREGION.Items.Add(_ListItemEx);
|
||
}
|
||
|
||
if (CurrObject.SHOPREGION != null)
|
||
{
|
||
SHOPREGION.SelectedValue = CurrObject.SHOPREGION.ToString();
|
||
}
|
||
}
|
||
|
||
//OnDataAction_XXXXX 有一个系列可用,在此加入界面的逻辑处理
|
||
//e.CancelDataAction 来处理是否取消该动作;
|
||
//失败的原因可以用Page.Alert()传递到页面
|
||
public override void OnDataAction_BeforeSave(DataActionEventArgs<Business.MATERIAL> e)
|
||
{
|
||
e.CurrObject.STAFF_ID = Page.PassportInfo.ID;
|
||
e.CurrObject.STAFF_NAME = Page.PassportInfo.Name;
|
||
e.CurrObject.OPERATE_DATE = DateTime.Now;
|
||
//e.CurrObject.SERVERPART_ID = Request["SERVERPART_ID"].ToDecryptInt32();
|
||
if (!DateTime.TryParse(BUYING_TIME.Text, out DateTime dateTime))
|
||
{
|
||
e.CurrObject.BUYING_TIME = null;
|
||
}
|
||
if (!DateTime.TryParse(SCRAP_TIME.Text, out dateTime))
|
||
{
|
||
e.CurrObject.SCRAP_TIME = null;
|
||
}
|
||
base.OnDataAction_BeforeSave(e);
|
||
}
|
||
|
||
public override void OnDataAction_AfterSave(DataActionEventArgs<Business.MATERIAL> e)
|
||
{
|
||
if (!string.IsNullOrEmpty(e.CurrObject.MATERIAL_ID.ToString()))
|
||
{
|
||
Business.MATERIAL _MATERIAL = new Business.MATERIAL(Transaction);
|
||
_MATERIAL.MATERIAL_ID = e.CurrObject.MATERIAL_ID;
|
||
if (_MATERIAL.Select())
|
||
{
|
||
if (string.IsNullOrEmpty(e.CurrObject.MATERIAL_CODE))
|
||
{
|
||
_MATERIAL.MATERIAL_CODE = e.CurrObject.MATERIAL_ID.ToString().PadLeft(8, '0');
|
||
}
|
||
if (!DateTime.TryParse(BUYING_TIME.Text, out DateTime dateTime))
|
||
{
|
||
_MATERIAL.BUYING_TIME = null;
|
||
_MATERIAL.ASSET_YEAR = "";
|
||
}
|
||
if (!DateTime.TryParse(SCRAP_TIME.Text, out dateTime))
|
||
{
|
||
_MATERIAL.SCRAP_TIME = null;
|
||
_MATERIAL.ASSET_YEAR = "";
|
||
}
|
||
|
||
_MATERIAL.Update();
|
||
}
|
||
}
|
||
//e.CurrObject.SERVERPART_ID = Request["SERVERPART_ID"].ToDecryptInt32();
|
||
base.OnDataAction_AfterSave(e);
|
||
}
|
||
|
||
protected void BUYING_TIME_CallBackSetControl(object sender, ClientSetEventArgs e)
|
||
{
|
||
if (DateTime.TryParse(BUYING_TIME.Text, out DateTime BuyingTime) && DateTime.TryParse(SCRAP_TIME.Text, out DateTime ScrapTime))
|
||
{
|
||
TimeSpan timeSpan = ScrapTime.Subtract(BuyingTime);
|
||
if (timeSpan.TotalDays > 365)
|
||
{
|
||
ASSET_YEAR.Text = (ScrapTime.Year - BuyingTime.Year) + "年";
|
||
}
|
||
else
|
||
{
|
||
ASSET_YEAR.Text = Math.Round((timeSpan.TotalDays) / 30) + "个月";
|
||
}
|
||
e.SetValue(ASSET_YEAR);
|
||
}
|
||
else
|
||
{
|
||
ASSET_YEAR.Text = "";
|
||
e.SetValue(ASSET_YEAR);
|
||
}
|
||
}
|
||
}
|
||
}
|