您的位置:首页 > 其它

海马汽车经销商管理系统技术解析(四)新增预约

2015-05-30 20:17 441 查看

新增预约单

预约新增就是录入客户的基本信息、预约到厂时间、添加预约明细信息预约维修项目、所需配件等信息。界面如(图一)、(图二)所示:



(图一)



(图二)



因该下拉框用自动完成源功能,所以可以通过下拉框选择,也可手动输入后再选,如果系统没有该车辆的信息,可跳转到客户档案新增界面新增。

从界面上看到的控件有:
空间名称
说明
文本框(TextBox)
编辑控件可以在工具箱直接拖动至窗体,拖至窗体后右击属性可以修改控件的样式和各种属性,
还可以设置控件的事件。
日期控件(DataTimepPicker)
(NumericUpDown)
下拉框(ComboBox)
复选框(CheckBox)
表格(DataGridView)
选项卡(TabControl)
按钮(Button)
(ToolStrip)
1、数据库功能实现
第一步:数据库

1、表和关系



表1:预约单表(PW_BespeakBillList)
列名

数据类型

主键/外键
说明

BespeakBillID

int - Identity

主键
预约单ID

BespeakOddNumBer

nchar (20)

预约单号

CarNewsID

int

外键
车辆信息表,车辆信息ID

BespeakTime

datetime

预约时间

AttributeMinuteID_BespeakWay

int

外键

属性明细表,属性明细ID_预约方式

BespeakMileage

decimal (18, 2)

预约里程

BespeakStatus

nchar (20)

预约状态

Gross

decimal (18, 2)

总计金额

FailCause

nchar (100)

失败原因

StaffID_HearPersons

int

外键

员工档案表,员工ID_受理人

StaffID_Receiver

int

外键

员工档案表,员工ID_接待人

LastTimeInTheFactory

nchar (20)

上次进厂时间

IfBespeakSucceed

bit

预约成功否

StaffID_AlterationPerson

nchar (20)

外键

员工档案表,员工ID_变更人

BookingCarDeliveryTime

nchar (20)

预约交车时间

BespeakWarnTime

nchar (20)

预约提醒时间

ServiceOddNumber

nchar (20)

外键

维修单表,维修单号

NewBespeakOddlNumber

nchar (20)

新预约单号

OldBespeakOddNumber

nchar (20)

旧预约单号

AlterationTime

nchar (20)

变更时间

AlterationCauses

nchar (100)

变更原因

ClientDescribe

nchar (100)

客户描述

Remarks

nchar (100)

备注

IfResourceRelease

bit

资源释放否

表2:预约配件表(BespeakPartsList)
列名

数据类型

主键/外键
说明

BespeakPartsID

int

主键
预约配件ID

BespeakBillID

int

外键
预约单表,预约单ID

PartsID

int

外键
配件表,配件ID

AttributeMinuteID_AccountType

int

外键
属性明细表,属性明细ID_帐类

ObligateNumBer

decimal (18, 2)

预留数量

NeedNumber

decimal (18, 2)

需求数量

InTranSitNumBer

decimal (18, 2)

在途数量

AvailableForSaleNumber

decimal (18, 2)

可售数量

Price

decimal (18, 2)

单价

IfResourceRelease

bit

资源释放否

表3:预约维修项目表(BespeakServiceItemList)
列名

数据类型

主键/外键
说明

BespeakServiceItemID

int

主键
预约维修项目ID

BespeakBillID

int

外键
预约单表,预约单ID

WorkHoursItemMinuteID

int

外键
工时项目明细表,工时项目明细ID

AttributeMinuteID_AccountType

int

外键
属性明细表,属性明细ID_帐类

WorkHoursPrice

decimal (18, 2)

工时单价

GuestAccountWorkHours

decimal (18, 2)

客帐工时

ParWorkHours

decimal (18, 2)

标准工时

AnticipatedWorkHoursMoney

decimal (18, 2)

预计工时金额

功能实现
1、设置表格控件(DataGridView)的属性。Load事件里面写。

dgvSettel.AutoGenerateColumns = false;//不允许自动添加列
dgvSettel.ReadOnly = true;//只读,不能编辑


2、绑定下拉框(可自动完成源)
第一步:数据库存储过程

IF(@TYPE='FRM_YuYueGuanLi_Insert_Load_Selectchepaihao')
BEGIN
SELECT     CarNewsID,LTRIM(RTRIM (LicensePlateNumber))AS LicensePlateNumber
FROM         BM_CarNewsList
WHERE BM_CarNewsList.IfEffective=1
END


