public Boolean addbook(string txtBookcode, string txtBookname, string txtbookauthor, string txtbooktitle, string txtbooktranslater, string txtpublisher, string txtyear, string txtshabak, string txtbookcategory, int txtPublish_Number) { { SqlCommand sqlcmd = new SqlCommand(); sqlcmd.Connection = sqlcon; sqlcmd.CommandType = CommandType.StoredProcedure; sqlcmd.CommandText = "Insert_Book"; sqlcmd.Parameters.Add("@Code", SqlDbType.Int).Value = int.Parse(txtBookcode); sqlcmd.Parameters.Add("@Name", SqlDbType.NVarChar, 50).Value = txtBookname; sqlcmd.Parameters.Add("@Author", SqlDbType.NVarChar, 50).Value = txtbookauthor; sqlcmd.Parameters.Add("@Title", SqlDbType.NVarChar, 50).Value = txtbooktitle; sqlcmd.Parameters.Add("@Translater", SqlDbType.NVarChar, 50).Value = txtbooktranslater; sqlcmd.Parameters.Add("@Publisher", SqlDbType.NVarChar, 50).Value = txtpublisher; sqlcmd.Parameters.Add("@Publish_Year", SqlDbType.NVarChar, 50).Value = txtyear; sqlcmd.Parameters.Add("@SHABAK", SqlDbType.NVarChar, 50).Value = txtshabak; sqlcmd.Parameters.Add("@Category", SqlDbType.NVarChar, 50).Value = txtbookcategory; sqlcmd.Parameters.Add("@Publish_Number", SqlDbType.Int).Value = txtPublish_Number; sqlcmd.Parameters.Add("@r", SqlDbType.Int).Direction = ParameterDirection.ReturnValue; sqlcmd.Parameters.Add("@Reserved", SqlDbType.Bit).Value = false; sqlcmd.Parameters.Add("@Deposited", SqlDbType.Bit).Value = false; sqlcon.Open(); sqlcmd.ExecuteNonQuery(); if (sqlcmd.Parameters["@r"].Value.ToString() == "1") { return(true); lib lib1 = new lib(1); } else { return(false); } sqlcon.Close(); } }
private void btnAdd_Click(object sender, EventArgs e) { if (txtBookcode.Text == "" || txtBookname.Text == "" || txtbookauthor.Text == "" || txtpublisher.Text == "" || txtyear.Text == "" || txtPublish_Number.Text == "" || txtPublish_Number.Text == "") { MessageBox.Show("لطفا فیلد های ستاره دار را پر نمایید "); } else { SqlCommand sqlcmd = new SqlCommand(); sqlcmd.Connection = sqlcon; sqlcmd.CommandType = CommandType.StoredProcedure; sqlcmd.CommandText = "Insert_Book"; sqlcmd.Parameters.Add("@Code", SqlDbType.Int).Value = int.Parse(txtBookcode.Text); sqlcmd.Parameters.Add("@Name", SqlDbType.NVarChar, 50).Value = txtBookname.Text; sqlcmd.Parameters.Add("@Author", SqlDbType.NVarChar, 50).Value = txtbookauthor.Text; sqlcmd.Parameters.Add("@Title", SqlDbType.NVarChar, 50).Value = txtbooktitle.Text; sqlcmd.Parameters.Add("@Translater", SqlDbType.NVarChar, 50).Value = txtbooktranslater.Text; sqlcmd.Parameters.Add("@Publisher", SqlDbType.NVarChar, 50).Value = txtpublisher.Text; sqlcmd.Parameters.Add("@Publish_Year", SqlDbType.NVarChar, 50).Value = txtyear.Text; sqlcmd.Parameters.Add("@SHABAK", SqlDbType.NVarChar, 50).Value = txtshabak.Text; sqlcmd.Parameters.Add("@Category", SqlDbType.NVarChar, 50).Value = txtbookcategory.Text; sqlcmd.Parameters.Add("@Publish_Number", SqlDbType.Int).Value = txtPublish_Number.Text; sqlcmd.Parameters.Add("@r", SqlDbType.Int).Direction = ParameterDirection.ReturnValue; sqlcmd.Parameters.Add("@Reserved", SqlDbType.Bit).Value = false; sqlcmd.Parameters.Add("@Deposited", SqlDbType.Bit).Value = false; sqlcon.Open(); sqlcmd.ExecuteNonQuery(); if (sqlcmd.Parameters["@r"].Value.ToString() == "1") { MessageBox.Show("با موفیت درج شد"); lib lib1 = new lib(1); } else { MessageBox.Show("این کتاب وجود دارد"); } sqlcon.Close(); } defaultview(); clear(); }