farzinmonsef / tk1

0 stars 0 forks source link

Phase 1 #5

Open farzinmonsef opened 4 years ago

farzinmonsef commented 4 years ago

Phase1

(https://github.com/farzinmonsef/tk1/files/4394667/CreateTable_Transaction_n_data.zip)

EQM.Site.zip lib.zip

farzinmonsef commented 4 years ago

SQL

CREATE TABLE [dbo].[Types]( Id [int] IDENTITY(1,1) NOT NULL, TypeNo [int] NULL, Code [int] NULL, TypesName varchar NULL, Comment varchar NULL, Link int NULL, Status [int] NULL, Actions[int] NULL

CONSTRAINT [PK_Types_Id] PRIMARY KEY NONCLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

) ON [PRIMARY] GO

farzinmonsef commented 4 years ago

On Main Controller, Starting

public ActionResult Index() { try { //Tool.writeExe(); //Tool.AppendFile("test test", @"C:\Users\U612702\source\repos\WBRS.ReportsOnline.Site\RunReport2.Log"); Session["msgShow"] = "
<img src=\"../Images/Chat128.png\" />
<h4 style=\"color:darkblue\">Select Report to Enter Related Parameters and See the Printed Output on the Screen


"; Session["ApplicationList"] = Tool.refreshApplicationList(db); Session["Parameters"] = (from p in db.ReportParameters where (p.ReportID == 0) orderby p.SortOrder select p); Session["enumReportTypes"] = HtmlDropDownExtensions.MapEnumToDictionary(); Session["enumDatabaseType"] = HtmlDropDownExtensions.MapEnumToDictionary(); Session["enumParameterTypes"] = HtmlDropDownExtensions.MapEnumToDictionary(); Session["enumValidationType"] = HtmlDropDownExtensions.MapEnumToDictionary(); Session["enumValidationCompareOperator"] = HtmlDropDownExtensions.MapEnumToDictionary(); refreshAllReportParameterReportID(0); refreshAllReportParameter(); Session["reportID"] = "0"; Session["ParameterIDs"] = "0"; //getReportParameterReportID(); //Session["ReportID"] = "5000"; //refreshAllReportParameter(); //Session["allReportParameter"] = Tool.refreshAllReportParameter(db, 0); return View(); } catch (Exception ex) { throw ex; //return View("Error", new HandleErrorInfo(ex, "Report", "Index")); } }

farzinmonsef commented 4 years ago

Helper\Tools.cs

using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data.Entity; using System.Data.SqlClient; using System.Diagnostics; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Reflection; using System.Web; using System.Web.Mvc; using System.Web.Mvc.Html; using WBRS.ReportsOnline.Site.Models; namespace WBRS.ReportsOnline.Site.Helpers { public static class HtmlDropDownExtensions { ///

/// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// public static SelectList EnumSelectListItem(TEnum selectedValue) //public static MvcHtmlString EnumDropDownList(this HtmlHelper htmlHelper, string name, TEnum selectedValue) { var dictionary = MapEnumToDictionary(); SelectList selectList = new SelectList(dictionary.Select(s => new { Key = s.Key, Value = s.Value, Selected = (s.Value.ToLower().Equals(selectedValue.ToString().ToLower())) }), "Key", "Value"); return selectList; } public static Dictionary<int, string> MapEnumToDictionary() { // Ensure T is an enumerator if (!typeof(T).IsEnum) { throw new ArgumentException("T must be an enumerator type."); } // Return Enumertator as a Dictionary return Enum.GetValues(typeof(T)).Cast().ToDictionary(i => (int)Convert.ChangeType(i, i.GetType()), t => t.ToString()); } //------------------------------------------------------------------------------------- public static SelectList EnumSelectListItemString(TEnum selectedValue) //public static MvcHtmlString EnumDropDownList(this HtmlHelper htmlHelper, string name, TEnum selectedValue) { var dictionary = MapEnumToDictionaryString(); SelectList selectList = new SelectList(dictionary.Select(s => new { Key = s.Key, Value = s.Value, Selected = (s.Value.ToLower().Equals(selectedValue.ToString().ToLower())) }), "Key", "Value"); return selectList; } public static Dictionary<string, string> MapEnumToDictionaryString() { // Ensure T is an enumerator if (!typeof(T).IsEnum) { throw new ArgumentException("T must be an enumerator type."); } // Return Enumertator as a Dictionary return Enum.GetValues(typeof(T)).Cast().ToDictionary(i => ((char)((int)Convert.ChangeType(i, i.GetType()))).ToString(), t => t.ToString()); } //------------------------------------------------------------------------------------- public static SelectList EnumSelectListItemStringBothValue(TEnum selectedValue) //public static MvcHtmlString EnumDropDownList(this HtmlHelper htmlHelper, string name, TEnum selectedValue) { var dictionary = MapEnumToDictionaryStringBothValue(); SelectList selectList = new SelectList(dictionary.Select(s => new { Key = s.Key, Value = s.Value, Selected = (s.Value.ToLower().Equals(selectedValue.ToString().ToLower())) }), "Key", "Value"); return selectList; } public static Dictionary<string, string> MapEnumToDictionaryStringBothValue() { // Ensure T is an enumerator if (!typeof(T).IsEnum) { throw new ArgumentException("T must be an enumerator type."); } // Return Enumertator as a Dictionary var tt = Enum.GetValues(typeof(T)).Cast().ToDictionary(t => t.ToString(), t => t.ToString()); return (Dictionary<string, string>)tt; } //------------------------------------------------------------------------------------- public static Dictionary<int, string> MapEnumToDictionary(List ListKeyValue, string KeyName, string ValueName) { IDictionary<int, string> myList = new Dictionary<int, string>(); return Enum.GetValues(typeof(T)).Cast().ToDictionary(i => (int)Convert.ChangeType(i, i.GetType()), t => t.ToString()); } /// /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// private static readonly SelectListItem[] SingleEmptyItem = new[] { new SelectListItem { Text = "", Value = "" } }; private static Type GetNonNullableModelType(ModelMetadata modelMetadata) { Type realModelType = modelMetadata.ModelType; Type underlyingType = Nullable.GetUnderlyingType(realModelType); if (underlyingType != null) { realModelType = underlyingType; } return realModelType; } public static MvcHtmlString EnumDropDownListFor<TModel, TEnum>(this HtmlHelper htmlHelper, Expression<Func<TModel, TEnum>> expression) { ModelMetadata metadata = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData); Type enumType = GetNonNullableModelType(metadata); IEnumerable values = Enum.GetValues(enumType).Cast(); IEnumerable items = values.Select(value => new SelectListItem { Text = value.ToString(), Value = value.ToString(), Selected = value.Equals(metadata.Model) }); if (metadata.IsNullableValueType) { items = SingleEmptyItem.Concat(items); } return htmlHelper.DropDownListFor( expression, items ); } /// /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// public static IEnumerable EnumSelectListItemOLD(TEnum selectedValue) { IEnumerable values = Enum.GetValues(typeof(TEnum)).Cast(); IEnumerable items = from value in values select new SelectListItem { Text = value.ToString(), Value = value.ToString(), Selected = (value.Equals(selectedValue)) }; return items; } public static ICollection ToSelectList(TEnum? selectedValue) where TEnum : struct { IEnumerable values = Enum.GetValues(typeof(TEnum)).Cast(); var selectList = new List(); selectList = values .Select(x => new SelectListItem() { Value = x.ToString(), Text = x.ToString(), Selected = selectedValue != null && (int)(object)x == (int)(object)selectedValue }) .ToList(); return selectList; } public static string GetEnumDescription(Enum value) { FieldInfo fi = value.GetType().GetField(value.ToString()); DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes( typeof(DescriptionAttribute), false); if (attributes != null && attributes.Length > 0) return attributes[0].Description; else return value.ToString(); } } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////// TOOL Class ///////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static class Tool { public static short getFractionDigitNumber(string No) { string tempNo = No.ToString(); string fraction = ""; if (tempNo.IndexOf(".") >= 0) { fraction = tempNo.Split('.')[1]; } return (short)fraction.Length; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static List refreshApplicationList(CIBRSEntities db)//, bool swRefresh = false) { //if ((Session["ApplicationList"] == null) || (swRefresh)) { List ApplicationList = (from a in db.Applications orderby a.Name select a).ToList(); return ApplicationList; //Session["ApplicationList"] = ApplicationList; } } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// [OutputCache(Duration = 0)] public static IEnumerable refreshAllReportParameter(CIBRSEntities db, int reportID)//, bool swRefresh = false) { try { var allReportParameter = (from p in db.ReportParameters where p.ReportID == reportID select new { //ReportID = p.ReportID, ReportParameterID = p.ReportParameterID, DisplayName = p.DisplayName }); //if (reportID != null) //{ //allReportParameter = allReportParameter.Where(p => p.ReportID == reportID); //} return allReportParameter.ToList(); //Session["ApplicationList"] = ApplicationList; } catch (Exception ex) { throw ex; } } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static string Base64Encode(string plainText) { var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText ?? ""); return System.Convert.ToBase64String(plainTextBytes); } public static string Base64Decode(string base64EncodedData) { var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData ?? ""); return System.Text.Encoding.UTF8.GetString(base64EncodedBytes); } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static void CreateCommand(string queryString, string connectionString) { try { using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand command = new SqlCommand(queryString, connection); command.Connection.Open(); command.ExecuteNonQuery(); } } catch (Exception ex) { throw; //Utils.Errorlog("Applicaiton Error", "", ex, 0); //Server.ClearError(); } } public static void AppendFile(string data, string fileNamePath = @"C:\Users\U612702\source\repos\WBRS.ReportsOnline.Site\RunReport.Log" ) { try { //string myExe = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName; ////string myExe1 = Path.GetFileName(System.Reflection.Assembly.GetEntryAssembly().Location); //string myExePath = System.Reflection.Assembly.GetCallingAssembly().Location; //string path = @"C:\Users\U612702\source\repos\WBRS.ReportsOnline.Site\RunReport.Log";//myExePath.Replace(".exe", ".log"); //// This text is added only once to the file. //if (!File.Exists(path)) //{ // // Create a file to write to. // string createText = "Hello and Welcome" + Environment.NewLine; // File.WriteAllText(path, createText); //} // This text is always added, making the file longer over time // if it is not deleted. //string appendText = "This is extra text" + Environment.NewLine; File.AppendAllText(fileNamePath, data); //// Open the file to read from. //string readText = File.ReadAllText(path); //Console.WriteLine(readText); } catch (Exception e) { } } public static void writeExe() { try { Trace.WriteLine( System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName); //Trace.WriteLine( // System.Reflection.Assembly.GetEntryAssembly().Location); Trace.WriteLine( System.Reflection.Assembly.GetExecutingAssembly().Location); Trace.WriteLine( System.Reflection.Assembly.GetCallingAssembly().Location); } catch (Exception e) { } } } }

farzinmonsef commented 4 years ago

Views\Shared_LayoutSidebar.cshtml

<!DOCTYPE html>

@ViewBag.Title WBRS, Reports Online @Scripts.Render("~/ScriptsBundle/jquery") @Scripts.Render("~/ScriptsBundle/modernizr") @Scripts.Render("~/ScriptsBundle/validate") @Scripts.Render("~/ScriptsBundle/bootstrap") @Scripts.Render("~/ScriptsBundle/appScript") @Scripts.Render("~/ScriptsBundle/common") @Styles.Render("~/CssBundle/jquery") @Styles.Render("~/CssBundle/base") @Styles.Render("~/CssBundle/bootstrap") @Styles.Render("~/CssBundle/font-awesome") @Styles.Render("~/CssBundle/kendo") @Styles.Render("~/CssBundle/alertifyjs")
farzinmonsef commented 4 years ago

BaseController.cs

using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Web; using System.Web.Mvc; namespace WBRS.ReportsOnline.Site.Controllers { public class BaseController : Controller { protected override void OnException(ExceptionContext filterContext) { logDB(filterContext); Exception exception = filterContext.Exception; filterContext.ExceptionHandled = true; var Result = this.View("Error", new HandleErrorInfo(exception, filterContext.RouteData.Values["controller"].ToString(), filterContext.RouteData.Values["action"].ToString())); filterContext.Result = Result; } private void logDB(ExceptionContext filterContext) { var connectionString = ConfigurationManager.ConnectionStrings["CIBRS"].ConnectionString; using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); string sql = "insert into LogDB (Date_Time, UserName, Controller, Action, Message, Comment)"+ "values (@Date_Time, @UserName, @Controller, @Action, @Message, @Comment)"; using (SqlCommand command = new SqlCommand(sql, connection)) { var Date_Time = new SqlParameter("Date_Time", SqlDbType.DateTime); Date_Time.Value = DateTime.Now; command.Parameters.Add(Date_Time); var UserName = new SqlParameter("UserName", SqlDbType.VarChar); UserName.Value = (string)Session["UserID"] + "|" + (string)Session["UserFullName"]; command.Parameters.Add(UserName); var Controller = new SqlParameter("Controller", SqlDbType.VarChar); Controller.Value = filterContext.RouteData.Values["controller"].ToString(); command.Parameters.Add(Controller); var Action = new SqlParameter("Action", SqlDbType.VarChar); Action.Value = filterContext.RouteData.Values["action"].ToString(); command.Parameters.Add(Action); var Message = new SqlParameter("Message", SqlDbType.VarChar); Message.Value = filterContext.Exception.ToString(); command.Parameters.Add(Message); var Comment = new SqlParameter("Comment", SqlDbType.VarChar); Comment.Value = ""; command.Parameters.Add(Comment); var results = command.ExecuteReader(); } } } private void logDB_old(ExceptionContext filterContext) { var connectionString = ConfigurationManager.ConnectionStrings["CIBRS"].ConnectionString; string queryString = "SELECT Top 1 [Id], [Date_Time],[UserName],[Controller],[Action],[Message],[Comment] FROM LogDB;"; using (var connection = new SqlConnection(connectionString)) { using (SqlDataAdapter dataAdapter = new SqlDataAdapter(queryString, connection)) { DataSet dataSet = new DataSet(); dataAdapter.Fill(dataSet); DataRow newLog = dataSet.Tables[0].NewRow(); newLog["Date_Time"] = DateTime.Now; newLog["UserName"] = (string)Session["UserID"] + "|" + (string)Session["UserFullName"]; newLog["Controller"] = filterContext.RouteData.Values["controller"].ToString(); newLog["Action"] = filterContext.RouteData.Values["action"].ToString(); newLog["Message"] = filterContext.Exception.ToString(); newLog["Comment"] = ""; dataSet.Tables[0].Rows.Add(newLog); } } } } }

farzinmonsef commented 4 years ago

Metadat

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.ComponentModel.DataAnnotations;

namespace EQM.Site.Models { [MetadataType(typeof(TransactionMetaData))] public partial class Transaction { public static explicit operator List(Transaction t) { throw new NotImplementedException(); } } public class TransactionMetaData { //[UIHint("Date")] [ScaffoldColumn(false)] [Display(Name = "Transaction ID")] public int Id { get; set; } [Required(ErrorMessage = "Transaction Type is fundumental required.")] [Display(Name = "Transaction Type")] public Nullable TransactionType { get; set; }

    [DataType(DataType.Date)]
    [Display(Name = "Today's Date")]
    public string TodayDate { get; set; }

    [DataType(DataType.Date)]
    //[UIHint("Date")]
    [Display(Name = "Transaction Effective Date")]
    public string TransactionEffectiveDate { get; set; }
    [Display(Name = "Requisition Number")]
    public string RequisitionNumber { get; set; }

    [Required()]
    [StringLength(255)]
    [RegularExpression(@"^[a-zA-Z''-'\s ]{5,255}$",
        ErrorMessage = "Reserve Name sgould be between 5 to 255 Characters, and just alphabets/space are allowed")]
    //[Required( ErrorMessage = "Phone is a Required field." )]
    //[DataType( DataType.PhoneNumber )]
    //[RegularExpression("^[01]?[- .]?\\(?[2-9]\\d{2}\\)?[- .]?\\d{3}[- .]?\\d{4}$",
    //    ErrorMessage = "Phone is required and must be properly formatted.")]
    [Display(Name = "Reserve Name")]
    public string ReserveName { get; set; }
    [Display(Name = "Total Vested Shares")]
    public string TotalVestedShares { get; set; }
    [StringLength(255)]
    [Display(Name = "Memo")]
    public Nullable<bool> Memo { get; set; }
    [StringLength(255)]
    [Display(Name = "Attachments")]
    public Nullable<int> Attachments { get; set; }
    //[StringLength(200)]
    [Display(Name = "Status")]
    public Nullable<int> Status { get; set; }
    [Range(1, 5, ErrorMessage = "Action must be between 1 and 5")]
    [Display(Name = "Actions")]
    public Nullable<bool> Actions { get; set; }

}

}

farzinmonsef commented 4 years ago

EditTransaction

@model EQM.Site.Models.Transaction

@{ ViewBag.Title = "Edit"; }

Edit

@using (Html.BeginForm()) { @Html.AntiForgeryToken() var attributes = new System.Collections.Generic.Dictionary<string, object>(); attributes.Add("class", "form-control k-header");

<div class="form-horizontal">
    <h4>Transaction</h4>
    <hr />
    @Html.ValidationSummary(true, "", new { @class = "text-danger" })
    @Html.HiddenFor(model => model.Id)

    <div class="form-group">
        @Html.LabelFor(model => model.TransactionType, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.TransactionType, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.TransactionType, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.TodayDate, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.TodayDate, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.TodayDate, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.TransactionEffectiveDate, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.TransactionEffectiveDate, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.TransactionEffectiveDate, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.RequisitionNumber, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.RequisitionNumber, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.RequisitionNumber, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.ReserveName, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.ReserveName, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.ReserveName, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.TotalVestedShares, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.TotalVestedShares, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.TotalVestedShares, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.Memo, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.Memo, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.Memo, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.Attachments, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.Attachments, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.Attachments, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.Status, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.Status, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.Status, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.Actions, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.Actions, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.Actions, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        <div class="col-md-offset-2 col-md-10">
            <input type="submit" value="Save" class="btn btn-default" />
        </div>
    </div>
</div>

}