第二步:逻辑层(BLL)
//查询系统所有的车牌号
[OperationContract]
public DataSet FRM_YuYueGuanLi_Insert_Load_Selectchepaihao()
{
SqlParameter[] mySqlParameters =
{
new SqlParameter("@TYPE",SqlDbType.Char),
};
mySqlParameters[0].Value = "FRM_YuYueGuanLi_Insert_Load_Selectchepaihao";
DataTable dt = myDALMethod.QueryDataTable("预约管理_FRM_YuYueGuanLi_Insert", mySqlParameters);
DataSet ds = new DataSet();
ds.Tables.Add(dt);
return ds; //返回一个数据集,就是数据表的集合

第三步:界面层(UIL)。Load事件里写代码。

BLL海马汽车销售系统.预约管理.FRM_YuYueGuanLi_Insert.FRM_YuYueGuanLi_InsertClient myFRM_YuYueGuanLi_InsertClient =
new BLL海马汽车销售系统.预约管理.FRM_YuYueGuanLi_Insert.FRM_YuYueGuanLi_InsertClient();

DataTable dtChePaiHaoMa = myFRM_YuYueGuanLi_InsertClient.FRM_YuYueGuanLi_Insert_Load_Selectchepaihao().Tables[0];//查询数据
cboLicensePlateNumber.DataSource = dtChePaiHaoMa;//给下拉框绑定数据源
cboLicensePlateNumber.DisplayMember = "LicensePlateNumber";//设置下拉框显示的值
cboLicensePlateNumber.ValueMember = "CarNewsID";//设置下拉框的属性
cboLicensePlateNumber.DropDownStyle = ComboBoxStyle.DropDown; //或者是 ComboBoxStyle.Simple ,当为DropDownList时,ComboBox不能输入任何文本,因此自动完成源无效
string[] str = new string[dtChePaiHaoMa.Rows.Count];//实例化数组,指定长度
for (int x = 0; x < dtChePaiHaoMa.Rows.Count; x++)//循环表
{
str[x] = dtChePaiHaoMa.Rows[x]["LicensePlateNumber"].ToString();//把显示的值加进数组
}
cboLicensePlateNumber.AutoCompleteSource = AutoCompleteSource.CustomSource;//指定源
cboLicensePlateNumber.AutoCompleteCustomSource.AddRange(str);//为源添加数据
cboLicensePlateNumber.AutoCompleteMode = AutoCompleteMode.Suggest;//为用户完成源并显示下拉框给用户选择


3、检测时间和计算时间
第一步:界面层(UIL)日期控件(DateTimePicker)值改变事件或控件NumericUpDown值改变事件

private void dtpYuYueShiJian_ValueChanged(object sender, EventArgs e)
{
double dblGongShi = 0;
for (int j = 0; j < dgvBespeakServiceItem.Rows.Count; j++)//循环预约维修项目表
{
dblGongShi += Convert.ToDouble(dgvBespeakServiceItem.Rows[j].Cells["标准工时"].Value);//把每项维修项目的工时相加
}
DateTime datYuYueShiJian = dtpBespeakTime.Value.Date.AddHours(Convert.ToDouble(nudhour.Value)).AddMinutes(Convert.ToDouble(nudminute.Value));
if (datYuYueShiJian > DateTime.Now)//如果预约来厂时间晚于当前时间
{
txtBookingCarDeliveryTime.Text = datYuYueShiJian.AddHours(dblGongShi).AddMinutes(30).ToString();//対预约交车时间赋值
DataTable dtTiXing = myFRM_YuYueGuanLi_InsertClient.FRM_YuYueGuanLi_Insert_SelectShangBanShiJian().Tables[0];//提取系统设置的提前提醒时间数
//txtBespeakWarnTime.Text = Convert.ToString(datYuYueShiJian.AddHours(Convert.ToDouble(dtTiXing.Rows[0]["DefaultValue"])));//对预约提醒时间赋值
double dblTiQian = Convert.ToDouble(datYuYueShiJian.Hour) - Convert.ToDouble(dtTiXing.Rows[0]["DefaultValue"]);
//对预约来厂时间进行赋值。
txtBespeakWarnTime.Text = Convert.ToString(datYuYueShiJian.Date.AddHours(Convert.ToDouble(datYuYueShiJian.Hour) - Convert.ToDouble(dtTiXing.Rows[0]["DefaultValue"])).AddMinutes(datYuYueShiJian.Minute));
}
else//如果预约来厂时间早于当前时间
{
dtpBespeakTime.Value = DateTime.Now.Date;//当前时间的日期部分
//nudhour.Value = DateTime.Now.Hour;
//nudminute.Value = DateTime.Now.Minute;
MessageBox.Show("预约时间不能早于当前时间!", "提示");
}
}


4、提取车辆信息和车主信息
第一步:数据库存储过程

IF(@TYPE='FRM_YuYueGuanLi_Insert_cboChePaiHaoMa_SelectedIndexChanged')
BEGIN
SELECT     BM_CarNewsList.CarOwnerNewsID, BM_CarOwnerNewsList.CarOwnerCode, BM_CarOwnerNewsList.MobilePhone, BM_CarNewsList.VINCode, BM_CarNewsList.BuyCarDate,
BM_CarNewsList.BodyworkColour, BM_CarNewsList.CarModelsCode, BM_CarOwnerNewsList.CarOwnerName
FROM         BM_CarNewsList INNER JOIN
BM_CarOwnerNewsList ON BM_CarNewsList.CarOwnerNewsID = BM_CarOwnerNewsList.CarOwnerNewsID
WHERE  BM_CarNewsList.CarNewsID=@CarNewsID
END


第二步:逻辑层(BLL)
//查询车辆信息
[OperationContract]
public DataSet FRM_YuYueGuanLi_Insert_cboChePaiHaoMa_SelectedIndexChanged(int intCheLiangXinXiID)
{
SqlParameter[] mySqlParameters =
{
new SqlParameter("@TYPE",SqlDbType.Char),
new SqlParameter("@CarNewsID",SqlDbType.Int),
};
mySqlParameters[0].Value = "FRM_YuYueGuanLi_Insert_cboChePaiHaoMa_SelectedIndexChanged";
mySqlParameters[1].Value=intCheLiangXinXiID;
DataTable dt = myDALMethod.QueryDataTable("预约管理 _FRM_YuYueGuanLi_Insert", mySqlParameters);
DataSet ds = new DataSet();
ds.Tables.Add(dt);
return ds; //返回一个数据集
}
第三步:界面层(UIL)

BLL海马汽车销售系统.预约管理.FRM_YuYueGuanLi_Insert.FRM_YuYueGuanLi_InsertClient myFRM_YuYueGuanLi_InsertClient =
new BLL海马汽车销售系统.预约管理.FRM_YuYueGuanLi_Insert.FRM_YuYueGuanLi_InsertClient();
private void cboChePaiHaoMa_SelectedIndexChanged(object sender, EventArgs e)
{
int intNemBer = 0;
//查询车辆所有的预约信息
DataTable dtYongHuChengXinDu = myFRM_YuYueGuanLi_InsertClient.FRM_PeiJianDingDan_Insert_SelecteYongHuChengXinDu(Convert.ToInt32(cboLicensePlateNumber.SelectedValue)).Tables[0];
if (dtYongHuChengXinDu.Rows.Count > 0)//如果该车辆有预约信息存在
{
for (int j = 0; j < dtYongHuChengXinDu.Rows.Count; j++)//循环表
{
if (dtYongHuChengXinDu.Rows[i]["FailCause"].ToString() != "")//如果该条单据预约失败
{
intNemBer++;//加一
}
}
if (intNemBer / dtYongHuChengXinDu.Rows.Count > 0.3)//如果预约失败比例大于30%
{
MessageBox.Show("此人多次爽约,请注意!");
}
}
//查询该车辆的信息
DataTable dt = myFRM_YuYueGuanLi_InsertClient.FRM_YuYueGuanLi_Insert_cboChePaiHaoMa_SelectedIndexChanged(Convert.ToInt32(cboLicensePlateNumber.SelectedValue)).Tables[0];
//给各个空间赋值
txtCarOwnerName.Text = dt.Rows[0]["CarOwnerName"].ToString();
txtMobilePhone.Text = dt.Rows[0]["MobilePhone"].ToString();
txtBuyCarDate.Text = dt.Rows[0]["BuyCarDate"].ToString();
txtVINCode.Text = dt.Rows[0]["VINCode"].ToString();
txtCarModelsCode.Text = dt.Rows[0]["CarModelsCode"].ToString();
txtBodyworkColour.Text = dt.Rows[0]["BodyworkColour"].ToString();
//查询该车辆历史预约成功信息
DataTable dtLastTimeInTheFactory = myFRM_YuYueGuanLi_InsertClient.FRM_PeiJianDingDan_Insert_SelectLastTimeInTheFactory(Convert.ToInt32(cboLicensePlateNumber.SelectedValue)).Tables[0];
if (dtLastTimeInTheFactory.Rows.Count > 0)//如果有历史预约成功信息
{
//给“上次进厂”文本框赋值
txtLastTimeInTheFactory.Text = dtLastTimeInTheFactory.Rows[dt.Rows.Count - 1]["EntranceTime"].ToString();
}
}
5、提取工时项目信息

第一步:数据库存储过程

IF(@TYPE='FRM_YuYueGuanLi_Insert_cboXiangMuDaiMa_SelectedIndexChanged')
BEGIN
SELECT     BM_WorkHoursItemList.ItemName, BM_WorkHoursItemList.WorkKindID, BM_WorkHoursItemMinuteList.CarModels, BM_WorkHoursItemMinuteList.GuestAccountWorkHours,
BM_WorkHoursItemMinuteList.WorkHoursMoney, BM_WorkHoursItemMinuteList.ParWorkHours, BM_WorkHoursItemList.WorkHoursItemID,
BM_WorkHoursItemMinuteList.IfWorkHoursMultiplyUnitPrice, BM_WorkHoursItemMinuteList.Discount, BM_WorkHoursItemList.ItemCode,
BM_WorkHoursItemMinuteList.WorkHoursItemID AS Expr1, BM_WorkHoursItemMinuteList.WorkHoursItemMinuteID, BM_WorkKindList.WorkKindName
FROM         BM_WorkHoursItemMinuteList INNER JOIN
BM_WorkHoursItemList ON BM_WorkHoursItemMinuteList.WorkHoursItemID = BM_WorkHoursItemList.WorkHoursItemID INNER JOIN
BM_WorkKindList ON BM_WorkHoursItemList.WorkKindID = BM_WorkKindList.WorkKindID

WHERE   BM_WorkHoursItemMinuteList.WorkHoursItemID = @WorkHoursItemID
END


第二步:逻辑层(BLL)
//查询工时项目信息
[OperationContract]
public DataSet FRM_YuYueGuanLi_Insert_cboXiangMuDaiMa_SelectedIndexChanged(int intGongShiXiangMuID)
{
SqlParameter[] mySqlParameters =
{
new SqlParameter("@TYPE",SqlDbType.Char),
new SqlParameter("@WorkHoursItemID",SqlDbType.Int),
};
mySqlParameters[0].Value = "FRM_YuYueGuanLi_Insert_cboXiangMuDaiMa_SelectedIndexChanged";
mySqlParameters[1].Value=intGongShiXiangMuID;
DataTable dt = myDALMethod.QueryDataTable("预约管理_FRM_YuYueGuanLi_Insert", mySqlParameters);
DataSet ds = new DataSet();
ds.Tables.Add(dt);
return ds; //返回一个数据集
}


第三步:界面层(UIL)

BLL海马汽车销售系统.预约管理.FRM_YuYueGuanLi_Insert.FRM_YuYueGuanLi_InsertClient myFRM_YuYueGuanLi_InsertClient =
new BLL海马汽车销售系统.预约管理.FRM_YuYueGuanLi_Insert.FRM_YuYueGuanLi_InsertClient();
private void cboXiangMuDaiMa_SelectedIndexChanged(object sender, EventArgs e)
{
if (dgvBespeakServiceItem.Rows.Count > 0)//如果dgv(预约维修项目)不为空
{
for (int j = 0; j < dgvBespeakServiceItem.Rows.Count; j++)//循环dgv
{
//如果工时项目相同
if (Convert.ToInt32(cboItemCode.SelectedValue) == Convert.ToInt32(dgvBespeakServiceItem.Rows[j].Cells["工时项目ID1"].Value))
{
MessageBox.Show("不能选择相同的项目!");
return;
}
}
}
dgvItems.ReadOnly = true;
dgvItems.AutoGenerateColumns = false;
dgvItems.Visible = true;//dgv(工时项目)可见
//为dgv(工时项目)绑定数据源
dgvItems.DataSource = myFRM_YuYueGuanLi_InsertClient.FRM_YuYueGuanLi_Insert_cboXiangMuDaiMa_SelectedIndexChanged(Convert.ToInt32(cboItemCode.SelectedValue)).Tables[0];
}
private void dgvXiangMuXuanZe_MouseDoubleClick(object sender, MouseEventArgs e)
{
//给各个控件赋值
txtWorkHoursItem.Text = dgvItems.CurrentRow.Cells["项目代码1"].Value.ToString();
txtWorkKind.Text = dgvItems.CurrentRow.Cells["工种1"].Value.ToString();
txtWorkHoursPrice.Text = dgvItems.CurrentRow.Cells["工时金额"].Value.ToString();
txtAnticipatedWorkHoursMoney.Text = dgvItems.CurrentRow.Cells["工时金额"].Value.ToString();
txtGuestAccountWorkHours.Text = dgvItems.CurrentRow.Cells["客帐工时1"].Value.ToString();
txtParWorkHours.Text = dgvItems.CurrentRow.Cells["标准工时1"].Value.ToString();
intGongShiXiangMuMingXiID =Convert.ToInt32(dgvItems.CurrentRow.Cells["工时项目明细ID"].Value);
intGongShiXiangMuID = Convert.ToInt32(dgvItems.CurrentRow.Cells["工时项目ID"].Value);
dgvItems.Visible = false;//dgv(工时项目)不可见
}


6、提取配件信息
第一步:数据库存储过程
IF(@TYPE='FRM_YuYueGuanLi_Insert_cboPeiJianBianMa_SelectedIndexChanged')
BEGIN
SELECT     BM_PartsList.PartsID, BM_PartsList.PartsName, BM_PartsList.PartsCoding, BM_PartsList.CarModels,
BM_PartsList.SellPrice, BM_PartsList.AttributeMinuteID_Unit, AttributeMinuteList.AttributeMinuteName
FROM         BM_PartsList INNER JOIN
AttributeMinuteList ON BM_PartsList.AttributeMinuteID_Unit = AttributeMinuteList.AttributeMinuteID
WHERE BM_PartsList.PartsID=@PartsID
END


第二步:逻辑层(BLL)
//查询配件信息
[OperationContract]
public DataSet FRM_YuYueGuanLi_Insert_cboPeiJianBianMa_SelectedIndexChanged(int PeiJianID)
{
SqlParameter[] mySqlParameters =
{
new SqlParameter("@TYPE",SqlDbType.Char),
new SqlParameter("@PartsID",SqlDbType.Int),
};
mySqlParameters[0].Value = "FRM_YuYueGuanLi_Insert_cboPeiJianBianMa_SelectedIndexChanged";
mySqlParameters[1].Value = PeiJianID;
DataTable dt = myDALMethod.QueryDataTable("预约管理_FRM_YuYueGuanLi_Insert", mySqlParameters);
DataSet ds = new DataSet();
ds.Tables.Add(dt);
return ds; //返回一个数据集
}


第三步:界面层(UIL)。下拉框(配件编码)索引改变事件
BLL海马汽车销售系统.预约管理.FRM_YuYueGuanLi_Insert.FRM_YuYueGuanLi_InsertClient myFRM_YuYueGuanLi_InsertClient =
new BLL海马汽车销售系统.预约管理.FRM_YuYueGuanLi_Insert.FRM_YuYueGuanLi_InsertClient();
private void cboPeiJianBianMa_SelectedIndexChanged(object sender, EventArgs e)
{

if (dgvBespeakParts.Rows.Count > 0)//dgv(预约配件)不为空
{
for (int j = 0; j < dgvBespeakParts.Rows.Count; j++)//循环dgv
{
//如果选择的配件出现相同
if (Convert.ToInt32(cboPartsCoding.SelectedValue) == Convert.ToInt32(dgvBespeakParts.Rows[j].Cells["配件ID"].Value))
{
MessageBox.Show("不能选择相同的配件!");
return;
}
}
}
//查询配件信息
DataTable dtPeiJianXuanZe = myFRM_YuYueGuanLi_InsertClient.FRM_YuYueGuanLi_Insert_cboPeiJianBianMa_SelectedIndexChanged(Convert.ToInt32(cboPartsCoding.SelectedValue)).Tables[0];
//给各个控件赋值
txtPartsName.Text = dtPeiJianXuanZe.Rows[0]["PartsName"].ToString();
txtCarModels.Text = dtPeiJianXuanZe.Rows[0]["CarModels"].ToString();
txtPrice.Text = dtPeiJianXuanZe.Rows[0]["SellPrice"].ToString();
KeShouShu(Convert.ToInt32(cboPartsCoding.SelectedValue));//调用方法,查询可售数量
txtAvailableForSaleNumber.Text = decKeShouShu.ToString();//给“可售数”赋值
}
}


