2025-03-27 15:05:14 +08:00

191 lines
6.9 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.IO;
using SuperMap.RealEstate.Utility;
using SuperMap.RealEstate.Web.UI;
using HWSB = SuperMap.RealEstate.HighWay.Storage.Business;
using HZQR.Common;
namespace SuperMap.RealEstate.HighWay.Common
{
public partial class IMAGEPage : SuperMap.RealEstate.Web.UI.Page
{
string TABLE_NAME = "HIGHWAY_STORAGE.T_METERBILL";
string ImgType = "";
protected void Page_Load(object sender, EventArgs e)
{
if (Request["Search"].TryParseToInt() == 1)
{
mFileUpload.Visible = false;
ButtonSave.Visible = false;
ButtonDelete.Visible = false;
}
if (!string.IsNullOrEmpty(Request["TABLE_NAME"]))
{
TABLE_NAME = Request["TABLE_NAME"].ToDecrypt();
switch (TABLE_NAME)
{
case "MHIGHWAY_STORAGE.T_METERBILL":
//Label1.Text = "注上传格式为118px*118px。";
break;
}
}
if (!string.IsNullOrEmpty(Request["IMAGE_TYPE"]))
{
ImgType = Request["IMAGE_TYPE"];
}
if (IsPostBack) return;
//载入数据
//ButtonDelete.Enabled = IMAGE1.LoadData();
//设置删除提示
SetControlConfirm(ButtonDelete, "您确认删除该记录,删除后将无法恢复数据?");
//设置按钮状态
SetControlClientAction(ButtonDelete, false, true, true);
SetControlClientAction(ButtonSave);
//注册遮罩式窗口关闭脚本
SetControlClosePopDialog(ButtonClose);
if (Request["ReadOnly"] != null && Request["ReadOnly"].ToString() == ModifyTypeEnum.ReadOnlyVisible.ToString())
{
ButtonSave.Visible = false;
ButtonDelete.Visible = false;
}
}
protected void ButtonSave_Click(object sender, EventArgs e)
{
try
{
if (mFileUpload.FileName.ToString() == "")
{
Alert("请选择图片");
return;
}
string ImagePathSrc = string.Empty;
HWSB.IMAGE _IMAGE = new HWSB.IMAGE(this.Transaction);
if (mFileUpload.HasFile)
{
string extension = Path.GetExtension(mFileUpload.PostedFile.FileName).ToLower();
string newname = DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss_ffff") + extension;
if (extension == ".jpg" || extension == ".gif" || extension == ".png")
{
string savePath = "";
string tableId = Request["TABLE_ID"].ToDecrypt();
if (TABLE_NAME == "HIGHWAY_STORAGE.T_METERBILL")
{
ImagePathSrc = "/UploadImageDir/METERBILL/" + tableId + "/";
savePath = Server.MapPath("~/UploadImageDir/METERBILL/" + tableId + "/");
}
else
{
ImagePathSrc = "/UploadImageDir/MERCHANTS/" + tableId + "/";
savePath = Server.MapPath("~/UploadImageDir/MERCHANTS/" + tableId + "/");
}
if (!Directory.Exists(savePath))
{
Directory.CreateDirectory(savePath);
}
mFileUpload.PostedFile.SaveAs(savePath + newname);
ImagePathSrc += newname;
if (!string.IsNullOrEmpty(ImgType))
{
_IMAGE.IMAGE_TYPE = Convert.ToInt16(ImgType);
}
_IMAGE.IMAGE_PATH = ImagePathSrc;
_IMAGE.Table_ID = Convert.ToInt32(tableId);
_IMAGE.Table_Name = TABLE_NAME;
_IMAGE.IMAGE_DATE = System.DateTime.Now;
_IMAGE.IMAGE_TITLE = IMAGE_TITLE.Text;
_IMAGE.ISVALID = 1;
_IMAGE.Insert();
//RefreshOpener();
RefreshOpenerGridPage(RefreshGridPageType.Refresh, 1);
Alert("保存图片成功!", 3);
IMAGE1.BindTreeView();
if (TABLE_NAME == "HIGHWAY_STORAGE.T_METERBILL")
{
//修改已缴费的状态
HWSB.METERBILL _METERBILL = new HWSB.METERBILL(this.Transaction);
_METERBILL.AddSearchParameter("METERBILL_ID",tableId);
_METERBILL.AddSearchParameter("PAYMENT_STATE",1000);
if (_METERBILL.Search())
{
_METERBILL.PAYMENT_STATE = 2000;
_METERBILL.Update();
}
}
}
}
else
{
Alert("图片格式有误!", 3);
}
}
catch (Exception)
{
Alert("图片格式有误!", 3);
}
}
/// <summary>
/// 将B转换为MB
/// </summary>
/// <param name="b"></param>
/// <returns></returns>
private double GetMB(long b)
{
for (int i = 0; i < 2; i++)
{
b /= 1024;
}
return b;
}
protected void ButtonDelete_Click(object sender, EventArgs e)
{
try
{
//if (IMAGE1.CurrObject.Image_ID == 0 || IMAGE1.CurrObject.Image_ID == null)
//{
// Alert("请选择要删除的图片!");
// return;
//}
//删除数据
//ButtonDelete.Enabled = !IMAGE1.Delete();
IMAGE1.Delete();
//刷新弹出页列表
RefreshOpenerGridPage(RefreshGridPageType.Delete);
//RefreshOpener();
//提示信息
Alert("删除成功!", 3);
//ClosePopDialog();
}
catch (Exception ex)
{
//回滚事务
Transaction.Rollback();
//记录日志
ErrorLogHelper.Write(ex);
#if DEBUG
Alert("删除失败!可能的原因:\n" + ex.Message);
#else
Alert("删除失败!");
#endif
}
}
protected void BtnAdd_Click(object sender, EventArgs e)
{
IMAGE1.CurrObject.ResetProperty();
IMAGE1.LoadData();
}
}
}