C#

.NET este un framework software care rulează pe sistemele de operare din gama Windows.
Acest framework include o librărie mare cu soluţii pentru problemele des întâlnite de programatori. Aici vorbim despre C#, J#, VB.NET, ASP.NET, DELPHI.NET etc.

C#

Postby coddo » 31 Mar 2010, 22:40

Am o problema in C#. Intr-un form principal am pus un buton. Aceluia vreau sa ii atribui sa citeasca numere din consola (de la tastatura) pe care sa le pun in vectori si primesc eroarea:" Error 1 No overload for method 'Read' takes '1' arguments". Toata eroarea este in acel button1.
Este prima oara cand fac ceva in C#, deci nu ma luati tare va rog :).

  1.  
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Windows.Forms;
  10.  
  11. namespace WindowsFormsApplication4
  12. {
  13.     public partial class ZINGO : Form
  14.     {
  15.         public ZINGO()
  16.         {
  17.             InitializeComponent();
  18.            
  19.         }
  20.  
  21.         private void Form1_Load(object sender, EventArgs e)
  22.         {
  23.  
  24.         }
  25.  
  26.         private void button1_Click(object sender, EventArgs e)
  27.         {
  28.  
  29.             int n, i;
  30.             int[] x;
  31.             Console.Write("Introduceti numarul de elemente cu care doriti sa lucrati: ");
  32.             Console.Read(n);
  33.             Console.WriteLine();
  34.             for (i=1;i<=n;i++)
  35.             {
  36.                 if (i==1)
  37.                     Console.Write ("Introduceti primul numar: ");
  38.                 else
  39.                     Console.Write ("Introduceti al ",i,"-lea numar: ");
  40.                 Console.Read (x[i]);
  41.                 Console.WriteLine();
  42.             }
  43.                
  44.            
  45.         }
  46.  
  47.         private void richTextBox2_TextChanged(object sender, EventArgs e)
  48.         {
  49.  
  50.         }
  51.     }
  52. }
  53.  
0,0p / 0 votes
User avatar
coddo
Bit
 
Joined: 23 Mar 2010
Location: Deva, Romania
Status: 0

Re: C#

Postby DarkByte » 01 Apr 2010, 00:13

N-am programat in viata mea in C#, dar incearca in felul urmator:

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace WindowsFormsApplication4
  11. {
  12.     public partial class ZINGO : Form
  13.     {
  14.         public ZINGO()
  15.         {
  16.             InitializeComponent();
  17.            
  18.         }
  19.  
  20.         private void Form1_Load(object sender, EventArgs e)
  21.         {
  22.  
  23.         }
  24.  
  25.         private void button1_Click(object sender, EventArgs e)
  26.         {
  27.  
  28.             int n, i;
  29.             int[] x;
  30.             Console.Write("Introduceti numarul de elemente cu care doriti sa lucrati: ");
  31.             n = Console.Read();
  32.             Console.WriteLine();
  33.             for (i=1;i<=n;i++)
  34.             {
  35.                 if (i==1)
  36.                     Console.Write ("Introduceti primul numar: ");
  37.                 else
  38.                     Console.Write ("Introduceti al ",i,"-lea numar: ");
  39.                 x[i] = Console.Read ();
  40.                 Console.WriteLine();
  41.             }
  42.                
  43.            
  44.         }
  45.  
  46.         private void richTextBox2_TextChanged(object sender, EventArgs e)
  47.         {
  48.  
  49.         }
  50.     }
  51. } 


Daca nu merge, o sa am motiv sa ma apuc de C# :-s
0,0p / 0 votes
User avatar
DarkByte
11011011
 
Joined: 29 Dec 2009
Status: 136

Re: C#

Postby coddo » 01 Apr 2010, 20:07

Acuma imi zice ca x ii unassigned. Deci nu-mi recunoaste vectorul acuma.
Am incercat sa scriu si x = new int[10] si tot aceeasi eroare.
0,0p / 0 votes
User avatar
coddo
Bit
 
Joined: 23 Mar 2010
Location: Deva, Romania
Status: 0

Re: C#

Postby DarkByte » 01 Apr 2010, 20:45