7、增加维修项目
第一步:界面层(UIL)。“新增”按钮点击事件。
private void btnXinZeng_Click(object sender, EventArgs e)
{
if (cboItemCode.Text == "")//项目名称为空
{
MessageBox.Show("请选择项目!");
return;
}
if(cboAccountType.Text=="")//帐类为空
{
MessageBox.Show("请选择帐类!");
return;
}

dgvBespeakServiceItem.Rows.Add();//dgv(预约项目)新增一行
//给dgv最后一行的各列赋值
dgvBespeakServiceItem.Rows[dgvBespeakServiceItem.Rows.Count - 1].Cells["项目代码"].Value = txtWorkHoursItem.Text;
dgvBespeakServiceItem.Rows[dgvBespeakServiceItem.Rows.Count - 1].Cells["预约维修项目"].Value = cboItemCode.Text;
dgvBespeakServiceItem.Rows[dgvBespeakServiceItem.Rows.Count - 1].Cells["工种"].Value = txtWorkKind.Text;
dgvBespeakServiceItem.Rows[dgvBespeakServiceItem.Rows.Count - 1].Cells["帐类"].Value = cboAccountType.Text;
dgvBespeakServiceItem.Rows[dgvBespeakServiceItem.Rows.Count - 1].Cells["帐类ID1"].Value =Convert.ToInt32(cboAccountType.SelectedValue);
dgvBespeakServiceItem.Rows[dgvBespeakServiceItem.Rows.Count - 1].Cells["工时单价"].Value = txtWorkHoursPrice.Text;
dgvBespeakServiceItem.Rows[dgvBespeakServiceItem.Rows.Count - 1].Cells["客帐工时"].Value = txtGuestAccountWorkHours.Text;
dgvBespeakServiceItem.Rows[dgvBespeakServiceItem.Rows.Count - 1].Cells["标准工时"].Value = txtParWorkHours.Text;
dgvBespeakServiceItem.Rows[dgvBespeakServiceItem.Rows.Count - 1].Cells["预计工时金额"].Value = txtAnticipatedWorkHoursMoney.Text;
dgvBespeakServiceItem.Rows[dgvBespeakServiceItem.Rows.Count - 1].Cells["工时项目ID1"].Value =Convert.ToInt32(cboItemCode.SelectedValue);
dgvBespeakServiceItem.Rows[dgvBespeakServiceItem.Rows.Count - 1].Cells["工时项目明细ID1"].Value = intGongShiXiangMuMingXiID;
//初始化各个控件
cboItemCode.Text = "";
txtWorkHoursItem.Text="";
txtWorkKind.Text="";
cboAccountType.SelectedValue = 72;
txtWorkHoursPrice.Text="";
txtGuestAccountWorkHours.Text="";
txtParWorkHours.Text="";
txtAnticipatedWorkHoursMoney.Text = "";
ZongJinE();//调用自定义方法计算总金额
}
public void ZongJinE()//自定义方法
{
decimal XiangMuZongJinE = 0;
for (int i = 0; i < dgvBespeakServiceItem.Rows.Count; i++)//循环dgv(预约维修项目)
{
//累加金额
decimal XiangMuJinE = Convert.ToDecimal(dgvBespeakServiceItem.Rows[i].Cells["预计工时金额"].Value);
XiangMuZongJinE = XiangMuZongJinE + XiangMuJinE;
}
decimal decPeiJianZongJinE = 0;
for (int j = 0; j < dgvBespeakParts.Rows.Count; j++)//循环dgv(预约配件)
{
//累加金额
decimal decPeiJianJinE = Convert.ToDecimal(dgvBespeakParts.Rows[j].Cells["金额"].Value);
decPeiJianZongJinE = decPeiJianZongJinE + decPeiJianJinE;
}
txtGross.Text = Convert.ToString(XiangMuZongJinE + decPeiJianZongJinE);//给“总金额”赋值
}


