private void btninsert_Click(object sender, EventArgs e)
{
string check = br.createreceipt(int.Parse(txtreceptcode.Text),
int.Parse(comboBox_kala.SelectedValue.ToString()),
int.Parse(comboBox_suplier.SelectedValue.ToString()
), int.Parse(txtqty.Text), DateTime.Parse(dateTimePicker_recept.Text));
if (check == "true")
{
dtrecept = br.getdata();
dataGridViewrecept.DataSource = dtrecept;
txtreceptcode.Text = null;
txtqty.Text = null;
}
}
kala表格
private void btnkalainsert_Click(object sender, EventArgs e)
{
string check = bk.createkala(int.Parse(txtkalacode.Text), txtkalaname.Text, int.Parse(txtkqty.Text),
int.Parse(txtkalapoint.Text));
if (check=="true")
{
dt = bk.Getdata();
dataGridViewkala.DataSource = dt;
}
else
{
MessageBox.Show(check);
}
}
接待DAL:
namespace DAL
{
public class TblreceiptionDal
{
SqlConnection cn=new SqlConnection("Data Source=(local);Initial Catalog=store;Integrated Security=true");
public DataTable getall()
{
DataSet ds=new DataSet();
SqlDataAdapter sa = new SqlDataAdapter("Spinforeceip", cn);
sa.SelectCommand.CommandType = CommandType.StoredProcedure;
sa.Fill(ds, "Spinforeceip");
return ds.Tables["Spinforeceip"];
}
public string createreceipt(int recept_id,int kala_id,int suplier_id,int recept_qty ,DateTime recept_date)
{
try
{
SqlCommand cmd = new SqlCommand("Sptblreception_insert", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@recept_id", recept_id);
cmd.Parameters.AddWithValue("@kala_id", kala_id);
cmd.Parameters.AddWithValue("@suplier_id", suplier_id);
cmd.Parameters.AddWithValue("@recept_qty", recept_qty);
cmd.Parameters.AddWithValue("@recept_date", recept_date);
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
return "true";
}
catch (Exception ex)
{
return ex.Message;
throw;
}
}
public String deletereceipt(int recept_id)
{
try
{
SqlCommand cmd = new SqlCommand("Sptblreception_delete",cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@recept_id", recept_id);
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
return "true";
}
catch (Exception ex)
{
return ex.Message;
throw;
}
}
public string updatereceipt(int recept_id,int kala_id,int suplier_id,int recept_qty ,DateTime recept_date)
{
try
{
SqlCommand cmd = new SqlCommand("Sptblreception_update", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@recept_id", recept_id);
cmd.Parameters.AddWithValue("@kala_id", kala_id);
cmd.Parameters.AddWithValue("@suplier_id", suplier_id);
cmd.Parameters.AddWithValue("@recept_qty", recept_qty);
cmd.Parameters.AddWithValue("@recept_date", recept_date);
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
return "true";
}
catch (Exception ex)
{
return ex.Message;
throw;
}
}
public string receptgetbyid(int recept_id)
{
try
{
SqlCommand cmd = new SqlCommand("Sptblreception_getbyid",cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@recept_id", recept_id);
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
return "true";
}
catch (Exception ex)
{
return ex.Message;
throw;
}
}
}
}
接待BLL:
namespace BLL
{
public class Bllreceipt
{
TblreceiptionDal tr = new TblreceiptionDal();
public DataTable getdata()
{
return tr.getall();
}
public string createreceipt(int recept_id,int kala_id,int suplier_id,int recept_qty ,DateTime recept_date)
{
return tr.createreceipt(recept_id, kala_id, suplier_id, recept_qty, recept_date);
}
public String deletereceipt(int recept_id)
{
return tr.deletereceipt(recept_id);
}
public string updatereceipt(int recept_id,int kala_id,int suplier_id,int recept_qty ,DateTime recept_date)
{
return tr.updatereceipt(recept_id, kala_id, suplier_id, recept_qty, recept_date);
}
public string receptgetbyid(int recept_id)
{
return tr.receptgetbyid(recept_id);
}
}
}
kala DAL:
namespace DAL
{
public class TblkalaDal
{
SqlConnection cn=new SqlConnection("Data Source=(local); Initial Catalog=store;Integrated Security=True");
public DataTable Getdata()
{
try
{
DataSet ds=new DataSet();
SqlDataAdapter da = new SqlDataAdapter("Sptblkala_getdata",cn);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.Fill(ds, "Sptblkala_getdata");
return ds.Tables["Sptblkala_getdata"];
}
catch (Exception)
{
return null;
throw;
}
}
public string createkala(int kala_id,string kala_name,int kala_qty,int kala_orderpoint)
{
try
{
SqlCommand cmd = new SqlCommand("Sptblkala_insert", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@kala_id", kala_id);
cmd.Parameters.AddWithValue("@kala_name", kala_name);
cmd.Parameters.AddWithValue("@kala_qty", kala_qty);
cmd.Parameters.AddWithValue("@kala_orderpoint", kala_orderpoint);
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
return "true";
}
catch (Exception ex)
{
return ex.Message;
throw;
}
}
public string Deletekala(int kala_id)
{
try
{
SqlCommand dm = new SqlCommand("Sptblkala_delete", cn);
dm.CommandType = CommandType.StoredProcedure;
dm.Parameters.AddWithValue("@kala_id", kala_id);
cn.Open();
dm.ExecuteNonQuery();
cn.Close();
return "true";
}
catch (Exception ex)
{
return ex.Message;
throw;
}
}
public string updatekala(int kala_id,string kala_name,int kala_qty,int kala_orderpoint)
{
try
{
SqlCommand uk = new SqlCommand("Sptblkala_update", cn);
uk.CommandType = CommandType.StoredProcedure;
uk.Parameters.AddWithValue("@kala_id", kala_id);
uk.Parameters.AddWithValue("@kala_name", kala_name);
uk.Parameters.AddWithValue("@kala_qty", kala_qty);
uk.Parameters.AddWithValue("@kala_orderpoint", kala_orderpoint);
cn.Open();
uk.ExecuteNonQuery();
cn.Close();
return "true";
}
catch (Exception)
{
throw;
}
}
}
}
Kala BLL:
namespace BLL
{
public class bllkala
{
TblkalaDal tk=new TblkalaDal();
public string createkala(int kala_id,string kala_name,int kala_qty,int kala_orderpoint)
{
return tk.createkala(kala_id, kala_name, kala_qty, kala_orderpoint);
}
public string deletekala(int kala_id)
{
return tk.Deletekala(kala_id);
}
public string updatekala(int kala_id,string kala_name,int kala_qty,int kala_orderpoint)
{
return tk.updatekala(kala_id, kala_name, kala_qty, kala_orderpoint);
}
public DataTable Getdata()
{
return tk.Getdata();
}
}
}
答案 0 :(得分:0)
您可以使用此解决方案:
Form frm = Application.OpenForms["formName"];
TextBox txt = (TextBox)frm.Controls.Find("textboxName",true)[0];
txt.Text = "yourValue";
请注意,此代码不安全,请自行执行安全部件(尝试捕获可能是很好的方法,您也可以通过检查if / else块中容易出错的部分来实现)