Incearca sa pui asa:
  1.             ........
  2.             int n, i;
  3.             int[] x;
  4.             Console.Write("Introduceti numarul de elemente cu care doriti sa lucrati: ");
  5.             n = Console.Read();
  6.             x = new int[n];
  7.             Console.WriteLine();
  8.             for (i=1;i<=n;i++)
  9.             ........

Linia care am adaugat-o este linia cu numarul 6.
0,0p / 0 votes
User avatar
DarkByte
11011011
 
Joined: 29 Dec 2009
Status: 136

Re: C#

Postby coddo » 01 Apr 2010, 21:58

Functioneaza...mersi mult. Atata, daca ai putea te rog sa imi si explici de ce acuma merge ?
0,0p / 0 votes
User avatar
coddo
Bit
 
Joined: 23 Mar 2010
Location: Deva, Romania
Status: 0

Re: C#

Postby DarkByte » 01 Apr 2010, 22:03

Sincer, nu prea am habar.

Chestia cu x = new int[10] care zici ca ai pus-o ar fi trebuit sa aiba acelasi efect (cu diferenta legata de marimea array-ului, evident). Pot doar sa presupun ca, poate, nu ai pus bucata asta de cod in locul care trebuia.
0,0p / 0 votes
User avatar
DarkByte
11011011
 
Joined: 29 Dec 2009
Status: 136

Re: C#

Postby coddo » 05 Apr 2010, 12:54

baieti, am o noua problema tot in C#. La apasarea unui buton vreau sa imi inchida forma existenta si sa imi deschida alta forma, iar pt asta am folosit this.Close(); ....dar nu se intampla asa, ci imi inchide ambele forme, practic imi opreste aplicatia. Uitati codul:

  1.  
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Windows.Forms;
  10.  
  11. namespace Zingo
  12. {
  13.     public partial class StartPage : Form
  14.     {
  15.         public StartPage()
  16.         {
  17.             InitializeComponent();
  18.  
  19.         }
  20.         private Zingo f;
  21.         private void button1_Click(object sender, EventArgs e)
  22.         {
  23.             this.Close();
  24.             f = new Zingo();
  25.             f.ShowDialog();
  26.         }
  27.  
  28.         private void button2_Click(object sender, EventArgs e)
  29.         {
  30.             Application.Exit();
  31.         }
  32.     }
  33. }
  34.  
0,0p / 0 votes
User avatar
coddo
Bit
 
Joined: 23 Mar 2010
Location: Deva, Romania
Status: 0

Re: C#

Postby Mihai » 05 Apr 2010, 13:01

Trebuie sa folosesti metoda Hide in loc de Close. Vezi aici mai multe detalii.
0,0p / 0 votes
User avatar
Mihai
Byte
 
Joined: 29 Dec 2009
Status: 25

Re: C#

Postby coddo » 05 Apr 2010, 13:51

Ah, ce chestie :))...mersi mult.
0,0p / 0 votes
User avatar
coddo
Bit
 
Joined: 23 Mar 2010
Location: Deva, Romania
Status: 0

Re: C#

Postby Payne » 06 Apr 2010, 01:02

Sau poti sa lucrezi cu thread-uri. Fiecare form sa aiba thread-ul lui si cand inchizi unul cu form.close() sa nu se inchida al2lea.

Adaugi
  1. using System.Threading;