8、增加预约配件
第一步:界面层(UIL)。“新增”单击事件。
private void btnInsert2_Click(object sender, EventArgs e)
{
if (cboPartsCoding.Text == "")//如果配件为空
{
MessageBox.Show("请选择配件!");
return;
}
if( cboAccountType1.Text == "")//如果帐类为空
{
MessageBox.Show("请选择帐类!");
return;
}
if (txtNeedNumber.Text == "")//如果数量为空
{
MessageBox.Show("请输入数量!");
return;
}
dgvBespeakParts.Rows.Add();//dgv(预约配件)新增一行
//给dgv最后一行各列赋值
dgvBespeakParts.Rows[dgvBespeakParts.Rows.Count - 1].Cells["配件编码"].Value = cboPartsCoding.Text;
dgvBespeakParts.Rows[dgvBespeakParts.Rows.Count - 1].Cells["配件名称"].Value = txtPartsName.Text;
dgvBespeakParts.Rows[dgvBespeakParts.Rows.Count - 1].Cells["车型"].Value = txtCarModels.Text;
dgvBespeakParts.Rows[dgvBespeakParts.Rows.Count - 1].Cells["帐类1"].Value = cboAccountType1.Text;
dgvBespeakParts.Rows[dgvBespeakParts.Rows.Count - 1].Cells["帐类ID"].Value = Convert.ToInt32(cboAccountType1.SelectedValue);
dgvBespeakParts.Rows[dgvBespeakParts.Rows.Count - 1].Cells["预留数量"].Value = txtObligateNumBer.Text;
dgvBespeakParts.Rows[dgvBespeakParts.Rows.Count - 1].Cells["需求数量"].Value = txtNeedNumber.Text;
dgvBespeakParts.Rows[dgvBespeakParts.Rows.Count - 1].Cells["在途数量"].Value = txtInTranSitNumBer.Text;
dgvBespeakParts.Rows[dgvBespeakParts.Rows.Count - 1].Cells["可售数量"].Value = txtAvailableForSaleNumber.Text;
dgvBespeakParts.Rows[dgvBespeakParts.Rows.Count - 1].Cells["单价"].Value = txtPrice.Text;
dgvBespeakParts.Rows[dgvBespeakParts.Rows.Count - 1].Cells["金额"].Value = txtAllMoney.Text;
dgvBespeakParts.Rows[dgvBespeakParts.Rows.Count - 1].Cells["配件ID"].Value = cboPartsCoding.SelectedValue;
//初始化各个控件
cboPartsCoding.Text = "";
txtPartsName.Text = "";
txtCarModels.Text = "";
cboAccountType1.Text = "";
txtObligateNumBer.Text = "1";
txtNeedNumber.Text = "1";
txtInTranSitNumBer.Text = "0";
txtAvailableForSaleNumber.Text = "";
txtPrice.Text = "";
txtAllMoney.Text = "";
ZongJinE();//调用自定义方法计算总金额
}


