Wednesday, April 30, 2014

C# allow nullable value get from EF

You can get value from Entity framework which can allow null able and you can also perform filtering in your query.

  private static IQueryable<EmployeeInformation> ReportFilteringEmployeeInformations(Guid factoryId, Guid departmentId, Guid designationId, string empId,  
     string empName, Guid sectionId, Guid categoryEmpId, int? CategoryTypeID, Guid categorySalaryID, Guid blockID,string cardNo, PayrollEntities context)  
     {  
       var query =  
         from emp in context.vw_PIS_TblEmployeeGenInfo  
         join des in context.vw_PIS_TblEmployeeDesignation on emp.GDesignationInfoID equals des.GDesignationInfoID into  
           des_J  
         join dept in context.vw_PIS_tblDepartment on emp.GDepartmentID equals dept.GDepartmentID into dept_J  
         join sec in context.vw_PIS_TblSection on emp.SectionID equals sec.SectionID into sec_J  
         from des1 in des_J.DefaultIfEmpty()  
         from dept1 in dept_J.DefaultIfEmpty()  
         from sec1 in sec_J.DefaultIfEmpty()  
         select new EmployeeInformation  
         {  
           GEmployeeGenInfoID = emp.GEmployeeGenInfoID,  
           GFactoryID = emp.GFactoryID ?? Guid.Empty,  
           GDepartmentID = emp.GDepartmentID ?? Guid.Empty,  
           GDesignationInfoID = emp.GDesignationInfoID ?? Guid.Empty,  
           GSectionID = emp.SectionID ?? Guid.Empty,  
           GEmployeeCatID = emp.GEmployeeCatID ?? Guid.Empty,  
           CategoryEmpID = emp.CategoryEmpID,  
           GCategorySalaryID = emp.CategorySalaryID ?? Guid.Empty,  
           BlockID = emp.BlockID ?? Guid.Empty,  
           StrEmpID = emp.StrEmpID,  
           StrEmpCardNo = emp.StrEmpCardNo,  
           StrEmpName = emp.StrEmpName,  
           dtJoiningDate = emp.dtJoiningDate,  
           DtConfirmationDate = emp.DtConfirmationDate ?? DateTime.MaxValue,  
           strDesignationName = des1.StrDesignationName,  
           strDepartmentName = dept1.StrDepartmentName,  
           SectionName = sec1.SectionName,  
           CategoryTypeID = emp.CategoryTypeID,  
           GSalaryIncrementID = Guid.Empty,  
           dtIncrementDate = null,  
           dtEffectiveDate = null  
         };  
       /*********************************************************************/  
       // FILTER / where clause   
       if (factoryId != Guid.Empty)  
         query = query.Where(x => x.GFactoryID == factoryId);  
       if (departmentId != Guid.Empty)  
         query = query.Where(x => x.GDepartmentID == departmentId);  
       if (designationId != Guid.Empty)  
         query = query.Where(x => x.GDesignationInfoID == designationId);  
       if (!String.IsNullOrEmpty(empId))  
         query = query.Where(x => x.StrEmpID == empId);  
       if (!String.IsNullOrEmpty(empName))  
         query = query.Where(x => x.StrEmpName == empName);  
       if (sectionId != Guid.Empty)  
         query = query.Where(x => x.GSectionID == sectionId);  
       if (categoryEmpId != Guid.Empty)  
         query = query.Where(x => x.CategoryEmpID == categoryEmpId);  
       if (categorySalaryID != Guid.Empty)  
         query = query.Where(x => x.GCategorySalaryID == categorySalaryID);  
       if (blockID != Guid.Empty)  
         query = query.Where(x => x.BlockID == blockID);  
       if (!String.IsNullOrEmpty(cardNo))  
         query = query.Where(x => x.StrEmpCardNo == cardNo);  
       if (CategoryTypeID != null && CategoryTypeID != 0)  
         query = query.Where(x => x.CategoryTypeID == CategoryTypeID);  
       return query;  
     }  

C# time difference between two times


       DateTime dtFrom = DateTime.Parse("3:00 PM");  
       DateTime dtTo = DateTime.Parse("5:00 PM");  
       DateTime now = DateTime.Now;  
       if ((now>=dtFrom) && now<= dtTo )  
       {  
       // Do Something  
       }  


Thursday, April 24, 2014

Schedule Mail Sending with attachment file ASP.NET MVC

For scheduling mail i am using JobcashAction. It's simple