Si pui in acel buton

  1. ThreadStart thrStart = delegate  { Application.Run(new frm2()); // unde frm2 e numele formului(in cazult tau Zingo).
  2. Thread thr = new Thread(thrStart);
  3. thr.Start();
  4. this.close();
  5.  


Ce nu am inteles e cum tu cu o aplicatie de windows(form) citesti consola.

Poate citesti un textbox sau citesti un richtextbox sau orice alt component, dar nu consola.
0,0p / 0 votes
Suit up!
User avatar
Payne
Byte
 
Joined: 04 Jan 2010
Location: 0x7C00
Status: 17

Re: C#

Postby coddo » 07 Apr 2010, 15:26

Payne wrote:
Ce nu am inteles e cum tu cu o aplicatie de windows(form) citesti consola.

Poate citesti un textbox sau citesti un richtextbox sau orice alt component, dar nu consola.

---------------------------------------------------------------------------------------------------------------------------
Ca sa iti raspund la intrebare, aia a fost prima mea testare in C# si a incercat tot felul de lucruri fara logica sincer sa fiu.

Acuma am alta problema, am o baza de date cu 4 tabele. Aici ma voi lega de una singura: tabelul Angajati, care are urmatoarele coloane:
-Cod A de tip int
-Nume de tip string
-Prenume de tip string
- Data nastere de tip datetime (aici este problema)
- Salar dorit de tip money
- Disponibilitate de tip string [1]

Well, am o forma cu 5 textboxuri, in care voi introduce date de tipul celor de mai sus, in afara de Cod A, care se auto-incrementeaza.
In al 3-lea text box, introduc o data de tipul: 12/21/2012 si imi zice ca nu se potriveste la tipul datelor si se blocheaza efectiv programul.

Ce sugestii ati avea in legatura cu aceasta problema ? Sau mai bine zis, ce introduc gresit acolo de nu imi recunoaste ?

Codul prin care fac asta este:
  1.  
  2.         private void button1_Click(object sender, EventArgs e)
  3.         {
  4.             if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "" || textBox5.Text == "")
  5.             {
  6.                 MessageBox.Show("NU ATI COMPLETAT TOATE CAMPURILE !");
  7.                 return;
  8.             }
  9.             else
  10.                 angajatiTableAdapter1.Insert(textBox1.Text, textBox2.Text, DateTime.Parse(textBox3.Text), decimal.Parse(textBox4.Text), textBox5.Text);
  11.  

*Acel "button 1" este butonul adaugare care imi va face insert in tabelul Angajati din baza de date cu ceea ce scriu in cele 5 textboxuri.
0,0p / 0 votes
User avatar
coddo
Bit
 
Joined: 23 Mar 2010
Location: Deva, Romania
Status: 0

Re: C#

Postby DarkByte » 07 Apr 2010, 18:09

Probabil e vorba de formatul de data (system locale).

Vezi prin astea:
http://www.csharp-examples.net/string-format-datetime/
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
pentru mai multe detalii ...

Sper ca ti-am fost de ajutor.
0,0p / 0 votes
User avatar
DarkByte
11011011
 
Joined: 29 Dec 2009
Status: 136

Re: C#

Postby Payne » 08 Apr 2010, 10:12

^^ Normal, deoarece DateTime.Parse() intoarce o valoare de tipul "ziua/luna/an h:m:s". Adica tu incerci sa introduci intr-un camp de tip-ul Date un DateTime(Data si ora).

Incearca asa
  1.  
  2. DateTime.Parse(textbox3.Text).ToString("dd/MM/yyyy");
  3.  


L.E Acum am vazut ca campul e DateTime. Atunci nu inteleg de ce apare acea eroare. Esti complet sigur de ca e asa? Si pentru ce ai nevoie de ora si minutul nasterii?
0,0p / 0 votes
Suit up!
User avatar
Payne
Byte
 
Joined: 04 Jan 2010
Location: 0x7C00
Status: 17

Re: C#

Postby coddo » 09 Apr 2010, 10:39

Payne wrote:^^ Normal, deoarece DateTime.Parse() intoarce o valoare de tipul "ziua/luna/an h:m:s". Adica tu incerci sa introduci intr-un camp de tip-ul Date un DateTime(Data si ora).

Incearca asa
  1.  
  2. DateTime.Parse(textbox3.Text).ToString("dd/MM/yyyy");
  3.  


L.E Acum am vazut ca campul e DateTime. Atunci nu inteleg de ce apare acea eroare. Esti complet sigur de ca e asa? Si pentru ce ai nevoie de ora si minutul nasterii?


De eroare sunt sigur ca asa zice. Iar in legatura cu ora si minutul nasterii....singura chestie care am gasit-o acolo in lista de select ii asta, chiar daca mie imi trebuie numai data si nu si ora, minutul si secunda. O sa incerc maine sa scriu asa cum ai spus, ca nu am laptopul disponibil momentan si o sa scriu aici ce rezultate am.

EDIT:
Am rezolvat problema, se pare ca am pus textboxurile aiurea si eu am crezut ca sunt in ordine, de aceea primeam acele erori . Am rezolvat problema, multumesc :).

