Coding.....................................
UDP connection lost ?
What is SqlConnectionStringBuilder used for?
using System; using System.Data.SqlClient; namespace ConsoleApp3 { class Program { static void Main(string[] args) { // Create a new SqlConnectionStringBuilder and // initialize it with a few name/value pairs. SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(GetConnectionString()); // The input connection string used the // Server key, but the new connection string uses // the well-known Data Source key instead. Console.WriteLine(builder.ConnectionString); // Pass the SqlConnectionStringBuilder an existing // connection string, and you can retrieve and // modify any of the elements. builder.ConnectionString = "server=(local);user id=ab;" +"password= a!Pass113;initial catalog=AdventureWorks"; // Now that the connection string has been parsed, // you can work with individual items. Console.WriteLine(builder.Password); builder.Password = "new@1Password"; builder.AsynchronousProcessing = true; // You can refer to connection keys using strings, // as well. When you use this technique (the default // Item property in Visual Basic, or the indexer in C#), // you can specify any synonym for the connection string key // name. builder["Server"] = "."; builder["Connect Timeout"] = 1000; builder["Trusted_Connection"] = true; Console.WriteLine(builder.ConnectionString); Console.WriteLine("Press Enter to finish."); Console.ReadLine(); } private static string GetConnectionString() { // To avoid storing the connection string in your code, // you can retrieve it from a configuration file. return "Server=(local);Integrated Security=SSPI;" +"Initial Catalog=AdventureWorks"; } } }
How to know if a file copying process has completed?
I am working on a project that I need to do the following:
1) Copy a file from a source to a destination folder location (say c:\test, for example);
2) Since the file may be quite large (e.g. 10M) it would take time (e.g. 5 seconds) for the copying process to be fully completed;
3) I am using the File.Copy(string sourceFileName, string destFileName, bool overwrite) API to do the above copying process;
4) Now the problem is I have no way to check exactly when the copying process is completed. How can the program be notified if the copying process has finished? Any events or methods can be used?
Could you please advise on this? If you do have any better solutions to acheive the above "Copied then Notifies me" process, please also let me know.
Thanks a lot for your help.
Tigger
Syntax for conditions
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows.Forms; namespace Decompression { public partial class SearchWindow : Form { public SearchWindow() { InitializeComponent(); } private bool IsAutoIdValid() { if(findCarTextBox.Text=="") { IsGoodsValid(); return false; } else if((findCarTextBox.Text=="@tr_numb") && (findGoodsTextBox.Text=="@comment")) { IsAllValid(); return false; } else if(Regex.IsMatch(findCarTextBox.Text,@"^\*$")) { MessageBox.Show("Car number must contain only numbers and letters"); return false; } else { return true; } } private bool IsGoodsValid() { if (Regex.IsMatch(findGoodsTextBox.Text, @"^\*$")) { MessageBox.Show("Goods name must contain only numbers and letters"); return false; } else { return true; } } private bool IsAllValid() { if (("@comment" == findGoodsTextBox.Text) && ("@tr_numb" == findCarTextBox.Text)) { return true; } else { return false; } } private void btnFind_Click(object sender, EventArgs e) { if (IsAllValid()) { using (SqlConnection cn = new SqlConnection(Properties.Settings.Default.connString)) { const string sqlcom = "select* from hawk.dbo.transport where comment=@comment" +"and @tr_numb=tr_numb"; using (SqlCommand sqm = new SqlCommand(sqlcom, cn)) { sqm.Parameters.Add(new SqlParameter("@comment", SqlDbType.VarChar, 1000)); sqm.Parameters["@comment"].Value = findGoodsTextBox.Text; sqm.Parameters.Add(new SqlParameter("@tr_numb", SqlDbType.VarChar, 10)); sqm.Parameters["@tr_numb"].Value = findCarTextBox.Text; try { cn.Open(); using (SqlDataReader cr = sqm.ExecuteReader()) { DataTable dt = new DataTable(); dt.Load(cr); this.dgvCarFind.DataSource = dt; cr.Close(); } } catch { MessageBox.Show("Information is not find"); } finally { cn.Close(); } } } } else if (IsAutoIdValid()) { using (SqlConnection cn = new SqlConnection(Properties.Settings.Default.connString)) { const string sqlcom = "select* from hawk.dbo.transport where tr_numb=@tr_numb"; using (SqlCommand sqm = new SqlCommand(sqlcom, cn)) { sqm.Parameters.Add(new SqlParameter("@tr_numb", SqlDbType.VarChar, 10)); sqm.Parameters["@tr_numb"].Value = findCarTextBox.Text; try { cn.Open(); using (SqlDataReader cr = sqm.ExecuteReader()) { DataTable dt = new DataTable(); dt.Load(cr); this.dgvCarFind.DataSource = dt; cr.Close(); } } catch { MessageBox.Show("Car number is not find"); } finally { cn.Close(); } } } } else if (IsGoodsValid()) { using (SqlConnection cn = new SqlConnection(Properties.Settings.Default.connString)) { const string sqlcom = "select* from hawk.dbo.transport where comment=@comment"; using (SqlCommand sqm = new SqlCommand(sqlcom, cn)) { sqm.Parameters.Add(new SqlParameter("@comment", SqlDbType.VarChar, 1000)); sqm.Parameters["@comment"].Value = findGoodsTextBox.Text; try { cn.Open(); using (SqlDataReader cr = sqm.ExecuteReader()) { DataTable dt = new DataTable(); dt.Load(cr); this.dgvCarFind.DataSource = dt; cr.Close(); } } catch { MessageBox.Show("Goods name is not find"); } finally { cn.Close(); } } } } } } }
error when trying to connect to access database
i have read alot of threads about this error and cannot find an explanation.
im using Visual Studio 2010 and trying to access a database made in access 2010, i get this error:
the 'microsoft.ace.oledb.12.0' provider is not registered on the local machine
i have also tried just adding the connectionstring code, but it doesnt work
//opens connection to DB and sets connection string
OleDbConnection connect = new OleDbConnection();
connect.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=G:\Student.accdb;Persist Security Info=False;";
connect.Open();
i have also tried using this http://www.microsoft.com/download/en/details.aspx?id=13255 but i get the same error :(
please help me i cannot work out what is causing this error
P.S. i am using legit versions of VS and Access :)streamreader readline stops at tabs
NewGuid()
I've been trying to understand what is a default seed value in
public static Guid NewGuid ();
I've done many google searches but I didn't find something trusted.
If someone could say me how works NewGuid() without any argument I would really appreciate it.
Thanks,
Zap
Help with MoveWindow
Hello,
I am a newbie to PINVOKE. I am just trying to learn the MoveWindow command and I have encounter this error
Cannot convert argument "hWnd", with value: "", for "MoveWindow" to type "System.IntPtr": "Cannot convert null to type "System.IntPtr"."
I am just trying to figure out what it meant , and how to fix it. Please let me know if you have any comments or suggestions.
Thanks so much for all of the helps.
Attached is my simple program that gave me the above error message
Add-Type -AssemblyName System.Windows.FormsAdd-Type @"using System;using System.Collections;using System.Collections.Generic;using System.Runtime.InteropServices;using System.Text; public class Win32 { [DllImport("user32.dll", SetLastError = true)] public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint); [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, ExactSpelling = true, SetLastError = true)] public static extern bool GetWindowRect(IntPtr hWnd, ref RECT rect); } public struct RECT { public int Left; // x position of upper-left corner public int Top; // y position of upper-left corner public int Right; // x position of lower-right corner public int Bottom; // y position of lower-right corner }"@#[Win32]::GetWindowRect$Handle = (Get-Process -Name audiodg).MainWindowHandle$Rectangle = New-Object RECT[Win32]::GetWindowRect($Handle,[ref]$Rectangle)$Rectangle$retVal = [Win32]::MoveWindow($Handle, 200, 150, 175, 300, 1)
Student at Georgia Tech
How to add xml element at specific position in multiple records of xml file
i have large xml file which has multiple tables. i want to add one element at specific position. i tried but in my case element is getting added at last which is not desirable.
my tables are. TickerBroker , Broker, BrokerTab and TickerBrokerDateFormatMap
i have multiple Broker element and when i am adding a new Broker then it is getting added in xml fileafter TickerBrokerDateFormatMap element at the end. i want to add Broker element at the end of last Broker element in xml file.
if no Broker element exist in xml file then my added Broker element should be adding at the end of lastTickerBroker element.
here i am giving my sample xml data which is bit big file.
<?xml version="1.0" standalone="yes"?><TickerBrokerDateMap><TickerBroker><Ticker_Id>ADBE</Ticker_Id><Ticker_Id_auto>ADBE</Ticker_Id_auto></TickerBroker><Broker ID="MV-P1" Ticker_Id="ADBE" BrokerCategory="Cascade" Client=""><Broker_Id>25</Broker_Id><ALLTabsUnderBroker><Broker>MV-P1</Broker><TAB>QIS</TAB><Commnet1 /><Commnet2 /><Broker_Id>25</Broker_Id><ReviewedEarnings>3Q 2019</ReviewedEarnings><Pre-Post>Post</Pre-Post></ALLTabsUnderBroker><ALLTabsUnderBroker><Broker>MV-P1</Broker><TAB>BS</TAB><Commnet1 /><Commnet2 /><Broker_Id>25</Broker_Id><ReviewedEarnings>3Q 2019</ReviewedEarnings><Pre-Post>Post</Pre-Post></ALLTabsUnderBroker><ALLTabsUnderBroker><Broker>MV-P1</Broker><TAB>METRICS</TAB><Commnet1 /><Commnet2 /><Broker_Id>25</Broker_Id><ReviewedEarnings>3Q 2019</ReviewedEarnings><Pre-Post>Post</Pre-Post></ALLTabsUnderBroker><ALLTabsUnderBroker><Broker>MV-P1</Broker><TAB>ESTIMATE</TAB><Commnet1 /><Commnet2 /><Broker_Id>25</Broker_Id><ReviewedEarnings /></ALLTabsUnderBroker><ALLTabsUnderBroker><Broker>MV-P1</Broker><TAB>EPS</TAB><Commnet1 /><Commnet2 /><Broker_Id>25</Broker_Id><ReviewedEarnings>3Q 2019</ReviewedEarnings><Pre-Post>Post</Pre-Post></ALLTabsUnderBroker></Broker><Broker ID="UN" Ticker_Id="ADBE" BrokerCategory="Contributing" Client=""><Broker_Id>27</Broker_Id><ALLTabsUnderBroker><Broker>UN</Broker><TAB>ModelCover</TAB><Commnet1 /><Commnet2 /><Broker_Id>27</Broker_Id><ReviewedEarnings /></ALLTabsUnderBroker><ALLTabsUnderBroker><Broker>UN</Broker><TAB>Assumptions</TAB><Commnet1 /><Commnet2 /><Broker_Id>27</Broker_Id><ReviewedEarnings /></ALLTabsUnderBroker><ALLTabsUnderBroker><Broker>UN</Broker><TAB>Revenue Build</TAB><Commnet1 /><Commnet2 /><Broker_Id>27</Broker_Id><ReviewedEarnings>4Q2019</ReviewedEarnings><Pre-Post>Pre</Pre-Post></ALLTabsUnderBroker><ALLTabsUnderBroker><Broker>UN</Broker><TAB>Segment Breakout</TAB><Commnet1 /><Commnet2 /><Broker_Id>27</Broker_Id><ReviewedEarnings /></ALLTabsUnderBroker><ALLTabsUnderBroker><Broker>UN</Broker><TAB>Geographic Breakout</TAB><Commnet1 /><Commnet2 /><Broker_Id>27</Broker_Id><ReviewedEarnings>4Q2019</ReviewedEarnings><Pre-Post>Pre</Pre-Post></ALLTabsUnderBroker><ALLTabsUnderBroker><Broker>UN</Broker><TAB>Calcs</TAB><Commnet1 /><Commnet2 /><Broker_Id>27</Broker_Id><ReviewedEarnings /></ALLTabsUnderBroker><ALLTabsUnderBroker><Broker>UN</Broker><TAB>Debt</TAB><Commnet1 /><Commnet2 /><Broker_Id>27</Broker_Id><ReviewedEarnings /></ALLTabsUnderBroker><ALLTabsUnderBroker><Broker>UN</Broker><TAB>GAAP Income Statement</TAB><Commnet1 /><Commnet2 /><Broker_Id>27</Broker_Id><ReviewedEarnings>4Q2019</ReviewedEarnings><Pre-Post>Pre</Pre-Post></ALLTabsUnderBroker><ALLTabsUnderBroker><Broker>UN</Broker><TAB>Non-GAAP Income Statement</TAB><Commnet1 /><Commnet2 /><Broker_Id>27</Broker_Id><ReviewedEarnings>4Q2019</ReviewedEarnings><Pre-Post>Pre</Pre-Post></ALLTabsUnderBroker><ALLTabsUnderBroker><Broker>UN</Broker><TAB>Balance Sheet</TAB><Commnet1 /><Commnet2 /><Broker_Id>27</Broker_Id><ReviewedEarnings>4Q2019</ReviewedEarnings><Pre-Post>Pre</Pre-Post></ALLTabsUnderBroker><ALLTabsUnderBroker><Broker>UN</Broker><TAB>Cash Flow</TAB><Commnet1 /><Commnet2 /><Broker_Id>27</Broker_Id><ReviewedEarnings>4Q2019</ReviewedEarnings><Pre-Post>Pre</Pre-Post></ALLTabsUnderBroker><ALLTabsUnderBroker><Broker>UN</Broker><TAB>Disclosures</TAB><Commnet1 /><Commnet2 /><Broker_Id>27</Broker_Id><ReviewedEarnings /></ALLTabsUnderBroker></Broker><Broker ID="BW" Ticker_Id="ADBE" BrokerCategory="NonContributing" Client=""><Broker_Id>28</Broker_Id><ALLTabsUnderBroker><Broker>BW</Broker><TAB>Adobe Model_Stifel</TAB><Commnet1 /><Commnet2 /><Broker_Id>28</Broker_Id><ReviewedEarnings>4Q 2019</ReviewedEarnings><Pre-Post>Pre</Pre-Post></ALLTabsUnderBroker><ALLTabsUnderBroker><Broker>BW</Broker><TAB>Disclaimer (Read first)</TAB><Commnet1 /><Commnet2 /><Broker_Id>28</Broker_Id><ReviewedEarnings /></ALLTabsUnderBroker><ALLTabsUnderBroker><Broker>BW</Broker><TAB>Sources</TAB><Commnet1 /><Commnet2 /><Broker_Id>28</Broker_Id><ReviewedEarnings /></ALLTabsUnderBroker></Broker><Broker ID="PJ-C1" Ticker_Id="ADBE" BrokerCategory="Contributing" Client=""><Broker_Id>29</Broker_Id><ALLTabsUnderBroker><Broker>PJ-C1</Broker><TAB>IS</TAB><Commnet1>Use Custom</Commnet1><Commnet2>Use Custom</Commnet2><Broker_Id>29</Broker_Id><ReviewedEarnings>4Q 2019</ReviewedEarnings><Pre-Post>Pre</Pre-Post></ALLTabsUnderBroker><ALLTabsUnderBroker><Broker>PJ-C1</Broker><TAB>BS</TAB><Commnet1>Use Custom</Commnet1><Commnet2>Use Custom</Commnet2><Broker_Id>29</Broker_Id><ReviewedEarnings>4Q 2019</ReviewedEarnings><Pre-Post>Pre</Pre-Post></ALLTabsUnderBroker><ALLTabsUnderBroker><Broker>PJ-C1</Broker><TAB>CF</TAB><Commnet1>Use Custom</Commnet1><Commnet2>Use Custom</Commnet2><Broker_Id>29</Broker_Id><ReviewedEarnings>4Q 2019</ReviewedEarnings><Pre-Post>Pre</Pre-Post></ALLTabsUnderBroker><ALLTabsUnderBroker><Broker>PJ-C1</Broker><TAB>Segment Breakout</TAB><Commnet1>Use Custom</Commnet1><Commnet2>Use Custom</Commnet2><Broker_Id>29</Broker_Id><ReviewedEarnings>4Q 2019</ReviewedEarnings><Pre-Post>Pre</Pre-Post></ALLTabsUnderBroker></Broker><BrokerTab name="IS" Broker_Id="0" Ticker_Id="ADBE" Revise_Date="11-19-2019"><BrokerTab_Id>0</BrokerTab_Id><Tab_index>0</Tab_index><save_flag>true</save_flag><isUSed>true</isUSed></BrokerTab><BrokerTab name="Drivers" Broker_Id="0" Ticker_Id="ADBE" Revise_Date="11-19-2019"><BrokerTab_Id>1</BrokerTab_Id><Tab_index>1</Tab_index><save_flag>true</save_flag><isUSed>true</isUSed></BrokerTab><BrokerTab name="BS" Broker_Id="0" Ticker_Id="ADBE" Revise_Date="11-19-2019"><BrokerTab_Id>2</BrokerTab_Id><Tab_index>2</Tab_index><save_flag>true</save_flag><isUSed>true</isUSed></BrokerTab><BrokerTab name="CF" Broker_Id="0" Ticker_Id="ADBE" Revise_Date="11-19-2019"><BrokerTab_Id>3</BrokerTab_Id><Tab_index>3</Tab_index><save_flag>true</save_flag><isUSed>true</isUSed></BrokerTab><TickerBrokerDateFormatMap BrokerTab_Id="154" Broker_Id="29" Ticker_Id="ADBE"><StandardDate>2021 FYE</StandardDate><ColumnCoordinate>AQ</ColumnCoordinate><TickerBrokerDateFormatMaps_Id>168</TickerBrokerDateFormatMaps_Id><BrokerDate StandardDate="2021 FYE" Broker_Id="29" BrokerTab_Id="154"><year>2021 FYE</year><Quater>2021 FYE</Quater></BrokerDate></TickerBrokerDateFormatMap></TickerBrokerDateMap>
here i am giving my c# code to add xml broker element which is adding at the end of file which is not desirable.
string srclocalfile = @"C:\FILE1.xml"; string strZipBrokerID = "10"; string strSourceBrokerID = "12"; string broker = "UN"; XDocument xmlDocZip = XDocument.Load(srclocalfile); var zipbrokerrow = xmlDocZip.Descendants().Elements("Broker").FirstOrDefault(b => b.Attribute("ID").Value.ToString().Trim().Equals(broker)); if (zipbrokerrow != null) { XElement oSubElm = null; XElement brokerelement = new XElement("Broker", new XAttribute("ID", broker), new XAttribute("Ticker_Id", strTicker), new XAttribute("BrokerCategory", zipbrokerrow.Attribute("BrokerCategory").Value), new XAttribute("Client", zipbrokerrow.Attribute("Client").Value), new XElement("Broker_Id", strSourceBrokerID)); foreach (XElement e in zipbrokerrow.Descendants("ALLTabsUnderBroker")) { string _broker = e.Element("Broker").Value; string _TAB = e.Element("TAB").Value; string _Commnet1 = e.Element("Commnet1").Value; string _Commnet2 = e.Element("Commnet2").Value; string _Broker_Id = e.Element("Broker_Id").Value; string _ReviewedEarnings = e.Element("ReviewedEarnings").Value; oSubElm = new XElement("ALLTabsUnderBroker", new XElement("Broker", _broker), new XElement("TAB", _TAB), new XElement("Commnet1", _Commnet1), new XElement("Commnet2", _Commnet2), new XElement("Broker_Id", _Broker_Id), new XElement("ReviewedEarnings", _ReviewedEarnings)); brokerelement.Add(oSubElm); } xmlDocZip.Root.Descendants("Broker").FirstOrDefault().Parent.Add(brokerelement); xmlDocZip.Save(srclocalfile); }
see i am using XDocument class. so please post your sample code using XDocument. thanks
Can't get player sprite to move in maze game?
Hi there! Probably a bit of a simple question but I could really use some help!
I'm trying to make a maze game, but no matter what I do, I can't get the player sprite to move - I've tried with arrow keys, separate If statements.. can't seem to find anything to work, as there's no errors, it just doesn't move!
I've pasted what I have so far below, please let me know if you spot anything that might be causing the issue, I'm very much a beginner!
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Maze_game { public partial class Mazegame : Form { readonly bool goleft; readonly bool goright; //int score = 0; //int points = 13; int playerSpeed = 500; //int health = 100; public Mazegame() { InitializeComponent(); } private void MazeGame_Load(object sender, EventArgs e) { } private void timer1_Tick(object sender, EventArgs e) { if (goleft) { ball.Left -= playerSpeed; } if (goright) { ball.Left += playerSpeed; } } private void Keyisdown(object sender, KeyEventArgs e) { int x = ball.Location.X; int y = ball.Location.Y; if (e.KeyCode == Keys.W) ball.Top = ball.Top - 5; else if (e.KeyCode == Keys.D) ball.Left = ball.Left + 5; else if (e.KeyCode == Keys.A) ball.Left = ball.Left - 5; else if (e.KeyCode == Keys.S) ball.Top = ball.Top + 5; foreach (Control a in this.Controls) ; } private void Mazegame_Load(object sender, EventArgs e) { } private void KeyIsUp(object sender, KeyEventArgs e) { int x = ball.Location.X; int y = ball.Location.Y; if (e.KeyCode == Keys.W) ball.Top = ball.Top - 5; else if (e.KeyCode == Keys.D) ball.Left = ball.Left + 5; else if (e.KeyCode == Keys.A) ball.Left = ball.Left - 5; else if (e.KeyCode == Keys.S) ball.Top = ball.Top + 5; foreach (Control a in this.Controls) ; } } }
What should I learn to create a HTTP server with C# for games?
Hello, I'm new to server programming, I have beeing creating small Unity games using C# (the only language I know), and now I need a simple server just for players to login and save their progress, maybe also generate some random numbers for gameplay.
The server doesn't need to repond to clients very quickly, and doesn't need to maintain a connection with clients either, only clients call the server when needed. And I don't want to go directly with lower level socket programming. I think a HTTP kind of server may just do the work (I also use HTTP modules on the client side).
So in this case, I want to know what should I learn, or whether there are some frameworks / architectures I can leverage. Shall I learn ASP.NET? But it's for game, there will be no web page involved. I'm totally new to server programming, so I'm sorry if I ask the question in a wrong way.
Btw, I don't want to use some game server engines like Photon or Unity network features, just want to build something of my own (but it's also good if there are some frameworks / architectures I can leverage).
Thank you very much for checking out my question.
subtract anonymous method from delegate
delegate void Deleg2();
Deleg2 deleg2 = new Deleg2( () => Console.WriteLine("first line")); deleg2 += () => Console.WriteLine("secnd line"); deleg2 += () => Console.WriteLine("third line");
i'm trying to remove one of the 3 methods, and non of the next lines works
deleg2 -= new Deleg2(() => { }); deleg2 -= () => Console.WriteLine("third line");
I can't connect to MS Access (accdb) database that uses Large Number
I have an Access database that has a table with a field that uses the Large Number data type. When trying to connect using Microsoft.ACE.OLEDB (12 or 16) in C# code, i get following error:
"The database you are trying to open requires a newer version of Microsoft Access."In the Microsoft forum cites the problem when trying to connect to this type of database and suggests using the Access version 16.0.7xxxx (https://docs.microsoft.com/en-us/office/troubleshoot/access/database-requires-newer-access). My version of Access I can upgrade to a higher version of the suggested, however, the most current Access engine available is version 16.0.4. How do I connect to this database type without changing the column data type?
Note: I have tried to install several different engines and use the 2016 version of X64 and X32 installed simultaneously.
Adding Items to ListView Columns in c# WPF.
Hiii,
I have one TextBox is for entering UserName and PasswordBox for Password. and 1 ADDButton to add items to ListView Control.
My Question is : Is this posible to ADD Both Username and Password to listview ?? If Possible how can i do program for that.??
Anyone knows Please Answer me..
<TextBox x:Name="Textbox_SOTAUName" Margin="0,26,563,0" HorizontalAlignment="Stretch" Grid.Column="1" /> <PasswordBox HorizontalAlignment="Stretch" Grid.Column="1" x:Name="Passwordbox_SPassword" ClipToBounds="False" MaxLength="8" PasswordChar="*" VerticalAlignment="Stretch" Foreground="#FF083042" Margin="-2"> <PasswordBox.BorderBrush> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="Black" Offset="0"/> <GradientStop Color="#FFFFE9EF" Offset="1"/> </LinearGradientBrush> </PasswordBox.BorderBrush> </PasswordBox><ListBox x:Name="ListBox_User_Pass" Margin="19,30,265,18" Visibility="Visible" ScrollViewer.VerticalScrollBarVisibility="Auto" Grid.ColumnSpan="2" Grid.Column="2" Grid.Row="4" RenderTransformOrigin="0.503,0.306" FontSize="13" FontWeight="Bold"> <ListBox.RenderTransform> <TransformGroup> <ScaleTransform/> <SkewTransform AngleX="-0.972"/> <RotateTransform/> <TranslateTransform X="-0.613"/> </TransformGroup> </ListBox.RenderTransform> </ListBox>
Thank you,
CS1009 Unrecognized escape sequence
using System; using System.IO; using System.Runtime.InteropServices; using Excel = Microsoft.Office.Interop.Excel; namespace openingworkbook { class Program { static void Main(string[] args) { var exApp = new Microsoft.Office.Interop.Excel.Application(); var exWbk = exApp.Workbooks.Open(@"C:\Temp\ExcelTest\lineup.xlsx"); exApp.Visible = true; exApp.Run("C:\Temp\ExcelTest\lineup.xlsx!lineup"); exWbk.Save(); exApp.Workbooks.Close(); exApp.Quit(); exWbk.Close(); } } }So I am trying to open an already existing .xlsx file and run a macro inside of excel then save and quit. The error code is CS1009 and the description is Unrecognized escape sequence. I've look around on the internet for a solution but am struggling to find up to date code that works. Not asking for a complete solution but guidance will be appreciated.
High precision timers in C#
Performance Issue - FileSystemWatcher
Hi Experts,
Am working on file processing task where I need to bulk load the files into Database SQL Server for this am using the FileSystemWatcher which works as required and am a newbie in C#.
The problem starts to build up when the drive gets a massive load of 10-20 files gets loaded in the directory getting monitored with each file around 30-40 mb in size..
The CPU starts peaking 50-60 percent.. To avoid the CPU issue , am trying
File Caching but still issue persists. Am thinking if I could delay the processing file by 1-2 seconds interval between each file that may reduce the overhead on the processor. Please suggest if delay need to be added what's the best way or any other approach.
The process method simply obtains the csv --> use csvhelper to load to data table --> datatable finally gets loaded into SQL Server using bulk insert.
It may contain 40-50 k records per file. Please share optimisation techniques
private static MemoryCache FilesToProcess = MemoryCache.Default;
private static void AddToCache(string fullPath) { var item = new CacheItem(fullPath, fullPath); var policy = new CacheItemPolicy { RemovedCallback = ProcessFile, SlidingExpiration = TimeSpan.FromSeconds(5), }; FilesToProcess.Add(item, policy); }
private static void FileCreated(object sender, FileSystemEventArgs e) { AddToCache(e.FullPath); } private static void ProcessFile(CacheEntryRemovedArguments args) { if (args.RemovedReason == CacheEntryRemovedReason.Expired) { var fileProcessor = new DataProcessing(args.CacheItem.Key); fileProcessor.Process(); } else { } }
Thanks
Priya
How to know if a file copying process has completed?
I am working on a project that I need to do the following:
1) Copy a file from a source to a destination folder location (say c:\test, for example);
2) Since the file may be quite large (e.g. 10M) it would take time (e.g. 5 seconds) for the copying process to be fully completed;
3) I am using the File.Copy(string sourceFileName, string destFileName, bool overwrite) API to do the above copying process;
4) Now the problem is I have no way to check exactly when the copying process is completed. How can the program be notified if the copying process has finished? Any events or methods can be used?
Could you please advise on this? If you do have any better solutions to acheive the above "Copied then Notifies me" process, please also let me know.
Thanks a lot for your help.
Tigger
Fill Absent text in empty place using pivot sql
Below is pivot query for my requiremnt.
Declare @cols NVARCHAR(Max)='';
;With log_date AS (
SELECT BatchStartDate as l_date FROM Table_Batch_Lookup
UNION ALL
SELECT DATEADD(dd, 1, l_date) FROM log_date AS ld , Table_Batch_Lookup AS tb WHERE ld.l_date<DATEADD(dd, -1, tb.BatchEndDate)
)
SELECT @cols = COALESCE (@cols + ',[' + CONVERT(NVARCHAR,CONVERT(VARCHAR(10), l_Date, 111), 106) + ']','[' + CONVERT(NVARCHAR, l_Date, 106) + ']') FROM (SELECT DISTINCT CONVERT(VARCHAR(10), l_Date, 111) AS l_date FROM log_date)
PV;
Declare @totalScore INT =len(@cols) - len(replace(@cols, ',', ''))
DECLARE @query NVARCHAR(MAX);
SET @query = 'SELECT t_info.TraineeID,t_batch.BatchId,t_info.Name,t_info.Mobile'+@cols+' FROM Table_TraineeInfo AS t_info Left JOIN
(SELECT * FROM
(
SELECT TraineeID,BatchId,Attendance,CONVERT(VARCHAR(10), l_Date, 111) AS l_date FROM Table_Attendance_Log
) x
PIVOT
(
MAX(Attendance)
FOR l_Date IN (' + right(@cols, len(@cols)-1)+ ')
) p ) AS f_pv ON t_info.TraineeID=f_pv.TraineeID JOIN Table_Batch_Lookup as t_batch ON t_batch.BatchId=t_info.BatchId
WHERE t_batch.BatchId=45;
' ;
EXEC SP_EXECUTESQL @query;
Below is my scrip table creation scripts with data. Table_TraineeInfo is candidate registeration details table, Table_Batch_Lookup is batch detail when batch start date and end date base on filling in pivot, Table_Attendance_Log is candidate attendance log.
CREATE TABLE [dbo].[Table_TraineeInfo](
[TraineeID] [int] NULL,
[BatchId] [int] NULL,
[Name] [varchar](max) NULL,
[Mobile] [varchar](10) NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
INSERT [dbo].[Table_TraineeInfo] ([TraineeID], [BatchId], [Name], [Mobile]) VALUES (243, 45, N'demo201', N'9888562341')
INSERT [dbo].[Table_TraineeInfo] ([TraineeID], [BatchId], [Name], [Mobile]) VALUES (244, 45, N'demo202', N'9888562342')
INSERT [dbo].[Table_TraineeInfo] ([TraineeID], [BatchId], [Name], [Mobile]) VALUES (246, 45, N'demo204', N'9888562344')
INSERT [dbo].[Table_TraineeInfo] ([TraineeID], [BatchId], [Name], [Mobile]) VALUES (247, 45, N'demo205', N'9999999999')
/****** Object: Table [dbo].[Table_Batch_Lookup] Script Date: 12/15/2019 04:34:41 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Table_Batch_Lookup](
[BatchId] [int] NULL,
[BatchStartDate] [datetime] NULL,
[BatchEndDate] [datetime] NULL
) ON [PRIMARY]
GO
INSERT [dbo].[Table_Batch_Lookup] ([BatchId], [BatchStartDate], [BatchEndDate]) VALUES (45, CAST(0x0000AB2200000000 AS DateTime), CAST(0x0000AB25018B80D4 AS DateTime))
/****** Object: Table [dbo].[Table_Attendance_Log] Script Date: 12/15/2019 04:34:41 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Table_Attendance_Log](
[TraineeID] [int] NULL,
[BatchId] [int] NULL,
[Attendance] [varchar](10) NULL,
[l_date] [datetime] NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
INSERT [dbo].[Table_Attendance_Log] ([TraineeID], [BatchId], [Attendance], [l_date]) VALUES (243, 45, N'Present', CAST(0x0000AB220127842A AS DateTime))
INSERT [dbo].[Table_Attendance_Log] ([TraineeID], [BatchId], [Attendance], [l_date]) VALUES (243, 45, N'Present', CAST(0x0000AB2301281C2A AS DateTime))
INSERT [dbo].[Table_Attendance_Log] ([TraineeID], [BatchId], [Attendance], [l_date]) VALUES (243, 45, N'Present', CAST(0x0000AB240128E416 AS DateTime))
INSERT [dbo].[Table_Attendance_Log] ([TraineeID], [BatchId], [Attendance], [l_date]) VALUES (244, 45, N'Present', CAST(0x0000AB24012A05AB AS DateTime))
INSERT [dbo].[Table_Attendance_Log] ([TraineeID], [BatchId], [Attendance], [l_date]) VALUES (246, 45, N'Present', CAST(0x0000AB23012B245A AS DateTime))
INSERT [dbo].[Table_Attendance_Log] ([TraineeID], [BatchId], [Attendance], [l_date]) VALUES (246, 45, N'Present', CAST(0x0000AB24012B245A AS DateTime))
My current output
Name | Mobile | 12/13/2019 | 12/14/2019 | 12/15/2019 | 12/16/2019 |
demo201 | 9888562341 | Present | Present | Present | NULL |
demo202 | 9888562342 | NULL | NULL | Present | NULL |
demo204 | 9888562344 | NULL | Present | Present | NULL |
demo205 | 9999999999 | NULL | NULL | NULL | NULL |
I want below output if date is less than or equal to today date fill empty vales to Absent(past date) and Future date should be like that no absent in 12/16/2019 is future date no need to fill absent.
Name | Mobile | 12/13/2019 | 12/14/2019 | 12/15/2019 | 12/16/2019 |
demo201 | 9888562341 | Present | Present | Present | NULL |
demo202 | 9888562342 | Absent | Absent | Present | NULL |
demo204 | 9888562344 | Absent | Present | Present | NULL |
demo205 | 9999999999 | Absent | Absent | Absent | NULL |
code abstraction
using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.Geometry; using Autodesk.AutoCAD.EditorInput; [CommandMethod("AccessSpace")] public static void AccessSpace() { // Get the current document and database Document acDoc = Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; // Start a transaction using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { // Open the Block table for read BlockTable acBlkTbl; acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable; // Open the Block table record for read BlockTableRecord acBlkTblRec; // Request which table record to open PromptKeywordOptions pKeyOpts = new PromptKeywordOptions(""); pKeyOpts.Message = "\nEnter which space to create the line in "; pKeyOpts.Keywords.Add("Model"); PromptResult pKeyRes = acDoc.Editor.GetKeywords(pKeyOpts); if (pKeyRes.StringResult == "Model") { // Get the ObjectID for Model space from the Block table acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; } // Create a line that starts at 2,5 and ends at 10,7 Line acLine = new Line(new Point3d(2, 5, 0), new Point3d(10, 7, 0)); acLine.SetDatabaseDefaults(); // Add the new object to the block table record and the transaction acBlkTblRec.AppendEntity(acLine); acTrans.AddNewlyCreatedDBObject(acLine, true); // Save the new line to the database acTrans.Commit(); } }is there a way to apply ABSTRACTION to this code, i want it to be more simpe and REUSABLE, if it possible to generalize the code and make it simple and looks elegant ?