How to connect Devexpress scheduler with a custom data table - devexpress-windows-ui

DataSet1 ds1 = new DataSet1();
ds1.tblSchedul.Rows.Add(0, "t_test", "4/10/2013 11:30:00 AM", "0", "D", "", "", "", "4/10/2013 8:15:45 AM", "2", "sub", "0");
tblSchedulBindingSource.DataSource = ds1.tblSchedul;
But it is not working. Whats the possible solution ??

using System.Threading;
using System.Text.RegularExpressions;
using System.Data.Odbc;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors;
namespace Project
{
public partial class frmSchedule : Form
{
DataSet scheduleDataset;
SQLConnection scheduleConn;
SQLDataAdapter scheduleAdapter;
private void Form1_Load(object sender, EventArgs e)
{
schedulerControl1.Start = DateTime.Now;
scheduleDataset = new DataSet();
scheduleConn = objconnection.getConnection();// DatabaseConnection
scheduleConn.Open();
fillData("SELECT * FROM table_name");
}
private void fillData(string query)
{
scheduleDataset = new DataSet();
scheduleAdapter = new SQLDataAdapter(query, scheduleConn);
scheduleAdapter.RowUpdated += new SQLRowUpdatedEventHandler(scheduleAdapter_RowUpdated);
scheduleAdapter.Fill(scheduleDataset, "table_name");
this.appointmentsBS.DataSource = scheduleDataset;
this.appointmentsBS.DataMember = "table_name";
this.appointmentsBS.Position = 0;
this.schedulerStorage1.Appointments.DataSource = this.appointmentsBS;
this.schedulerStorage1.Appointments.Mappings.field1= "Field1";
this.schedulerStorage1.Appointments.Mappings.Field2= "Field2";
AppointmentCustomFieldMapping IDD = new AppointmentCustomFieldMapping("IDD", "IDD");
schedulerStorage1.Appointments.CustomFieldMappings.Add(IDD);
SQLCommandBuilder cmdBuilder = new SQLCommandBuilder(scheduleAdapter);
scheduleAdapter.InsertCommand = cmdBuilder.GetInsertCommand();
scheduleAdapter.DeleteCommand = cmdBuilder.GetDeleteCommand();
scheduleAdapter.UpdateCommand = cmdBuilder.GetUpdateCommand();
}
}
}

You need to use Appointments Mapping for the database tabel .
first , load the database tabel in DataTabel and use mapping method to maps the fields .
try looking at this code : Devexpress Mapping

Related

World map not dispalyed in crystal reports

I'm generating a pdf report using crystal report, I would like to use Data Map Tool
In c# code I've a dataset containing geographicals fields and some values to display in the map.
public class CrystalReportViewerPlugIn : ICrystalReportViewer
{
private ReportDocument _reportDocument;
private CrystalReportViewer _crystalReportViewer;
public void Init(string fileName, DataSet dataSet)
{
_reportDocument = new ReportDocument();
_reportDocument.Load(fileName);
_reportDocument.SetDataSource(dataSet);
_crystalReportViewer = new CrystalReportViewer();
_crystalReportViewer.DisplayToolbar = false;
_crystalReportViewer.DisplayGroupTree = false;
_crystalReportViewer.PageToTreeRatio = 4;
_crystalReportViewer.RefreshReport();
_crystalReportViewer.ReportSource = _reportDocument;
}
}
Then I export the result into a strem:
public MemoryStream GetCrystalReportResults(string rptFileName, DataSet ds)
{
var crystalReportViewer = new CrystalReportViewerPlugIn();
crystalReportViewer.PlugIn.Init(rptFileName, ds);
crystalReportViewer.PlugIn.Control.Visible = true;
var oStream = crystalReportViewer.PlugIn.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
var byteArray = new byte[oStream.Length];
oStream.Read(byteArray, 0, Convert.ToInt32(oStream.Length - 1));
return new MemoryStream(byteArray);
}
The stream is exported as pdf:
protected virtual IHttpActionResult FinalizeExport(MemoryStream data, string name)
{
string contentType = "application/octet-stream";
name = name.GetCleanFileName();
var response = Request.CreateResponse(HttpStatusCode.OK);
response.Content = new StreamContent(data);
response.Content.Headers.Remove("content-type");
response.Content.Headers.Add("content-type", contentType);
response.Content.Headers.Remove("x-filename");
response.Content.Headers.Add("x-filename", name);
response.Content.Headers.Add("Content-Disposition", "inline; filename=\"" + name + "\"");
response.Content.Headers.Add("Content-Length", data.Length.ToString());
return ResponseMessage(response);
}
The world map is not displayed, do you have anny idea about this issue ?
Crystal report's map works only in 32 bits environment.

