I have created a file treelist in my WinForms application. The files and folders are displayed in a correct way. But when I try to drag a file from my pc (for ex. from my desktop) to the application the draggednode and the target node are null. Moving folders within my application works fine. How to change my application that I can drag files into the folders in the application?
Code:
class FileListHelper
{
string rootPath;
TreeList Tree;
private DevExpress.XtraTreeList.Columns.TreeListColumn treeListColumn1;
private DevExpress.XtraTreeList.Columns.TreeListColumn treeListColumn2;
private DevExpress.XtraTreeList.Columns.TreeListColumn treeListColumn3;
private DevExpress.XtraTreeList.Columns.TreeListColumn treeListColumn4;
private DevExpress.XtraTreeList.Columns.TreeListColumn treeListColumn5;
TreeListMenu folderMenu;
public FileListHelper(TreeList tree)
{
Tree = tree;
InitColumns();
Tree.BeforeExpand += new DevExpress.XtraTreeList.BeforeExpandEventHandler(this.treeList1_BeforeExpand);
Tree.AfterExpand += new DevExpress.XtraTreeList.NodeEventHandler(this.treeList1_AfterExpand);
Tree.AfterCollapse += new DevExpress.XtraTreeList.NodeEventHandler(this.treeList1_AfterCollapse);
Tree.CalcNodeDragImageIndex += new DevExpress.XtraTreeList.CalcNodeDragImageIndexEventHandler(this.treeList1_CalcNodeDragImageIndex);
Tree.DragDrop += new System.Windows.Forms.DragEventHandler(this.treeList1_DragDrop);
Tree.DoubleClick += new System.EventHandler(this.treeList1_DoubleClick);
Tree.PopupMenuShowing += new PopupMenuShowingEventHandler(Tree_PopupMenuShowing);
Tree.DragEnter += new DragEventHandler(this.treeList1_DragEnter); //added shows icons
tree.CellValueChanged += new CellValueChangedEventHandler(tree_CellValueChanged);
InitData();
folderMenu = new TreeListMenu(Tree);
folderMenu.Items.Add(new DXMenuItem("Create New Folder",MenuAddClick));
folderMenu.Items.Add(new DXMenuItem("Delete", MenuDeleteClick));
}
#region DragEnter
void treeList1_DragEnter(object sender,DragEventArgs e)
{
if (e.Data.GetDataPresent("FileGroupDescriptor"))
{
e.Effect = DragDropEffects.All;
}
else if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.Copy;
//ensure FileGroupDescriptor is present before allowing drop
}
else if (e.Data.GetDataPresent("RenPrivateMessages"))
{
e.Effect = DragDropEffects.All;
}
else
{
e.Effect = DragDropEffects.Move;
}
}
#endregion DragEnter
#region Rename
void tree_CellValueChanged(object sender, CellValueChangedEventArgs e)
{
if (e.Column.Caption =="Name")
{
if (e.Node["Type"] == "Folder")
{
DirectoryInfo di = e.Node["Info"] as DirectoryInfo;
di.MoveTo(di.Parent.FullName+"//"+e.Value);
}
else
{
FileInfo fi = e.Node["Info"] as FileInfo;
fi.MoveTo(fi.Directory.FullName + "//" + e.Value);
}
}
}
#endregion
#region Popup Menu
void Menu_Click(object sender, EventArgs e)
{
throw new Exception("The method or operation is not implemented.");
}
void Tree_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e)
{
TreeListNode node = Tree.CalcHitInfo(e.Point).Node;
if (node != null)
{
e.Menu = folderMenu;
e.Menu.Tag = node;
//e.Menu.Items.Add(new DXMenuItem("Create New Folder"));
}
}
void MenuAddClick(object sender, EventArgs e)
{
DirectoryInfo di;
int ParentId = -1;
TreeListNode curentNode = folderMenu.Tag as TreeListNode;
TreeListNode folderParentNode;
if (curentNode["Type"] == "Folder")
folderParentNode = curentNode;
else
folderParentNode = curentNode.ParentNode;
if (folderParentNode == null)
{
di = new DirectoryInfo(rootPath);
}
else
{
ParentId = folderParentNode.Id;
di=folderParentNode["Info"] as DirectoryInfo;
}
DirectoryInfo newDirectory = Directory.CreateDirectory(di.FullName + "\\New Folder");
if (newDirectory != null)
{
Tree.FocusedNode = Tree.AppendNode(new object[] { newDirectory.FullName, newDirectory.Name, "Folder", null, newDirectory }, ParentId);
}
Tree.FocusedColumn = Tree.Columns["Name"];
Tree.ShowEditor();
}
void MenuDeleteClick(object sender, EventArgs e)
{
TreeListNode curentNode = folderMenu.Tag as TreeListNode;
(curentNode["Info"] as FileSystemInfo).Delete();
Tree.DeleteNode(curentNode);
}
#endregion
#region Initializing TreeList
void InitColumns()
{
this.treeListColumn1 = new DevExpress.XtraTreeList.Columns.TreeListColumn();
this.treeListColumn2 = new DevExpress.XtraTreeList.Columns.TreeListColumn();
this.treeListColumn3 = new DevExpress.XtraTreeList.Columns.TreeListColumn();
this.treeListColumn4 = new DevExpress.XtraTreeList.Columns.TreeListColumn();
this.treeListColumn5 = new DevExpress.XtraTreeList.Columns.TreeListColumn();
this.treeListColumn1.Caption = "FullName";
this.treeListColumn1.FieldName = "FullName";
this.treeListColumn2.Caption = "Name";
this.treeListColumn2.FieldName = "Name";
this.treeListColumn2.VisibleIndex = 0;
this.treeListColumn2.Visible = true;
this.treeListColumn2.SortOrder = SortOrder.Ascending;
this.treeListColumn2.SortIndex = 1;
this.treeListColumn3.Caption = "Type";
this.treeListColumn3.FieldName = "Type";
this.treeListColumn3.VisibleIndex = 1;
this.treeListColumn3.Visible = true;
this.treeListColumn3.SortOrder = SortOrder.Descending;
this.treeListColumn3.SortIndex = 0;
this.treeListColumn3.OptionsColumn.AllowEdit = false;
this.treeListColumn4.AppearanceCell.Options.UseTextOptions = true;
this.treeListColumn4.AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Far;
this.treeListColumn4.Caption = "Size(Bytes)";
this.treeListColumn4.FieldName = "Size";
this.treeListColumn4.VisibleIndex = 2;
this.treeListColumn4.Visible = true;
this.treeListColumn4.OptionsColumn.AllowEdit = false;
this.treeListColumn5.Caption = "treeListColumn5";
this.treeListColumn5.FieldName = "Info";
this.treeListColumn5.Name = "treeListColumn5";
Tree.Columns.AddRange(new DevExpress.XtraTreeList.Columns.TreeListColumn[] {
this.treeListColumn1,
this.treeListColumn2,
this.treeListColumn3,
this.treeListColumn4,
this.treeListColumn5});
}
private void InitData()
{
//int currentIncidentId=2;
//rootPath = Directory.GetDirectoryRoot(Directory.GetCurrentDirectory());
rootPath = "C:\\Data\\98-ProgrammData\\Maintenance\\Dossier\\"/*+currentIncidentId*/;
InitFolders(rootPath, null);
}
private void InitFolders(string path, TreeListNode pNode)
{
Tree.BeginUnboundLoad();
TreeListNode node;
DirectoryInfo di;
try
{
string[] root = Directory.GetDirectories(path);
foreach (string s in root)
{
try
{
di = new DirectoryInfo(s);
node = Tree.AppendNode(new object[] { s, di.Name, "Folder", null, di }, pNode);
node.StateImageIndex = 0;
node.HasChildren = HasFiles(s);
if (node.HasChildren)
node.Tag = true;
}
catch { }
}
}
catch { }
InitFiles(path, pNode);
Tree.EndUnboundLoad();
}
private void InitFiles(string path, TreeListNode pNode)
{
TreeListNode node;
FileInfo fi;
try
{
string[] root = Directory.GetFiles(path);
foreach (string s in root)
{
fi = new FileInfo(s);
node = Tree.AppendNode(new object[] { s, fi.Name, "File", fi.Length, fi }, pNode);
node.StateImageIndex = 1;
node.HasChildren = false;
}
}
catch { }
}
private void treeList1_FilterNode(object sender, DevExpress.XtraTreeList.FilterNodeEventArgs e)
{
TreeList tree = sender as TreeList;
if (string.IsNullOrEmpty(tree.FindFilterText)) return;
e.Node.Visible = IsNodeVisible(e.Node);
e.Handled = true;
}
private bool IsNodeVisible(TreeListNode node)
{
if (node.ParentNode == null)
{
foreach (TreeListColumn column in node.TreeList.VisibleColumns)
{
object val = node[column.FieldName];
if (val != null && val.ToString().ToUpper().Equals(node.TreeList.FindFilterText.ToUpper()))
return true;
}
return false;
}
return IsNodeVisible(node.ParentNode);
}
private bool HasFiles(string path)
{
string[] root = Directory.GetFiles(path);
if (root.Length > 0) return true;
root = Directory.GetDirectories(path);
if (root.Length > 0) return true;
return false;
}
private void treeList1_BeforeExpand(object sender, DevExpress.XtraTreeList.BeforeExpandEventArgs e)
{
if (e.Node.Tag != null)
{
Cursor currentCursor = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
InitFolders(e.Node.GetDisplayText("FullName"), e.Node);
e.Node.Tag = null;
Cursor.Current = currentCursor;
}
}
private void treeList1_AfterExpand(object sender, DevExpress.XtraTreeList.NodeEventArgs e)
{
if (e.Node.StateImageIndex != 1) e.Node.StateImageIndex = 2;
}
private void treeList1_AfterCollapse(object sender, DevExpress.XtraTreeList.NodeEventArgs e)
{
if (e.Node.StateImageIndex != 1) e.Node.StateImageIndex = 0;
}
#endregion
#region Dragging
private void treeList1_CalcNodeDragImageIndex(object sender, DevExpress.XtraTreeList.CalcNodeDragImageIndexEventArgs e)
{
if (e.Node[treeListColumn3].ToString() == "Folder")
{
e.ImageIndex = 0;
}
if (e.Node[treeListColumn3].ToString() == "File")
{
if (e.Node.ParentNode == Tree.FocusedNode.ParentNode)
{
e.ImageIndex = -1;
return;
}
if (e.ImageIndex == 0)
if (e.Node.Id > Tree.FocusedNode.Id)
e.ImageIndex = 2;
else
e.ImageIndex = 1;
}
}
private void treeList1_DragDrop(object sender, DragEventArgs e)
{
TreeListNode draggedNode = e.Data.GetData(typeof(TreeListNode)) as TreeListNode;
TreeListNode tagretNode = Tree.ViewInfo.GetHitTest(Tree.PointToClient(new Point(e.X, e.Y))).Node;
if (tagretNode == null || draggedNode == null) return;
if (tagretNode[treeListColumn3].ToString() == "File")
{
if (tagretNode.ParentNode == draggedNode.ParentNode)
return;
MoveInFolder(draggedNode, tagretNode.ParentNode);
}
else
{
MoveInFolder(draggedNode, tagretNode);
}
e.Effect = DragDropEffects.None;
}
void MoveInFolder(TreeListNode sourceNode, TreeListNode destNode)
{
Tree.MoveNode(sourceNode, destNode);
if (sourceNode == null) return;
FileSystemInfo sourceInfo = sourceNode[treeListColumn5] as FileSystemInfo;
string sourcePath = sourceInfo.FullName;
string destPath;
if (destNode == null)
destPath = rootPath + sourceInfo.Name;
else
{
DirectoryInfo destInfo = destNode[treeListColumn5] as DirectoryInfo;
destPath = destInfo.FullName + "\\" + sourceInfo.Name;
}
if (sourceInfo is DirectoryInfo)
Directory.Move(sourcePath, destPath);
else
File.Move(sourcePath, destPath);
sourceNode[treeListColumn5] = new DirectoryInfo(destPath);
}
#endregion
#region Executing
private void treeList1_DoubleClick(object sender, EventArgs e)
{
if ((sender as TreeList).FocusedNode[treeListColumn3].ToString() == "File")
Process.Start(((sender as TreeList).FocusedNode[treeListColumn5] as FileSystemInfo).FullName, null);
}
#endregion
}
These two lines are null:
TreeListNode draggedNode = e.Data.GetData(typeof(TreeListNode)) as TreeListNode;
TreeListNode tagretNode = Tree.ViewInfo.GetHitTest(Tree.PointToClient(new Point(e.X, e.Y))).Node;
How to fix this?
Related
I had to shut down the app from task manager.
For example I'm searching the entire D:\ drive and there are over 400000 files.
The first time it's getting the files and the second time search in each file for a specific given string.
Starting a background worker:
private void startButton_Click(object sender, EventArgs e)
{
ListViewCostumControl.lvnf.Items.Clear();
numberoffiles = 0;
numberofrestrictedFiles = 0;
numberofdirs = 0;
label24.Text = "0";
label1.Text = "0";
label15.Text = "0";
Logger.Write("Operation started");
label21.Text = "Phase 1: Retrieving files";
label21.Visible = true;
startButton.Enabled = false;
stopButton.Enabled = true;
pauseresumeButton.Enabled = true;
label1.Select();
timer1.Start();
if (!backgroundWorker1.IsBusy)
{
SetWorkerMode(true);
backgroundWorker1.RunWorkerAsync();
}
}
Inside the DoWork:
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
_stopwatch.Restart();
string[] values = textBox1.Text.Split(new string[] { ",," }, StringSplitOptions.None);
DirSearch(textBox3.Text, textBox2.Text, values, worker, e);
_stopwatch.Stop();
}
The DirSearch method:
int numberofdirs = 0;
void DirSearch(string rootDirectory, string filesExtension, string[] textToSearch, BackgroundWorker worker, DoWorkEventArgs e)
{
List<string> resultsoftextfound = new List<string>();
List<string> resultsoftextfound1 = new List<string>();
List<string> filePathList = new List<string>();
int numberoffiles = 0;
try
{
filePathList = SearchAccessibleFilesNoDistinct(rootDirectory, null,worker,e).ToList();
}
catch (Exception err)
{
string ad = err.ToString();
}
label21.Invoke((MethodInvoker)delegate
{
label21.Text = "Phase 2: Searching in files";
});
MyProgress myp = new MyProgress();
myp.Report4 = filePathList.Count.ToString();
foreach (string file in filePathList)
{
try
{
var tempFR = File.ReadAllText(file);
_busy.WaitOne();
if (worker.CancellationPending == true)
{
e.Cancel = true;
return;
}
bool reportedFile = false;
for (int i = 0; i < textToSearch.Length; i++)
{
if (tempFR.IndexOf(textToSearch[i], StringComparison.InvariantCultureIgnoreCase) >= 0)
{
resultsoftextfound.Add(file + " " + textToSearch[i]);
if (!reportedFile)
{
numberoffiles++;
myp.Report1 = file;
myp.Report2 = numberoffiles.ToString();
myp.Report3 = textToSearch[i];
backgroundWorker1.ReportProgress(0, myp);
reportedFile = true;
}
}
}
numberofdirs++;
label1.Invoke((MethodInvoker)delegate
{
label1.Text = string.Format("{0}/{1}", numberofdirs, myp.Report4);
label1.Visible = true;
});
}
catch (Exception)
{
}
}
}
And the two recursive searching methods it's a bit long but all the methods are connected to each other:
int counter = 0;
IEnumerable<string> SearchAccessibleFilesNoDistinctOnlyExtension(string root, List<string> files)
{
if (files == null)
files = new List<string>();
if (Directory.Exists(root))
{
foreach (var file in Directory.EnumerateFiles(root))
{
string extension = Path.GetExtension(file);
if (!files.Contains(extension))
{
files.Add(extension);
counter++;
}
}
foreach (var subDir in Directory.EnumerateDirectories(root))
{
try
{
SearchAccessibleFilesNoDistinctOnlyExtension(subDir, files);
}
catch (UnauthorizedAccessException)
{
}
}
}
return files;
}
string restrictedFile = "";
List<string> restrictedFiles = new List<string>();
int numberofrestrictedFiles = 0;
int numberoffiles = 0;
IEnumerable<string> SearchAccessibleFilesNoDistinct(string root, List<string> files,BackgroundWorker worker, DoWorkEventArgs e)
{
_busy.WaitOne();
if (files == null)
files = new List<string>();
if (Directory.Exists(root))
{
foreach (var file in Directory.EnumerateFiles(root))
{
if (worker.CancellationPending == true)
{
e.Cancel = true;
return files;
}
restrictedFile = file;
string ext = Path.GetExtension(file);
if (!files.Contains(file) && (ext == "." + textBox2.Text || textBox2.Text == "*"))
//if (!files.Contains(file) && ext == textBox2.Text)
{
files.Add(file);
}
numberoffiles++;
label24.Invoke((MethodInvoker)delegate
{
label24.Text = numberoffiles.ToString();
label24.Visible = true;
});
}
foreach (var subDir in Directory.EnumerateDirectories(root))
{
if (worker.CancellationPending == true)
{
e.Cancel = true;
return files;
}
try
{
SearchAccessibleFilesNoDistinct(subDir, files,worker, e);
//files.Add(subDir);
}
catch (UnauthorizedAccessException)
{
restrictedFiles.Add(restrictedFile);
numberofrestrictedFiles++;
label11.Invoke((MethodInvoker)delegate
{
label11.Text = numberofrestrictedFiles.ToString();
label11.Visible = true;
});
continue;
}
}
}
return files;
}
It's working fine with small amount of files to search in.
But I want to be able to search also over a large size amount of files. For example 400000 files. The problem is that at some point it's taking all the ram usage 2GB memory usage even close to 3GB at some points.
I'm trying to get Tweet ID via TweetInvi API but always get null point exception. I'm out of options and can't understand what i did wrong. Here is my code. Problem occurs when i select desired Item from view and press retweet.
namespace MIF_TwitterApplication
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Auth.SetUserCredentials("KEY", "KEY", "KEY",
"KEY");
}
private void Form1_Load(object sender, EventArgs e)
{
var user = User.GetAuthenticatedUser();
//PROFILE
profileImage.ImageLocation = user.ProfileImageUrlFullSize;
nameLabel.Text = user.Name;
usernameLabel.Text = "#" + user.ScreenName;
followersLabel.Text = "Followers: " + user.FollowersCount;
}
//Tweeting with PICS
private void tweetBtn_Click(object sender, EventArgs e)
{
if (tweetBox.Text != "")
{
if (imgUploadPath.Text != "")
{
byte[] file = File.ReadAllBytes(imgPreview.ImageLocation);
Tweet.PublishTweetWithImage(tweetBox.Text, file);
imgPreview.ImageLocation = "";
imgUploadPath.Text = "";
tweetBox.Clear();
MessageBox.Show("Tweet posted!");
}
else
{
Tweet.PublishTweet(tweetBox.Text);
MessageBox.Show("Tweet posted!");
tweetBox.Clear();
}
}
else
{
MessageBox.Show("Please enter text!");
tweetBox.Clear();
}
}
private void addImg_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.ShowDialog();
imgPreview.ImageLocation = ofd.FileName;
imgUploadPath.Text = ofd.FileName;
}
private void dropImg_Click(object sender, EventArgs e)
{
imgPreview.ImageLocation = "";
imgUploadPath.Text = "";
}
private void timelineBtn_Click(object sender, EventArgs e)
{
var user = User.GetAuthenticatedUser();
var getTweets = Timeline.GetHomeTimeline(40);
listView1.Clear();
listView1.View = View.Details;
listView1.GridLines = true;
listView1.FullRowSelect = true;
listView1.Columns.Add("Tweet", 570);
listView1.Columns.Add("Created By", 130);
listView1.Columns.Add("Create Time", 130);
listView1.Columns.Add("Likes", 60);
listView1.Columns.Add("Retweets", 70);
int x = 0;
foreach (var t in getTweets)
{
ListViewItem listItem = new ListViewItem(t.Text);
listItem.SubItems.Add(t.CreatedBy.ScreenName.ToString());
listItem.SubItems.Add(t.CreatedAt.ToString());
listItem.SubItems.Add(t.FavoriteCount.ToString());
listItem.SubItems.Add(t.RetweetCount.ToString());
listView1.Items.Add(listItem);
listView1.Items[x].Tag = t.Id;
}
}
private void postsBtn_Click(object sender, EventArgs e)
{
var user = User.GetAuthenticatedUser();
var getTweets = Timeline.GetUserTimeline(user, 40);
listView1.Clear();
listView1.View = View.Details;
listView1.GridLines = true;
listView1.FullRowSelect = true;
listView1.Columns.Add("Tweet", 570);
listView1.Columns.Add("Created By", 130);
listView1.Columns.Add("Create Time", 130);
listView1.Columns.Add("Likes", 60);
listView1.Columns.Add("Retweets", 70);
int x = 0;
foreach (var t in getTweets)
{
ListViewItem listItem = new ListViewItem(t.Text);
listItem.SubItems.Add(t.CreatedBy.ScreenName.ToString());
listItem.SubItems.Add(t.CreatedAt.ToString());
listItem.SubItems.Add(t.FavoriteCount.ToString());
listItem.SubItems.Add(t.RetweetCount.ToString());
listView1.Items.Add(listItem);
listView1.Items[x].Tag = t.Id;
}
}
private void retweetBtn_Click(object sender, EventArgs e)
{
var checkedItems = listView1.SelectedItems;
long a = (long)listView1.SelectedItems[0].Tag;
var user = User.GetAuthenticatedUser();
var retweet = Tweet.PublishRetweet(a);
MessageBox.Show("Retweet was successfull");
listView1.Items.Clear();
}
}
}
Breakes on long a, I can't figure out how to get that Long Tweet ID
Here is the full code
Problem was that my X was not incrementing correctly as it was out of for loop.
int x = 0;
foreach (var t in getTweets)
{
ListViewItem listItem = new ListViewItem(t.Text);
listItem.SubItems.Add(t.CreatedBy.ScreenName.ToString());
listItem.SubItems.Add(t.CreatedAt.ToString());
listItem.SubItems.Add(t.FavoriteCount.ToString());
listItem.SubItems.Add(t.RetweetCount.ToString());
listView1.Items.Add(listItem);
listView1.Items[x].Tag = t.Id;
x = x +1;
}
I have userControl(wpf)
public WebBrowserControl()
{
InitializeComponent();
_Browser = new WebBrowser();
_pipeClient = new NamedPipeClient<WebMessage>("TestPipe");
_pipeClient.ServerMessage += PipeClientOnServerMessage;
_pipeClient.Error += PipeClientOnError;
_pipeClient.Start();
InternetExplorerBrowserEmulation.SetBrowserEmulationMode();
SuppressScriptErrors(_Browser, false);
SetWebBrowserFeatures();
GridBrrw.Children.Add(_Browser);
_Browser.ObjectForScripting = new ObjectForScripting(_pipeClient);
_Browser.LoadCompleted += new LoadCompletedEventHandler(_Browser_OnLoadCompleted);
_Browser.Navigating += _Browser_OnNavigating;
var th = new Thread(ExecuteInForeground);
th.Start();
}
private void ExecuteInForeground()
{
int i = 0;
while (i<=9)
{
Thread.Sleep(1000);
_pipeClient.PushMessage(new WebMessage() {Actions = "allo"});
i++;
}
}
private void _Browser_OnNavigating(object sender, NavigatingCancelEventArgs e)
{
if (IsClick)
{
var mes = new WebMessage { Actions = "OpenUrl" };
mes.Url = e.Uri.AbsoluteUri;
_pipeClient.PushMessage(mes);
e.Cancel = false;
}
return;
e.Cancel = false;
}
private void _Browser_OnLoadCompleted(object sender, NavigationEventArgs e)
{
try
{
var br = sender as WebBrowser;
if (br?.Source != null && br.Source.AbsoluteUri != e.Uri.AbsoluteUri)
{
MessageBox.Show($"Source = {br.Source.AbsoluteUri},\r\n AbsoluteUri = {e.Uri.AbsoluteUri}");
return;
}
Document = (HTMLDocument)br.Document;
if (!string.IsNullOrEmpty(FindElement))
{
var node = HtmlNode.CreateNode(FindElement);
while (GetElement(node) == null)
{
System.Windows.Forms.Application.DoEvents();
}
}
if (WaitAjax)
{
ConnectToAjax();
return;
}
if (Sleep > 0)
{
var time = TimeSpan.FromSeconds(Sleep);
Thread.Sleep(time);
}
var mes = new WebMessage { Actions = "Load" };
mes.Title = Document.title;
mes.Url = br.Source.AbsoluteUri;
mes.Domain = br.Source.Host.Replace("http", "").Replace("http://", "").Replace("https://", "").Replace("https", "");
mes.Fovicon = $"http://www.google.com/s2/favicons?domain={mes.Domain}";
if (Document != null)
{
var htmls = Document.getElementsByTagName("html");
if (htmls != null && htmls.length > 0)
{
var html = htmls.item(0) as IHTMLElement;
mes.Html = html.outerHTML;
}
}
_pipeClient.PushMessage(mes);
}
catch (Exception ex)
{
throw ex;
}
}
Event Navigating firing, ExecuteInForeground sends messages, but LoadCompleted event is not firing. Could this be due to the settings window - Property = "ResizeMode" Value = "NoResize". What am I doing wrong?
I want to display data Master/Details stype with DataGrid not GridView or anything else. At the present I must put a dropdownlist to do this manually. So how can do it automatically whenever we click one master item in the Master DataGrid then it link to Details DataGird , like this:
private void BindGridMaster()
{
grdReceivedNote.DataSource = ReceivedNoteService.ReceivedNote_GetByAll();
grdReceivedNote.DataBind();
if (grdReceivedNote.PageCount <= 1)
{
grdReceivedNote.PagerStyle.Visible = false;
}
else
{
grdReceivedNote.PagerStyle.Visible = true;
}
}
private void BindGridDetails()
{
grdReceivedNoteDetails.DataSource = RevNoteDetailsService.RevNoteDetails_GetByAll();
grdReceivedNoteDetails.DataBind();
if (grdReceivedNoteDetails.PageCount <= 1)
{
grdReceivedNoteDetails.PagerStyle.Visible = false;
}
else
{
grdReceivedNoteDetails.PagerStyle.Visible = true;
}
}
protected void grdReceivedNote_ItemDataBound(object sender, DataGridItemEventArgs e)
{
ListItemType itemType = e.Item.ItemType;
if ((itemType != ListItemType.Footer) && (itemType != ListItemType.Separator))
{
if (itemType == ListItemType.Header)
{
object checkBox = e.Item.FindControl("chkSelectAll");
if ((checkBox != null))
{
((CheckBox)checkBox).Attributes.Add("onClick", "Javascript:chkSelectAll_OnClick(this)");
}
}
else
{
string tableRowId = grdReceivedNote.ClientID + "_row" + e.Item.ItemIndex.ToString();
e.Item.Attributes.Add("id", tableRowId);
object checkBox = e.Item.FindControl("chkSelect");
if ((checkBox != null))
{
e.Item.Attributes.Add("onMouseMove", "Javascript:chkSelect_OnMouseMove(this)");
e.Item.Attributes.Add("onMouseOut", "Javascript:chkSelect_OnMouseOut(this," + e.Item.ItemIndex.ToString() + ")");
((CheckBox)checkBox).Attributes.Add("onClick", "Javascript:chkSelect_OnClick(this," + e.Item.ItemIndex.ToString() + ")");
}
}
}
}
protected void grdReceivedNoteDetails_ItemDataBound(object sender, DataGridItemEventArgs e)
{
ListItemType itemType = e.Item.ItemType;
if ((itemType != ListItemType.Footer) && (itemType != ListItemType.Separator))
{
if (itemType == ListItemType.Header)
{
object checkBox = e.Item.FindControl("chkSelectAll");
if ((checkBox != null))
{
((CheckBox)checkBox).Attributes.Add("onClick", "Javascript:chkSelectAll_OnClick(this)");
}
}
else
{
string tableRowId = grdReceivedNote.ClientID + "_row" + e.Item.ItemIndex.ToString();
e.Item.Attributes.Add("id", tableRowId);
object checkBox = e.Item.FindControl("chkSelect");
if ((checkBox != null))
{
e.Item.Attributes.Add("onMouseMove", "Javascript:chkSelect_OnMouseMove(this)");
e.Item.Attributes.Add("onMouseOut", "Javascript:chkSelect_OnMouseOut(this," + e.Item.ItemIndex.ToString() + ")");
((CheckBox)checkBox).Attributes.Add("onClick", "Javascript:chkSelect_OnClick(this," + e.Item.ItemIndex.ToString() + ")");
}
}
}
}
protected void grdReceivedNote_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
{
grdReceivedNote.CurrentPageIndex = e.NewPageIndex;
BindGridMaster();
}
protected void grdReceivedNoteDetails_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
{
grdReceivedNoteDetails.CurrentPageIndex = e.NewPageIndex;
BindGridMaster();
}
protected void grdReceivedNote_ItemCommand(object source, DataGridCommandEventArgs e)
{
string strCA = e.CommandArgument.ToString();
switch (e.CommandName)
{
case "Edit":
Insert = false;
Id = strCA;
ViewCustomers();
ViewRevType();
//ViewRevNote();
//ViewItems();
List<Data.ReceivedNote> listE = ReceivedNoteService.ReceivedNote_GetById(Id);
txtRevNote_No.Text = listE[0].RevNote_No;
txtRevDate.Text = listE[0].RevDate;
txtNotes.Text = listE[0].Notes;
drlCustIdAdd.SelectedValue = listE[0].CustID;
drlRevTypeIdAdd.SelectedValue = listE[0].RevTypeID;
pnViewMaster.Visible = false;
pnUpdateMaster.Visible = true;
break;
case "Delete":
ReceivedNoteService.ReceivedNote_Delete(strCA);
BindGridMaster();
break;
}
}
protected void grdReceivedNoteDetails_ItemCommand(object source, DataGridCommandEventArgs e)
{
string strCA = e.CommandArgument.ToString();
switch (e.CommandName)
{
case "Edit":
Insert = false;
Id = strCA;
//ViewCustomers();
//ViewRevType();
ViewRevNote();
ViewItems();
List<Data.RevNoteDetails> listE = RevNoteDetailsService.RevNoteDetails_GetById(Id);
txtQuantity.Text = listE[0].Quantity;
drlRevNoteIdAdd.SelectedValue = listE[0].RevNoteID;
drlItemIdAdd.SelectedValue = listE[0].ItemID;
pnlViewDetails.Visible = false;
pnlUpdateDetails.Visible = true;
break;
case "Delete":
RevNoteDetailsService.RevNoteDetails_Delete(strCA);
BindGridDetails();
break;
}
}
Need your help guys.
I have a web application which hangs after clicking a checkbox which is set to autopostback. This checkbox is supposed to do some process.
It didn't fire the OnPreLoad and the OnLoad events.
Below are the codes
protected override void BindReference()
{
BindComboBox(ref rcbPortfolioId, CNPL_Portfolio.GetPortfolioDicWithAll());
BindComboBox(ref rcbProductId, CNPL_Product.GetProductDicWithAll());
BindComboBox(ref rcbNewAgencyId, CNPL_Agency.GetAgencyDicWithAll());
BindComboBox(ref rcbPreviousAgencyId, CNPL_Agency.GetAgencyDicWithAll());
BindComboBox(ref rcbAccountStatusId, CNPL_AccountStatus.GetStatusDic());
BindComboBox(ref rcbAgencyHeader, CNPL_Agency.GetAgencyDic());
}
protected override void SetViewStates()
{
ViewState["ETemp"] = eTemp;
ViewState["AgencyIDRgTemp"] = _AgencyIDRgTemp;
ViewState["PreviousIDRgTemp"] = _PreviousIDRgTemp;
ViewState["ProductIDRgTemp"] = _ProductIDRgTemp;
ViewState["IsRetainedRgTemp"] = _IsRetainedRgTemp;
}
protected override void GetViewStates()
{
if (ViewState["ETemp"] != null)
{
eTemp = (List<CNPL_EndorsementTemp>)ViewState["ETemp"];
}
if (ViewState["AgencyIDRgTemp"] != null)
{
_AgencyIDRgTemp = (int)ViewState["AgencyIDRgTemp"];
}
if (ViewState["PreviousIDRgTemp"] != null)
{
_PreviousIDRgTemp = (int)ViewState["PreviousIDRgTemp"];
}
if (ViewState["ProductIDRgTemp"] != null)
{
_ProductIDRgTemp = (int)ViewState["ProductIDRgTemp"];
}
if (ViewState["IsRetainedRgTemp"] != null)
{
_IsRetainedRgTemp = (bool)ViewState["IsRetainedRgTemp"];
}
}
protected void chkEndorseAuto_OnCheckChange(object sender, EventArgs e)
{
DirectDBAccess db = new DirectDBAccess();
SqlCommand cmd = new SqlCommand("dbo.Proc_UpdateIsIncludedEndorsementTemp");
Int32 _AgencyID=0;
Int32 _PreviousAgencyID=0;
Int32 _IsRetained=0;
Int32 _ProductID=0;
Int32 _IsIncluded=0;
Int32 _NewIsIncluded = 0;
CheckBox cBox = (sender as CheckBox);
GridDataItem item = (cBox.Parent.Parent as GridDataItem);
if (!Int32.TryParse(item["AgencyID"].Text, out _AgencyID))
throw new Exception("Endorsement: Error in parsing");
if (!Int32.TryParse(item["PreviousAgencyID"].Text, out _PreviousAgencyID))
throw new Exception("Endorsement: Error in parsing");
if (!Int32.TryParse(item["ProductID"].Text, out _ProductID))
throw new Exception("Endorsement: Error in parsing");
if (item["IsRetained"].Text.ToLower() == "true")
_IsRetained = 1;
else if (item["IsRetained"].Text.ToLower() == "false")
_IsRetained = 0;
else
throw new Exception("Endorsement: Error in parsing");
if (cBox.Checked)
{
_NewIsIncluded = 1;
_IsIncluded = 0;
}
else
{
_NewIsIncluded = 0;
_IsIncluded = 1;
}
cmd.CommandTimeout = 9500;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("#AgencyID",_AgencyID));
cmd.Parameters.Add(new SqlParameter("#PreviousAgencyID", _PreviousAgencyID));
cmd.Parameters.Add(new SqlParameter("#IsRetained", _IsRetained));
cmd.Parameters.Add(new SqlParameter("#ProductID", _ProductID));
cmd.Parameters.Add(new SqlParameter("#IsIncluded", _IsIncluded));
cmd.Parameters.Add(new SqlParameter("#NewIsIncluded", _NewIsIncluded));
db.Open();
db.CommandExecuteNonQuery(cmd,CommandType.StoredProcedure);
db.Close();
}
void rcbPortfolioId_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
{
Int32 _PortfolioID;
_PortfolioID = Int32.Parse(rcbPortfolioId.SelectedValue);
if(_PortfolioID >0)
BindComboBox(ref rcbProductId, CNPL_Product.GetProductDicWithAll(_PortfolioID));
else
BindComboBox(ref rcbProductId, CNPL_Product.GetProductDicWithAll());
}
private void InitializeEndorsementDate()
{
int curingDays;
if (!Int32.TryParse(CNPL_DataSettings.GetSettingValue("CuringPeriod").ToString(), out curingDays))
curingDays = 120;
rdpEndorsementDateFrom.SelectedDate = DateTime.Now;
rdpEndorsementDateTo.SelectedDate = DateTime.Now.AddDays(curingDays - 1);
}
private void InitializeGrids()
{
rgEndorsements.DataSource = new List<CNPL_EndorsementTemp>();
rgEndorsements.DataBind();
//Added by Ryan Estandarte 11/2/2010
rgEndorsements.AllowPaging = true;
rgEndorsements.PageSize = 10;
rgEndorsementTemp.DataSource = new List<CNPL_EndorsementTemp>();
rgEndorsementTemp.DataBind();
}
public Dictionary<int, string> PopulateRgAgencyId()
{
return CNPL_Agency.GetAgencyDic();
}
void btnSearch_Click(object sender, EventArgs e)
{
AssignAccountToEndorsementTemp();
RadAjaxManager1.Alert("finished automatic distribution");
}
private void BindRgEndorsements()
{
rgEndorsements.DataSource = CNPL_EndorsementTemp.GetGroupedEndorsementTemp();
rgEndorsements.DataBind();
}
private void ClearTotals()
{
rntbTotalAccounts.Text = "";
rntbTotalPrincipal.Text = "";
rntbTotalPenalty.Text = "";
rntbTotalInterest.Text = "";
rntbTotalOutstandingBalance.Text = "";
}
private void ShuffleAgencies(ref List<CNPL_Agency> agencyToShuffle)
{
int N = agencyToShuffle.Count;
Random random = new System.Random();
for (int index = 0; index < N; ++index)
{
int randomIndex = index + (int)(random.Next(N - index));
CNPL_Agency _agencyTemp = agencyToShuffle[randomIndex];
agencyToShuffle[randomIndex] = agencyToShuffle[index];
agencyToShuffle[index] = _agencyTemp;
}
}
private void AssignAccountToEndorsementTemp()
{
DirectDBAccess db = new DirectDBAccess();
SqlCommand cmd = new SqlCommand();
string sql;
InitializeGrids();
sql = "dbo.Proc_AssignAccountsForEndorsement";
cmd.CommandText = sql;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandTimeout = 59500;
cmd.Parameters.Add(new SqlParameter("#PortfolioID_Criteria",Int32.Parse(rcbPortfolioId.SelectedValue)));
cmd.Parameters.Add(new SqlParameter("#ProductID_Criteria",Int32.Parse(rcbProductId.SelectedValue)));
cmd.Parameters.Add(new SqlParameter("#NewAgencyID_Criteria",Int32.Parse(rcbNewAgencyId.SelectedValue)));
cmd.Parameters.Add(new SqlParameter("#PreviousAgencyID_Criteria",Int32.Parse(rcbPreviousAgencyId.SelectedValue)));
db.Open();
db.CommandExecuteNonQuery(cmd,CommandType.StoredProcedure);
db.Close();
BindRgEndorsements();
}
void rgEndorsements_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == "btnDetails")
{
int pageSize = 10;
if (chkPagingManual.Checked == true)
{
rgEndorsementTemp.AllowPaging = true;
Int32.TryParse(rntbPageSizeManual.Text, out pageSize);
rgEndorsementTemp.PageSize = pageSize;
}
else
rgEndorsementTemp.AllowPaging = false;
_AgencyIDRgTemp = Int32.Parse((e.Item as GridDataItem)["AgencyId"].Text);
_PreviousIDRgTemp = Int32.Parse((e.Item as GridDataItem)["PreviousAgencyId"].Text);
_ProductIDRgTemp = Int32.Parse((e.Item as GridDataItem)["ProductID"].Text);
_IsRetainedRgTemp = Boolean.Parse((e.Item as GridDataItem)["IsRetained"].Text);
BindRgEndorsementTemp();
}
else if (e.CommandName == "btnChange")
{
IList<CNPL_EndorsementTemp> endorsementTemps = new List<CNPL_EndorsementTemp>();
RadComboBox rcbAgencyId = (RadComboBox)(e.Item as GridDataItem).FindControl("rcbAgency");
int _AgencyID = Int32.Parse(rcbAgencyId.SelectedValue);
UpdateEndorsement(e.Item as GridDataItem);
Helper.SaveList(endorsementTemps,this.Web.CurrentUser.LoginName);
//rebind rgEndosements
BindRgEndorsements();
//rebind RgEndorsementTemp w/ respect to agencyid being edited
_AgencyIDRgTemp = Int32.Parse((e.Item as GridDataItem)["AgencyId"].Text);
_PreviousIDRgTemp = Int32.Parse((e.Item as GridDataItem)["PreviousAgencyId"].Text);
BindRgEndorsementTemp();
RadAjaxManager1.Alert("Updated");
}
}
protected void chkEndorseAutoHeader_OnCheckChange(object sender, EventArgs e)
{
CheckBox chk = new CheckBox();
CheckBox chkHeader = sender as CheckBox;
foreach (GridDataItem item in rgEndorsements.Items)
{
chk = (CheckBox)item.FindControl("chkEndorseAuto");
chk.Checked = chkHeader.Checked;
}
IncludeAll(chkHeader.Checked);
}
private void IncludeAll(Boolean chk)
{
DirectDBAccess db = new DirectDBAccess();
string sql;
if(chk == true)
sql = "update CNPL_EndorsementTemp set IsIncluded='True'";
else
sql = "update CNPL_EndorsementTemp set IsIncluded='False'";
SqlCommand cmd = new SqlCommand(sql);
db.Open();
db.CommandExecuteNonQuery(cmd, CommandType.Text);
db.Close();
}
private IList<CNPL_EndorsementTemp> UpdateEndorsement(GridDataItem tempGridDataItem)
{
//update endorsementtemp to database
IList<CNPL_EndorsementTemp> endorsementTemps = new List<CNPL_EndorsementTemp>();
RadComboBox rcbAgencyId = (RadComboBox)tempGridDataItem.FindControl("rcbAgency");
Int32 _AgencyID = Int32.Parse(tempGridDataItem["AgencyID"].Text);
Int32 _PreviousAgencyID = Int32.Parse(tempGridDataItem["PreviousAgencyID"].Text);
string _IsRetained = tempGridDataItem["IsRetained"].Text;
Int32 _ProductID = Int32.Parse(tempGridDataItem["ProductID"].Text);
string filter = string.Format("Where AgencyID={0} And PreviousAgencyID={1} And IsRetained='{2}' And ProductID={3}", _AgencyID, _PreviousAgencyID, _IsRetained, _ProductID);
endorsementTemps = CNPL_EndorsementTemp.GetAllWithFilter(filter);
foreach (CNPL_EndorsementTemp endorsementTemp in endorsementTemps)
{
endorsementTemp.AgencyID = Int32.Parse(rcbAgencyId.SelectedValue);
}
return endorsementTemps;
}
private IList<CNPL_EndorsementTemp> UpdateEndorsementAllChecked(GridDataItem tempGridDataItem)
{
//update endorsementtemp to database
IList<CNPL_EndorsementTemp> endorsementTemps = new List<CNPL_EndorsementTemp>();
Int32 _AgencyID = Int32.Parse(tempGridDataItem["AgencyID"].Text);
Int32 _PreviousAgencyID = Int32.Parse(tempGridDataItem["PreviousAgencyID"].Text);
string filter = string.Format("Where AgencyID={0} And PreviousAgencyID={1}", _AgencyID, _PreviousAgencyID);
endorsementTemps = CNPL_EndorsementTemp.GetAllWithFilter(filter);
foreach (CNPL_EndorsementTemp endorsementTemp in endorsementTemps)
{
endorsementTemp.AgencyID = Int32.Parse(rcbAgencyUpdateAuto.SelectedValue);
}
return endorsementTemps;
}
void btnUpdateAutoAll_Click(object sender, EventArgs e)
{
List<CNPL_EndorsementTemp> endorsementTemps = new List<CNPL_EndorsementTemp>();
//IList<CNPL_EndorsementTemp> temps = new List<CNPL_EndorsementTemp>();
foreach (GridDataItem item in rgEndorsements.Items)
{
CheckBox chk = new CheckBox();
chk = (CheckBox)item.FindControl("chkEndorseAuto");
if (chk.Checked == true)
{
endorsementTemps.AddRange(UpdateEndorsementAllChecked(item));
}
}
if (endorsementTemps.Count > 0)
Helper.SaveList(endorsementTemps, this.Web.CurrentUser.LoginName);
BindRgEndorsements();
_AgencyIDRgTemp = 0;
_PreviousIDRgTemp = 0;
BindRgEndorsementTemp();
RadAjaxManager1.Alert("Updated");
}
void btnEndorse_Click(object sender, EventArgs e)
{
EndorseToAgencies();
RadAjaxManager1.Alert("finished endorsement");
}
private void EndorseToAgencies()
{
DirectDBAccess db = new DirectDBAccess();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "dbo.Proc_EndorseToAgencies";
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandTimeout = 59500;
cmd.Parameters.Add(new SqlParameter("#User", Web.CurrentUser.LoginName));
cmd.Parameters.Add(new SqlParameter("#EndorsementDateFrom", rdpEndorsementDateFrom.SelectedDate));
cmd.Parameters.Add(new SqlParameter("#EndorsementDateTo", rdpEndorsementDateTo.SelectedDate));
db.Open();
db.CommandExecuteNonQuery(cmd, CommandType.StoredProcedure);
db.Close();
BindRgEndorsements();
_AgencyIDRgTemp = 0;
_PreviousIDRgTemp = 0;
BindRgEndorsementTemp();
}
private IList<CNPL_EndorsementDetail> ConvertEndorsementTempToDetails()
{
IList<CNPL_EndorsementTemp> temps = new List<CNPL_EndorsementTemp>();
IList<CNPL_EndorsementDetail> details = new List<CNPL_EndorsementDetail>();
temps = CNPL_EndorsementTemp.GetAll();
details.Clear();
foreach (CNPL_EndorsementTemp temp in temps)
{
CNPL_EndorsementDetail detail = new CNPL_EndorsementDetail();
CNPL_Account _account = new CNPL_Account();
_account = CNPL_Account.GetByID(temp.AccountID);
detail.Account = _account;
detail.Account.IsCurrentlyEndorsed = true;
if (detail.Account.NewAgencyID != 0)
{
detail.Account.PreviousAgencyID = detail.Account.NewAgencyID;
}
detail.Account.EndorsementDateTo = rdpEndorsementDateTo.SelectedDate;
detail.Account.EndorsementDateFrom = rdpEndorsementDateFrom.SelectedDate;
detail.Account.NewAgencyID = temp.AgencyID;
detail.AccountID = temp.AccountID;
detail.AgencyID = temp.AgencyID;
detail.CreatedBy = this.Web.CurrentUser.LoginName;
detail.CreatedDate = DateTime.Now;
details.Add(detail);
}
return details;
}
void rgEndorsementTemp_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == "btnChange")
{
RadComboBox rcbAgencyId = (RadComboBox)(e.Item as GridDataItem).FindControl("rcbAgency");
int _AgencyID = Int32.Parse(rcbAgencyId.SelectedValue);
UpdateEndorsementTemp(e.Item as GridDataItem);
BindRgEndorsements();
_AgencyIDRgTemp = Int32.Parse((e.Item as GridDataItem)["OldAgencyID"].Text);
BindRgEndorsementTemp();
RadAjaxManager1.Alert("Updated");
}
}
private void BindRgEndorsementTemp()
{
rgEndorsementTemp.DataSource = CNPL_EndorsementTemp.GetDetailsEndorsementTemp(_AgencyIDRgTemp,_PreviousIDRgTemp,_ProductIDRgTemp,_IsRetainedRgTemp);
rgEndorsementTemp.DataBind();
}
private void UpdateEndorsementTemp(GridDataItem tempGridDataItem)
{
CNPL_EndorsementTemp _EndorsementTemp = new CNPL_EndorsementTemp();
Int32 _ID = Int32.Parse(tempGridDataItem["EndorsementTempID"].Text);
_EndorsementTemp = CNPL_EndorsementTemp.GetByID(_ID);
RadComboBox rcbAgencyId = (RadComboBox)tempGridDataItem.FindControl("rcbAgency");
_EndorsementTemp.AgencyID = Int32.Parse(rcbAgencyId.SelectedValue);
_EndorsementTemp.AccountID = Int32.Parse(tempGridDataItem["AccountID"].Text);
_EndorsementTemp.Save();
}
protected void chkEndorseManualHeader_OnCheckChange(object sender, EventArgs e)
{
CheckBox chk = new CheckBox();
CheckBox chkHeader = sender as CheckBox;
foreach (GridDataItem item in rgEndorsementTemp.Items)
{
chk = (CheckBox)item.FindControl("chkEndorseManual");
chk.Checked = chkHeader.Checked;
}
}
void rgEndorsementTemp_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
rgEndorsementTemp.DataSource = CNPL_EndorsementTemp.GetDetailsEndorsementTemp(_AgencyIDRgTemp, _PreviousIDRgTemp, _ProductIDRgTemp, _IsRetainedRgTemp);
}
void btnUpdateManualAll_Click(object sender, EventArgs e)
{
IList<CNPL_EndorsementTemp> temps = new List<CNPL_EndorsementTemp>();
foreach (GridDataItem item in rgEndorsementTemp.Items)
{
CheckBox chk = new CheckBox();
chk = (CheckBox)item.FindControl("chkEndorseManual");
if(chk.Checked == true)
{
CNPL_EndorsementTemp _EndorsementTemp = new CNPL_EndorsementTemp();
Int32 _ID = Int32.Parse(item["EndorsementTempID"].Text);
_EndorsementTemp = CNPL_EndorsementTemp.GetByID(_ID);
_EndorsementTemp.AgencyID = Int32.Parse(rcbAgencyHeader.SelectedValue);
_EndorsementTemp.AccountID = Int32.Parse(item["AccountID"].Text);
temps.Add(_EndorsementTemp);
}
}
if (temps.Count > 0)
Helper.SaveList(temps, this.Web.CurrentUser.LoginName);
BindRgEndorsements();
BindRgEndorsementTemp();
RadAjaxManager1.Alert("Updated");
}
private void GetAccountPerCollectorRatio()
{
accountCollectorRatios = CNPL_AccountCollectorRatio.GetAll();
}
void btnSearchManualAdd_Click(object sender, EventArgs e)
{
if (rbAccountNoMA.Checked == true)
{
if (txtAccountNoMA.Text.Length > 0)
accounts = CNPL_Account.GetAccountLikeAccountNo(txtAccountNoMA.Text);
else
RadAjaxManager1.Alert("Requires search parameter");
}
else if (rbAccountNameMA.Checked == true)
{
if(txtAccountNameMA.Text.Length > 0)
accounts = CNPL_Account.GetAccountLikeAccountName(txtAccountNameMA.Text);
else
RadAjaxManager1.Alert("Requires search parameter");
}
BindRgManualAdd();
}
private void BindRgManualAdd()
{
rgManualAdd.DataSource = accounts;
rgManualAdd.DataBind();
}
void rgManualAdd_ItemCommand(object source, GridCommandEventArgs e)
{
CNPL_Account _Account = CNPL_Account.GetByID(Int32.Parse((e.Item as GridDataItem)["AccountID"].Text));
if (e.CommandName == "btnAdd")
{
CNPL_EndorsementTemp _EndorsementTemp = new CNPL_EndorsementTemp();
List<CNPL_EndorsementTemp> _EndorsementTemps = (List<CNPL_EndorsementTemp>)CNPL_EndorsementTemp.GetAll();
_EndorsementTemp.AccountID = _Account.Id;
_EndorsementTemp.ProductID = _Account.ProductID;
_EndorsementTemp.CurrentBalance = _Account.CurrentBalance;
_EndorsementTemp.AgencyID = _Account.NewAgencyID; Int32.Parse((e.Item as GridDataItem)["NewAgencyID"].Text);
_EndorsementTemp.PreviousAgencyID = _Account.NewAgencyID; Int32.Parse((e.Item as GridDataItem)["PreviousAgencyID"].Text);
_EndorsementTemp.IsRetained = _Account.IsCurrentlyEndorsed==true?true:false;
_EndorsementTemp.IsIncluded = true;
if (_EndorsementTemps.Exists(delegate(CNPL_EndorsementTemp temp) { return temp.AccountID == _EndorsementTemp.AccountID; }))
{
RadAjaxManager1.Alert(_Account.AccountName + " already exists");
}
else
{
_EndorsementTemp.Save(Web.CurrentUser.LoginName);
BindRgEndorsements();
}
}
}
void chkUseManualAdd_CheckedChanged(object sender, EventArgs e)
{
if (!CNPL_EndorsementTemp.DeleteEndorsementTemp())
throw new Exception("endorsement: cannot clear temporary table");
if (chkUseManualAdd.Checked == true)
{
pnlManualAdd.Visible = true;
btnSearch.Enabled = false;
BindRgEndorsements();
BindRgManualAdd();
}
else
{
pnlManualAdd.Visible = false;
btnSearch.Enabled = true;
}
}
protected override void OnInit(EventArgs e)
{
try
{
rcbPortfolioId.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(rcbPortfolioId_SelectedIndexChanged);
btnSearch.Click += new EventHandler(btnSearch_Click);
btnEndorse.Click += new EventHandler(btnEndorse_Click);
tnUpdateManualAll.Click += new EventHandler(btnUpdateManualAll_Click);
rgEndorsements.ItemCommand += new GridCommandEventHandler(rgEndorsements_ItemCommand);
rgEndorsements.NeedDataSource += new GridNeedDataSourceEventHandler(rgEndorsements_NeedDataSource);
rgEndorsementTemp.ItemCommand += new GridCommandEventHandler(rgEndorsementTemp_ItemCommand);
rgEndorsementTemp.NeedDataSource += new GridNeedDataSourceEventHandler(rgEndorsementTemp_NeedDataSource);
rgEndorsements.ItemEvent += new GridItemEventHandler(rgEndorsements_ItemEvent);
btnSearchManualAdd.Click += new EventHandler(btnSearchManualAdd_Click);
rgManualAdd.ItemCommand += new GridCommandEventHandler(rgManualAdd_ItemCommand);
chkUseManualAdd.CheckedChanged += new EventHandler(chkUseManualAdd_CheckedChanged);
btnViewDistributed.Click += new EventHandler(btnViewDistributed_Click);
btnPullout.Click += new EventHandler(btnPullout_Click);
base.OnInit(e);
}
catch (Exception ex)
{
string message = ex.Message;
}
}
protected void UpdateAgency(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
int newAgencyID = 0;
RadComboBox newAgencyDropdown = sender as RadComboBox;
foreach (GridDataItem item in rgEndorsements.Items)
{
newAgencyDropdown = (RadComboBox)item.FindControl("rcbAgency");
Int32 _AgencyID = Int32.Parse(item["AgencyID"].Text);
newAgencyID = int.Parse(newAgencyDropdown.SelectedValue);
if (_AgencyID != newAgencyID)
{
Int32 _PreviousAgencyID = Int32.Parse(item["PreviousAgencyID"].Text);
string _IsRetained = item["IsRetained"].Text;
Int32 _ProductID = Int32.Parse(item["ProductID"].Text);
DirectDBAccess db = new DirectDBAccess();
string sqlEndorse = string.Format("UPDATE CNPL_EndorsementTemp SET AgencyID={0} Where AgencyID={1} And PreviousAgencyID={2} And IsRetained='{3}' And ProductID={4}", newAgencyID, _AgencyID, _PreviousAgencyID, _IsRetained, _ProductID);
SqlCommand cmd = new SqlCommand(sqlEndorse);
db.Open();
db.CommandExecuteNonQuery(cmd, CommandType.Text);
db.Close();
break;
}
}
BindRgEndorsements();
}
protected override void OnUnload(EventArgs e)
{
try
{
base.OnUnload(e);
Locker.inUse = false;
Locker.isCompleted = true;
Locker.user = "";
}
catch (Exception ex)
{
string message = ex.Message;
}
}
protected override void OnLoad(EventArgs e)
{
try
{
Server.ScriptTimeout = 9500;
if (Locker.inUse == true && Locker.isCompleted == false && Locker.user.ToLower() != this.Web.CurrentUser.LoginName.ToLower())
{
Response.Redirect("error.aspx?innerException=Another User is already accessing endorsement&pageFrom=Endorsement To Agency"); //throw new Exception("Another user is already processing endorsement");
}
Locker.inUse = true;
Locker.isCompleted = false;
Locker.user = this.Web.CurrentUser.LoginName;
security = new Security(this.Web.CurrentUser);
userGroups = security.GetUserGroups();
if (userGroups.Contains(SecurityGroups.Star))
{
;
}
else if (userGroups.Contains(SecurityGroups.Agency))
{
Response.Redirect("Error.aspx?innerException=" + "Unauthorized Access." + "&pageFrom=AgencyProfile");
}
else if (userGroups.Contains(SecurityGroups.TeamCollector))
{
Response.Redirect("Error.aspx?innerException=" + "Unauthorized Access." + "&pageFrom=AgencyProfile");
}
else
Response.Redirect("Error.aspx?innerException=" + "Unauthorized Access." + "&pageFrom=AgencyProfile");
if (!Page.IsPostBack)
{
BindReference();
InitializeGrids();
InitializeEndorsementDate();
rbAccountNoMA.Checked = true;
chkUseManualAdd.Checked = false;
pnlManualAdd.Visible = false;
}
else
{
GetViewStates();
}
base.OnLoad(e);
}
catch (Exception ex)
{
string message = ex.Message;
}
}
protected override void OnPreRender(EventArgs e)
{
try
{
ComputeEndorsementTotals();
SetViewStates();
base.OnPreRender(e);
}
catch (Exception ex)
{
string message = ex.Message;
}
}
}
There is an error somewhere in your OnInit
Try placing try catch blocks around each step and step into (not over) each function in there to see if you have any problems.
My guess is you have a try...catch with an empty catch statement - otherwise you'd have an exception to deal with.
We really need to see the code behind, its probably obvious to some of us here when we see the code.
I found the answer to my problem.
There's one event that is not used, and it is this.
rgEndorsements.ItemEvent += new GridItemEventHandler(rgEndorsements_ItemEvent);
It seems that we must check if all the events that are "instantiated" are being used. Thanks for your suggestions! Highly appreciate it.