Open your Global.asax.cs file just use the following code.

  public class MvcApplication : System.Web.HttpApplication  
   {  
     // Define Path Of the Job  
     private const string JobCashAction = "http://localhost:38416/Home/AddJobCache";  
     protected void Application_Start()  
     {  
       AreaRegistration.RegisterAllAreas();  
       WebApiConfig.Register(GlobalConfiguration.Configuration);  
       FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);  
       RouteConfig.RegisterRoutes(RouteTable.Routes);  
       BundleConfig.RegisterBundles(BundleTable.Bundles);  
       AuthConfig.RegisterAuth();  
     }  
     protected void Application_BeginRequest(object sender, EventArgs e)  
     {  
       if (HttpContext.Current.Cache["jobkey"] == null)  
       {  
         HttpContext.Current.Cache.Add("jobkey",  
                         "jobvalue", null,  
                         DateTime.MaxValue,  
                         TimeSpan.FromSeconds(15), // set the time interval  
                         CacheItemPriority.Default, JobCacheRemoved);  
       }  
     }  
     private static void JobCacheRemoved(string key, object value, CacheItemRemovedReason reason)  
     {  
       var client = new WebClient();  
       client.DownloadData(JobCashAction);  
       ScheduleJob();  
     }  
     private static void ScheduleJob()  
     {  
       // ExecuteAnyMethod  
     }  
   }  


Now just use the code in you controller as you define in JobcashAction path in Global 

"http://localhost:38416/Home/AddJobCache";

 I use AddJobCache  ActionResult it in my home controller.



 public ActionResult AddJobCache()  
     {  
       // Report data  
       List<Student> studentList = new List<Student>();  
       studentList = GetStudentInfo(); // Get the StudentList Data  
       ReportDocument details = new ReportDocument();  
       details.Load(Server.MapPath("../Report/rptStudent.rpt")); // Crystal report path  
       details.SetDataSource(studentList); // Set the StudentList Data as report source  
       details.ExportToDisk(ExportFormatType.PortableDocFormat, "D:\\ff.pdf"); // save file as pdf  
       // Mail Send  
       MailMessage mail = new MailMessage();  
       SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");  
       mail.From = new MailAddress("atiour.islam@gmail.com"); // Sender Email Address  
       mail.To.Add("atik.kotha@gmail.com"); // Send Mail to  
       mail.Subject = "Test"; // Email Subject  
       mail.Body = "Hi"; // Email Body  
       System.Net.Mail.Attachment attachment;  
       attachment = new System.Net.Mail.Attachment("D:\\ff.pdf");// Get Attach file path  
       mail.Attachments.Add(attachment);  
       SmtpServer.Port = 587;  
       SmtpServer.Credentials = new System.Net.NetworkCredential("atiour.islam@gmail.com", "yourpassword");// Sender Email & Password  
       SmtpServer.EnableSsl = true;  
       SmtpServer.Timeout = 60000;  
       SmtpServer.Send(mail);  
       return null;  
     }  

Enjoy...



Wednesday, April 23, 2014

ASP.NET MVC Mail Sending with attachment file

You can send mail with attach file using the code



 MailMessage mail = new MailMessage();  
       SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");  
       mail.From = new MailAddress("atiour.islam@gmail.com");  
       mail.To.Add("atik.kotha@gmail.com");  
       mail.Subject = "Test";  
       mail.Body = "Hi";  
       System.Net.Mail.Attachment attachment;  
       attachment = new System.Net.Mail.Attachment("D:\\ff.pdf");  
       mail.Attachments.Add(attachment);  
       SmtpServer.Port = 587;  
       SmtpServer.Credentials = new System.Net.NetworkCredential("atiour.islam@gmail.com", "password");  
       SmtpServer.EnableSsl = true;  
       SmtpServer.Timeout = 60000;  
       SmtpServer.Send(mail);   


Crystal report Save as Pdf in defined path


Spending a lot's of time i figure out that you can save a crystal report as pdf in your defined path, It can be your local drive or server path.

  List<Student> studentList = new List<Student>();  
  studentList = GetStudentInfo();  
  ReportDocument details = new ReportDocument();  
  details.Load(Server.MapPath("../Report/rptStudent.rpt"));  
  details.SetDataSource(studentList);  
  details.ExportToDisk(ExportFormatType.PortableDocFormat, "D:\\ff.pdf");  

Hope it will help you.

Wednesday, April 16, 2014

SQL datetime to AM/PM

just set you datefield in
Payroll_tblAttendance.InTime

Finally:

 (SELECT RIGHT(LTRIM(RIGHT(CONVERT(varchar, Payroll_tblAttendance.InTime, 100),8)),8)) InTime,  

Thursday, April 10, 2014

Sap crystal report front size problem after export in pdf

1. open Command Window
2. enter 'regedit' and enter
3. Navigate to HKEY_CURRENT_USER -> Software -> Business Objects-> Suite 12-> Crystal Reports-> Export
4. Rightclick 'Export' -> New -> Key
5. Enter 'PDF'
6. In the newly created Key add 3 new DWORD
a. 'ForceLargerFonts' with value 1
b. 'TruncationAdjustment' with value 2
c. 'UsePrecisePositioningForText' with value 1
6.Navigate to HKEY_LOCAL_MACHINE -> Software->Wow6432Node->Business Objects->Suite 12-> Crystal Reports-> Export
7.Repeat steps 4,5 and 6


Or Follow the Link

http://www.linkedin.com/groups/Fonts-margin-shrinking-when-exporting-123302.S.138244632

Wednesday, April 9, 2014

