Posts

Showing posts from 2018

EncryptDecrypt Web config c#

  public static void WebEncryptDecrypt()         {             Configuration config = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);             ConfigurationSection configSection = config.GetSection("appSettings");             ConnectionStringsSection ConSection = config.GetSection("connectionStrings") as ConnectionStringsSection;             if (configSection.SectionInformation.IsProtected)             {                 configSection.SectionInformation.UnprotectSection();                 ConSection.SectionInformation.UnprotectSection();                 config.Save();                           ...

sum list of object property using recursions c#

 class Program     {         static void Main(string[] args)         {             List<EMPLOYEE> employees = new List<EMPLOYEE>();             employees.Add(new EMPLOYEE { NAME = "AAAA", SALARY = 1 });             employees.Add(new EMPLOYEE { NAME = "BBBB", SALARY = 2 });             employees.Add(new EMPLOYEE { NAME = "CCCC", SALARY = 2 });             employees.Add(new EMPLOYEE { NAME = "DDDD", SALARY = 2 });             employees.Add(new EMPLOYEE { NAME = "EEEE", SALARY = 2 });             employees.Add(new EMPLOYEE { NAME = "FFFF", SALARY = 2 });             //Print total salary using recursion method in SumSalary             Console.Writ...

Ajax Autocomplete Extender - Passing more parameters to the server c#

<asp:TextBox runat="server" ID="txtName" AutoPostBack="True" CssClass="form-control" OnTextChanged="txtName_TextChanged"></asp:TextBox> <asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="txtName" EnableCaching="false" UseContextKey="true" BehaviorID="AutoCompleteCities" OnClientPopulating="autoComplete1_OnClientPopulating" ServiceMethod="GetItem" ServicePath="RequisitionUI.aspx" MinimumPrefixLength="1" CompletionInterval="500" CompletionSetCount="10" FirstRowSelected="true"> ...

SQL update query using joins sql server

UPDATE A SET foo = B . bar FROM TableA A JOIN TableB B ON A . col1 = B . colx WHERE ...

Setting multiple choices using jquery chosen pluging

$('#ShopId').val(array).trigger('chosen:updated'); $ ( '#btnshop' ). click ( function () { $ ( '#ShopId' ). chosen ( 'destroy' ). val ([ "shop1" , "shop2" , "shop3" ]). chosen (); });   $.ajax({             url: 'CustomerReport/GetAllShop',             data: {},             success: function (data) {                 var array = [];                 $(data.data).each(function (index, car) {                     array.push(car.ShopID);                 });                 $('#ShopId').val(array).trigger('chosen:updated');             },             error: function () {         ...

Open New Window inside Update Panel in C# using JavaScript code

string URL = ResolveUrl("~/Report/Viewers/ReportViewer.aspx?ReportType=AssembleIssueReport&ItemIssueNo=" + issue.ChallanNo + "");                     ScriptManager.RegisterStartupScript(UpdatePanel1, typeof(string), "Package", "window.open('" + URL + "');", true);

Parse Date format in c#

var date=DateTime.ParseExact(txtdate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture); 

Load Crystal Report from Physical Path c#

using(CrystalDecisions.CrystalReports.Engine.ReportDocument rd = new ReportDocument()) { var path = HttpContext.Current.Server.MapPath((@ "~/Reports/rptDatewiseSaleSummaryReport.rpt")); rd.Load(path); rd.SetDataSource(items); string fname = System.Web.HttpContext.Current.Server.MapPath("~/CReports") + "/" + guid.ToString() + "." + type; CrystalDecisions.Shared.DiskFileDestinationOptions dfo = new CrystalDecisions.Shared.DiskFileDestinationOptions(); dfo.DiskFileName = fname; switch (type) { case "pdf": rd.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat; break; case "xls": rd.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.Excel; break; } rd.ExportOptions.DestinationOptions = dfo; rd.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile; rd.Export(); rd.Close(); }

Grant EXECUTE to user for stored procedures in a schema.

GRANT EXECUTE ON schema ::< schema name > TO < user name > GRANT EXECUTE ON Sp_DateWiseItemSalesReport TO storemanager

Select query to get data And Execute SQL Statement in SQL Server

public class SQLDAL { private SqlConnection connection; public SQLDAL () { connection = new SqlConnection(GlobalConnection()); } public string GlobalConnection () { string entityConnectionString = ConfigurationManager.ConnectionStrings[ "DefaultConnection" ].ConnectionString; //string providerConnectionString = new EntityConnectionStringBuilder(entityConnectionString).ProviderConnectionString; return entityConnectionString; } #region Query Execute public Result ExecuteQuery ( string SQL) { Result oResult = new Result(); SqlCommand oCmd = null ; try { if (connection != null ) { connection.Open(); oCmd = new SqlCommand(SQL, connection); oCmd.ExecuteNonQuery(); oResu...

Capturing all inner exception details c#

I have this extension method which suits my purposes just fine. public static class ExceptionExtensions { public static string ToMessageAndCompleteStacktrace ( this Exception exception) { Exception e = exception; StringBuilder s = new StringBuilder(); while (e != null ) { s.AppendLine( "Exception type: " + e.GetType().FullName); s.AppendLine( "Message : " + e.Message); s.AppendLine( "Stacktrace:" ); s.AppendLine(e.StackTrace); s.AppendLine(); e = e.InnerException; } return s.ToString(); } } And use it like this : using SomeNameSpaceWhereYouStoreExtensionMethods ; try { // Some code that throws an exception } catch (Exception ex) { Console.WriteLine(ex.ToMessageAndCompleteStacktrace()); } Links : https://stackoverflow.com/questions/18489387/what-is-the-best-practice-for-capturing-all-inner-exception-det...

Easy Ui Jquery easyui-textbox change onChange event

$( '#LastName' ).textbox({ onChange: function (newValue, oldValue) { console.log( 'onchange fired...textbox, newValue:' + newValue + ";oldValue:" + oldValue); $( "#Fullname" ).textbox({ value: $ ( '#FirstName' ).val().trim() + " " + $( '#MiddleName' ).val().trim() + " " + $( '#LastName' ).val().trim() }); } }); <tr> <td> <label style= "font-size: 12px" > First Name : </label> </td> <td> @* <input name= "FirstName" id= "FirstName" class= "easyui-textbox" required= "true" ></input> *@ @* <input name= "FirstName" class= "easyui-textbox" ...

Easy Ui Jquery easyui-combobox change onSelect event

< input id = "ShopId" class = "easyui-combobox" name = "ShopId" data - options = "valueField:'ShopID',textField:'ShopName',url:'Outlet/LoadAllShopsForDropDown'" > $( '#ShopId' ).combobox({ onSelect: function (record) { console.log(record); $.ajax({ type : "get" , url : 'CustomerProfile/LoadAllByShopId' , dataType : 'json' , data : { ShopID: record.ShopID }, }).done( function (responseJson) { $( '#dg' ).datagrid( 'loadData' , responseJson); }); } });

back-end errors or serverError handling in Angularjs

app.factory( 'ActionMessageService' , function () { var objToReturn = {}; var _MESSAGE_DETAIL = { ERROR : { type : "ERROR" , bootstrapClass : "alert alert-danger" }, OK : { type : "OK" , bootstrapClass : "alert alert-success" }, INFO : { type : "INFO" , bootstrapClass : "alert alert-info" }, WARNING : { type : "WARNING" , bootstrapClass : "alert alert-warning" }, NOT_FOUND : { type : "ERROR" , bootstrapClass : "alert alert-danger" }, }; var _MESSAGE_STATUS = { 400: _MESSAGE_DETAIL.WARNING , 200: _MESSAGE_DETAIL.OK , 500: _MESSAGE_DETAIL.ERROR , 404: _MESSAGE_DETAIL.NOT_FOUND }; var _getActionMessage = function (response) { var actionMessage = response.data.Message; if (response.data.ModelState) { _.forEach(_.flatMap(response.data.ModelSta...

ajax calls not working with ASP.Net Web Forms

<script type = "text/javascript" > $ ( document ). ready ( function () { $ . ajax ({ url : '/Default.aspx/GetData' , type : 'POST' , beforeSend : function ( xhr ) { xhr . setRequestHeader ( "Content-type" , "application/json; charset=utf-8" ); }, success : function ( result ) { var resultData = ( result . d ? result . d : result ); alert ( resultData ); }, error : function (){ alert ( 'error' ); } }); }); </script> [ System . Web . Services . WebMethod ] public static string GetData () { return "Hello" ; } Add FriednlyUrls to the project. Remove the line in  RegisterRoutes  method that sets  settings.AutoRedirect...