PDA

View Full Version : عدم خطا ولی کار نکردن کد



saba664
سه شنبه 30 آبان 1396, 07:59 صبح
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace finaldoctor2
{
public partial class Flogin : Form
{
public Flogin()
{
InitializeComponent();
}
LoginLogoutHandller LO = new LoginLogoutHandller();
ManegerHandller MH = new ManegerHandller();
ClerkHandller CH = new ClerkHandller ();
LoginLogout L;

private void login_Load(object sender, EventArgs e)
{
txtname.Enabled = false;
txtpass.Enabled = false;
}

private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
txtname.Enabled = true;
txtpass.Enabled = true;
}

private void button1_Click(object sender, EventArgs e)
{
//Fmainf m = new Fmainf();
// this.Hide();
// m.Show();


if (txtpass.Text != "" && txtname.Text != "")
{
if (radioButton1.Checked)
{

if (LO.loginManager(txtname.Text, txtpass.Text))
{
Initializer.Managerid = MH.Getid(txtname.Text, txtpass.Text);
Initializer.Clerkid = 0;
L = new LoginLogout(Initializer.shelltime() + " , " + DateTime.Now.ToShortTimeString(), "نامعلوم", Initializer.Clerkid , Initializer.Managerid );
LO.RecordTraffic(L);
//MessageBox.Show(id.ToString());
Fmainf f = new finaldoctor2.Fmainf();
this.Hide();
f.ShowDialog();
}
else
MessageBox.Show("نام کاربری یا رمز عبور در سیستم تعریف نشده است", "توجه ", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign);


}
else if (radioButton2.Checked)
{
if (LO.loginClerk (txtname.Text, txtpass.Text))
{
Initializer.Clerkid = CH.Getid(txtname.Text, txtpass.Text);
Initializer.Managerid = 0;
L = new LoginLogout(Initializer.shelltime() + " , " + DateTime.Now.ToShortTimeString(), "نامعلوم", Initializer.Clerkid , Initializer.Managerid );
LO.RecordTraffic(L);
//int id = CH.GetId(txtUserName.Text, txtPass.Text);
//MessageBox.Show(id.ToString());
Fclerk f = new finaldoctor2.Fclerk();
this.Hide();
f.ShowDialog();
}
else
MessageBox.Show("نام کاربری یا رمز عبور در سیستم تعریف نشده است", "توجه ", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign);

}
else
MessageBox.Show("لطفا یکی از آیتم های مدیر یا صندوق دار را انتخاب کنید", "توجه ", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign);
}
else
MessageBox.Show("رمز عبور یا نام کاربری را وارد کنید ");




}

private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
txtname.Enabled = true;
txtpass.Enabled = true;
}

private void button2_Click(object sender, EventArgs e)
{
txtname.Text = "";
txtpass.Text = "";
}

private void button3_Click(object sender, EventArgs e)
{
DialogResult dialog = MessageBox.Show("آیا مطمئن هستید؟", "خروج", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
if (dialog == DialogResult.Yes)
{
Application.Exit();
}
}
}
}




این کد منه

و کلاس هام هم به ترتیب

