121 lines
5.4 KiB
C#
121 lines
5.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Web;
|
|
using System.Web.Mvc;
|
|
using CScommon;
|
|
using Resources;
|
|
using Resources.Helper;
|
|
using Weee.Areas.Admin.Filter;
|
|
using Weee.Controllers;
|
|
using Weee.DAL;
|
|
|
|
namespace Weee.Areas.Admin.Controllers
|
|
{
|
|
[AdminAuthorize(Roles = ProgramConstants.admin)]
|
|
public class AdminControllerBase : QcarbonControllerBase
|
|
{
|
|
//protected readonly WeeeDataContext db;
|
|
|
|
public AdminControllerBase(WeeeDataContext d) : base(d)
|
|
{
|
|
//db = d;
|
|
List<SelectListItem> activityItems = new List<SelectListItem>();
|
|
activityItems.Add(new SelectListItem() { Text = "", Value = "0" });
|
|
activityItems.Add(new SelectListItem() { Text = Resource.autoContinuousMeasure, Value = "1" });
|
|
activityItems.Add(new SelectListItem() { Text = Resource.indirectMeasure, Value = "2" });
|
|
activityItems.Add(new SelectListItem() { Text = Resource.selfEstimate, Value = "3" });
|
|
ViewBag.activityItems = activityItems;
|
|
List<SelectListItem> emitParaItems = new List<SelectListItem>();
|
|
emitParaItems.Add(new SelectListItem() { Text = "", Value = "0" });
|
|
emitParaItems.Add(new SelectListItem() { Text = Resource.measureEnergyBalance, Value = "1" });
|
|
emitParaItems.Add(new SelectListItem() { Text = Resource.sameSituationExperience, Value = "2" });
|
|
emitParaItems.Add(new SelectListItem() { Text = Resource.factorFromManufacturer, Value = "3" });
|
|
emitParaItems.Add(new SelectListItem() { Text = Resource.regionEmissionFactor, Value = "4" });
|
|
emitParaItems.Add(new SelectListItem() { Text = Resource.nationEmissionFactor, Value = "5" });
|
|
emitParaItems.Add(new SelectListItem() { Text = Resource.internationalFactor, Value = "6" });
|
|
ViewBag.emitParaItems = emitParaItems;
|
|
List<SelectListItem> warmGasTypes = new List<SelectListItem>();
|
|
warmGasTypes.Add(new SelectListItem() { Text = "", Value = "" });
|
|
warmGasTypes.Add(new SelectListItem() { Text = Resource.fixedSource, Value = "1" });
|
|
warmGasTypes.Add(new SelectListItem() { Text = Resource.movingSource, Value = "2" });
|
|
warmGasTypes.Add(new SelectListItem() { Text = Resource.escapeSource, Value = "3" });
|
|
warmGasTypes.Add(new SelectListItem() { Text = Resource.manufactureSource, Value = "4" });
|
|
warmGasTypes.Add(new SelectListItem() { Text = Resource.landUsageSource, Value = "5" });
|
|
warmGasTypes.Add(new SelectListItem() { Text = Resource.externalEnergySource, Value = "6" });
|
|
ViewBag.warmGasTypes = warmGasTypes;
|
|
}
|
|
|
|
protected override IAsyncResult BeginExecuteCore(AsyncCallback callback, object state)
|
|
{
|
|
string cultureName = null;
|
|
|
|
// Attempt to read the culture cookie from Request
|
|
HttpCookie cultureCookie = Request.Cookies["_culture"];
|
|
if (cultureCookie != null)
|
|
cultureName = cultureCookie.Value;
|
|
else
|
|
cultureName = Request.UserLanguages != null && Request.UserLanguages.Length > 0 ? Request.UserLanguages[0] : null; // obtain it from HTTP header AcceptLanguages
|
|
|
|
// Validate culture name
|
|
cultureName = CultureHelper.GetImplementedCulture(cultureName); // This is safe
|
|
|
|
// Modify current thread's cultures
|
|
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(cultureName);
|
|
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
|
|
|
|
return base.BeginExecuteCore(callback, state);
|
|
}
|
|
|
|
protected string excelNextColumn(string excelColumn)
|
|
{
|
|
string ret;
|
|
char c1, c2;
|
|
if (excelColumn.Length <= 0 || excelColumn.Length > 2 || excelColumn == "ZZ")
|
|
throw new Exception("Excel column out of range!");
|
|
if (excelColumn.Length == 1)
|
|
{
|
|
if (excelColumn == "Z")
|
|
return "AA";
|
|
c1 = char.Parse(excelColumn);
|
|
c1++;
|
|
ret = c1.ToString();
|
|
}
|
|
else
|
|
{
|
|
c1 = char.Parse(excelColumn.Substring(0, 1));
|
|
c2 = char.Parse(excelColumn.Substring(1, 1));
|
|
if (c2=='Z')
|
|
{
|
|
c2 = 'A';
|
|
c1++;
|
|
}
|
|
else
|
|
c2++;
|
|
ret = c1.ToString() + c2.ToString();
|
|
}
|
|
return ret;
|
|
}
|
|
protected string excelCellIdDispname(string excelCell, out int? ret, out string dispName)
|
|
{
|
|
ret = null;
|
|
dispName = "";
|
|
excelCell = excelCell.Trim();
|
|
// find last right quote )
|
|
if (excelCell.Substring(excelCell.Length - 1, 1) != ")")
|
|
return "last right quote not found";
|
|
// find last left quote (
|
|
int li = excelCell.LastIndexOf('(');
|
|
if (li < 0)
|
|
return "last left quote not found";
|
|
string theId = excelCell.Substring(li + 1, excelCell.Length - li - 2);
|
|
dispName = excelCell.Substring(0, li);
|
|
int tmpI;
|
|
if (!int.TryParse(theId, out tmpI))
|
|
return "Id invalid number";
|
|
ret = tmpI;
|
|
return "";
|
|
}
|
|
}
|
|
} |