287 lines
11 KiB
C#
287 lines
11 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Configuration;
|
||
using System.Data;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Web;
|
||
using System.Web.UI;
|
||
using System.Web.UI.WebControls;
|
||
using SuperMap.RealEstate.Utility;
|
||
using SuperMap.RealEstate.Web.UI;
|
||
using Business = SuperMap.RealEstate.Coop.Merchant.Business;
|
||
using MSPB = SuperMap.RealEstate.MobileServicePlatform.Business;
|
||
using HZQR.Common;
|
||
|
||
namespace Coop.Merchant.CommonPage
|
||
{
|
||
public partial class IMAGEPage : SuperMap.RealEstate.Web.UI.Page
|
||
{
|
||
#region 方法 -> 获取上传图片类型ImgType
|
||
public string ImgType
|
||
{
|
||
//通过对应的内码
|
||
get
|
||
{
|
||
if (!string.IsNullOrEmpty(Request["IMAGE_TYPE"]))
|
||
{
|
||
return Request["IMAGE_TYPE"];
|
||
}
|
||
else
|
||
{
|
||
return "";
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 获取上传图片表名TABLE_NAME
|
||
public string TABLE_NAME
|
||
{
|
||
//通过对应的内码
|
||
get
|
||
{
|
||
if (!string.IsNullOrEmpty(Request["TABLE_NAME"]))
|
||
{
|
||
return Request["TABLE_NAME"].ToDecrypt();
|
||
}
|
||
else
|
||
{
|
||
return "MOBILESERVICE_PLATFORM.T_SERVERPARTSHOP";
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 页面加载
|
||
protected void Page_Load(object sender, EventArgs e)
|
||
{
|
||
switch (TABLE_NAME)
|
||
{
|
||
case "MOBILESERVICE_PLATFORM.T_SERVERPARTSHOP":
|
||
Label1.Text = "注:上传格式为118px*118px。";
|
||
break;
|
||
}
|
||
|
||
if (IsPostBack) return;
|
||
|
||
//载入数据
|
||
//ButtonDelete.Enabled = IMAGE1.LoadData();
|
||
TreeView MyTreeView = IMAGE1.FindControl("MyTreeView") as TreeView;
|
||
if (MyTreeView.Nodes.Count > 0)
|
||
{
|
||
string indexName = MyTreeView.Nodes[MyTreeView.Nodes.Count - 1].Text;
|
||
IMAGE_INDEX.Text = (indexName.Split('[')[1].Split(']')[0].TryParseToInt() + 10) + "";
|
||
}
|
||
//页面只读,则隐藏按钮控件
|
||
if (Request["ReadOnly"] != null && Request["ReadOnly"].ToString() == ModifyTypeEnum.ReadOnlyVisible.ToString())
|
||
{
|
||
ButtonSave.Visible = false;
|
||
ButtonDelete.Visible = false;
|
||
mFileUpload.Visible = false;
|
||
IMAGE_TITLE.Visible = false;
|
||
Label1.Visible = false;
|
||
BtnSelectPicture.Visible = false;
|
||
}
|
||
else if (!string.IsNullOrEmpty(Request["SelectType"]))
|
||
{
|
||
BtnSelectPicture.Visible = true;
|
||
divUploadImage.Visible = false;
|
||
}
|
||
else
|
||
{
|
||
BtnSelectPicture.Visible = false;
|
||
divUploadImage.Visible = true;
|
||
}
|
||
//设置删除提示
|
||
SetControlConfirm(ButtonDelete, "您确认删除该记录,删除后将无法恢复数据?");
|
||
//设置按钮状态
|
||
SetControlClientAction(ButtonDelete, false, true, true);
|
||
SetControlClientAction(ButtonSave);
|
||
//注册遮罩式窗口关闭脚本
|
||
SetControlClosePopDialog(ButtonClose);
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 图片保存事件
|
||
protected void ButtonSave_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
if (mFileUpload == null || string.IsNullOrWhiteSpace(mFileUpload.FileName))
|
||
{
|
||
Alert("请选择图片");
|
||
return;
|
||
}
|
||
|
||
if (IMAGE_TITLE.Text == "")
|
||
{
|
||
IMAGE_TITLE.Text = mFileUpload.FileName;
|
||
}
|
||
|
||
string ImagePathSrc = string.Empty;
|
||
Business.IMAGE _IMAGE = new Business.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 == "MOBILESERVICE_PLATFORM.T_SERVERPARTSHOP")
|
||
{
|
||
ImagePathSrc = "/UploadImageDir/SERVERPARTSHOP/" + tableId + "/";
|
||
savePath = Server.MapPath("~/UploadImageDir/SERVERPARTSHOP/" + tableId + "/");
|
||
}
|
||
else if (TABLE_NAME == "MOBILESERVICE_PLATFORM.T_SERVERPARTSELLER")
|
||
{
|
||
ImagePathSrc = "/UploadImageDir/SELLER/" + tableId + "/";
|
||
savePath = Server.MapPath("~/UploadImageDir/SELLER/" + tableId + "/");
|
||
}
|
||
else if (TABLE_NAME == "T_COMMODITY")
|
||
{
|
||
ImagePathSrc = "/UploadImageDir/COMMODITY/" + tableId + "/";
|
||
savePath = Server.MapPath("~/UploadImageDir/COMMODITY/" + tableId + "/");
|
||
}
|
||
else if (TABLE_NAME.Contains("T_SUPPLIER"))
|
||
{
|
||
ImagePathSrc = "/UploadImageDir/SUPPLIER/" + tableId + "/";
|
||
savePath = Server.MapPath("~/UploadImageDir/SUPPLIER/" + tableId + "/");
|
||
}
|
||
else if (TABLE_NAME.Contains("COUPON"))
|
||
{
|
||
ImagePathSrc = "/UploadImageDir/COUPON/" + tableId + "/";
|
||
savePath = Server.MapPath("~/UploadImageDir/COUPON/" + tableId + "/");
|
||
}
|
||
if (savePath != "" && !Directory.Exists(savePath))
|
||
{
|
||
Directory.CreateDirectory(savePath);
|
||
}
|
||
|
||
mFileUpload.PostedFile.SaveAs(savePath + newname);
|
||
ImagePathSrc += newname;
|
||
|
||
string otherShopId = "";
|
||
if (TABLE_NAME == "MOBILESERVICE_PLATFORM.T_SERVERPARTSHOP")
|
||
{
|
||
string serverPartId = Request["SERVERPARTID"].ToDecrypt();
|
||
string provinceCode = Request["PROVINCECODE"].ToDecrypt();
|
||
string shopShortName = Request["SHOPSHORTNAME"].ToDecrypt();
|
||
string shopId = Request["SHOPID"].ToDecrypt();
|
||
string sql = string.Format(@"SELECT SERVERPARTSHOP_ID FROM MOBILESERVICE_PLATFORM.T_SERVERPARTSHOP
|
||
WHERE SERVERPART_ID = {0} AND PROVINCE_CODE = '{1}' AND SHOPSHORTNAME = '{2}' AND
|
||
SERVERPARTSHOP_ID <> {3}", serverPartId, provinceCode, shopShortName, shopId);
|
||
MSPB.SERVERPARTSHOP _SERVERPARTSHOP = new MSPB.SERVERPARTSHOP(this.Transaction);
|
||
DataTable dt = _SERVERPARTSHOP.ExecuteDataTable(sql);
|
||
if (dt.Rows.Count > 0)
|
||
{
|
||
otherShopId = provinceCode + dt.Rows[0]["SERVERPARTSHOP_ID"].ToString();
|
||
}
|
||
}
|
||
|
||
int _ImageIndex = 0;
|
||
int.TryParse(IMAGE_INDEX.Text.Trim(), out _ImageIndex);
|
||
_IMAGE.IMAGE_INDEX = _ImageIndex;
|
||
|
||
if (!string.IsNullOrEmpty(ImgType))
|
||
{
|
||
_IMAGE.IMAGE_TYPE = Convert.ToInt16(ImgType);
|
||
}
|
||
_IMAGE.IMAGE_PATH = ImagePathSrc;
|
||
_IMAGE.TABLE_ID = Convert.ToInt64(tableId);
|
||
_IMAGE.TABLE_NAME = TABLE_NAME;
|
||
_IMAGE.IMAGE_DATE = System.DateTime.Now;
|
||
_IMAGE.IMAGE_TITLE = IMAGE_TITLE.Text;
|
||
//_IMAGE.IMAGE_URL = ConfigurationManager.AppSettings["CoopMerchantUrls"] + _IMAGE.IMAGE_PATH;
|
||
_IMAGE.ISVALID = 1;
|
||
_IMAGE.Insert();
|
||
|
||
if (!string.IsNullOrEmpty(otherShopId))
|
||
{
|
||
_IMAGE.ResetProperty();
|
||
if (!string.IsNullOrEmpty(ImgType))
|
||
{
|
||
_IMAGE.IMAGE_TYPE = Convert.ToInt16(ImgType);
|
||
}
|
||
_IMAGE.IMAGE_PATH = ImagePathSrc;
|
||
_IMAGE.TABLE_ID = Convert.ToInt64(otherShopId);
|
||
_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();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
Alert("图片格式有误!", 3);
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
Alert("图片格式有误!", 3);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 文件大小转换:将B转换为MB
|
||
/// <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;
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 图片删除按钮事件
|
||
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
|
||
}
|
||
}
|
||
#endregion
|
||
}
|
||
} |