实现会员管理的会员升级规则窗体功能代码(二十一)

实现会员管理的会员升级规则窗体功能代码(二十一)

3.5.2会员升级规则

3.5.2.1会员升级规则主界面

当会员卡类别设置好后,会员卡还可以根据积分进行升级。这里是设置一个升级的规则,可以根据会员卡的等级高低进行排序和升级的设置,如当普通卡积分到600分时就可以升级为银卡,这里只能从低级的卡升至高级。积分是在收费录入时根据结账的多少进行积分的,只有是拥有会员卡的才能积分,积分规则:消费一元积分0.01分。

主界面截图:

实现会员管理的会员升级规则窗体功能代码(二十一)_第1张图片

 

3.5.2.1(图1

从界面上可以看到我们这里用到的控件有:

控件名称

说明

按钮控件button

第一要设置每个控件的Text,第二设置控件Name;不同的是dataGridView右键进行编辑列。

表格控件dataGridView

查询功能实现

第一步:数据库

1、  表与关系

实现会员管理的会员升级规则窗体功能代码(二十一)_第2张图片

3.5.2.1(图2

表1:会员升级规则表(BT_MembeUpgradeRuleTable)

列名

数据类型

主键/外键

说明

MembeUpgradeRuleID

int - Identity

主键

会员升级规则ID

Original_MemberCategoryID

int

外键

原卡类别_会员类别ID

Upgraded_MemberCategoryID

int

 

升级后卡类别_会员类别ID

UpgradeCondition

nchar (100)

 

升级条件

WhetherEffective

bit

 

有效否

 

表2:会员类别表(BT_MemberCategoryTable

列名

数据类型

主键/外键

说明

MemberCategoryID

int - Identity

主键

会员类别 ID

MemberCategoryNumber

nchar (30)

 

会员类别编号

MemberCategoryDiscount

numeric (18, 2)

 

会员类别折扣

MemberCategoryName

nchar (30)

 

会员类别名称

Remarks

nchar (150)

 

备注

WhetherEffective

bit

 

有效否

功能代码实现

查询会员升级规则

1)、存储过程代码:

--查询会员升级规则
IF(@Type ='FRM_HuiYuanShengJiGuiZe_Load_ChaXunShengJiGuiZe')	
	BEGIN
		SELECT        LTRIM(RTRIM(BT_MembeUpgradeRuleTable.MembeUpgradeRuleID))AS MembeUpgradeRuleID, 
		          LTRIM(RTRIM(BT_MemberCategoryTable.MemberCategoryName)) AS Original,
		          LTRIM(RTRIM(BT_MembeUpgradeRuleTable.UpgradeCondition))AS UpgradeCondition, 
		          LTRIM(RTRIM(BT_MemberCategoryTable_1.MemberCategoryName))AS MemberCategoryName, 
		          LTRIM(RTRIM(BT_MembeUpgradeRuleTable.WhetherEffective))AS WhetherEffective
				 
				  
		FROM          BT_MemberCategoryTable INNER JOIN
				  BT_MembeUpgradeRuleTable ON BT_MemberCategoryTable.MemberCategoryID = BT_MembeUpgradeRuleTable.Original_MemberCategoryID 
				  INNER JOIN BT_MemberCategoryTable AS BT_MemberCategoryTable_1 ON
				  BT_MembeUpgradeRuleTable.Upgraded_MemberCategoryID = BT_MemberCategoryTable_1.MemberCategoryID
		WHERE         BT_MembeUpgradeRuleTable.WhetherEffective =1
	END
--查询会员卡类别
IF(@Type='FRM_HuiYuanShengJiGuiZe_Insert_Load_ChaXunKaLeiXing')
	BEGIN
		SELECT    LTRIM(RTRIM(MemberCategoryID)) AS MemberCategoryID, 
		          LTRIM(RTRIM(MemberCategoryName)) AS MemberCategoryName
		FROM         BT_MemberCategoryTable
	END

2)、逻辑层代码:

[OperationContract]
        #region 查询升级规则
        public DataSet FRM_HuiYuanShengJiGuiZe_Load_ChaXunShengJiGuiZe()
        {
            SqlParameter[] SQLCMDpas ={
                                          new  SqlParameter ("@Type",SqlDbType.Char),
                                              };
            SQLCMDpas[0].Value = "FRM_HuiYuanShengJiGuiZe_Load_ChaXunShengJiGuiZe";
            DataTable myDataTable = myDALMethod.QueryDataTable("HuiYuanGuanLi_FRM_HuiYuanShengJiGuiZe", SQLCMDpas);
            DataSet myDataSet = new DataSet();
            myDataSet.Tables.Add(myDataTable);
            return myDataSet;
        }
        #endregion

3)、界面层代码:

#region Load事件
        private void FRM_HuiYuanShengJiGuiZe_Load(object sender, EventArgs e)
        {
            // 查询绑定会员升级规则
            dgvMembeUpgradeRule.DataSource = myFRM_HuiYuanShengJiGuiZeClient.FRM_HuiYuanShengJiGuiZe_Load_ChaXunShengJiGuiZe().Tables[0];
            dgvMembeUpgradeRule.ClearSelection();//清空默认选行
            
        }
        #endregion

删除会员升级规则

1)、存储过程代码:

--删除会员升级规则
IF(@Type ='btnBaoCun_Click_DeleteShengJiGuiZe')
	BEGIN		
		DELETE   BT_MembeUpgradeRuleTable
		WHERE    BT_MembeUpgradeRuleTable.MembeUpgradeRuleID =@MembeUpgradeRuleID
	END

2)、逻辑层代码:

[OperationContract]
        #region 删除升级规则
        public int btnBaoCun_Click_DeleteShengJiGuiZe(int intMembeUpgradeRuleID)
        {
            SqlParameter[] SQLCMDpas ={
                                          new  SqlParameter ("@Type",SqlDbType.Char),
                                          new  SqlParameter ("@MembeUpgradeRuleID",SqlDbType.Int),                                         
                                              };
            SQLCMDpas[0].Value = "btnBaoCun_Click_DeleteShengJiGuiZe";
            SQLCMDpas[1].Value = intMembeUpgradeRuleID;           
            int count = myDALMethod.UpdateData("HuiYuanGuanLi_FRM_HuiYuanShengJiGuiZe", SQLCMDpas);
            return count;
        }
        #endregion

3)、界面层代码:

#region 删除事件
        private void btnShanChu_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show("是否删除?", "系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);//弹出确定对话框
            if (dr == DialogResult.OK)//如果点了确定按钮
            {
                MembeUpgradeRuleID = Convert.ToInt32(dgvMembeUpgradeRule.CurrentRow.Cells["会员升级规则ID"].Value);//获取点击行的会员升级规则
                if (MembeUpgradeRuleID != 0)
                {
                    myFRM_HuiYuanShengJiGuiZeClient.btnBaoCun_Click_DeleteShengJiGuiZe(MembeUpgradeRuleID);//执行删除会员升级规则
                    dgvMembeUpgradeRule.DataSource = myFRM_HuiYuanShengJiGuiZeClient.FRM_HuiYuanShengJiGuiZe_Load_ChaXunShengJiGuiZe().Tables[0];//刷新界面                   

                }
                else
                {
                    MessageBox.Show("请选择要删除的行。。");
                }
            }
        }
        #endregion

3.5.2.2新增会员升级规则

界面显示的原卡类别升级前该卡所属的类别,升级后卡别是指经过积分规则升级后的卡的类别。升级后卡别不可以比原卡类别高级。

新增会员升级规则截图:

实现会员管理的会员升级规则窗体功能代码(二十一)_第3张图片

 

3.5.2.2(图1

 

新增会员升级规则

1)、存储过程代码:


 

--新增会员升级规则
IF(@Type='btnBaoCun_Click_BaoCunXinZengShengJiGuiZe')
	BEGIN
	BEGIN TRAN
		INSERT       BT_MembeUpgradeRuleTable(Original_MemberCategoryID, Upgraded_MemberCategoryID, 
				  UpgradeCondition, WhetherEffective)
		VALUES       (@Original_MemberCategoryID, @Upgraded_MemberCategoryID, @UpgradeCondition, @WhetherEffective) 
		          
	SELECT @@IDENTITY 
	COMMIT TRAN
	END

