#一个简单的三层架构之仓库管理系统的入库出库
今天来讲一下一个简单的三层架构的程序,一个仓库管理系统的简单的出库入库操作,还有供应商的信息录入。
欢迎大家添加 仓库管理系统群(matlab、c#、java均可,有需求请联系我们)721623451
首先是在sql中(access也行)中建表,建表的字段设计如下
包括4个表(实际上我建的不止,后期扩展的有供应商的表格等等,很多需要后期加表),分别是,货物属性信息表、进货入库表,出货出库表,用户信息表,以下详细说明我的每个表,以下所有的表id均为自动增加,不再说明
用户表:一共三个字段,用户名,用户密码,用户权限
进货表:入库编号、货物编号、货物名称、供应商名称、仓库名称、货物规格、计量单位、入库数量、入库价格、入库总金额、入库日期、经手人、备注
出货表:出库编号、仓库名称、货物名称、货物规格、计量单位、出库数量、出库价格、出库总金额、出库日期、提货单位、提货人、经手人、备注
货物信息表:货物编号、货物名称、仓库名称、货物规格、计量单位、货物数量、货物入库价格、货物出库价格、货物低线存储、货物顶线存储、记录修改人、修改日期
(供应商表不累加说明,自己按照之前的做就是了。很简单。)
界面设计:(我一开始做的比较丑,简单的功能先实现就好了)
主界面设计(多窗体(创建父窗体,子窗体等等))
好嘞,下面上代码!(记住要创建app.config文件记住配置,配置过程网上有)
class instoremodel
{
public string goodsname { get; set; }
public string prname { get; set; }
public string storename { get; set; }
public int goodsid { get; set; }
public string goodsspec { get; set; }
public string goodsunit { get; set; }
public int goodsnum { get; set; }
public decimal goodsprice { get; set; }
public decimal goodsaprice { get; set; }
public DateTime indate { get; set; }
public string handlepeople { get; set; }
public string inremark { get; set; }
}
class instoredal
{
public int addnew(instoremodel p)
{
object obg = null;
//sqlhelper h = new sqlhelper();
obg = sqlhelper.ExecuteScalar(
"insert into instore (goodsid,goodsname,prname,storename,goodsspec,goodsunit,goodsnum,goodsprice,goodsaprice,indate,handlepeople,remark) values" +
"(@goodsid,@goodsname,@prname,@storename,@goodsspec,@goodsunit,@goodsnum,@goodsprice,@goodsaprice,@indate,@handlepeople,@remark);select @@identity"
, new System.Data.SqlClient.SqlParameter("goodsid",p.goodsid), new System.Data.SqlClient.SqlParameter("goodsname", p.goodsname)
, new System.Data.SqlClient.SqlParameter("prname", p.prname), new System.Data.SqlClient.SqlParameter("goodsspec", p.goodsspec)
, new System.Data.SqlClient.SqlParameter("storename", p.storename), new System.Data.SqlClient.SqlParameter("goodsunit", p.goodsunit)
, new System.Data.SqlClient.SqlParameter("goodsnum", p.goodsnum), new System.Data.SqlClient.SqlParameter("goodsprice", p.goodsprice)
, new System.Data.SqlClient.SqlParameter("goodsaprice", p.goodsaprice), new System.Data.SqlClient.SqlParameter("indate", p.indate)
, new System.Data.SqlClient.SqlParameter("handlepeople", p.handlepeople), new System.Data.SqlClient.SqlParameter("remark", p.inremark)
);
return Convert.ToInt32(obg);
}
public int delect(int goodsid)
{
return sqlhelper.ExecuteNonQuery("delete from instore where inid=@inid", new System.Data.SqlClient.SqlParameter("inid", goodsid));
}
public int update(instoremodel p)
{
return sqlhelper.ExecuteNonQuery("update instore set goodsid=@goodsid,goodsname=@goodsname,prname=@prname," +
"storename=@storename,goodsspec=@goodsspec,goodsunit=@goodsunit,goodsnum=@goodsnum,goodsprice=goodsprice," +
"goodsaprice=@goodsaprice,indate=@indate,handlepeople=@handlepeople,remark=@remark" +
" where goodsid=@goodsid"
, new System.Data.SqlClient.SqlParameter("goodsid", p.goodsid), new System.Data.SqlClient.SqlParameter("goodsname", p.goodsname)
, new System.Data.SqlClient.SqlParameter("prname", p.prname), new System.Data.SqlClient.SqlParameter("goodsspec", p.goodsspec)
, new System.Data.SqlClient.SqlParameter("storename", p.storename), new System.Data.SqlClient.SqlParameter("goodsunit", p.goodsunit)
, new System.Data.SqlClient.SqlParameter("goodsnum", p.goodsnum), new System.Data.SqlClient.SqlParameter("goodsprice", p.goodsprice)
, new System.Data.SqlClient.SqlParameter("goodsaprice", p.goodsaprice), new System.Data.SqlClient.SqlParameter("indate", p.indate)
, new System.Data.SqlClient.SqlParameter("handlepeople", p.handlepeople), new System.Data.SqlClient.SqlParameter("remark", p.inremark)
);
}
public instoremodel get(int goodsid)
{
DataTable data = sqlhelper.ExecuteDataTable("select * from instore where goodsid=@goodsid", new System.Data.SqlClient.SqlParameter
("goodsid", goodsid));
if (data.Rows.Count <= 0)
return null;
else if (data.Rows.Count == 1)
{
instoremodel result = new instoremodel();
DataRow r = data.Rows[0];
result.goodsid = (int )r["goodsid"];
result.goodsaprice = (decimal)r["goodsaprice"];
result.goodsname = (string)r["goodsname"];
result.goodsnum = (int )r["goodsnum"];
result.goodsprice = (decimal)r["goodsprice"];
result.goodsspec = (string)r["goodsspec"];
result.goodsunit = (string)r["goodsunit"];
result.handlepeople= (string)r["handlepeople"];
result.indate = (DateTime)r["indate"];
result.inremark= (string)r["remark"];
result.prname= (string)r["prname"];
result.storename = (string)r["storename"];
return result;
}
else
throw new Exception("出现多条数据!");
}
public DataTable get()
{
DataTable dt = sqlhelper.ExecuteDataTable("select inid as '入库编号',goodsid as '货物编号',goodsname as '货物名称',prname as '供应商',storename as '仓库名称'," +
"goodsspec as '货物规格',goodsunit as '计量单位',goodsnum as '货物数量',goodsprice as '货物价格',goodsaprice" +
" as '货物总价格' ,indate as '入库时间',handlepeople as '经手人',remark as '备注' from instore");
return dt;
}
}
class outstore
{
public string storename { get; set; }
public string goodsname { get; set; }
public string goodsspec { get; set; }
public string goodsunit { get; set; }
public int goodsnum { get; set; }
public decimal goodsprice { get; set; }
public decimal goodsaprice { get; set; }
public DateTime outdate { get; set; }
public string pgprovider { get; set; }
public string pgpeople { get; set; }
public string handlepeople { get; set; }
public string remark { get; set; }
}
public int addnew(outstore p)
{
object obg = null;
//sqlhelper h = new sqlhelper();
obg = sqlhelper.ExecuteScalar(
"insert into outstore (goodsname,pgprovider,pgpeople,storename,goodsspec,goodsunit,goodsnum,goodsprice,goodsaprice,outdate,handlepeople,remark) values" +
"(@pgpeople,@goodsname,@pgprovider,@storename,@goodsspec,@goodsunit,@goodsnum,@goodsprice,@goodsaprice,@outdate,@handlepeople,@remark);select @@identity"
, new System.Data.SqlClient.SqlParameter("pgpeople", p.pgpeople), new System.Data.SqlClient.SqlParameter("goodsname", p.goodsname)
, new System.Data.SqlClient.SqlParameter("pgprovider", p.pgprovider), new System.Data.SqlClient.SqlParameter("goodsspec", p.goodsspec)
, new System.Data.SqlClient.SqlParameter("storename", p.storename), new System.Data.SqlClient.SqlParameter("goodsunit", p.goodsunit)
, new System.Data.SqlClient.SqlParameter("goodsnum", p.goodsnum), new System.Data.SqlClient.SqlParameter("goodsprice", p.goodsprice)
, new System.Data.SqlClient.SqlParameter("goodsaprice", p.goodsaprice), new System.Data.SqlClient.SqlParameter("outdate", p.outdate)
, new System.Data.SqlClient.SqlParameter("handlepeople", p.handlepeople), new System.Data.SqlClient.SqlParameter("remark", p.remark)
);
return Convert.ToInt32(obg);
}
public int delect(int goodsid)
{
return sqlhelper.ExecuteNonQuery("delete from outstore where outid=@outid", new System.Data.SqlClient.SqlParameter("outid", goodsid));
}
public int update(outstore p)
{
return sqlhelper.ExecuteNonQuery("update instore set pgprovider=@pgprovider,goodsname=@goodsname,pgpeople=@pgpeople," +
"storename=@storename,goodsspec=@goodsspec,goodsunit=@goodsunit,goodsnum=@goodsnum,goodsprice=goodsprice," +
"goodsaprice=@goodsaprice,outdate=@outdate,handlepeople=@handlepeople,remark=@remark" +
" where goodsid=@goodsid"
, new System.Data.SqlClient.SqlParameter("pgprovider", p.pgprovider), new System.Data.SqlClient.SqlParameter("goodsname", p.goodsname)
, new System.Data.SqlClient.SqlParameter("pgpeople", p.pgpeople), new System.Data.SqlClient.SqlParameter("goodsspec", p.goodsspec)
, new System.Data.SqlClient.SqlParameter("storename", p.storename), new System.Data.SqlClient.SqlParameter("goodsunit", p.goodsunit)
, new System.Data.SqlClient.SqlParameter("goodsnum", p.goodsnum), new System.Data.SqlClient.SqlParameter("goodsprice", p.goodsprice)
, new System.Data.SqlClient.SqlParameter("goodsaprice", p.goodsaprice), new System.Data.SqlClient.SqlParameter("outdate", p.outdate)
, new System.Data.SqlClient.SqlParameter("handlepeople", p.handlepeople), new System.Data.SqlClient.SqlParameter("remark", p.remark)
);
}
public outstore get(int outid)
{
DataTable data = sqlhelper.ExecuteDataTable("select * from outstore where outid=@outid", new System.Data.SqlClient.SqlParameter
("outid", outid));
if (data.Rows.Count <= 0)
return null;
else if (data.Rows.Count == 1)
{
outstore result = new outstore();
DataRow r = data.Rows[0];
result.pgprovider = (string)r["pgprovider"];
result.goodsaprice = (decimal)r["goodsaprice"];
result.goodsname = (string)r["goodsname"];
result.goodsnum = (int)r["goodsnum"];
result.goodsprice = (decimal)r["goodsprice"];
result.goodsspec = (string)r["goodsspec"];
result.goodsunit = (string)r["goodsunit"];
result.handlepeople = (string)r["handlepeople"];
result.outdate = (DateTime)r["outdate"];
result.remark = (string)r["remark"];
result.pgpeople = (string)r["pgpeople"];
result.storename = (string)r["storename"];
return result;
}
else
throw new Exception("出现多条数据!");
}
public DataTable get()
{
DataTable dt = sqlhelper.ExecuteDataTable("select outid as '出库编号',pgprovider as '提货单位',goodsname as '货物名称',pgpeople as '提货人',storename as '仓库名称'," +
"goodsspec as '货物规格',goodsunit as '计量单位',goodsnum as '货物数量',goodsprice as '货物价格',goodsaprice" +
" as '货物总价格' ,outdate as '出库时间',handlepeople as '经手人',remark as '备注' from outstore");
return dt;
}
}
class provider
{
public string providername { get; set; }
public string phone { get; set; }
public string manager { get; set; }
public string remark { get; set; }
public int providerid { get; set; }
}
class providerdal
{
public int addnew(provider p)
{
object obg = null;
//sqlhelper h = new sqlhelper();
obg = sqlhelper.ExecuteScalar(
"insert into goodsprovider (providername,manager,phone,remark) values(@providername,@manager,@phone,@remark);select @@identity"
, new System.Data.SqlClient.SqlParameter("providername", p.providername), new System.Data.SqlClient.SqlParameter("manager", p.manager)
, new System.Data.SqlClient.SqlParameter("phone", p.phone), new System.Data.SqlClient.SqlParameter("remark", p.remark)
);
return Convert.ToInt32(obg);
}
public int delect(string providername)
{
return sqlhelper.ExecuteNonQuery("delete from goodsprovider where providername=@providername", new System.Data.SqlClient.SqlParameter("providername", providername));
}
public int update(provider p)
{
return sqlhelper.ExecuteNonQuery("update users set providername=@providername ,manager=@manager ,phone=@phone,remark=@remark,providerid=@providerid" +
" where providerid=@providerid",
new System.Data.SqlClient.SqlParameter("providername", p.providername), new System.Data.SqlClient.SqlParameter("manager", p.manager)
, new System.Data.SqlClient.SqlParameter("phone", p.phone)
, new System.Data.SqlClient.SqlParameter("remark", p.remark)
, new System.Data.SqlClient.SqlParameter("providerid", p.providerid)
);
}
public provider get(string providername)
{
DataTable data = sqlhelper.ExecuteDataTable("select * from users where providername=@providername", new System.Data.SqlClient.SqlParameter("providername", providername));
if (data.Rows.Count <= 0)
return null;
else if (data.Rows.Count == 1)
{
provider result = new provider();
DataRow r = data.Rows[0];
result.providername = (string)r["providername"];
result.manager = (string)r["manager"];
result.phone = (string)r["phone"];
result.remark = (string)r["remark"];
result.providerid = (Int32)r["providerid"];
return result;
}
else
throw new Exception("出现多条数据!");
}
public DataTable get()
{
DataTable dt = sqlhelper.ExecuteDataTable("select providername as '供应商名称' ,manager as'负责人' ,phone as'电话',remark as'备注' from goodsprovider");
return dt;
}
}
class sqlhelper
{
private static readonly string connstr= ConfigurationManager.ConnectionStrings["connstr"].ConnectionString;
public static int ExecuteNonQuery(string cmdText,
params SqlParameter[] parameters)
{
using (SqlConnection conn = new SqlConnection(connstr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = cmdText;
cmd.Parameters.AddRange(parameters);
return cmd.ExecuteNonQuery();
}
}
}
public static object ExecuteScalar(string cmdText,
params SqlParameter[] parameters)
{
using (SqlConnection conn = new SqlConnection(connstr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = cmdText;
cmd.Parameters.AddRange(parameters);
return cmd.ExecuteScalar();
}
}
}
public static DataTable ExecuteDataTable(string cmdText,
params SqlParameter[] parameters)
{
using (SqlConnection conn = new SqlConnection(connstr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = cmdText;
cmd.Parameters.AddRange(parameters);
using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
adapter.Fill(dt);
return dt;
}
}
}
}
public static SqlDataReader ExecuteDataReader(string cmdText,
params SqlParameter[] parameters)
{
SqlConnection conn = new SqlConnection(connstr);
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = cmdText;
cmd.Parameters.AddRange(parameters);
return cmd.ExecuteReader(CommandBehavior.CloseConnection);
}
}
}