可以說商品的折扣率是連貫整個系統的中樞,每個病人的醫療的費用都要根據該商品是否設置到折扣的問題,按照不同的醫療方式商品設置不同的折扣,在病人消費的時候根據病人的醫療方式進行對應的折扣。
打開設置商品折扣價
界面如(圖1):可以對一個商品打勾,點擊單個保存,也可以全選點擊批量保存,進行設置折扣率如(圖2)
(圖1)
(圖2)
表和關係
表1折扣類型表
列名 |
數據類型 |
說明 |
DiscountTypeID |
Int(主鍵) |
折扣類型ID |
DiscountTypeName |
nchar(20) |
折扣類型名稱 |
表2第三方表
說明:第三方表主要是爲了讓折扣類型表和藥品表形成多對多的關係。
列名 |
數據類型 |
說明 |
ThirdPartyID |
int(主鍵) |
第三方ID |
DiscountTypeID |
Int(外鍵) |
折扣類型ID |
MedicineID |
int(外鍵) |
藥品ID |
Discountrate |
decimal(18, 2) |
折扣率 |
單個保存操作,首先要對哪個商品進行折扣的勾上,再設置折扣,點擊單個保存,實現代碼
數據庫存儲過程
if @Type='Frm_ShangPingZheKouSheZhi_InsertZheKou'
begin
insert BS_ThirdPartyList(DiscountTypeID, MedicineID, Discountrate)
values (@DiscountTypeID, @MedicineID, @Discountrate)
end--新增折扣
if @Type='Frm_ShangPingZheKouSheZhi_SelectThirdPartyID'
begin
SELECT ThirdPartyID
from BS_ThirdPartyList
where BS_ThirdPartyList.MedicineID=@MedicineID
and BS_ThirdPartyList.DiscountTypeID=@DiscountTypeID
end--查詢
if @Type='Frm_ShangPingZheKouSheZhi_UpdateZheKou'
begin
update BS_ThirdPartyList
set Discountrate=@Discountrate
where BS_ThirdPartyList.ThirdPartyID=@ThirdPartyID
end --修改折扣
邏輯層代碼
[OperationContract]
public int Frm_ShangPingZheKouSheZhi_InsertZheKou(int DiscountTypeID, int MedicineID, decimal Discountrate)
{
SqlParameter[] mySqlParameters = {
new SqlParameter ("@Type",SqlDbType .Char),
new SqlParameter ("@DiscountTypeID",SqlDbType .Int),
new SqlParameter ("@MedicineID",SqlDbType .Int),
new SqlParameter ("@Discountrate",SqlDbType .Decimal),
};
mySqlParameters[0].Value = "Frm_ShangPingZheKouSheZhi_InsertZheKou";
mySqlParameters[1].Value =DiscountTypeID;
mySqlParameters[2].Value =MedicineID;
mySqlParameters[3].Value = Discountrate;
return myDALMethod.UpdateData("信息設置_Frm_ShangPingZheKouSheZhi", mySqlParameters);
}
[OperationContract]
public DataSet Frm_ShangPingZheKouSheZhi_SelectZheKouHouShuJu(int MedicineID)
{
SqlParameter[] mySqlParameters = {
new SqlParameter ("@Type",SqlDbType .Char),
new SqlParameter ("@MedicineID",SqlDbType .Int),
};
mySqlParameters[0].Value = "Frm_ShangPingZheKouSheZhi_SelectZheKouHouShuJu";
mySqlParameters[1].Value = MedicineID;
DataTable dt = myDALMethod.QueryDataTable("信息設置_Frm_ShangPingZheKouSheZhi", mySqlParameters);
DataSet ds = new DataSet();
ds.Tables.Add(dt);
return ds;
}
[OperationContract]
public DataSet Frm_ShangPingZheKouSheZhi_SelectThirdPartyID(int MedicineID, int DiscountTypeID)
{
SqlParameter[] mySqlParameters = {
new SqlParameter ("@Type",SqlDbType .Char),
new SqlParameter ("@MedicineID",SqlDbType .Int),
new SqlParameter ("@DiscountTypeID",SqlDbType .Int),
};
mySqlParameters[0].Value = "Frm_ShangPingZheKouSheZhi_SelectThirdPartyID";
mySqlParameters[1].Value = MedicineID;
mySqlParameters[2].Value = DiscountTypeID;
DataTable dt = myDALMethod.QueryDataTable("信息設置_Frm_ShangPingZheKouSheZhi", mySqlParameters);
DataSet ds = new DataSet();
ds.Tables.Add(dt);
return ds;
}
[OperationContract]
public int Frm_ShangPingZheKouSheZhi_UpdateZheKou(decimal Discountrate, int ThirdPartyID)
{
SqlParameter[] mySqlParameters = {
new SqlParameter ("@Type",SqlDbType .Char),
new SqlParameter ("@Discountrate",SqlDbType .Decimal),
new SqlParameter ("@ThirdPartyID",SqlDbType .Int),
};
mySqlParameters[0].Value = "Frm_ShangPingZheKouSheZhi_UpdateZheKou";
mySqlParameters[1].Value = Discountrate;
mySqlParameters[2].Value = ThirdPartyID;
return myDALMethod.UpdateData("信息設置_Frm_ShangPingZheKouSheZhi", mySqlParameters);
}
界面層代碼
點擊單個保存
private void btnDanGeBaoCun_Click(object sender, EventArgs e)
{ int Z=0;
int ChengGong=0;
foreach(DataGridViewRow dgv in dgvShangPingXinXi.Rows)
{
if (Convert.ToBoolean(dgv.Cells["選擇"].Value))
{
for (int i = 0; i < dgvZheKouXinXi.Rows.Count; i++)
{
int ZheKouLeiXingID = Convert.ToInt32(dgvZheKouXinXi.Rows[i].Cells["DiscountTypeID"].Value);
decimal ZheKouBi = Convert.ToDecimal(dgvZheKouXinXi.Rows[i].Cells["Discountrate"].Value);
if (ZheKouBi > 1)
{
MessageBox.Show("折扣比必須在0—1間");
return;
}
//根據藥品ID,折扣類型ID,獲取數據庫的ThirdPartyID
DataTable dtThirdPartyID = myFrm_ShangPingZheKouSheZhiClient.
Frm_ShangPingZheKouSheZhi_SelectThirdPartyID(YaoPingID, ZheKouLeiXingID).Tables[0];
//如果數據庫中存在ThirdPartyID
if (dtThirdPartyID.Rows.Count > 0)
{
//獲取ThirdPartyID出來
int ThirdPartyID = Convert.ToInt32(dtThirdPartyID.Rows[0][0]);
//根據ThirdPartyID修改折扣率
ChengGong= myFrm_ShangPingZheKouSheZhiClient.
Frm_ShangPingZheKouSheZhi_UpdateZheKou(ZheKouBi,ThirdPartyID);
}
else
{
//否則新增
Z= myFrm_ShangPingZheKouSheZhiClient.
Frm_ShangPingZheKouSheZhi_InsertZheKou(ZheKouLeiXingID, YaoPingID, ZheKouBi);
}
}
}
}
if (ChengGong > 0 || Z > 0)
{
MessageBox.Show("保存成功");
dgvShangPingXinXi_CellClick(null,null);
}
}
批量設置折扣
設置窗口的實現,因爲折扣類型的不定的變化,根據醫院可能會增加或者減少折扣類型,所以爲了適應,只能用動態來實現。
private void plZheKou_Paint(object sender, PaintEventArgs e)
{
dt = myFrm_ShangPingZheKouSheZhiClient.Frm_ShangPingZheKouSheZhi_SelectZheKouLeiXing().Tables[0];
for (int i = 0 ,leftX = 10, leftY = 2; i < dt.Rows.Count; i++)
{
leftY += 30;
//定義畫筆實例
Pen mypen = new Pen(Color.Black);
//定義畫筆實例
Graphics myGraphics = e.Graphics;
//賦值
string Name = dt.Rows[i]["DiscountTypeName"].ToString().Trim();
myGraphics.DrawString(Name,new Font("宋體", 10, FontStyle.Regular),
SystemBrushes.ControlText, leftX, leftY);
}
}
在窗體Load事件中給每個折扣類型對應賦值ID
private void Frm_ZheKouBiSheZhiXiaoChuanTi_Load(object sender, EventArgs e)
{
dt = myFrm_ShangPingZheKouSheZhiClient.Frm_ShangPingZheKouSheZhi_SelectZheKouLeiXing().Tables[0];
DtCount = dt.Rows.Count;//查詢折扣類型ID
ZheKouShuZhu = new string[DtCount];//定義數組的長度爲折扣類型的個數
//循環給每個折扣類型賦值ID
for (int i = 0, leftX = 10, leftY = 2; i < dt.Rows.Count; i++)
{
leftY += 30;
TextBox txtZheKouLv = new TextBox();
txtZheKouLv.Size = new Size(100, 21);
txtZheKouLv.Text = "1.00";
txtZheKouLv.Tag = dt.Rows[i]["DiscountTypeID"].ToString().Trim();
//數組記錄一開始的折扣比
ZheKouShuZhu[i] = txtZheKouLv.Text.ToString().Trim();
txtZheKouLv.Location = new Point(leftX + 120, leftY);
//設置文本邊框格式
txtZheKouLv.BorderStyle = System.Windows.Forms.BorderStyle.None;
//設置文本下劃線
txtZheKouLv.Font=new Font(new Font("宋體",15),FontStyle.Underline);
plZheKou.Controls.Add(txtZheKouLv);
txtZheKouLv.TextChanged+=new EventHandler(txtZheKouLv_TextChanged);
}
}
每次編輯折扣率時對應用數組記錄下來
private void Frm_ZheKouBiSheZhiXiaoChuanTi_Load(object sender, EventArgs e)
{
dt = myFrm_ShangPingZheKouSheZhiClient.Frm_ShangPingZheKouSheZhi_SelectZheKouLeiXing().Tables[0];
DtCount = dt.Rows.Count;//查詢折扣類型ID
ZheKouShuZhu = new string[DtCount];//定義數組的長度爲折扣類型的個數
//循環給每個折扣類型賦值ID
for (int i = 0, leftX = 10, leftY = 2; i < dt.Rows.Count; i++)
{
leftY += 30;
TextBox txtZheKouLv = new TextBox();
txtZheKouLv.Size = new Size(100, 21);
txtZheKouLv.Text = "1.00";
txtZheKouLv.Tag = dt.Rows[i]["DiscountTypeID"].ToString().Trim();
//數組記錄一開始的折扣比
ZheKouShuZhu[i] = txtZheKouLv.Text.ToString().Trim();
txtZheKouLv.Location = new Point(leftX + 120, leftY);
//設置文本邊框格式
txtZheKouLv.BorderStyle = System.Windows.Forms.BorderStyle.None;
//設置文本下劃線
txtZheKouLv.Font=new Font(new Font("宋體",15),FontStyle.Underline);
plZheKou.Controls.Add(txtZheKouLv);
txtZheKouLv.TextChanged+=new EventHandler(txtZheKouLv_TextChanged);
}
}
設置好折扣率後點擊保存
decimal ZheKouBi;
int WangChengCount=0;
private void btnSave_Click(object sender, EventArgs e)
{
for (int i = 0; i < Frm_ShangPingZheKouSheZhi.YaoPing.Length; i++)
{ //獲取數組值
int YaoPingID = Frm_ShangPingZheKouSheZhi.YaoPing[i];
for (int j = 0; j < dt.Rows.Count; j++)
{ //獲取折扣類型ID
int ZheKouLeiXingID = Convert.ToInt32(dt.Rows[j]["DiscountTypeID"]);
ZheKouBi = Convert.ToDecimal(ZheKouShuZhu[j]);
//根據藥品ID,折扣類型ID,獲取數據庫的ThirdPartyID
DataTable dtThirdPartyID = myFrm_ShangPingZheKouSheZhiClient.
Frm_ShangPingZheKouSheZhi_SelectThirdPartyID(YaoPingID, ZheKouLeiXingID).Tables[0];
//如果數據庫中存在ThirdPartyID
if (dtThirdPartyID.Rows.Count > 0)
{
//獲取ThirdPartyID出來
int ThirdPartyID = Convert.ToInt32(dtThirdPartyID.Rows[0][0]);
//根據ThirdPartyID修改折扣率
myFrm_ShangPingZheKouSheZhiClient.
Frm_ShangPingZheKouSheZhi_UpdateZheKou(ZheKouBi, ThirdPartyID);
}
else
{
//否則新增
myFrm_ShangPingZheKouSheZhiClient.
Frm_ShangPingZheKouSheZhi_InsertZheKou(ZheKouLeiXingID, YaoPingID, ZheKouBi);
}
}
WangChengCount++;//記錄成功的數量
}
//如果完成數量=全選的商品數量
if (WangChengCount == Frm_ShangPingZheKouSheZhi.YaoPing.Length)
{
plHuanChong.Visible = false;
MessageBox.Show("設置成功!");
}
}
僅供學習,禁止商業用途!