2)、逻辑层代码:

[OperationContract]
        #region 新增升级规则
        public int btnBaoCun_Click_BaoCunXinZengShengJiGuiZe(int intOriginal_MemberCategoryID, int intUpgraded_MemberCategoryID,
            string strUpgradeCondition, bool blWhetherEffective)
        {
            SqlParameter[] SQLCMDpas ={
                                          new  SqlParameter ("@Type",SqlDbType.Char),
                                          new  SqlParameter ("@Original_MemberCategoryID",SqlDbType.Int),
                                          new  SqlParameter ("@Upgraded_MemberCategoryID",SqlDbType.Int),
                                          new  SqlParameter ("@UpgradeCondition",SqlDbType.Char),
                                          new  SqlParameter ("@WhetherEffective",SqlDbType.Bit),
                                              };
            SQLCMDpas[0].Value = "btnBaoCun_Click_BaoCunXinZengShengJiGuiZe";
            SQLCMDpas[1].Value = intOriginal_MemberCategoryID;
            SQLCMDpas[2].Value = intUpgraded_MemberCategoryID;
            SQLCMDpas[3].Value = strUpgradeCondition;
            SQLCMDpas[4].Value = blWhetherEffective;
            int count = myDALMethod.UpdateData("HuiYuanGuanLi_FRM_HuiYuanShengJiGuiZe", SQLCMDpas);
            return count;
        }
        #endregion    

3)、界面层代码:

#region 保存数据到表中
        private void btnBaoCunShuJuDaoBiaoGe_Click(object sender, EventArgs e)
        {
            //从界面控件中赋值给dgvHuiYuanShengJiGuiZe
            int index = 0;
            index = dgvHuiYuanShengJiGuiZe.Rows.Add();
            dgvHuiYuanShengJiGuiZe.Rows[index].Cells["原卡类别"].Value = cboOriginalMemberCategory.Text.ToString().Trim();
            dgvHuiYuanShengJiGuiZe.Rows[index].Cells["原卡类别ID"].Value = cboOriginalMemberCategory.SelectedValue;
            dgvHuiYuanShengJiGuiZe.Rows[index].Cells["升级后卡别ID"].Value = cboUpgradedMemberCategory.SelectedValue;
            dgvHuiYuanShengJiGuiZe.Rows[index].Cells["升级后卡别"].Value = cboUpgradedMemberCategory.Text.ToString().Trim();
            dgvHuiYuanShengJiGuiZe.Rows[index].Cells["升级条件"].Value = txtBeginUpgradeCondition.Text + "—" + EndUpgradeCondition.Text;
            dgvHuiYuanShengJiGuiZe.Rows[index].Cells["有效否"].Value = Convert.ToBoolean(1);            
        }
        #endregion 
#region 新增会员卡升级规则
        private void btnBaoCun_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show("确定新增?", "系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);//弹出确定对话框
            if (dr == DialogResult.OK)//如果点了确定按钮
            {
                if (dgvHuiYuanShengJiGuiZe.Rows.Count > 0)//判断dgvHuiYuanShengJiGuiZe行数大于0
                {
                    int count = 0;//声明一个整形变量
                    for (int i = 0; i < dgvHuiYuanShengJiGuiZe.Rows.Count; i++)//循环dgvHuiYuanShengJiGuiZe行数
                    {
                        int intOriginal_MemberCategoryID = Convert.ToInt32(dgvHuiYuanShengJiGuiZe.Rows[i].Cells["原卡类别ID"].Value);//给声明的变量原卡类别ID intOriginal_MemberCategoryID赋值
                        int intUpgraded_MemberCategoryID = Convert.ToInt32(dgvHuiYuanShengJiGuiZe.Rows[i].Cells["升级后卡别ID"].Value);//给声明的变量升级后卡别ID intUpgraded_MemberCategoryID赋值
                        string strUpgradeCondition = dgvHuiYuanShengJiGuiZe.Rows[i].Cells["升级条件"].Value.ToString();//给声明的变量升级条件strUpgradeCondition赋值
                        bool blWhetherEffective = Convert.ToBoolean(dgvHuiYuanShengJiGuiZe.Rows[i].Cells["有效否"].Value);//给声明的变量有效否blWhetherEffective赋值
                        count += myFRM_HuiYuanShengJiGuiZeClient.btnBaoCun_Click_BaoCunXinZengShengJiGuiZe(intOriginal_MemberCategoryID,
                            intUpgraded_MemberCategoryID, strUpgradeCondition, blWhetherEffective);//执行新增会员升级规则
                    }
                    if (count > 0)
                    {
                        MessageBox.Show("保存成功!");
                        this.Close();//关闭当前窗体
                    }
                    else
                    {
                        MessageBox.Show("保存失败!");
                    }
                }
            }
        }
        #endregion