how to store dbcontext.emps.ToList() data in a data table

how to store the dbcontext.emp.tolist(); data in datatable to perform sorting using entity frame database first approach and linq .
here i am uploading my code.
please help.
how to perform soting operation for grid using entity frame work and linq.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace sortingby_crud
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
//this.BindGrid();
GridView1.DataSource = BindGrid();
GridView1.DataBind();
}
}
private DataTable BindGrid()
{
using (dbEntities db = new dbEntities())
{
//GridView1.DataSource = db.emps.ToList();
//GridView1.DataBind();
DataTable dt = new DataTable();
dt= db.emps.ToList();
return dt;
}
}
public SortDirection dir
{
get
{
if (ViewState["dirState"] == null)
{
ViewState["dirState"] = SortDirection.Ascending;
}
return (SortDirection)ViewState["dirState"];
}
set
{
ViewState["dirState"] = value;
}
}
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
string sortingDirection = string.Empty;
if (dir == SortDirection.Ascending)
{
dir = SortDirection.Descending;
sortingDirection = "Desc";
}
else
{
dir = SortDirection.Ascending;
sortingDirection = "Asc";
}
DataView sortedView = new DataView(BindGrid());
sortedView.Sort = e.SortExpression + " " + sortingDirection;
GridView1.DataSource = sortedView;
GridView1.DataBind();
}
}
}
public DataTable data() // or keep return type is also
as void .
/convert db.context in data table.
{
DataTable table = new DataTable();
var list = db.SupplierAssignmentones.ToList();
//Defining the header for the datatable.
table.Columns.Add("VendorId", typeof(int));
table.Columns.Add("VendorName", typeof(string));
table.Columns.Add("VendorDescription", typeof(string));
table.Columns.Add("SupHie1_CD", typeof(string));
table.Columns.Add("SupHie2_CD", typeof(string));
table.Columns.Add("SupHie3_CD", typeof(string));
table.Columns.Add("Is_Active", typeof(string));
//assigning the data for data table rows.
foreach (var data in list)
{
table.Rows.Add(data.VendorId, data.VendorName, data.VendorDescription, data.SupHie1_CD, data.SupHie2_CD, data.SupHie3_CD, data.Is_Active);
}
return table;
}

Unit testing methods using AddOrUpdate with Entity Framework 6 Repository

I've managed to Mock an Entity Framework dbcontext and dbset to allow for unit testing querying functions against a repository component.
I've been unable to perform a successful test against an a method using Entity Frameworks' AddOrUpdate() method. The error received is:
"Unable to call public, instance method AddOrUpdate on derived IDbSet type 'Castle.Proxies.DbSet`1Proxy'. Method not found."
Is it at all possible to test this?
private IRepository _Sut;
private Mock<DbSet<JobListing>> _DbSet;
private Mock<RecruitmentDb> _DbContext;
[SetUp]
public void Setup()
{
_DbContext = new Mock<RecruitmentDb>();
var JobsData = GenerateJobs().AsQueryable();
_DbSet = new Mock<DbSet<JobListing>>();
_DbSet.As<IQueryable<JobListing>>().Setup(x => x.Provider).Returns(JobsData.Provider);
_DbSet.As<IQueryable<JobListing>>().Setup(x => x.Expression).Returns(JobsData.Expression);
_DbSet.As<IQueryable<JobListing>>().Setup(x => x.ElementType).Returns(JobsData.ElementType);
_DbSet.As<IQueryable<JobListing>>().Setup(x => x.GetEnumerator()).Returns(JobsData.GetEnumerator());
_DbContext.Setup(x => x.JobListings).Returns(_DbSet.Object);
_Sut = new JobListingRepository(_DbContext.Object);
}
[Test]
public void Update_ChangedTitleProperty_UpdatedDetails()
{
var Actual = GenerateJobs().First();
var OriginalJob = Actual;
Actual.Title = "Newly Changed Title";
_Sut.Update(Actual);
Actual.Title.Should().NotBe(OriginalJob.Title);
Actual.Id.Should().Be(OriginalJob.Id);
}
private List<JobListing> GenerateJobs()
{
return new List<JobListing>
{
new JobListing{ Id = 1,
Title = "Software Developer",
ShortDescription = "This is the short description",
FullDescription = "This is the long description",
Applicants = new List<Applicant>(),
ClosingDate = DateTime.Now.AddMonths(5).Date},
new JobListing{
Id = 2,
Title = "Head Chef",
ShortDescription = "This is the short description",
FullDescription = "This is the long description",
Applicants = new List<Applicant>(),
ClosingDate = DateTime.Now.AddMonths(2).Date
},
new JobListing
{
Id = 3,
Title = "Chief Minister",
ShortDescription = "This is the short description",
FullDescription = "This is the long description",
Applicants = new List<Applicant>(),
ClosingDate = DateTime.Now.AddMonths(2).Date
}
};
}
The issue is because AddOrUpdate is an extension method. I overcame this issue by designing a wrapper. You can mock/stub the IAddOrUpdateHelper interface instead.
public class AddOrUpdateHelper : IAddOrUpdateHelper
{
public void AddOrUpdateEntity<TEntity>(DataContext db, params TEntity[] entities) where TEntity : class
{
db.Set<TEntity>().AddOrUpdate(entities);
}
}
public interface IAddOrUpdateHelper
{
void AddOrUpdateEntity<TEntity>(DataContext db, params TEntity[] entities) where TEntity : class;
}