10、删除dgv中的行数据,以dgv(预约维修项目)为例。
第一步:界面层(UIL)
private void btnShanChu_Click(object sender, EventArgs e)
{
if(dgvBespeakServiceItem.Rows.Count>0)//如果dgv不为空
{
//移除当前行
dgvBespeakServiceItem.Rows.Remove(dgvBespeakServiceItem.CurrentRow);
}
}


11、保存
第一步:数据库存储过程
IF(@TYPE='FRM_YuYueGuanLi_Insert_btnBaoCun_Click')
BEGIN
INSERT  PW_BespeakBillList(BespeakOddNumBer, CarNewsID, BespeakTime, AttributeMinuteID_BespeakWay, BespeakMileage, BespeakStatus, Gross,
FailCause, StaffID_HearPersons, StaffID_Receiver,ApprovalPerson, ApprovalTime, IfBespeakSucceed, LastTimeInTheFactory,
AlterationPerson, BookingCarDeliveryTime, BespeakWarnTime, PredictAOGTime, ServiceOddNumBer, NewBespeakOddlNumber,
OldBespeakOddNumber, NeedOddNumber, AlterationTime, AlterationCauses, ClientDescribe, Remarks, IfResourceRelease, IfEffective,IfApproval)
VALUES  (@BespeakOddNumBer, @CarNewsID, @BespeakTime, @AttributeMinuteID_BespeakWay, @BespeakMileage, @BespeakStatus, @Gross,
@FailCause, @StaffID_HearPersons, @StaffID_Receiver, @ApprovalPerson, @ApprovalTime, @IfBespeakSucceed, @LastTimeInTheFactory,
@AlterationPerson, @BookingCarDeliveryTime, @BespeakWarnTime, @PredictAOGTime, @ServiceOddNumBer, @NewBespeakOddlNumber,
@OldBespeakOddNumber, @NeedOddNumber, @AlterationTime, @AlterationCauses, @ClientDescribe, @Remarks, @IfReleaseResource, @IfEffective,0)
SELECT @@IDENTITY
END
IF(@TYPE='FRM_YuYueGuanLi_Insert_SaveYuYueXiangMu')
BEGIN
INSERT     PW_BespeakServiceItemList(BespeakBillID, WorkHoursItemMinuteID, AttributeMinuteID_AccountType, WorkHoursPrice,
GuestAccountWorkHours, ParWorkHours, AnticipatedWorkHoursMoney)
VALUES         (@BespeakBillID, @WorkHoursItemMinuteID, @AttributeMinuteID_AccountType, @WorkHoursPrice, @GuestAccountWorkHours,
@ParWorkHours, @AnticipatedWorkHoursMoney)
END
IF(@TYPE='FRM_YuYueGuanLi_Insert_SaveYuYuePeiJian')
BEGIN
INSERT     PW_BespeakPartsList(BespeakBillID, PartsID, AttributeMinuteID_AccountType, ObligateNumBer, NeedNumber,
InTranSitNumBer, AvailableForSaleNumber, Price, IfResourceRelease, Money)
VALUES    (@BespeakBillID, @PartsID, @AttributeMinuteID_AccountType, @ObligateNumBer, @NeedNumber, @InTranSitNumBer,
@AvailableForSaleNumber, @Price, @IfReleaseResource, @Money)
END