کلاس یوزر

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace finaldoctor2
{
public class User
{
protected string name;
public string Name
{
get { return name; }
set { name = value; }
}
protected string family;
public string Family
{
get { return family; }
set { family = value; }
}
protected string mobile;
public string Mobile
{
get { return mobile; }
set { mobile = value; }
}
protected string telwork;
public string Telwork
{
get { return telwork; }
set { telwork = value; }
}
protected string address;
public string Address
{
get { return address; }
set { address = value; }
}
protected string dateinsert;
public string Dateinsert
{
get { return dateinsert ; }
set { dateinsert = value; }
}
protected string nezam;
public string Nezam
{
get { return nezam; }
set { nezam = value; }
}
protected string code;
public string Code
{
get { return code ; }
set { code = value; }
}
protected string father;
public string Father
{
get { return father ; }
set { father = value; }
}
protected Boolean jenseyat;
public Boolean Jenseyat
{
get { return jenseyat ; }
set { jenseyat = value; }
}
protected string country;
public string Country
{
get { return country ; }
set { country = value; }
}
protected string shahrestan;
public string Shahrestan
{
get { return shahrestan ; }
set { shahrestan = value; }
}
protected string reshteh;
public string Reshteh
{
get { return reshteh; }
set { reshteh = value; }
}
protected Boolean madarak;
public Boolean Madarak
{
get { return madarak ; }
set { madarak = value; }
}
protected string vemployment;
public string Vemployment
{
get { return vemployment; }
set { vemployment = value; }
}
protected string khed1;
public string Khed1
{
get { return khed1 ; }
set { khed1 = value; }
}
protected string khed2;
public string Khed2
{
get { return khed2 ; }
set {khed2 = value; }
}
protected string khed3;
public string Khed3
{
get { return khed3 ; }
set { khed3 = value; }
}
protected string khed4;
public string Khed4
{
get { return khed4 ; }
set { khed4 = value; }
}
protected Boolean heat;
public Boolean Heat
{
get { return heat ; }
set { heat = value; }
}
protected Boolean matab;
public Boolean Matab
{
get { return matab ; }
set { matab = value; }
}
protected Boolean parvaneh;
public Boolean Parvaneh
{
get { return parvaneh ; }
set { parvaneh = value; }
}
protected Boolean vazeat;
public Boolean Vazeat
{
get { return vazeat ; }
set { vazeat = value; }
}
protected string mmt;
public string Mmt
{
get { return mmt ; }
set { mmt = value; }
}
protected byte photo;
public byte Photo
{
get { return photo ; }
set { photo = value; }
}
}
}

saba664
سه شنبه 30 آبان 1396, 08:03 صبح
کلاس دیتابیس

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data.Common;

namespace finaldoctor2
{
public class DataBase
{

public SqlConnection ObjCnn;
private SqlCommand ObjCmm = new SqlCommand();
private String CnnStr;
string str = @"Server=(local); Database=finaldoctor2; Integrated Security=TRUE";

public DataBase()
{
CnnStr = str;
ObjCnn = new SqlConnection();
ObjCnn.ConnectionString = CnnStr;
ObjCmm = new SqlCommand();
ObjCmm.Connection = ObjCnn;
}

public void Connect()
{
try
{
ObjCnn.Open();
}
catch
{
throw new Exception("ارتباط با پایگاه داده برقرار نشد.");
}
}


public void Disconnect()
{
try
{
ObjCnn.Close();
}
catch (Exception e)
{
ObjCnn.Dispose();//Releases all resources used by the Component.
throw new Exception(e.Message);
}
}

public void ExecuteSQL(string StrSQL)
{
Connect();
ObjCmm.CommandText = StrSQL;
try
{
ObjCmm.ExecuteNonQuery();
}
catch (Exception n)
{
throw new Exception("عملیات درج ثبت نشد.");

}
finally
{
Disconnect();
}
}



public DataTable ExecuteSelectSQL(string StrSQL)
{
DataTable DT = new DataTable();
SqlDataAdapter DA = new SqlDataAdapter();
DA.SelectCommand = ObjCmm;
DA.SelectCommand.CommandText = StrSQL;
try
{
Connect();
DA.SelectCommand.Connection = ObjCnn;
DA.Fill(DT);
return DT;
}

catch (Exception e)
{
throw new Exception(e.Message);
}
finally
{
Disconnect();
}
}


}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace finaldoctor2
{
public class ManegerHandller
{
private DataBase DBcnn;
private String StrSQL;

public ManegerHandller()
{
DBcnn = new DataBase();
StrSQL = "";
}

public Boolean Update(Maneger M)
{
Boolean b = false;
try
{
DataBase db = new DataBase();
string SQL = @"update Maneger set name=N'" + M.Name + "',family=N'" + M.Family + "',code=N'" + M.Code + "',username=N'" + M.UserName + "',password=N'" + M.Password + "' where code=N'" + M.Code + "'";
db.ExecuteSQL(SQL);
b = true;
}
catch (Exception cv)
{
b = false;
}
return b;
}


public DataTable ShowAll()
{
string Sq = "select * from Maneger ORDER BY name,family Asc";
System.Data.DataTable dt = new System.Data.DataTable();
try
{
dt = DBcnn.ExecuteSelectSQL(Sq);
}
catch (Exception ex)
{
dt = null;
}
return dt;
}



public int Getid(string username, string pass)
{
int n = 0;
string Sq = "select id from Maneger where username=N'" + username + "' and password='" + pass + "'";
System.Data.DataTable dt = new System.Data.DataTable();
try
{
dt = DBcnn.ExecuteSelectSQL(Sq);
if (dt.Rows.Count != 0)
{
foreach (DataRow row in dt.Rows)
foreach (var item in row.ItemArray)
n = int.Parse(item.ToString());
}
else
n = 0;
}
catch (Exception ex)
{
n = 0;
}
return n;
}

}
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace finaldoctor2
{
public class ClerkHandller
{
private DataBase DBcnn;
private String StrSQL;

public ClerkHandller()
{
DBcnn = new DataBase();
StrSQL = "";
}

public Boolean Insert (Clerk C)
{
Boolean b = false;
StrSQL = "Insert INTO Clerk VALUES (N'" + C.Name + "',N'" + C.Family + "',N'" + C.Dateinsert + "',N'" + C.UserName + "',N'" + C.Password + "',N'" + C.Code + "');";
try
{
DBcnn.ExecuteSQL(StrSQL);
b = true;
}
catch (Exception e)
{
b = false;

}
return b;
}


public Boolean Delete(string mellicode)
{
Boolean b = false;
string SS = "delete from Clerk where mellicode=N'" + mellicode + "';";
try
{
DBcnn.ExecuteSQL(SS);
b = true;
}
catch (Exception vv)
{
b = false;
}
return b;
}

public Boolean Update(string name, string family, string dateinsert, string username, string password, string mellicode)
{
Boolean b = false;
try
{
DataBase db = new DataBase();
string SQL = @"update clerk set name=N'" + name + "',family=N'" + family + "',mellicode=N'" + mellicode + "',username=N'" + username + "',password=N'" + password + "' where mellicode=N'" + mellicode + "'";
db.ExecuteSQL(SQL);
b = true;
}
catch (Exception cv)
{
b = false;
}
return b;
}



public Boolean Update(string NewPass,string oldPass, int clerkid)
{
Boolean b = false;
try
{
DataBase db = new DataBase();
if (db.ExecuteSelectSQL("select * from clerk where id=N'" + clerkid + "' and Password=N'" + oldPass + "'").Rows.Count != 0)
{
string SQL = @"update Clerk set password=N'" + NewPass + "' where id=N'" + clerkid + "'";
db.ExecuteSQL(SQL);
b = true;
}
else
b = false;
}
catch (Exception cv)
{
b = false;
}
return b;
}


public DataTable ShowAll(int clerkid)
{
string Sq = "select * from clerk where id=N'"+clerkid +"' ORDER BY Name,Family Asc";
System.Data.DataTable dt = new System.Data.DataTable();
try
{
dt = DBcnn.ExecuteSelectSQL(Sq);
}
catch (Exception ex)
{
dt = null;
}
return dt;
}


public DataTable ShowAll()
{
string Sq = "select * from clerk ORDER BY Name,Family Asc";
System.Data.DataTable dt = new System.Data.DataTable();
try
{
dt = DBcnn.ExecuteSelectSQL(Sq);
}
catch (Exception ex)
{
dt = null;
}
return dt;
}




public Boolean Exist(string mellicode)
{
Boolean b = false;
string Sq = "select * from clerk where mellicode='" + mellicode + "'";
System.Data.DataTable dt = new System.Data.DataTable();
try
{
dt = DBcnn.ExecuteSelectSQL(Sq);
if (dt.Rows.Count != 0)
b = true;
else
b = false;
}
catch (Exception ex)
{
dt = null;
}
return b;
}


public int Getid(string username,string pass)
{
int n = 0;
string Sq = "select id from clerk where username=N'" + username+ "' and password='"+pass+"'";
System.Data.DataTable dt = new System.Data.DataTable();
try
{
dt = DBcnn.ExecuteSelectSQL(Sq);
if (dt.Rows.Count != 0)
{
foreach (DataRow row in dt.Rows)
foreach (var item in row.ItemArray)
n = int.Parse(item.ToString());
}
else
n = 0;
}
catch (Exception ex)
{
n = 0;
}
return n;
}

}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace finaldoctor2
{
public class Clerk:User
{

string userName;
public string UserName
{
get { return userName; }
set { userName = value; }
}

string password;
public string Password
{
get { return password; }
set { password = value; }
}


public Clerk()
{
name = "";
family = "";
mobile = "";
dateinsert = "";
userName = "";
password = "";
code = "";
}

public Clerk(string Name, string Family, string DateInsert, string UserName, string Password, string Code)
{

name = Name;
family = Family;
dateinsert = DateInsert;
userName = UserName;
password = Password;
code = Code;
}

}
}


اینم کلاس login

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace finaldoctor2
{
public class LoginLogout
{
string dateLogIn;
public string DateLogIn
{
get { return dateLogIn; }
set { dateLogIn = value; }
}

string dateLogOut;

public string DateLogOut
{
get { return dateLogOut; }
set { dateLogOut = value; }
}
int clerkid;

public int Clerkid
{
get { return clerkid ; }
set { clerkid = value; }
}
int manid;

public int Manid
{
get { return manid; }
set { manid = value; }
}

public LoginLogout()
{
this.dateLogIn = "";
this.dateLogOut = "";
this.manid = 0;
this.clerkid = 0;
}

public LoginLogout(string DateLogIn, string DateLogOut, int Clerkid, int MSanId)
{
this.dateLogIn = DateLogIn;
this.dateLogOut = DateLogOut;
this.manid = MSanId;
this.clerkid = Clerkid;
}





}
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;


namespace finaldoctor2
{
public class LoginLogoutHandller
{

private DataBase DBcnn;
private String StrSQL;

public LoginLogoutHandller()
{
DBcnn = new DataBase();
StrSQL = "";
}

public Boolean RecordTraffic(LoginLogout L)
{
Boolean b = false;
StrSQL = "INSERT INTO loginlogout VALUES (N'" + L.DateLogIn + "',N'" + L.DateLogOut + "',N'" + L.Clerkid + "',N'" + L.Manid + "');";
try
{
DBcnn.ExecuteSQL(StrSQL);
b = true;
}
catch (Exception e)
{
b = false;
}
return b;
}



public Boolean loginClerk(string username, string pass)
{
Boolean b = false;
string Sq = "select id from Clerk where UserName=N'" + username + "' and Password=N'" + pass + "';";
System.Data.DataTable dt = new System.Data.DataTable();
try
{
dt = DBcnn.ExecuteSelectSQL(Sq);
if (dt.Rows.Count != 0)
{
b = true;
}
else
b = false;
}
catch (Exception ex)
{
b = false;
}
return b;
}


public Boolean loginManager(string username, string pass)
{
Boolean b = false;
string Sq = "select id from Manager where UserName=N'" + username + "' and Password=N'" + pass + "';";
System.Data.DataTable dt = new System.Data.DataTable();
try
{
dt = DBcnn.ExecuteSelectSQL(Sq);
if (dt.Rows.Count != 0)
{
b = true;
}
else
b = false;
}
catch (Exception ex)
{
b = false;
}
return b;
}
}
}

saba664
سه شنبه 30 آبان 1396, 08:06 صبح
کلاس مدیر و کابر عادی و لاگین نوشته شده بدون هیچ خطایی کد مربوط به فرم هم نوشته شده بدون هیچ خطایی بعد توی جدول اس کیو ال اسم خودمه تعریف کردم به عنوان مدیر ولی وقتی ورود می زنم میگه تعریف نشده همچین اسمی

saba664
شنبه 04 آذر 1396, 13:58 عصر
من این سوال رو چند روز پیش پرسیدم

الان جوابشو فهمیدم اینجا maneger رو اشتباه تایپی داشتم داخل کلاس loginhandller

public Boolean loginManeger(string username, string pass)
{
Boolean b = false;
string Sq = "select id from Maneger where UserName=N'" + username + "' and Password=N'" + pass + "';";
System.Data.DataTable dt = new System.Data.DataTable();
کد درست شد