Maximum Report Processing has been reached for crystal report

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.Drawing.Imaging;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Xml;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.ReportSource;
using CrystalDecisions.Reporting;
using CrystalDecisions.Shared;
using CrystalDecisions.Web;
public partial class Schools : System.Web.UI.Page
{
ReportDocument crystalReport = new ReportDocument();
protected void Page_Init(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
try
{
string query = "select * from School Where Designation = 'Public' Order by School ASC";
crystalReport.Load(Server.MapPath("ReportPrimary.rpt"));
MPrimary dsCustomers = GetData(query);
crystalReport.SetDataSource(dsCustomers);
crystalReport.SetDatabaseLogon("username", "password.34", "mssql.webaddress.net,4118", "dataDB");
SchReport.ReportSource = crystalReport;
Session["ReportDocument"] = crystalReport;
}
catch (LogOnException ex)
{
//Throws an exception if an error is encountered on retrieval
}
}
else
{
string query = "select * from School Where Designation = " + "'" + drpSchoolDesignation.SelectedValue + "'" + " Order by School ASC";
// ReportDocument crystalReport = new ReportDocument();
crystalReport.Load(Server.MapPath("ReportPrimary.rpt"));
TextObject to = (TextObject)crystalReport.ReportDefinition.Sections["Section2"].ReportObjects["Text3"];
to.Text = drpSchoolDesignation.SelectedValue.ToUpper() + " SCHOOLS";
MPrimary dsCustomers = GetData(query);
crystalReport.SetDataSource(dsCustomers);
SchReport.FindControl("Text3");
crystalReport.SetDatabaseLogon("username", "password.34", "mssql.webaddress.net,4118", "dataDB");
ReportDocument doc = (ReportDocument)Session["ReportDocument"];
SchReport.ReportSource = doc;
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
private void OpenNewWindow(string url, string windowName, string windowParams)
{
if (url == null)
throw new ArgumentNullException("url");
if (windowName == null)
windowName = "";
if (windowParams == null)
windowParams = "";
string scriptCode =
string.Format(
"<script>window.open('{0}','{1}','{2}');</script>",
url, windowName, windowParams);
//write the script out to HTTP Response stream
Response.Write(scriptCode);
}
private MPrimary GetData(string query)
{
string conString = ConfigurationManager.ConnectionStrings["DBConnectionString1"].ConnectionString;
SqlCommand cmd = new SqlCommand(query);
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (MPrimary dsCustomers = new MPrimary())
{
sda.Fill(dsCustomers, "School");
return dsCustomers;
}
}
}
}
protected void drpSchoolDesignation_SelectedIndexChanged(object sender, EventArgs e)
{
drpDisplay.SelectedIndex = 0;
drpSort.SelectedIndex = 0;
string query = "select * from School Where Designation = " + "'" + drpSchoolDesignation.SelectedValue + "'" + " Order by School ASC";
crystalReport.Load(Server.MapPath("ReportPrimary.rpt"));
TextObject to = (TextObject)crystalReport.ReportDefinition.Sections["Section2"].ReportObjects["Text3"];
to.Text = drpSchoolDesignation.SelectedValue.ToUpper() + " SCHOOLS";
MPrimary dsCustomers = GetData(query);
crystalReport.SetDataSource(dsCustomers);
crystalReport.SetDatabaseLogon("username", "password.34", "mssql.webaddress.net,4118", "dataDB");
Session["ReportDocument"] = crystalReport;
SchReport.ReportSource = crystalReport;
}
protected void CrystalReportViewer1_Unload(object sender, EventArgs e)
{
crystalReport.Close();
crystalReport.Dispose();
}
protected void Button1_Click(object sender, EventArgs e)
{
//Select data from DB
//Action to be added later
}
}
This code is supposed to retrieve and display info using crystal reports.
It seems my object is not been properly disposed. Modifying this code disables the user from ever getting to page 3 of the document. Any help would be appreciated. Thanks guys in advance.