第二步:逻辑层(BLL)
//保存预约单信息
[OperationContract]
public int FRM_YuYueGuanLi_Insert_btnBaoCun_Click(string strYuYueDanHao, int intCheLiangXinXiID, DateTime datYuYueShiJian, int intYuYueFangShiID, decimal decYuYueLiCheng, string strYuYueZhuangTai, decimal decZongJiJinE, string strShiBaiYuanYin, int intShouLiRen, int intJieDaiRen, bool bitYuYueChengGongFou, string strShangCiJinChangShiJian, string strBianGengRen, string strYuYueJiCheShiJian, string strYuYueTiXingShiJian, string strWeiXiuDanHao, string strYuanYuYueDanHao, string strBianGengShiJian, string strBianGengYuanYin, string strGuKeMiaoShu, string strBeiZhu, bool bitZiYuanShiFangFou, bool bitYouXiaoFou, string strXinYuYueDanHao)
{

SqlParameter[] mySqlParameters =
{
new SqlParameter("@TYPE",SqlDbType.Char),
new SqlParameter("@BespeakOddNumBer",SqlDbType.NChar),
new SqlParameter("@CarNewsID",SqlDbType.Int),
new SqlParameter("@BespeakTime",SqlDbType.DateTime),
new SqlParameter("@AttributeMinuteID_BespeakWay",SqlDbType.Int),
new SqlParameter("@BespeakMileage",SqlDbType.Decimal),
new SqlParameter("@BespeakStatus",SqlDbType.NChar),
new SqlParameter("@Gross",SqlDbType.Decimal),
new SqlParameter("@FailCause",SqlDbType.NChar),
new SqlParameter("@StaffID_HearPersons",SqlDbType.Int),
new SqlParameter("@StaffID_Receiver",SqlDbType.Int),
new SqlParameter("@IfBespeakSucceed",SqlDbType.Bit),
new SqlParameter("@LastTimeInTheFactory",SqlDbType.NChar),
new SqlParameter("@AlterationPerson",SqlDbType.NChar),
new SqlParameter("@BookingCarDeliveryTime",SqlDbType.NChar),
new SqlParameter("@BespeakWarnTime",SqlDbType.NChar),
new SqlParameter("@ServiceOddNumBer",SqlDbType.NChar),
new SqlParameter("@OldBespeakOddNumber",SqlDbType.NChar),
new SqlParameter("@AlterationTime",SqlDbType.NChar),
new SqlParameter("@AlterationCauses",SqlDbType.NChar),
new SqlParameter("@ClientDescribe",SqlDbType.NChar),
new SqlParameter("@Remarks",SqlDbType.NChar),
new SqlParameter("@IfReleaseResource",SqlDbType.Bit),
new SqlParameter("@IfEffective",SqlDbType.Bit),
new SqlParameter("@NewBespeakOddlNumber",SqlDbType.NChar),
};
mySqlParameters[0].Value = "FRM_YuYueGuanLi_Insert_btnBaoCun_Click";
mySqlParameters[1].Value=strYuYueDanHao;
mySqlParameters[2].Value=intCheLiangXinXiID;
mySqlParameters[3].Value=datYuYueShiJian;
mySqlParameters[4].Value=intYuYueFangShiID;
mySqlParameters[5].Value=decYuYueLiCheng;
mySqlParameters[6].Value=strYuYueZhuangTai;
mySqlParameters[7].Value=decZongJiJinE;
mySqlParameters[8].Value=strShiBaiYuanYin;
mySqlParameters[9].Value=intShouLiRen;
mySqlParameters[10].Value=intJieDaiRen;
mySqlParameters[11].Value=bitYuYueChengGongFou;
mySqlParameters[12].Value=strShangCiJinChangShiJian;
mySqlParameters[13].Value=strBianGengRen;
mySqlParameters[14].Value=strYuYueJiCheShiJian;
mySqlParameters[15].Value=strYuYueTiXingShiJian;
mySqlParameters[16].Value=strWeiXiuDanHao;
mySqlParameters[17].Value=strYuanYuYueDanHao;
mySqlParameters[18.Value=strBianGengShiJian;
mySqlParameters[19].Value=strBianGengYuanYin;
mySqlParameters[20].Value=strGuKeMiaoShu;
mySqlParameters[21].Value=strBeiZhu;
mySqlParameters[22].Value=bitZiYuanShiFangFou;
mySqlParameters[23].Value=bitYouXiaoFou;
mySqlParameters[24].Value = strXinYuYueDanHao;
DataTable dt = myDALMethod.QueryDataTable("预约管理_FRM_YuYueGuanLi_Insert", mySqlParameters);
return Convert.ToInt32(dt.Rows[0][0]); //返回新增预约单的ID,大于0
}
//保存预约项目信息
[OperationContract]
public int FRM_YuYueGuanLi_Insert_SaveYuYueXiangMu(int intYuYueDanID, int IntGongShiXiangMuID, int intZhangLei, decimal decGongShiDanJia,
decimal decKeZhangGongShi, decimal decBiaoZhunGongShi, decimal DecYuJiGongShiJinE)
{
SqlParameter[] mySqlParameters =
{
new SqlParameter("@TYPE",SqlDbType.Char),
new SqlParameter("@BespeakBillID",SqlDbType.Int),
new SqlParameter("@WorkHoursItemMinuteID",SqlDbType.Int),
new SqlParameter("@AttributeMinuteID_AccountType",SqlDbType.Int),
new SqlParameter("@WorkHoursPrice",SqlDbType.Decimal),
new SqlParameter("@GuestAccountWorkHours",SqlDbType.Decimal),
new SqlParameter("@ParWorkHours",SqlDbType.Decimal),
new SqlParameter("@AnticipatedWorkHoursMoney",SqlDbType.Decimal),
};
mySqlParameters[0].Value = "FRM_YuYueGuanLi_Insert_SaveYuYueXiangMu";
mySqlParameters[1].Value=intYuYueDanID;
mySqlParameters[2].Value=IntGongShiXiangMuID;
mySqlParameters[3].Value=intZhangLei;
mySqlParameters[4].Value=decGongShiDanJia;
mySqlParameters[5].Value=decKeZhangGongShi;
mySqlParameters[6].Value=decBiaoZhunGongShi;
mySqlParameters[7].Value=DecYuJiGongShiJinE;
return myDALMethod.UpdateData("预约管理_FRM_YuYueGuanLi_Insert", mySqlParameters);
//返回的值为1的话,就保存成功,小于0就是异常。
}
//保存预约配件信息
[OperationContract]
public int FRM_YuYueGuanLi_Insert_SaveYuYuePeiJian(int intYuYueDanID, int intPeiJianID, int intZhangLei, decimal decYuLiuShuLiang, decimal decXuQiuShuLiang,
decimal decZaiTuShuLiang, decimal decKeShouShuLiang, decimal decDanJia, bool boolZiYuanShiFangFou,decimal decJinE)
{
SqlParameter[] mySqlParameters =
{
new SqlParameter("@TYPE",SqlDbType.Char),
new SqlParameter("@BespeakBillID",SqlDbType.Int),
new SqlParameter("@PartsID",SqlDbType.Int),
new SqlParameter("@AttributeMinuteID_AccountType",SqlDbType.Int),
new SqlParameter("@ObligateNumBer",SqlDbType.Decimal),
new SqlParameter("@NeedNumber",SqlDbType.Decimal),
new SqlParameter("@InTranSitNumBer",SqlDbType.Decimal),
new SqlParameter("@AvailableForSaleNumber",SqlDbType.Decimal),
new SqlParameter("@Price",SqlDbType.Decimal),
new SqlParameter("@IfReleaseResource",SqlDbType.Bit),
new SqlParameter("@Money",SqlDbType.Decimal),
};
mySqlParameters[0].Value = "FRM_YuYueGuanLi_Insert_SaveYuYuePeiJian";
mySqlParameters[1].Value=intYuYueDanID;
mySqlParameters[2].Value=intPeiJianID;
mySqlParameters[3].Value=intZhangLei;
mySqlParameters[4].Value=decYuLiuShuLiang;
mySqlParameters[5].Value=decXuQiuShuLiang;
mySqlParameters[6].Value=decZaiTuShuLiang;
mySqlParameters[7].Value=decKeShouShuLiang;
mySqlParameters[8].Value=decDanJia;
mySqlParameters[9].Value=boolZiYuanShiFangFou;
mySqlParameters[10].Value =decJinE;
return myDALMethod.UpdateData("预约管理_FRM_YuYueGuanLi_Insert", mySqlParameters);
//返回的值为1的话,就保存成功,小于0就是异常。
}


第三步:界面层(UIL)。“保存”按钮点击事件。
BLL海马汽车销售系统.预约管理.FRM_YuYueGuanLi_Insert.FRM_YuYueGuanLi_InsertClient myFRM_YuYueGuanLi_InsertClient =
new BLL海马汽车销售系统.预约管理.FRM_YuYueGuanLi_Insert.FRM_YuYueGuanLi_InsertClient();
private void btnSave_Click(object sender, EventArgs e)
{
if (cboLicensePlateNumber.Text == "")//如果车牌号为空
{
MessageBox.Show("请选择车辆!");
return;
}
int intYuYuePeiJian;
int intYuYueXiangMu;
//给各个参数赋值
string strXiaoShouShouKuan = "YY";
string strYuYueDanHao = ShengChengDanHao(strXiaoShouShouKuan);//调用方法生成单号
int intCheLiangXinXiID = Convert.ToInt32(cboLicensePlateNumber.SelectedValue);
DateTime datYuYueShiJian = dtpBespeakTime.Value.Date.AddHours(Convert.ToInt32(nudhour.Value)).AddMinutes(Convert.ToInt32(nudminute.Value));
int intYuYueFangShiID = Convert.ToInt32(cboBespeakWay.SelectedValue);
decimal decYuYueLiCheng = Convert.ToDecimal(txtBespeakMileage.Text);
string strYuYueZhuangTai = txtBespeakStatus.Text;
decimal decZongJiJinE = Convert.ToDecimal(txtGross.Text);
string strShiBaiYuanYin = txtFailCause.Text;
int intShouLiRen = Convert.ToInt32(cboHearPersons.SelectedValue);
int intJieDaiRen = Convert.ToInt32(cboReceiver.SelectedValue);
bool bitYuYueChengGongFou = Convert.ToBoolean(chbIfBespeakSucceed.Checked);
string strShangCiJinChangShiJian = txtLastTimeInTheFactory.Text;
string strBianGengRen = txtAlterationPerson.Text;
string strYuYueJiCheShiJian = txtBookingCarDeliveryTime.Text;
string strYuYueTiXingShiJian = txtBespeakWarnTime.Text;
string strWeiXiuDanHao = txtServiceOddNumBer.Text;
string strYuanYuYueDanHao = txtOldBespeakOddNumber.Text;
string strBianGengShiJian = txtAlterationTime.Text;
string strBianGengYuanYin = txtAlterationCauses.Text;
string strGuKeMiaoShu = txtClientDescribe.Text;
string strBeiZhu = txtRemarks.Text;
bool bitZiYuanShiFangFou = false;
bool bitYouXiaoFou = true;
string strXinYuYueDanHao = txtNewBespeakOddlNumber.Text;
//把预约信息保存到数据库
int intYuYueDan = myFRM_YuYueGuanLi_InsertClient.FRM_YuYueGuanLi_Insert_btnBaoCun_Click(strYuYueDanHao, intCheLiangXinXiID, datYuYueShiJian, intYuYueFangShiID, decYuYueLiCheng, strYuYueZhuangTai, decZongJiJinE, strShiBaiYuanYin, intShouLiRen, intJieDaiRen, strHeZhunRen, strShangCiJinChangShiJian, strBianGengRen, strYuYueJiCheShiJian, strYuYueTiXingShiJian, strWeiXiuDanHao, strYuanYuYueDanHao, strBianGengShiJian, strBianGengYuanYin, strGuKeMiaoShu, strBeiZhu, bitZiYuanShiFangFou, bitYouXiaoFou, strXinYuYueDanHao);

for (int i = 0; i < dgvBespeakServiceItem.Rows.Count; i++)//循环dgv(预约维修项目)
{
//给各个参数赋值
int intYuYueDanID = intYuYueDan;
int IntGongShiXiangMuID = Convert.ToInt32(dgvBespeakServiceItem.Rows[i].Cells["工时项目明细ID1"].Value);
int intZhangL = Convert.ToInt32(dgvBespeakServiceItem.Rows[i].Cells["帐类ID1"].Value);
decimal decGongShiDanJia = Convert.ToDecimal(dgvBespeakServiceItem.Rows[i].Cells["工时单价"].Value);
decimal datKeZhangGongShi = Convert.ToDecimal(dgvBespeakServiceItem.Rows[i].Cells["客帐工时"].Value);
decimal datBiaoZhunGongShi = Convert.ToDecimal(dgvBespeakServiceItem.Rows[i].Cells["标准工时"].Value);
decimal DecYuJiGongShiJinE = Convert.ToDecimal(dgvBespeakServiceItem.Rows[i].Cells["预计工时金额"].Value);
//把预约项目保存到数据库
intYuYueXiangMu = myFRM_YuYueGuanLi_InsertClient.FRM_YuYueGuanLi_Insert_SaveYuYueXiangMu(intYuYueDanID, IntGongShiXiangMuID, intZhangL, decGongShiDanJia,
datKeZhangGongShi, datBiaoZhunGongShi, DecYuJiGongShiJinE);
}

for (int j = 0; j < dgvBespeakParts.Rows.Count; j++)//循环dgv(预约配件)
{
//给各个参数赋值
int intYuYueDanID = intYuYueDan;
int intPeiJianID = Convert.ToInt32(dgvBespeakParts.Rows[j].Cells["配件ID"].Value);
int intZhangLei = Convert.ToInt32(dgvBespeakParts.Rows[j].Cells["帐类ID"].Value);
decimal decYuLiuShuLiang = Convert.ToDecimal(dgvBespeakParts.Rows[j].Cells["预留数量"].Value);
decimal decXuQiuShuLiang = Convert.ToDecimal(dgvBespeakParts.Rows[j].Cells["需求数量"].Value);
decimal decZaiTuShuLiang = Convert.ToDecimal(dgvBespeakParts.Rows[j].Cells["在途数量"].Value);
decimal decKeShouShuLiang = Convert.ToDecimal(dgvBespeakParts.Rows[j].Cells["可售数量"].Value);
decimal decDanJia = Convert.ToDecimal(dgvBespeakParts.Rows[j].Cells["单价"].Value);
bool boolZiYuanShiFangFou = false;
decimal decJinE = Convert.ToDecimal(dgvBespeakParts.Rows[j].Cells["金额"].Value);
//把预约配件信息保存到数据库
intYuYuePeiJian = myFRM_YuYueGuanLi_InsertClient.FRM_YuYueGuanLi_Insert_SaveYuYuePeiJian(intYuYueDanID, intPeiJianID, intZhangLei, decYuLiuShuLiang, decXuQiuShuLiang,
decZaiTuShuLiang, decKeShouShuLiang, decDanJia, boolZiYuanShiFangFou, decJinE);
}
if (intYuYueDan > 0) //如果调用方法成功
{
txtBespeakOddNumBer.Text = strYuYueDanHao;
MessageBox.Show("新增成功!!!");
}
}


12、退出
第一步:界面层(UIL)。“退出”按钮点击事件。
if (MessageBox.Show("确定退出?" + "\n推出前请确认数据已保存!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) //提示对话框,如果点击【是】
{
this.Dispose();//释放资源
this.Close();//关闭窗体
}


以上仅用于学习参考,禁止用于商业用途!!!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: