نمایش نتایج 1 تا 8 از 8

نام تاپیک: مشکل در قسمت ثبت کتاب

Threaded View

پست قبلی پست قبلی   پست بعدی پست بعدی
  1. #1
    کاربر دائمی آواتار AliRezaPro
    تاریخ عضویت
    شهریور 1386
    محل زندگی
    PE Header
    پست
    1,054

    مشکل در قسمت ثبت کتاب

    سلام دوستان
    این جدول من هست(عکس)

    و این هم کدی که نوشتم:
    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;
    using System.Data.SqlClient;

    namespace Library
    {
    public partial class trusteeshipRegister : Form
    {
    public string StrConnection = "server=(local);database=Library;trusted_connectio n=yes";

    SqlDataReader Reader;
    bool boolCheckExistUsr = false;
    bool boolCheckExistBook = false;

    public bool CheckForExistUser()
    {
    using (SqlConnection Connection = new SqlConnection(StrConnection))
    {
    int IDForUser = Int32.Parse(txtIdozviat.Text);
    SqlCommand objCommand = new SqlCommand();
    objCommand.Connection = Connection;
    objCommand.CommandType = CommandType.Text;
    objCommand.CommandText = "select ID,FirstName,LastName from RegisterUser where ID='" + IDForUser + "'AND FirstName='" + txtName.Text + "' AND LastName='" + txtFamilyName.Text + "'";

    Connection.Open();
    Reader = objCommand.ExecuteReader();
    if (Reader.HasRows == true)
    {

    label1.BackColor = Color.Green;
    label1.Text = "وجود دارد";
    label2.BackColor = Color.Green;
    label2.Text = "وجود دارد";
    boolCheckExistUsr = true;
    return boolCheckExistUsr;

    }

    else
    {
    label2.BackColor = Color.Red;
    label2.Text = "وجود ندارد";
    label1.BackColor = Color.Red;
    label1.Text = "وجود ندارد";
    boolCheckExistUsr = false;
    return boolCheckExistUsr;

    }

    }
    }

    private bool CheckExisBook()
    {
    using (SqlConnection Connection = new SqlConnection(StrConnection))
    {
    int IdForBook = Int32.Parse(txtNumberKetab.Text);
    SqlCommand objCommand = new SqlCommand();
    objCommand.Connection = Connection;
    objCommand.CommandType = CommandType.Text;
    objCommand.CommandText = "select IDBook,BookName from BookDetails where IDBook='" + IdForBook + "' AND BookName='" + txtNameBook.Text + "'";
    Reader = null;
    Reader.Close();
    if (Connection.State != ConnectionState.Open)
    Connection.Open();

    Reader = objCommand.ExecuteReader();

    if (Reader.HasRows == true)
    {
    label3.BackColor = Color.Green;
    label3.Text = label2.Text = "وجود دارد";
    boolCheckExistBook = true;
    return boolCheckExistBook;

    }
    else
    {
    label3.BackColor = Color.Red;
    label3.Text = "وجود ندارد";
    boolCheckExistBook = false;
    return boolCheckExistBook;
    }
    }
    }
    public trusteeshipRegister()
    {
    InitializeComponent();
    }


    private void button1_Click(object sender, EventArgs e)
    {
    using (SqlConnection objConnection = new SqlConnection(StrConnection))
    {
    if ((txtName.Text.Length > 0) && (txtFamilyName.Text.Length > 0) && (txtNameBook.Text.Length > 0) && (txtToDate_Masked.Text.Length > 0) && (txtDateAmanat_Masked.Text.Length > 0))
    {
    CheckForExistUser();
    CheckExisBook();
    if (boolCheckExistUsr == true && boolCheckExistBook == true)
    {
    int IdForBook = Int32.Parse(txtNumberKetab.Text );
    int IdUser = Int32.Parse(txtIdozviat.Text);
    try
    {
    SqlCommand objCommand = new SqlCommand();
    objCommand.CommandType = CommandType.Text;
    objCommand.Connection = objConnection;
    objCommand.CommandText = "insert into SabteAmanat (BookName,BookSubject,author,Translator,FirstName, LastName,membershipID,Tozihat,DateAmanat,DateBack, IdBook) values (@ID,@BookName,@BookSubject,@author,@Translator,@F irstName,@LastName,@membershipID,@Tozihat,@DateAma nat,@DateBack,@IdBook)";
    objCommand.Parameters.AddWithValue("@BookName", txtNameBook.Text);
    objCommand.Parameters.AddWithValue("@BookSubject", txtSubjectbook.Text);
    objCommand.Parameters.AddWithValue("@author", txtauthor.Text);
    objCommand.Parameters.AddWithValue("@Translator", txtTranslator.Text);
    objCommand.Parameters.AddWithValue("@FirstName", txtName.Text);
    objCommand.Parameters.AddWithValue("@LastName", txtFamilyName.Text);
    objCommand.Parameters.AddWithValue("@membershipID" , IdUser);
    objCommand.Parameters.AddWithValue("@Tozihat", txtDescribe.Text);
    objCommand.Parameters.AddWithValue("@DateAmanat", txtDateAmanat_Masked.Text);
    objCommand.Parameters.AddWithValue("@DateBack", txtToDate_Masked.Text);
    objCommand.Parameters.AddWithValue("@IdBook", IdForBook);

    if (objConnection.State != ConnectionState.Open)
    objConnection.Open();

    objCommand.ExecuteNonQuery();
    objConnection.Close();
    }
    catch (SqlException ee)
    {
    MessageBox.Show(ee.Message);
    }
    MessageBox.Show("امانت در دیتابیس ذخیره شد");
    }
    else
    {
    MessageBox.Show("مقادیر وارد شده صحیح نمی باشند");
    }


    }
    else
    {
    MessageBox.Show("لطفا جاهای خالی را پر کنید");
    } objConnection.Close();
    }
    }
    }
    }

    وقتی میخوام اینسرت کنم میگه مقادیر وارد شده صحیح نمی باشد(قسمت CheckExisBook()) !(مقادیر ابتدا چک میشوند اگر صحیح بود مقدار بولین ها ترو میشود)
    در صورتی که هر چی وارد میکنم درسته
    راستش تازه 2ماه و خوردی هست که کلا دارم کار میکنم بنابراین الگوریتمی که به ذهنم رسید همین کدی هست که دارید می بینید
    پس اگه یه فکر بهتر هم دارید بگید
    و بگید کجای کار مشکل داره ...
    آخرین ویرایش به وسیله AliRezaPro : شنبه 28 شهریور 1388 در 18:46 عصر

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •