private void Form1_Date (Object sender, System.EventArgs e)
{
System.TimeDate Date = System.DateTime.Get_Today();
}
I have errors compiling which do not specifically state the actual problem.
System.DateTime Date = System.DateTime.Get_Today();
Related
I am working on a windows application which freezes most of the time on button click events on Home Page. Please find the code below for your reference. Thanks
using System;
using System.Windows.Forms;
namespace FileMigrationAgen
{
public partial class HomePage : Form
{
public HomePage()
{
InitializeComponent();
}
private void tableLayoutPanel4_Paint(object sender, PaintEventArgs e)
{
}
private async void button1_Click(object sender, EventArgs e)
{
SharepointMigration sharepointMigration = new SharepointMigration();
sharepointMigration.Show();
this.Hide();
}
private async void button2_Click(object sender, EventArgs e)
{
OneDriveMigration oneDriveMigration = new OneDriveMigration();
oneDriveMigration.Show();
this.Hide();
}
private void HomePage_FormClosed(object sender, FormClosedEventArgs e)
{
Application.Exit();
}
}
}
I wouldn't recommend performing navigation in the manner that you have - hiding parent forms etc.
Have a look at this thread it has an example of using a static class to perform the navigation and keep track of the navigation stack.
When I test rewardAd, I can see the ad and I can get reward, but let's say I have 3 Revive ability I watched an ad and it gives 7 revive ability and let's say I watched again now it's not giving me reward, but if I spend my ability and watch again let's say I spend 2 now I have 8 when I watch reward ad it gives me 2 and it stucks at 10 again it never goes over 10 and if I have 2 ability it gives 8 if I have 5 ability it gives 5 it always completes at 10 I have no idea how to fix it, can you help me.
public void RequestRewardAd()
{
AdRequest request = new AdRequest.Builder().Build();
rewardBasedVideo.LoadAd(request, rewardBasedVideoId);
}
public void ShowRewardAd()
{
if (rewardBasedVideo.IsLoaded())
{
rewardBasedVideo.Show();
}
}
public void HandleRewardBasedVideoLoaded(object sender, EventArgs args)
{
Debug.Log("HandleRewardBasedVideoLoaded event received");
}
public void HandleRewardBasedVideoFailedToLoad(object sender, AdFailedToLoadEventArgs args)
{
Debug.Log("HandleRewardBasedVideoFailedToLoad event received with message: "+ args.Message);
}
public void HandleRewardBasedVideoOpened(object sender, EventArgs args)
{
Debug.Log("HandleRewardBasedVideoOpened event received");
}
public void HandleRewardBasedVideoStarted(object sender, EventArgs args)
{
Debug.Log("HandleRewardBasedVideoStarted event received");
}
public void HandleRewardBasedVideoClosed(object sender, EventArgs args)
{
Debug.Log("HandleRewardBasedVideoClosed event received");
RequestRewardAd();
}
public void HandleRewardBasedVideoRewarded(object sender, Reward args)
{
string type = args.Type;
PlayerPrefs.SetFloat("Revive", (int)args.Amount);
}
public void HandleRewardBasedVideoLeftApplication(object sender, EventArgs args)
{
Debug.Log("HandleRewardBasedVideoLeftApplication event received");
}
Following is the use case:
Invoker class (with main method)
public class Invoker {
public static void main(String[] args) {
String class_file="Batch_Status";
}
}
Class to be invoked (with the same method name as that of class name, e.g. in this case it is Batch_Status)
import java.util.*;
public class Batch_Status {
public static void Batch_Status(String args) {
......
......Code Goes Here
......
}
}
Now the problem is that i am not able to define any object such as test in Invoker class by using the value of string class_file such as class_file test = new class_file();
Above is just a snippet, in my production code the values in the String variable will vary and for each value, a different class file (the name of the class file will be same as that of value of the String variable).
Please suggest.
Regards
This code demonstrates being able to retrieve a class instance given a string:
String classString = "com.rbs.testing.Test";
try {
Class c = Class.forName(classString);
Test test = (Test) c.newInstance();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
If you don't know what class to cast to yet, you can dump
c.newInstance();
into an Object class, then use if else clauses until you find out the class type contained in the object.
Object o = c.newInstance();
if (o instanceof Test) {
} else if(o instanceof Test2) {
I hope this helps. Sorry if I misunderstood your need.
Thanks Michael,
In fact, while doing some brainstorming, i also did the same thing and it worked as desired. Now i am able to call the method as well which is also derived from the same string variable. Following is the code which i tried:
import java.lang.reflect.*;
import java.util.logging.*;
public class Invoker {
public static void main(String[] args){
try {
String str ="Batch_Status";
Class t = Class.forName(str);
t.getMethods()[0].invoke(t,str);
} catch (ClassNotFoundException | IllegalAccessException | InvocationTargetException ex) {
Logger.getLogger(Invoker.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
And when checked your reply, it seems to be quite similar. Thanks, i really appreciate that.
Regards
I am trying to achieve an update form.
I use a library to open a form when there is an updated file and download using edtFTPNet
In the form I pass the FTP object and start download, in FormLoad i handle two events and i use Thread to StartDownload(). My two events never invoking, i use them to set a progress bar.
public partial class UpdateProgressForm : XtraForm
{
public FTPConnection FtpConn { get; set; }
public string UpdateFileName { get; set; }
public UpdateProgressForm()
{
InitializeComponent();
}
private void OnLoad(object sender, EventArgs e)
{
FtpConn.Downloading += FileDownLoading;
FtpConn.BytesTransferred += FileBytesTransfered;
}
private void FileDownLoading(object sender, FTPFileTransferEventArgs e)
{
progressBar.Properties.Maximum = (int) e.FileSize;
}
private void FileBytesTransfered(object sender, BytesTransferredEventArgs e)
{
progressBar.Position = (int) e.ByteCount;
}
public void StartDownload()
{
FtpConn.DownloadFile(#".\" + UpdateFileName, UpdateFileName);
}
private void OnShown(object sender, EventArgs e)
{
Thread tt = new Thread(StartDownload) {IsBackground = true};
tt.Start();
}
}
Library method calling the Form:
private void DownloadUpdateFile(string updateFileName)
{
using (ProgressForm = new UpdateProgressForm { FtpConn = FtpConn, UpdateFileName = updateFileName })
{
ProgressForm.ShowDialog();
}
}
Any help? Thank you.
Take a look in the designer and make sure you subscribe to those events
Make sure you Instanciate and Show the from from the Main Thread.
Are you sure that the event handlers are not invoked? I think your problem rather is that you try to update the progress bar on the worker thread on which the event handlers are invoke (which is not the thread on which the GUI was created). You should make sure that the GUI updates are performed on the correct thread:
private void FileDownLoading(object sender, FTPFileTransferEventArgs e)
{
progressBar.Invoke((MethodInvoker) delegate
{
progressBar.Properties.Maximum = (int) e.FileSize;
});
}
I'm working on a GWT project and have several void remote services that seem to execute just fine, but on the client side, end up firing the onFailure() method. No exceptions are thrown anywhere, and the expected behavior is observed on the backend. I have no idea what could be going wrong. Here is the relevant code:
Interfaces and implementation...
#RemoteServiceRelativePath("DeleteSearchService")
public interface DeleteSearchService extends RemoteService {
/**
* Utility class for simplifying access to the instance of async service.
*/
public static class Util {
private static DeleteSearchServiceAsync instance;
public static DeleteSearchServiceAsync getInstance(){
if (instance == null) {
instance = GWT.create(DeleteSearchService.class);
}
return instance;
}
}
public void delete(SearchBean search);
}
public interface DeleteSearchServiceAsync {
public void delete(SearchBean bean, AsyncCallback<Void> callback);
}
public class DeleteSearchServiceImpl extends RemoteServiceServlet implements DeleteSearchService {
private static final long serialVersionUID = 1L;
#Override
public void delete(SearchBean search) {
try {
Connection conn = SQLAccess.getConnection();
String sql = "DELETE FROM `searches` WHERE `id`=?";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setInt(1, search.getSearchId());
ps.execute();
sql = "DELETE FROM `searchsourcemap` WHERE `search-id` = ?";
ps = conn.prepareStatement(sql);
ps.setInt(1, search.getSearchId());
ps.execute();
return;
} catch (Exception e) {
// TODO Log error
e.printStackTrace();
}
}
}
Calling code...
private class DeleteListener implements ClickListener {
public void onClick(Widget sender) {
DeleteSearchServiceAsync dss = DeleteSearchService.Util.getInstance();
SearchBean bean = buildBeanFromGUI();
dss.delete(bean, new AsyncCallback<Void>(){
//#Override
public void onFailure(Throwable caught) {
// TODO log
SearchNotDeleted snd = new SearchNotDeleted();
snd.show();
}
//#Override
public void onSuccess(Void result) {
SearchDeleted sd = new SearchDeleted();
sd.show();
searchDef.getParent().removeFromParent();
}
});
}
}
I know I'm a jerk for posting like 500 lines of code but I've been staring at this since yesterday and can't figure out where I'm going wrong. Maybe a 2nd set of eyes would help...
Thanks,
brian
LGTM I'm afraid.
Are you using the hosted mode or a full-fledged browser? You can try switching and see if it helps.
Also, it might help listening to that //TODO and perform a GWT.log when onFailure is invoked.