ASP.NET MVC Cashcading dropdown



View Page


 @model FactoryProduct.Web.Areas.Payroll.Models.EmployeeLeaveCalendarModels  
 <script>  
  function getDepartmentReleatedData(ctrl) {  
     var DepartmentId = $('#EmployeeLeaveCalendar_GDepartmentID').val();  
     var FactoryId = $('#EmployeeLeaveCalendar_GFactoryID').val();  
     var s = ',';  
     if (DepartmentId != "00000000-0000-0000-0000-000000000000" && DepartmentId != "" && FactoryId != "00000000-0000-0000-0000-000000000000" && FactoryId != "") {  
       var p = (FactoryId + s + DepartmentId)  
       GetDesignationByDepartment(p);  
       //GetCategogyByDepartmentId(p);  
       //GetSectionByDepartmentId(p);  
       //GetEmpCategogyByDepartmentId(p);  
     }  
     return false;  
   }  
   function GetDesignationByDepartment(Id) {  
     $('#EmployeeLeaveCalendar_GDesignationInfoID> option:not(:first)').remove();  
     var form = $("#frmLeaveOpeningDetails");  
     var serializedForm = form.serialize();  
     var url = "/PMS/Payroll/LeaveOpening/GetDepartmentWiseDesignationList/" + Id;  
     $.post(url, serializedForm, function (result) {  
       $.each(result, function () {  
         $("#EmployeeLeaveCalendar_GDesignationInfoID").append($("<option></option>").val(this['DesignationInfoID']).html(this['DesignationName']));  
       });  
       $("#EmployeeLeaveCalendar_GDesignationInfoID").change();  
     }, "json");  
     return false;  
   }  
 </script  
 <form id="frmLeaveOpeningDetails" action="">  
   <div>  
     <div>  
       <label>  
         Department Name</label>  
     </div>  
     <div>  
       @Html.DropDownListFor(m => m.EmployeeLeaveCalendar.GDepartmentID, Model.DepartmentListForEmployee, CommonMessage.SelectOne, new { @class = "selectBoxRegular" , onchange = "return getDepartmentReleatedData(this);"})   
     </div>  
     <div>  
       <label>  
         Designation</label>  
     </div>  
     <div>  
       @Html.DropDownListFor(m => m.EmployeeLeaveCalendar.GDesignationInfoID, Model.DesignationtListForEmployee, CommonMessage.SelectOne, new { @class = "selectBoxRegular" })  
     </div>  
   </div>  
  </form>  

Controller


  public JsonResult GetDepartmentWiseDesignationList(string id)  
     {  
       string[] dateString = id.Split(',');  
       string factoryId = dateString[0];  
       string departmentId = dateString[1];  
       ArrayList AssignDesignationList = new ArrayList();  
       try  
       {  
         List<Mohammadi.Core.PIS.Business.DesignationInfo> AssignDesignation = new List<Mohammadi.Core.PIS.Business.DesignationInfo>();  
         DesignationHelper designationHelperobj = new DesignationHelper();  
         AssignDesignation = designationHelperobj.GetAssignDesignationByDepartment(factoryId, departmentId);  
         var items = (from item in AssignDesignation  
                select new { item.DesignationInfoID, item.DesignationName }).ToList();  
         foreach (var item in items)  
         {  
           AssignDesignationList.Add(item);  
         }  
       }  
       catch (Exception ex)  
       {  
       }  
       return Json(AssignDesignationList);  
     }  


Model

 public EmployeeLeaveCalendar EmployeeLeaveCalendar { get; set; }  
 private SelectList designationtListForEmployee;  
     public SelectList DesignationtListForEmployee  
     {  
       get  
       {  
         List<Mohammadi.Core.PIS.Business.DesignationInfo> DesignationList = new List<Mohammadi.Core.PIS.Business.DesignationInfo>();  
         DesignationHelper designationHelperobj = new DesignationHelper();  
         if (this.EmployeeLeaveCalendar.GFactoryID != null && this.EmployeeLeaveCalendar.GFactoryID.ToString() != "00000000-0000-0000-0000-000000000000" && this.EmployeeLeaveCalendar.GDepartmentID != null && this.EmployeeLeaveCalendar.GDepartmentID.ToString() != "00000000-0000-0000-0000-000000000000")  
         {  
           DesignationList = designationHelperobj.GetAssignDesignationByDepartment(this.EmployeeLeaveCalendar.GFactoryID.ToString(), this.EmployeeLeaveCalendar.GDepartmentID.ToString());  
         }  
         else  
         {  
           DesignationList = designationHelperobj.GetFactoryWiseAllDesignation(this.EmployeeLeaveCalendar.GFactoryID);  
         }  
         this.designationtListForEmployee = new SelectList(DesignationList, "DesignationInfoID", "DesignationName");  
         return designationtListForEmployee;  
       }  
       set { designationtListForEmployee = value; }  
     }  








SQL Get all Index create script from Database

To get all script from database as a create new index into another database you can use the following --Get all Index Script SELECT...