List changed files in TFS but ordered by number of changes applied

Is there a way of listing all the files that have changed on a project, but ordered by the number of changes made to each file?
I want to do a code review but only from a selection of the most active files.
You may try to use Excel as a TFS reporting tool like in this blog post:
http://www.woodwardweb.com/vsts/getting_started.html
ps. I found that link in this question.
I searched different ways and finally I found that best way is using TFS API
here is the code :
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
namespace VControl
{
class Program
{
class SourceElement
{
public string filename;
public int numberOfModification;
}
static void Main(string[] args)
{
TfsTeamProjectCollection projectCollection = new
TfsTeamProjectCollection(new Uri("http://server:8080/tfs/ProjectCollection/"),
new System.Net.NetworkCredential("username", "password"));
projectCollection.EnsureAuthenticated();
Workspace workspace = null;
Boolean createdWorkspace = false;
String newFolder = String.Empty;
VersionControlServer versionControl = projectCollection.GetService<VersionControlServer>();
var teamProjects = new List<TeamProject>(versionControl.GetAllTeamProjects(false));
String workspaceName = String.Format("{0}-{1}", Environment.MachineName, "TestWorkspace");
try
{
workspace = versionControl.GetWorkspace(workspaceName, versionControl.AuthorizedUser);
}
catch (WorkspaceNotFoundException)
{
workspace = versionControl.CreateWorkspace(workspaceName, versionControl.AuthorizedUser);
createdWorkspace = true;
}
var serverFolder = String.Format("$/{0}", teamProjects[0].Name) + "/solutionFolder/";
var localFolder = Path.Combine(Path.GetTempPath(), "localFolder") + "/solutionFolder/";
var workingFolder = new WorkingFolder(serverFolder, localFolder);
// Create a workspace mapping.
workspace.CreateMapping(workingFolder);
if (!workspace.HasReadPermission)
{
throw new SecurityException(
String.Format("{0} does not have read permission for {1}",
versionControl.AuthorizedUser, serverFolder));
}
// Get the files from the repository.
workspace.Get();
string[] directories = Directory.GetDirectories(workspace.Folders[0].LocalItem);
FileStream outputFile = new FileStream("result.txt", FileMode.Create);
StreamWriter writer = new StreamWriter(outputFile);
List<SourceElement> fileLiset = new List<SourceElement>();
foreach (string dir in directories)
{
foreach (string file in Directory.GetFiles(dir))
{
string filenamae = System.IO.Path.GetFileName(file);
Item source = versionControl.GetItem(file);
System.Collections.IEnumerable history = versionControl.QueryHistory(file,
VersionSpec.Latest, 0, RecursionType.Full, null, null, null, 300, true, true, false, false);
int numberOfModification = 0;
foreach (var item in history)
numberOfModification++;
SourceElement fileElement = new SourceElement();
fileElement.filename = filenamae;
fileElement.numberOfModification = numberOfModification;
fileLiset.Add(fileElement);
}
}
var sortedList = fileLiset.OrderBy(x=> x.numberOfModification);
// Loop through keys.
foreach (var key in sortedList)
{
writer.WriteLine("{0}: {1}", key.filename, key.numberOfModification);
}
writer.Close();
}
}
}