Btw, Payne, nu trebuie sa introduc si ora si minutul si secunda :)), imi accepta numai data daca o introduc.
0,0p / 0 votes
User avatar
coddo
Bit
 
Joined: 23 Mar 2010
Location: Deva, Romania
Status: 0

Re: C#

Postby coddo » 12 Apr 2010, 19:57

Am reusit sa termin programul de care ma apucasem pentru un concurs. Am o problema acuma, cand pornesc programul freely, fara debugger, imi da o eroare cand incerc sa accesez baza de date a programului. Cand il rulez in debuggerul de la C#, n-are nici pe naiba :)).
Jos am sa atasez 2 fisiere: un setup al programului care l-am facut din plictiseala si o arhiva care contine tot proiectul :).
Daca este cineva binevoitor si priceput, va rog ajutati-ma sa rezolv si aceasta problema ! :>
0,0p / 0 votes
Attachments
Zingosetup.rar
Setup
(155.47 KiB) Downloaded 35 times
Zingo.rar
Project files
(331.58 KiB) Downloaded 37 times
User avatar
coddo
Bit
 
Joined: 23 Mar 2010
Location: Deva, Romania
Status: 0

Re: C#

Postby Payne » 12 Apr 2010, 20:55

Mie imi merge perfect si cu setup si fara(compilare facuta de mine).
0,0p / 0 votes
Suit up!
User avatar
Payne
Byte
 
Joined: 04 Jan 2010
Location: 0x7C00
Status: 17

Re: C#

Postby coddo » 12 Apr 2010, 21:33

Payne wrote:Mie imi merge perfect si cu setup si fara(compilare facuta de mine).


Dar dupa ce treci din startpage in programul principal si dai pe visualizare sau editare, nu iti da nicio eroare ?
0,0p / 0 votes
User avatar
coddo
Bit
 
Joined: 23 Mar 2010
Location: Deva, Romania
Status: 0

Re: C#

Postby Payne » 12 Apr 2010, 22:02

Niciuna, chiar pot sa adaug date si alte chestii. Esti sigur ca unde e exe-ul e si database1.sdf?
0,0p / 0 votes
Suit up!
User avatar
Payne
Byte
 
Joined: 04 Jan 2010
Location: 0x7C00
Status: 17

Re: C#

Postby coddo » 12 Apr 2010, 22:21

Da, sunt perfect sigur, pentru ca am folosit installerul care mi le-o pus toate in acelasi loc :). Daca rulez programul cu debuggerul de la C#, mere perfect, altfel imi da eroarea asta.
uite ce eroare primesc eu.
In continuarea ei scrie:
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.IO.FileNotFoundException: Could not load file or assembly 'System.Data.SqlServerCe, Version=3.5.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Data.SqlServerCe, Version=3.5.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91'
at ZINGO.Database1DataSetTableAdapters.AngajatiTableAdapter.Fill(AngajatiDataTable dataTable)
at ZINGO.E1.Etest_Load(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].



************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:///C:/Windows/Microsoft.NET/Framework64/v2.0.50727/mscorlib.dll
----------------------------------------
ZINGO
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Program%20Files%20(x86)/Coddo/ZINGO/ZINGO.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Data
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:///C:/Windows/assembly/GAC_64/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
System.Data.DataSetExtensions
Assembly Version: 3.5.0.0
Win32 Version: 3.5.30729.4926 built by: NetFXw7
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Data.DataSetExtensions/3.5.0.0__b77a5c561934e089/System.Data.DataSetExtensions.dll
----------------------------------------
System.Core
Assembly Version: 3.5.0.0
Win32 Version: 3.5.30729.4926 built by: NetFXw7
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Core/3.5.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
0,0p / 0 votes
User avatar
coddo
Bit
 
Joined: 23 Mar 2010
Location: Deva, Romania
Status: 0

Re: C#

Postby Payne » 12 Apr 2010, 23:58

Sub ce framework il compilezi? 2.0 , 3.0 sau 3.5? eu sub 3.5.
0,0p / 0 votes
Suit up!
User avatar
Payne
Byte
 
Joined: 04 Jan 2010
Location: 0x7C00
Status: 17

Next

Return to .NET

Who is online

Users browsing this forum: No registered users and 0 guests