修改调拨
修改调拨界面见下图:
选择调入仓要注意仓库的容量。
选择调出仓要注意该仓库的配件库存数。
调入仓与调出仓不能相同。
从【调拨修改】界面看到控件有:
控件 | 说明 |
文本框(TextBox) | 编辑控件可以在工具箱直接拖动至窗体,拖至窗体后右击属性可以修改控件的样式和各种属性,还可以设置事件。 |
下拉框(ComboBox) | |
日期控件(DateTimePicKer) | |
表格(DataGridView) | |
按钮(Button) |
1、数据库功能实现
第一步:数据库
1、表和关系
表1、调拨单表(PW_AllotRecordList)
列名 | 数据类型 | 主键/外键 | 说明 |
AllotRecordID | int - Identity | 主键 | 调拨单ID |
AllotOddNumbers | nchar (20) |
| 调拨单号 |
AllotData | datetime |
| 调拨日期 |
AllotGross | decimal (18, 2) |
| 调拨总量 |
DrawUp_StaffID | int | 外键 | 员工档案表,制单人_员工ID |
ExAminePerson_StaffID | int | 外键 | 员工档案表,核准人_员工ID |
IfEffective | bit |
| 有效否 |
表2、调拨单明细表(PW_AllotRecordMinuteList)
列名 | 数据类型 | 主键/外键 | 说明 |
AllotRecordMinuteID | int - Identity | 主键 | 调拨单明细ID |
AllotRecordID | int | 外键 | 调拨单表,调拨单ID |
PartsID | int | 外键 | 配件表,配件ID |
StorageID_ComeInStorage | int | 外键 | 仓库表,仓库ID_调入仓 |
StorageID_GoOutStorage | int | 外键 | 仓库表,仓库ID_调出仓 |
Quantity | decimal (18, 2) |
| 数量 |
表3、配件表(BM_PartsList)
列名 | 数据类型 | 主键/外键 | 说明 |
PartsID | int - Identity | 主键 | 配件ID |
PartsCoding | nchar (20) |
| 配件代码 |
PartsName | nchar (20) |
| 配件名称 |
CarModels | nchar (20) |
| 车型 |
Specification | nchar (20) |
| 规格 |
AttributeMinuteID_Unit | int | 外键 | 属性明细表,属性明细ID_单位 |
SellPrice | nchar (20) |
| 销售价格 |
表4:员工档案表(BM_StaffRecordList)
列名 | 数据类型 | 主键/外键 | 说明 |
StaffID | int - Identity | 主键 | 员工ID |
StaffBasicDataID | int | 外键 | 员工基本资料表,员工基本资料ID |
StaffNumber | nchar (20) |
| 员工编号 |
SuperiorCode | nchar (20) |
| 上级代码 |
StaffName | nchar (20) |
| 员工姓名 |
TheGenusShop | nchar (50) |
| 所属门店 |
SectionID | int | 外键 | 部门表,部门ID |
TeamID | int | 外键 | 班组表,班组ID |
OtherLinkWay | nchar (50) |
| 其他联系方式 |
MonthRestDay | datetime |
| 月休息日 |
StartWorkTime | datetime |
| 从业时间 |
BasicWages | decimal (18, 2) |
| 基本工资 |
OtherWages | decimal (18, 2) |
| 其他工资 |
IfApprentice | bit |
| 是否学徒 |
IfServiceman | bit |
| 是否维修技工 |
IfCanGet | bit |
| 是否可领料 |
IfInspectorGeneral | bit |
| 是否总检人 |
IfTestRun | bit |
| 是否试车人 |
IfSalesman | bit |
| 是否业务员 |
IfLeaveOffice | bit |
| 离职否 |
StaffPicture | nchar (1000) |
| 员工照片 |
表5、仓库表(BM_StorageList)
列名 | 数据类型 | 主键/外键 | 说明 |
StorageID | int - Identity | 主键 | 仓库ID |
StorageName | nchar (20) |
| 仓库名 |
Dimension | decimal (18, 2) |
| 容积 |
2、功能实现
1、窗体加载事件,绑定数据。
第一步:数据库存储过程
IF(@TYPE='DiaoBoGuanLi_Update_Load_SelectAllotRecord')
BEGIN
SELECT PW_AllotRecordList.AllotRecordID, PW_AllotRecordList.AllotOddNumbers, PW_AllotRecordList.AllotData, PW_AllotRecordList.AllotGross, PW_AllotRecordList.DrawUp_StaffID AS DrawUpID,
PW_AllotRecordList.ExAminePerson_StaffID AS ExAminePersonID, PW_AllotRecordList.IfEffective, BM_StaffRecordList_1.StaffName AS DrawUpID,
BM_StaffRecordList.StaffName AS ExAminePerson
FROM PW_AllotRecordList INNER JOIN
BM_StaffRecordList AS BM_StaffRecordList_1 ON PW_AllotRecordList.DrawUp_StaffID = BM_StaffRecordList_1.StaffID INNER JOIN
BM_StaffRecordList ON PW_AllotRecordList.ExAminePerson_StaffID = BM_StaffRecordList.StaffID
WHERE PW_AllotRecordList.AllotRecordID=@AllotRecordID
END
IF(@TYPE='DiaoBoGuanLi_Update_Load_SelectAllotRecordMinute')
BEGIN
SELECT PW_AllotRecordMinuteList.AllotRecordMinuteID, PW_AllotRecordMinuteList.AllotRecordID, PW_AllotRecordMinuteList.PartsID,
PW_AllotRecordMinuteList.StorageID_ComeInStorage AS ComeInStorageID, PW_AllotRecordMinuteList.StorageID_GoOutStorage AS GoOutStorageID, PW_AllotRecordMinuteList.Quantity,
BM_StorageList_1.StorageName AS ComeInStorage, BM_StorageList.StorageName AS GoOutStorage, AttributeMinuteList.AttributeMinuteName AS Unit, BM_PartsList.PartsCoding,
BM_PartsList.PartsName, BM_PartsList.AttributeMinuteID_Unit AS UnitID, BM_PartsList.Specification
FROM BM_StorageList INNER JOIN
BM_PartsList INNER JOIN
PW_AllotRecordMinuteList ON BM_PartsList.PartsID = PW_AllotRecordMinuteList.PartsID INNER JOIN
BM_StorageList AS BM_StorageList_1 ON PW_AllotRecordMinuteList.StorageID_ComeInStorage = BM_StorageList_1.StorageID ON
BM_StorageList.StorageID = PW_AllotRecordMinuteList.StorageID_GoOutStorage INNER JOIN
AttributeMinuteList ON BM_PartsList.AttributeMinuteID_Unit = AttributeMinuteList.AttributeMinuteID
WHERE PW_AllotRecordMinuteList.AllotRecordID=@AllotRecordID
END
IF(@TYPE='DiaoBoGuanLi_Update_DeleteAllotRecordMinute')
BEGIN
DELETE PW_AllotRecordMinuteList
WHERE PW_AllotRecordMinuteList.AllotRecordID=@AllotRecordID
END
第二步:逻辑层(BLL)
//查询调拨信息
[OperationContract]
public DataSet DiaoBoGuanLi_Update_Load_SelectAllotRecord(int intAllotRecordID)
{
SqlParameter[] mySqlParameters =
{
new SqlParameter("@TYPE",SqlDbType.NChar),
new SqlParameter("@AllotRecordID",SqlDbType.Int),
};
mySqlParameters[0].Value = "DiaoBoGuanLi_Update_Load_SelectAllotRecord";
mySqlParameters[1].Value = intAllotRecordID;
DataTable dt = myDALMethod.QueryDataTable("调拨管理_FRM_DiaoBoGuanLi_Update", mySqlParameters);
DataSet ds = new DataSet();
ds.Tables.Add(dt);
return ds; //返回数据集
}
//查询调拨明细信息
[OperationContract]
public DataSet DiaoBoGuanLi_Update_Load_SelectAllotRecordMinute(int intAllotRecordID)
{
SqlParameter[] mySqlParameters =
{
new SqlParameter("@TYPE",SqlDbType.NChar),
new SqlParameter("@AllotRecordID",SqlDbType.Int),
};
mySqlParameters[0].Value = "DiaoBoGuanLi_Update_Load_SelectAllotRecordMinute";
mySqlParameters[1].Value = intAllotRecordID;
DataTable dt = myDALMethod.QueryDataTable("调拨管理_FRM_DiaoBoGuanLi_Update", mySqlParameters);
DataSet ds = new DataSet();
ds.Tables.Add(dt);
return ds; //返回数据集
}
//删除调拨明细信息
[OperationContract]
public int DiaoBoGuanLi_Update_DeleteAllotRecordMinute(int intAllotRecordID)
{
SqlParameter[] mySqlParameters =
{
new SqlParameter("@TYPE",SqlDbType.NChar),
new SqlParameter("@AllotRecordID",SqlDbType.Int),
};
mySqlParameters[0].Value = "DiaoBoGuanLi_Update_DeleteAllotRecordMinute";
mySqlParameters[1].Value = intAllotRecordID;
return myDALMethod.UpdateData("调Ì¡Â拨|管¨¹理¤¨ª_FRM_DiaoBoGuanLi_Update", mySqlParameters);
//返回值为1是正常的,小于0是异常。
}
第三步:界面层(UIL)
BLL海马汽车销售系统.库存管理.FRM_DiaoboGuanLi_Update.FRM_DiaoboGuanLi_UpdateClient myFRM_DiaoboGuanLi_UpdateClient =
new BLL海马汽车销售系统.库存管理.FRM_DiaoboGuanLi_Update.FRM_DiaoboGuanLi_UpdateClient();
DataTable dtAllotRecordMinute;//定义表
private void FRM_DiaoBoGuanLi_Update_Load(object sender, EventArgs e)
{
//查询调拨信息
DataTable dtAllotRecord = myFRM_DiaoboGuanLi_UpdateClient.DiaoBoGuanLi_Update_Load_SelectAllotRecord(FRM_DiaoBoGuanLi.intAllotRecord).Tables[0];
//绑定数据
txtAllotRecordOddNumber.Text = dtAllotRecord.Rows[0]["AllotOddNumbers"].ToString().Trim();
txtGross.Text = dtAllotRecord.Rows[0]["AllotGross"].ToString().Trim();
dtpComeInAndGoOutData.Value = Convert.ToDateTime(dtAllotRecord.Rows[0]["AllotData"]);
cboDrawUp.SelectedValue = Convert.ToInt32(dtAllotRecord.Rows[0]["DrawUpID"]);
cboExAminePerson.SelectedValue = Convert.ToInt32(dtAllotRecord.Rows[0]["ExAminePersonID"]);
//查询调拨明细信息
dtAllotRecordMinute = myFRM_DiaoboGuanLi_UpdateClient.DiaoBoGuanLi_Update_Load_SelectAllotRecordMinute(FRM_DiaoBoGuanLi.intAllotRecord).Tables[0];
if (dtAllotRecordMinute.Rows.Count > 0)//表不为空
{
for (int i = 0; i < dtAllotRecordMinute.Rows.Count; i++)//循环表
{
//把数据绑定到dgv
dgvAllotRecord.Rows.Add();
dgvAllotRecord.Rows[dgvAllotRecord.Rows.Count - 1].Cells["调拨记录明细ID"].Value = dtAllotRecordMinute.Rows[i]["AllotRecordMinuteID"];
dgvAllotRecord.Rows[dgvAllotRecord.Rows.Count - 1].Cells["配件ID"].Value = dtAllotRecordMinute.Rows[i]["PartsID"];
dgvAllotRecord.Rows[dgvAllotRecord.Rows.Count - 1].Cells["配件编码"].Value = dtAllotRecordMinute.Rows[i]["PartsCoding"];
dgvAllotRecord.Rows[dgvAllotRecord.Rows.Count - 1].Cells["配件名称"].Value = dtAllotRecordMinute.Rows[i]["PartsName"];
dgvAllotRecord.Rows[dgvAllotRecord.Rows.Count - 1].Cells["单位"].Value = dtAllotRecordMinute.Rows[i]["Unit"];
dgvAllotRecord.Rows[dgvAllotRecord.Rows.Count - 1].Cells["规格"].Value = dtAllotRecordMinute.Rows[i]["Specification"];
dgvAllotRecord.Rows[dgvAllotRecord.Rows.Count - 1].Cells["调入仓ID"].Value = dtAllotRecordMinute.Rows[i]["ComeInStorageID"];
dgvAllotRecord.Rows[dgvAllotRecord.Rows.Count - 1].Cells["调入仓"].Value = dtAllotRecordMinute.Rows[i]["ComeInStorage"];
dgvAllotRecord.Rows[dgvAllotRecord.Rows.Count - 1].Cells["调出仓ID"].Value = dtAllotRecordMinute.Rows[i]["GoOutStorageID"];
dgvAllotRecord.Rows[dgvAllotRecord.Rows.Count - 1].Cells["调出仓"].Value = dtAllotRecordMinute.Rows[i]["GoOutStorage"];
dgvAllotRecord.Rows[dgvAllotRecord.Rows.Count - 1].Cells["数量"].Value = dtAllotRecordMinute.Rows[i]["Quantity"];
}
}
if (dgvAllotRecord.Rows.Count > 0)//如果dgv不为空
{
for (int i = 0; i < dgvAllotRecord.Rows.Count; i++)//循环dgv
{
//根据配件与调入仓查询库存数
DataTable dtKunCun = myFRM_RuKuGuanLi_InsertClient.FRM_RuKuGuanLi_Insert_SelectKuCun(Convert.ToInt32(dgvAllotRecord.Rows[i].Cells["配件ID"].Value), Convert.ToInt32(dgvAllotRecord.Rows[i].Cells["调出仓ID"].Value)).Tables[0];
if (dtKunCun.Rows.Count > 0)
{
//计算库存并保存到数据库
decimal decKuCunShu = Convert.ToDecimal(dgvAllotRecord.Rows[i].Cells["数量"].Value) + Convert.ToDecimal(dtKunCun.Rows[0]["StockNumber"]);
int intUpdate = myFRM_RuKuGuanLi_InsertClient.FRM_RuKuGuanLi_Insert_btnInsert_ClickUpdateStockNumber(decKuCunShu, Convert.ToInt32(dtKunCun.Rows[0]["StockID"]));
}
//根据配件与调出仓查询库存数
DataTable dtKunCun1 = myFRM_RuKuGuanLi_InsertClient.FRM_RuKuGuanLi_Insert_SelectKuCun(Convert.ToInt32(dgvAllotRecord.Rows[i].Cells["配件ID"].Value), Convert.ToInt32(dgvAllotRecord.Rows[i].Cells["调入仓ID"].Value)).Tables[0];
if (dtKunCun1.Rows.Count > 0)
{
//计算库存并保存到数据库
decimal decKuCunShu = Convert.ToDecimal(dtKunCun1.Rows[0]["StockNumber"]) - Convert.ToDecimal(dgvAllotRecord.Rows[i].Cells["数量"].Value);
int intUpdate = myFRM_RuKuGuanLi_InsertClient.FRM_RuKuGuanLi_Insert_btnInsert_ClickUpdateStockNumber(decKuCunShu, Convert.ToInt32(dtKunCun1.Rows[0]["StockID"]));
}
}
}
//删除调拨明细信息
int intDelete = myFRM_DiaoboGuanLi_UpdateClient.DiaoBoGuanLi_Update_DeleteAllotRecordMinute(FRM_DiaoBoGuanLi.intAllotRecord);
}
2、【修改】按钮点击事件
第一步:界面层(UIL)
BLL海马汽车销售系统.库存管理.FRM_RuKuGuanLi_Insert.FRM_RuKuGuanLi_InsertClient myFRM_RuKuGuanLi_InsertClient =
new BLL海马汽车销售系统.库存管理.FRM_RuKuGuanLi_Insert.FRM_RuKuGuanLi_InsertClient();
BLL海马汽车销售系统.库存管理.FRM_ChuKuGuanLi_Insert.FRM_ChuKuGuanLi_InsertClient myFRM_ChuKuGuanLi_InsertClient =
new BLL海马汽车销售系统.库存管理.FRM_ChuKuGuanLi_Insert.FRM_ChuKuGuanLi_InsertClient();
private void btnUpdate_Click(object sender, EventArgs e)
{
//如果调出仓与调入仓相同
if (Convert.ToInt32(cboGoOutStorage.SelectedValue) == Convert.ToInt32(cboComeInStorage.SelectedValue))
{
MessageBox.Show("调入仓与调出仓不能为同一仓库!");
return;
}
if (txtQuantity.Text == "")//如果数量为空
{
MessageBox.Show("请输入数量!");
}
decimal decKuCunShu = 0;
//查询库存数
DataTable dtKunCun = myFRM_RuKuGuanLi_InsertClient.FRM_RuKuGuanLi_Insert_SelectKuCun(Convert.ToInt32(cboPartsName.SelectedValue), Convert.ToInt32(cboGoOutStorage.SelectedValue)).Tables[0];
if (dtKunCun.Rows.Count > 0)//如果表不为空
{
//提取库存数
decKuCunShu = Convert.ToDecimal(dtKunCun.Rows[0]["StockNumber"]);
}
else
{
MessageBox.Show("调出仓中没有改配件!");
return;
}
if (decKuCunShu < Convert.ToDecimal(txtQuantity.Text))//如果库存不足
{
MessageBox.Show("该配件在该仓库库存不足!");
return;
}
//查询仓库总容量
DataTable dtKuCun = myFRM_RuKuGuanLi_InsertClient.FRM_RuKuGuanLi_Insert_SelectCangKuRoLiang(Convert.ToInt32(cboComeInStorage.SelectedValue)).Tables[0];
decimal decKuCun = Convert.ToDecimal(dtKuCun.Rows[0]["Dimension"]);
//查询已用容量
DataTable dtYiYongRoLiang = myFRM_RuKuGuanLi_InsertClient.FRM_RuKuGuanLi_Insert_SelectCangkuYiYongRoLiang(Convert.ToInt32(cboComeInStorage.SelectedValue)).Tables[0];
decimal decYiYongRoLiang = 0;
for (int j = 0; j < dtYiYongRoLiang.Rows.Count; j++)
{
//计算可用容量
decYiYongRoLiang += Convert.ToDecimal(dtYiYongRoLiang.Rows[j]["StockNumber"]) * Convert.ToDecimal(dtYiYongRoLiang.Rows[j]["Specification"]);
}
//计算可用容量
decimal decKeYongRoLiang = decKuCun - decYiYongRoLiang;
if (dgvAllotRecord.Rows.Count > 0)//如果dgv不为空
{
for (int k = 0; k < dgvAllotRecord.Rows.Count; k++)//循环dgv
{
//如果控件中的调入仓与dgv中的调入仓相同
if (Convert.ToInt32(cboComeInStorage.SelectedValue) == Convert.ToInt32(dgvAllotRecord.Rows[k].Cells["调入仓ID"].Value) && dgvAllotRecord.CurrentRow.Cells["调拨记录明细ID"].Value == "")
{
//计算可用容量
decKeYongRoLiang = decKeYongRoLiang - Convert.ToDecimal(dgvAllotRecord.Rows[k].Cells["数量"].Value) * Convert.ToDecimal(dgvAllotRecord.Rows[k].Cells["规格"].Value);
}
}
}
//如果控件中的配件、调入仓、调出仓与所选单据的配件、调入仓、调出仓相同
if (Convert.ToInt32(cboPartsName.SelectedValue) == Convert.ToInt32(dgvAllotRecord.CurrentRow.Cells["配件ID"].Value)
&& Convert.ToInt32(cboGoOutStorage.SelectedValue) == Convert.ToInt32(dgvAllotRecord.CurrentRow.Cells["调入仓ID"].Value)
&& Convert.ToInt32(cboComeInStorage.SelectedValue) == Convert.ToInt32(dgvAllotRecord.CurrentRow.Cells["调出仓ID"].Value))
{
}
else
{
if (dgvAllotRecord.Rows.Count > 0)
{
for (int i = 0; i < dgvAllotRecord.Rows.Count; i++)
{
//如果dgv中已存在与控件中的配件、调入仓、调出仓一一对应的单据
if (Convert.ToInt32(cboPartsName.SelectedValue) == Convert.ToInt32(dgvAllotRecord.Rows[i].Cells["配件ID"].Value)
&& Convert.ToInt32(cboGoOutStorage.SelectedValue) == Convert.ToInt32(dgvAllotRecord.Rows[i].Cells["调入仓ID"].Value)
&& Convert.ToInt32(cboComeInStorage.SelectedValue) == Convert.ToInt32(dgvAllotRecord.Rows[i].Cells["调出仓ID"].Value))
{
MessageBox.Show("该配件从该目标仓库中调出进入该目标仓库的单据已存在!");
return;
}
}
}
}
if (decKeYongRoLiang > Convert.ToDecimal(txtGuiGe.Text) * Convert.ToDecimal(txtQuantity.Text))//如果仓库容量充足
{
//覆盖所选行的数据
dgvAllotRecord.CurrentRow.Cells["调拨记录明细ID"].Value = "";
dgvAllotRecord.CurrentRow.Cells["配件ID"].Value = cboPartsName.SelectedValue;
dgvAllotRecord.CurrentRow.Cells["配件名称"].Value = cboPartsName.Text;
dgvAllotRecord.CurrentRow.Cells["配件编码"].Value = txtPartsCode.Text;
dgvAllotRecord.CurrentRow.Cells["规格"].Value = txtGuiGe.Text;
dgvAllotRecord.CurrentRow.Cells["单位"].Value = txtUnit.Text;
dgvAllotRecord.CurrentRow.Cells["调入仓ID"].Value = cboComeInStorage.SelectedValue;
dgvAllotRecord.CurrentRow.Cells["调入仓"].Value = cboComeInStorage.Text;
dgvAllotRecord.CurrentRow.Cells["调出仓ID"].Value = cboGoOutStorage.SelectedValue;
dgvAllotRecord.CurrentRow.Cells["调出仓"].Value = cboGoOutStorage.Text;
dgvAllotRecord.CurrentRow.Cells["数量"].Value = txtQuantity.Text;
}
else
{
MessageBox.Show("调入仓剩余空间不足!");
}
HeJi();
}
public void HeJi()
{
decimal decZongLiang = 0;
if (dgvComeInAndGoOut.Rows.Count > 0)//如果dgv不为空
{
for (int i = 0; i < dgvComeInAndGoOut.Rows.Count; i++)//循环dgv
{
//计算总数量
decZongLiang += Convert.ToDecimal(dgvComeInAndGoOut.Rows[i].Cells["数量"].Value);
}
}
3、【增加】按钮点击事件
第一步:界面层(UIL)
BLL海马汽车销售系统.库存管理.FRM_RuKuGuanLi_Insert.FRM_RuKuGuanLi_InsertClient myFRM_RuKuGuanLi_InsertClient =
new BLL海马汽车销售系统.库存管理.FRM_RuKuGuanLi_Insert.FRM_RuKuGuanLi_InsertClient();
BLL海马汽车销售系统.库存管理.FRM_ChuKuGuanLi_Insert.FRM_ChuKuGuanLi_InsertClient myFRM_ChuKuGuanLi_InsertClient =
new BLL海马汽车销售系统.库存管理.FRM_ChuKuGuanLi_Insert.FRM_ChuKuGuanLi_InsertClient();
private void txtQuantity_KeyPress(object sender, KeyPressEventArgs e)
{
PublicStaticMothd.pubPriceOrRate_KeyPress(sender, e);
}
private void btnInsert_Click(object sender, EventArgs e)
{
if (Convert.ToInt32(cboGoOutStorage.SelectedValue) == Convert.ToInt32(cboComeInStorage.SelectedValue))//如果调出仓与调入仓相同
{
MessageBox.Show("调入仓与调出仓不能为同一仓库!");
return;
}
if (txtQuantity.Text == "")//如果调拨数量为空
{
MessageBox.Show("请输入数量!");
}
if (dgvComeInAndGoOut.Rows.Count > 0)//如果dgv不为空
{
for (int i = 0; i < dgvComeInAndGoOut.Rows.Count; i++)//循环表
{
//如果dgv中已存在该配件从该调出仓调入该调入仓的单据
if (Convert.ToInt32(cboPartsName.SelectedValue) == Convert.ToInt32(dgvComeInAndGoOut.Rows[i].Cells["配件ID"].Value)
&& Convert.ToInt32(cboGoOutStorage.SelectedValue) == Convert.ToInt32(dgvComeInAndGoOut.Rows[i].Cells["调入仓ID"].Value)
&& Convert.ToInt32(cboComeInStorage.SelectedValue) == Convert.ToInt32(dgvComeInAndGoOut.Rows[i].Cells["调出仓ID"].Value))
{
MessageBox.Show("该配件从该目标仓库中调出进入该目标仓库的单据已存在!");
return;
}
}
}
decimal decKuCunShu = 0;
//根据配件与调出仓查询库存数
DataTable dtKunCun = myFRM_RuKuGuanLi_InsertClient.FRM_RuKuGuanLi_Insert_SelectKuCun(Convert.ToInt32(cboPartsName.SelectedValue), Convert.ToInt32(cboGoOutStorage.SelectedValue)).Tables[0];
if (dtKunCun.Rows.Count > 0)//如果有数据
{
//提取库存数
decKuCunShu = Convert.ToDecimal(dtKunCun.Rows[0]["StockNumber"]);
}
else
{
MessageBox.Show("调出仓中没有改配件!");
return;
}
if (decKuCunShu < Convert.ToDecimal(txtQuantity.Text))//如果库存不足
{
MessageBox.Show("该配件在该仓库库存不足!");
return;
}
//根据调入仓查询仓库容量
DataTable dtKuCun = myFRM_RuKuGuanLi_InsertClient.FRM_RuKuGuanLi_Insert_SelectCangKuRoLiang(Convert.ToInt32(cboComeInStorage.SelectedValue)).Tables[0];
//提取仓库容量
decimal decKuCun = Convert.ToDecimal(dtKuCun.Rows[0]["Dimension"]);
//根据调入仓查询已用容量
DataTable dtYiYongRoLiang = myFRM_RuKuGuanLi_InsertClient.FRM_RuKuGuanLi_Insert_SelectCangkuYiYongRoLiang(Convert.ToInt32(cboComeInStorage.SelectedValue)).Tables[0];
decimal decYiYongRoLiang=0;
for (int j = 0; j < dtYiYongRoLiang.Rows.Count; j++)//循环表
{
//计算已用的容量
decYiYongRoLiang += Convert.ToDecimal(dtYiYongRoLiang.Rows[j]["StockNumber"]) * Convert.ToDecimal(dtYiYongRoLiang.Rows[j]["Specification"]);
}
//计算可用容量
decimal decKeYongRoLiang = decKuCun - decYiYongRoLiang;
if (dgvComeInAndGoOut.Rows.Count > 0)
{
for (int k = 0; k < dgvComeInAndGoOut.Rows.Count; k++)//循环dgv
{
//如果控件中的调入仓与dgv中的调入仓相同
if (Convert.ToInt32(cboComeInStorage.SelectedValue) == Convert.ToInt32(dgvComeInAndGoOut.Rows[k].Cells["调入ID"].Value))
{
//计算可用容量
decKeYongRoLiang = decKeYongRoLiang - Convert.ToDecimal(dgvComeInAndGoOut.Rows[k].Cells["数量"].Value) * Convert.ToDecimal(dgvComeInAndGoOut.Rows[k].Cells["规格"].Value);
}
}
}
if (decKeYongRoLiang > Convert.ToDecimal(txtGuiGe.Text) * Convert.ToDecimal(txtQuantity.Text))//如果仓库容量充足
{
//把调拨明细信息增加到dgv
dgvComeInAndGoOut.Rows.Add();
dgvComeInAndGoOut.Rows[dgvComeInAndGoOut.Rows.Count - 1].Cells["配件ID"].Value = cboPartsName.SelectedValue;
dgvComeInAndGoOut.Rows[dgvComeInAndGoOut.Rows.Count - 1].Cells["配件名称"].Value = cboPartsName.Text;
dgvComeInAndGoOut.Rows[dgvComeInAndGoOut.Rows.Count - 1].Cells["配件编码"].Value = txtPartsCode.Text;
dgvComeInAndGoOut.Rows[dgvComeInAndGoOut.Rows.Count - 1].Cells["规格"].Value = txtGuiGe.Text;
dgvComeInAndGoOut.Rows[dgvComeInAndGoOut.Rows.Count - 1].Cells["单位"].Value = txtUnit.Text;
dgvComeInAndGoOut.Rows[dgvComeInAndGoOut.Rows.Count - 1].Cells["调入仓ID"].Value = cboComeInStorage.SelectedValue;
dgvComeInAndGoOut.Rows[dgvComeInAndGoOut.Rows.Count - 1].Cells["调入仓"].Value = cboComeInStorage.Text;
dgvComeInAndGoOut.Rows[dgvComeInAndGoOut.Rows.Count - 1].Cells["调出仓ID"].Value = cboGoOutStorage.SelectedValue;
dgvComeInAndGoOut.Rows[dgvComeInAndGoOut.Rows.Count - 1].Cells["调出仓"].Value = cboGoOutStorage.Text;
dgvComeInAndGoOut.Rows[dgvComeInAndGoOut.Rows.Count - 1].Cells["数量"].Value = txtQuantity.Text;
}
else
{
MessageBox.Show("调入仓剩余空间不足!");
}
HeJi();//调用自定义方法
}
public void HeJi()
{
decimal decZongLiang = 0;
if (dgvComeInAndGoOut.Rows.Count > 0)//如果dgv不为空
{
for (int i = 0; i < dgvComeInAndGoOut.Rows.Count; i++)//循环dgv
{
//计算总数量
decZongLiang += Convert.ToDecimal(dgvComeInAndGoOut.Rows[i].Cells["数量"].Value);
}
}
//给【总量】赋值
txtGross.Text = decZongLiang.ToString().Trim();
}
4、保存
第一步:界面层(UIL)
BLL海马汽车销售系统.库存管理.FRM_DiaoboGuanLi_Update.FRM_DiaoboGuanLi_UpdateClient myFRM_DiaoboGuanLi_UpdateClient =
new BLL海马汽车销售系统.库存管理.FRM_DiaoboGuanLi_Update.FRM_DiaoboGuanLi_UpdateClient();
BLL海马汽车销售系统.库存管理.FRM_DiaoBoGuanLi_Insert.FRM_DiaoBoGuanLi_InsertClient myFRM_DiaoBoGuanLi_InsertClient =
new BLL海马汽车销售系统.库存管理.FRM_DiaoBoGuanLi_Insert.FRM_DiaoBoGuanLi_InsertClient();
int intNember = 0;//变量
private void btnSave_Click(object sender, EventArgs e)
{
//给参数赋值
int intInsertAllotRecordMinute = 0;
string strAllotOddNumbers = txtAllotRecordOddNumber.Text;
DateTime dtmAllotData = dtpComeInAndGoOutData.Value;
decimal decAllotGross = Convert.ToDecimal(txtGross.Text);
int intDrawUp = Convert.ToInt32(cboDrawUp.SelectedValue);
int intExAminePerson = Convert.ToInt32(cboExAminePerson.SelectedValue);
//把修改后的调拨信息保存到数据库
int intInsertAllotRecord = myFRM_DiaoboGuanLi_UpdateClient.DiaoBoGuanLi_Update_UpdateAllotRecord(strAllotOddNumbers, dtmAllotData, decAllotGross, intDrawUp, intExAminePerson,FRM_DiaoBoGuanLi.intAllotRecord);
if (dgvComeInAndGoOut.Rows.Count > 0)//如果dgv不为空
{
for (int i = 0; i < dgvComeInAndGoOut.Rows.Count; i++)//循环dgv
{
//根据配件与调入仓查询库存数
DataTable dtKunCun = myFRM_RuKuGuanLi_InsertClient.FRM_RuKuGuanLi_Insert_SelectKuCun(Convert.ToInt32(dgvComeInAndGoOut.Rows[i].Cells["配件ID"].Value), Convert.ToInt32(dgvComeInAndGoOut.Rows[i].Cells["调入仓ID"].Value)).Tables[0];
if (dtKunCun.Rows.Count > 0)//如果存在数据
{
//计算库存数并保存进数据库
decimal decKuCunShu = Convert.ToDecimal(dgvComeInAndGoOut.Rows[i].Cells["数量"].Value) + Convert.ToDecimal(dtKunCun.Rows[0]["StockNumber"]);
int intUpdate = myFRM_RuKuGuanLi_InsertClient.FRM_RuKuGuanLi_Insert_btnInsert_ClickUpdateStockNumber(decKuCunShu, Convert.ToInt32(dtKunCun.Rows[0]["StockID"]));
}
else//如果没有数据
{
//新增库存配件
int intInsertStock = myFRM_RuKuGuanLi_InsertClient.FRM_RuKuGuanLi_Insert_InsertStock(Convert.ToInt32(dgvComeInAndGoOut.Rows[i].Cells["配件ID"].Value), Convert.ToInt32(dgvComeInAndGoOut.Rows[i].Cells["调入仓ID"].Value), Convert.ToDecimal(dgvComeInAndGoOut.Rows[i].Cells["数量"].Value));
}
//根据配件与调出仓查询库存数
DataTable dtKunCun1 = myFRM_RuKuGuanLi_InsertClient.FRM_RuKuGuanLi_Insert_SelectKuCun(Convert.ToInt32(dgvComeInAndGoOut.Rows[i].Cells["配件ID"].Value), Convert.ToInt32(dgvComeInAndGoOut.Rows[i].Cells["调出仓ID"].Value)).Tables[0];
if (dtKunCun1.Rows.Count > 0)
{
//计算库存数并保存进数据库
decimal decKuCunShu = Convert.ToDecimal(dtKunCun1.Rows[0]["StockNumber"])-Convert.ToDecimal(dgvComeInAndGoOut.Rows[i].Cells["数量"].Value) ;
int intUpdate = myFRM_RuKuGuanLi_InsertClient.FRM_RuKuGuanLi_Insert_btnInsert_ClickUpdateStockNumber(decKuCunShu, Convert.ToInt32(dtKunCun1.Rows[0]["StockID"]));
}
//给变量赋值
int intAllotRecordID = FRM_DiaoBoGuanLi.intAllotRecord;
int intPartsID=Convert.ToInt32(dgvComeInAndGoOut.Rows[i].Cells["配件ID"].Value) ;
int intComeInStorage = Convert.ToInt32(dgvComeInAndGoOut.Rows[i].Cells["调入仓ID"].Value);
int intGoOutStorage = Convert.ToInt32(dgvComeInAndGoOut.Rows[i].Cells["调出仓ID"].Value);
decimal decQuantity=Convert.ToDecimal(dgvComeInAndGoOut.Rows[i].Cells["数量"].Value);
//把调拨明细信息保存进数据库
intInsertAllotRecordMinute = myFRM_DiaoBoGuanLi_InsertClient.FRM_DiaoBoGuanLi_btnSave_ClickInsertAllotRecordMinute(intAllotRecordID, intPartsID, intComeInStorage, intGoOutStorage, decQuantity);
}
}
if(intInsertAllotRecord>0||intInsertAllotRecordMinute>0)//如果调用方法成功
{
MessageBox.Show("保存成功!");
}
intNember = 1;//变量赋值为1
}
5、窗体关闭前事件
第一步:界面层(UIL)
BLL海马汽车销售系统.库存管理.FRM_DiaoBoGuanLi_Insert.FRM_DiaoBoGuanLi_InsertClient myFRM_DiaoBoGuanLi_InsertClient =
new BLL海马汽车销售系统.库存管理.FRM_DiaoBoGuanLi_Insert.FRM_DiaoBoGuanLi_InsertClient();
private void FRM_DiaoBoGuanLi_Update_FormClosing(object sender, FormClosingEventArgs e)
{
if (intNember == 0)//变量值为1
{
if (dtAllotRecordMinute.Rows.Count > 0)//表不为空
{
for (int i = 0; i < dtAllotRecordMinute.Rows.Count; i++)//循环表
{
//查询调入仓库存
DataTable dtKunCun = myFRM_RuKuGuanLi_InsertClient.FRM_RuKuGuanLi_Insert_SelectKuCun(Convert.ToInt32(dtAllotRecordMinute.Rows[i]["PartsID"]), Convert.ToInt32(dtAllotRecordMinute.Rows[i]["ComeInStorageID"])).Tables[0];
if (dtKunCun.Rows.Count > 0)
{
//计算库存并保存
decimal decKuCunShu = Convert.ToDecimal(dtAllotRecordMinute.Rows[i]["Quantity"]) + Convert.ToDecimal(dtKunCun.Rows[0]["StockNumber"]);
int intUpdate = myFRM_RuKuGuanLi_InsertClient.FRM_RuKuGuanLi_Insert_btnInsert_ClickUpdateStockNumber(decKuCunShu, Convert.ToInt32(dtKunCun.Rows[0]["StockID"]));
}
//查询调出仓库存
DataTable dtKunCun1 = myFRM_RuKuGuanLi_InsertClient.FRM_RuKuGuanLi_Insert_SelectKuCun(Convert.ToInt32(dtAllotRecordMinute.Rows[i]["PartsID"]), Convert.ToInt32(dtAllotRecordMinute.Rows[i]["GoOutStorageID"])).Tables[0];
if (dtKunCun1.Rows.Count > 0)
{
//计算库存并保存
decimal decKuCunShu = Convert.ToDecimal(dtKunCun1.Rows[0]["StockNumber"]) - Convert.ToDecimal(dtAllotRecordMinute.Rows[i]["Quantity"]);
int intUpdate = myFRM_RuKuGuanLi_InsertClient.FRM_RuKuGuanLi_Insert_btnInsert_ClickUpdateStockNumber(decKuCunShu, Convert.ToInt32(dtKunCun1.Rows[0]["StockID"]));
}
//给变量赋值
int intAllotRecordID = FRM_DiaoBoGuanLi.intAllotRecord;
int intPartsID = Convert.ToInt32(dtAllotRecordMinute.Rows[i]["PartsID"]);
int intComeInStorage = Convert.ToInt32(dtAllotRecordMinute.Rows[i]["ComeInStorageID"]);
int intGoOutStorage = Convert.ToInt32(dtAllotRecordMinute.Rows[i]["GoOutStorageID"]);
decimal decQuantity = Convert.ToDecimal(dtAllotRecordMinute.Rows[i]["Quantity"]);
//保存调拨明细信息
int intInsertAllotRecordMinute = myFRM_DiaoBoGuanLi_InsertClient.FRM_DiaoBoGuanLi_btnSave_ClickInsertAllotRecordMinute(intAllotRecordID, intPartsID, intComeInStorage, intGoOutStorage, decQuantity);
}
}
}
}
以上仅供学习参考,禁止用于商业用途!!!