3.5.2.3修改会员升级规则

这里可以对会员卡升级规则进行修改,可以移除错误的规则,可以修改升级条件等。也可以新增升级规则。

修改会员升级规则截图:

实现会员管理的会员升级规则窗体功能代码(二十一)_第4张图片

 

3.5.2.3(图1

修改会员升级规则

1)、存储过程代码:

--修改会员升级规则
IF(@Type='btnBaoCun_Click_BaoCunXiuGaiShengJiGuiZe')
	BEGIN
	
		UPDATE       BT_MembeUpgradeRuleTable
		SET       Original_MemberCategoryID=@Original_MemberCategoryID, Upgraded_MemberCategoryID=@Upgraded_MemberCategoryID, 
		          UpgradeCondition=@UpgradeCondition 
		WHERE         BT_MembeUpgradeRuleTable.MembeUpgradeRuleID=@MembeUpgradeRuleID
	
	END

2)、逻辑层代码:

#region 修改升级规则
        public int btnBaoCun_Click_BaoCunXiuGaiShengJiGuiZe(int intOriginal_MemberCategoryID, int intUpgraded_MemberCategoryID,
            string strUpgradeCondition, int intMembeUpgradeRuleID)
        {
            SqlParameter[] SQLCMDpas ={
                                          new  SqlParameter ("@Type",SqlDbType.Char),
                                          new  SqlParameter ("@Original_MemberCategoryID",SqlDbType.Int),
                                          new  SqlParameter ("@Upgraded_MemberCategoryID",SqlDbType.Int),
                                          new  SqlParameter ("@UpgradeCondition",SqlDbType.Char),
                                          new  SqlParameter ("@MembeUpgradeRuleID",SqlDbType.Int),
                                              };
            SQLCMDpas[0].Value = "btnBaoCun_Click_BaoCunXiuGaiShengJiGuiZe";
            SQLCMDpas[1].Value = intOriginal_MemberCategoryID;
            SQLCMDpas[2].Value = intUpgraded_MemberCategoryID;
            SQLCMDpas[3].Value = strUpgradeCondition;
            SQLCMDpas[4].Value = intMembeUpgradeRuleID;
            int count = myDALMethod.UpdateData("HuiYuanGuanLi_FRM_HuiYuanShengJiGuiZe", SQLCMDpas);
            return count;
        }
        #endregion

3)、界面层代码:

#region Load事件
        private void FRM_HuiYuanShengJiGuiZe_Update_Load(object sender, EventArgs e)
        {
            DataTable dtKaLeiBie = myFRM_HuiYuanShengJiGuiZeClient.FRM_HuiYuanShengJiGuiZe_Insert_Load_ChaXunKaLeiXing().Tables[0];
            cboOriginalMemberCategory = PublicStaticMothd.SetZhiXiaLaKuang(cboOriginalMemberCategory, dtKaLeiBie, "MemberCategoryID", "MemberCategoryName");
            DataTable dtLeiBie = myFRM_HuiYuanShengJiGuiZeClient.FRM_HuiYuanShengJiGuiZe_Insert_Load_ChaXunKaLeiXing().Tables[0];
            cboUpgradedMemberCategory = PublicStaticMothd.SetZhiXiaLaKuang(cboUpgradedMemberCategory, dtLeiBie, "MemberCategoryID", "MemberCategoryName");
            dgvUpdateMembeUpgradeRule.DataSource = myFRM_HuiYuanShengJiGuiZeClient.FRM_HuiYuanShengJiGuiZe_Load_ChaXunShengJiGuiZe().Tables[0];
            dgvUpdateMembeUpgradeRule.ClearSelection();
        }
        #endregion
        #region 移除事件
        ArrayList arr = new ArrayList();
        private void dgvUpdateMembeUpgradeRule_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 0)
            {
                if (dgvUpdateMembeUpgradeRule.CurrentRow.Cells["MembeUpgradeRuleID"].Value == null)//当会员升级规则IDMembeUpgradeRuleID不为空
                {
                    if (dgvUpdateMembeUpgradeRule.Rows.Count == 1)
                    {
                        dgvUpdateMembeUpgradeRule.Rows.Clear();//清空会员升级规则表的行
                        dgvUpdateMembeUpgradeRule.Rows.Add();//新增会员升级规则表的行

                    }
                    else
                    {
                        if (MessageBox.Show("是否移除?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            dgvUpdateMembeUpgradeRule.Rows.Remove(dgvUpdateMembeUpgradeRule.CurrentRow);//移除界面新增的还没保存到数据库的数据
                        }
                    }
                }
                else
                {
                    arr.Add(dgvUpdateMembeUpgradeRule.CurrentRow.Cells["MembeUpgradeRuleID"].Value);//获取点击的行会员升级规则IDMembeUpgradeRuleID
                    dgvUpdateMembeUpgradeRule.Rows.Remove(dgvUpdateMembeUpgradeRule.CurrentRow);//移除会员升级规则表的点击的行
                    for (int i = 0; i < arr.Count; i++)
                    {
                        myFRM_HuiYuanShengJiGuiZeClient.btnBaoCun_Click_DeleteShengJiGuiZe(Convert.ToInt32(arr[i]));//移除数据库的数据
                    }
                }
            }
        }
        #endregion
        #region 保存修改事件
        private void btnBaoCun_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < dgvUpdateMembeUpgradeRule.Rows.Count; i++)//循环dgvUpdateMembeUpgradeRule行数
            {
                int intOriginal_MemberCategoryID = Convert.ToInt32(dgvUpdateMembeUpgradeRule.Rows[i].Cells["原卡类别ID"].Value);//给声明的变量原卡类别ID intOriginal_MemberCategoryID赋值
                int intUpgraded_MemberCategoryID = Convert.ToInt32(dgvUpdateMembeUpgradeRule.Rows[i].Cells["升级后卡别ID"].Value);//给声明的变量升级后卡别ID intUpgraded_MemberCategoryID赋值
                string strUpgradeCondition = dgvUpdateMembeUpgradeRule.Rows[i].Cells["升级条件"].Value.ToString();//给声明的变量升级条件strUpgradeCondition赋值
                int intMembeUpgradeRuleID = Convert.ToInt32(dgvUpdateMembeUpgradeRule.Rows[i].Cells["MembeUpgradeRuleID"].Value.ToString());
                myFRM_HuiYuanShengJiGuiZeClient.btnBaoCun_Click_BaoCunXiuGaiShengJiGuiZe(intOriginal_MemberCategoryID, intUpgraded_MemberCategoryID, strUpgradeCondition, intMembeUpgradeRuleID);
            }
        }
        #endregion       

仅供学习,禁止用于商业用途。


虽然我们不能决定自己生命的长度,但可以拓宽它的宽度;虽然我们不能改变容貌,但可以展现笑容;虽然我们不能控制他人,但可以掌握自己;虽然我们不能预知明天,但可以把握今天;虽然你不能样样顺利,但你可以事事尽力。

长相不令人讨厌,如果长得不好,就让自己有才气;如果才气也没有,那就总是微笑。

明日复明日,明日何其多?我生待明日,万事成蹉跎。———《明日歌》

 





你可能感兴趣的:(.NET)