新锐房地产销售管理系统(部分流程)技术解析(十) 销售管理_销售优惠设置

1.销售优惠设置主界面



 

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

控件名称

说明

标注(Label)

控件可以在工具箱直接拖动至窗体,拖至窗体后右击属性可以修改控件的样式和各种属性,还可以编辑事件。

选项卡(TabControl)

树状图(TreeView)

文本(TextBox)

按钮(Button)

菜单(ToolStripMenuItem)

复选框(CheckBox)

工具栏(ToolStrip)

图片列表(ImageList)

表格(DataGridView)

 

功能实现:

第一步:数据库

1、表与关系

表1: 房间资源表(dbo.SYS_RoomResource)

Primary Key(主键):  RoomResourcesID

非主键ID值均是外键

列名

数据类型

默认值

Nulls?

说明

RoomResourcesID

int - Identity

 

No

房间资源ID

 

FloorID

int

 

Yes

楼栋信息表,楼栋ID

 

TheCodeModelID

int

 

Yes

属性明细表,代码模式ID

 

Number

nchar (10)

 

Yes

编号

 

UnitNumberID

int

 

Yes

单元表,单元ID

 

FloorStotey

nchar (10)

 

Yes

楼层

 

RoomCategoryID

int

 

Yes

属性明细表,房间类别ID

 

TowardID

int

 

Yes

属性明细表,朝向ID

 

DoorModelID

int

 

Yes

属性明细表,户型ID

 

RoomTypeID

int

 

Yes

属性明细表,房间类型ID

 

RoomLandScapeID

int

 

Yes

属性明细表,房间景观ID

 

RoomSpecialID

int

 

Yes

属性明细表,房间特殊ID

 

ConstructionArea

decimal (18, 2)

 

Yes

建筑面积

 

PricateArea

decimal (18, 2)

 

Yes

私有面积

 

PublicArea

decimal (18, 2)

 

Yes

公摊面积

 

Usage

decimal (18, 2)

 

Yes

使用率

 

TheUnitPrice

decimal (18, 2)

 

Yes

标价单价

 

BidPrice

decimal (18, 2)

 

Yes

标价总价

 

NumberOfPrice

nchar (10)

 

Yes

价格次数

 

SalesStatusID

int

((102))

Yes

属性明细表,销售状态ID

 

BriefNote

nchar (30)

 

Yes

简要备注

 

SchematicDiagram

image

 

Yes

示意图

 

Chart

image

 

Yes

效果图

 

 

表2: 楼栋信息表(dbo.SYS_FloorInformation)

Primary Key(主键):  FloorID

非主键ID值均是外键

(这里因为在这个表里边没有设置有默认值,所以没有默认值的那一列)

列名

数据类型

Nulls?

说明

FloorID

int - Identity

No

楼栋ID

 

ProjectID

int

Yes

项目信息表,项目ID

 

FloorStructureID

int

Yes

属性明细表,楼栋结构ID

 

OpenBatchID

int

Yes

属性明细表,开盘批次ID

 

LaunchSituationID

int

Yes

属性明细表,推出情况ID

 

OpeningSituationID

int

Yes

属性明细表,开盘情况ID

 

FloorLevelID

int

Yes

楼栋级别ID

 

SortNumber

nchar (10)

Yes

序号

 

FloorName

nchar (20)

Yes

楼栋名称

 

PropertyRightFloorName

nchar (20)

Yes

产权楼栋名称

 

FloorStorey

nchar (10)

Yes

楼栋层数

 

LaunchDate

datetime

Yes

推出日期

 

DoMortgageDate

datetime

Yes

具备办按揭日期

 

CapsDate

datetime

Yes

封顶日期

 

AccumulationFundDate

datetime

Yes

具备办公积金日期

 

ExpectedPayDate

datetime

Yes

预计交房日期

 

PropertyRightDate

datetime

Yes

具备办产权日期

 

MakingRoomDate

datetime

Yes

交房日期

 

表3: 项目信息表(dbo.SYS_ProjectInformation)

Primary Key(主键):  ProjectID

非主键ID值均是外键

 

列名

数据类型

默认值

Nulls?

说明

ProjectID

int - Identity

 

No

项目ID

 

SortNumber

int

 

Yes

排序号

 

ProjectAreaID

int

 

Yes

属性明细表,项目区域ID

 

Project_FatherlID

int

 

Yes

项目信息表,项目级别ID

 

ProjectName

nchar (20)

 

Yes

项目名称

 

PropertyRightProjectName

nchar (20)

 

Yes

产权项目名称

 

ProjectCompanyName

nchar (20)

 

Yes

项目公司名称

 

ProjectAddress

nchar (50)

 

Yes

项目座落地址

 

CaseWhether

bit

 

Yes

是否结案

 

CancelWhether

bit

((0))

Yes

有效否

 

表4: 折扣优惠表 (dbo. SYS_DiscountOfPreferential)

Primary Key(主键):  DiscountID

非主键ID值均是外键

列名

数据类型

默认值

Nulls?

DiscountID

int - Identity

 

No

ProjectID

int

 

Yes

BuildingNumberIDGather

nvarchar (4000)

 

Yes

UnitNumberIDGather

nvarchar (4000)

 

Yes

DiscountName

nchar (50)

 

Yes

SerialNumber

nchar (20)

 

Yes

EffectiveDate

datetime

 

Yes

ExpiryDate

datetime

 

Yes

PreferentialTyoeID

int

 

Yes

CaluculationID

int

 

Yes

CaluculationTypeID

int

 

Yes

Discount

decimal (18, 2)

 

Yes

DiscountSum

decimal (18, 2)

 

Yes

ASingleSetOfHighestDiscountAmount

decimal (18, 2)

 

Yes

TotalDiscount

decimal (18, 2)

 

Yes

UsingRangeID

int

 

Yes

Privilege

nchar (100)

 

Yes

WhetherenableManagerPermissions

bit

 

No

CancelWhether

bit

((0))

Yes

表5: 折扣优惠明细表 (dbo. SYS_DiscountOfPreferentialDetail)

Primary Key(主键):  DiscountOfPreferentialDetailID

非主键ID值均是外键

列名

数据类型

默认值

Nulls?

DiscountOfPreferentialDetailID

int - Identity

 

No

DiscountID

int

 

Yes

FloorID

int

 

Yes

RoomResourceID

int

 

Yes

RecordDate

datetime

 

Yes

IncalidOr

bit

((0))

Yes

表6: 属性明细表(dbo.SYS_AttributeDetails)

Primary Key(主键):  AttributeDetailsID

列名

数据类型

默认值

Nulls?

说明

AttributeDetailsID

int - Identity

 

No

属性明细ID

 

AuttributeSetID

int

 

Yes

属性集合表,属性集合ID

 

AuttributeDetailsName

nchar (10)

 

Yes

属性明细名称

 

EffectiveWhether

bit

((1))

Yes

有效否

 

 

2、具体的代码实现

第一步:数据库的存储过程

 

 if(@type='InsertPreferentialDetails_Load_BindingcboProjectName')--查询查询项目
 begin
 SELECT     ProjectID, RTRIM(ProjectName) as 项目名称
 FROM         SYS_ProjectInformation
 end
 
 if(@type='InsertPreferentialDetails_Load_BindingcboPreferentialType')--查询销售优惠类型
 begin
 SELECT     AttributeDetailsID,RTRIM(AuttributeDetailsName) as 优惠类型
 FROM         SYS_AttributeDetails
 WHERE      AuttributeSetID=11
 end
 
 if(@type='InsertPreferentialDetails_Load_BindingcboCalculation')--查询计算方式
 begin
 SELECT     AttributeDetailsID,RTRIM(AuttributeDetailsName) as 计算方式
 FROM         SYS_AttributeDetails
 WHERE      AuttributeSetID=12
 end
 
 if(@type='InsertPreferentialDetails_Load_BindingcboCalculatetheType')--查询计算类型
 begin
 SELECT     AttributeDetailsID,RTRIM(AuttributeDetailsName) as 计算类型
 FROM         SYS_AttributeDetails
 WHERE      AuttributeSetID=13
 end
 
 if(@type='InsertPreferentialDetails_Load_BindingcboUsingRange')--查询使用范围
 begin
 SELECT     AttributeDetailsID,RTRIM(AuttributeDetailsName) as 使用范围
 FROM         SYS_AttributeDetails
 WHERE      AuttributeSetID=14
 end
 
 if(@type='InsertPreferentialDetails_btnSaveAndInsert_Click')--新增
 begin
 begin tran
 INSERT INTO SYS_DiscountOfPreferential
         (ProjectID, DiscountName, SerialNumber, EffectiveDate, ExpiryDate, PreferentialTyoeID, CaluculationID, CaluculationTypeID, Discount, DiscountSum, 
         ASingleSetOfHighestDiscountAmount, TotalDiscount, UsingRangeID, Privilege, WhetherenableManagerPermissions, BuildingNumberIDGather, UnitNumberIDGather)
 VALUES  (@ProjectID,@DiscountName,@SerialNumber,@EffectiveDate,@ExpiryDate,@PreferentialTyoeID,@CaluculationID,@CaluculationTypeID,@Discount,@DiscountSum,
         @ASingleSetOfHighestDiscountAmount,@TotalDiscount,@UsingRangeID,@Privilege,@WhetherenableManagerPermissions,@BuildingNumberIDGather,@UnitNumberIDGather)
 select @@IDENTITY
 commit tran
 end
 
 if(@type='btnSaveAndInsert_Click_InsertDetail')--新增明细
 begin
 INSERT INTO SYS_DiscountOfPreferentialDetail
                      (DiscountID, FloorID, RoomResourceID, RecordDate)
 VALUES     (@DiscountID, @FloorID, @RoomResourceID, GETDATE() )
 end
 
 
 
 if(@type='InsertPreferentialDetails_btnSelect_Click')--查询优惠明细
 begin
 SELECT     SYS_DiscountOfPreferential.DiscountID, SYS_DiscountOfPreferential.ProjectID, rtrim(SYS_DiscountOfPreferential.BuildingNumberIDGather) as BuildingNumberIDGather, rtrim(SYS_DiscountOfPreferential.UnitNumberIDGather) as UnitNumberIDGather, RTRIM(SYS_DiscountOfPreferential.DiscountName) as 优惠名称, 
                  RTRIM(SYS_DiscountOfPreferential.SerialNumber) as 序号, SYS_DiscountOfPreferential.EffectiveDate as 有效时间, SYS_DiscountOfPreferential.ExpiryDate as 失效时间, SYS_DiscountOfPreferential.PreferentialTyoeID, SYS_DiscountOfPreferential.CaluculationID, 
                  SYS_DiscountOfPreferential.CaluculationTypeID, RTRIM(SYS_DiscountOfPreferential.Discount) as 优惠折扣, RTRIM(SYS_DiscountOfPreferential.DiscountSum) AS 优惠单价, RTRIM(SYS_DiscountOfPreferential.ASingleSetOfHighestDiscountAmount) as 单套最高优惠额, 
                  RTRIM(SYS_DiscountOfPreferential.TotalDiscount) as 优惠总价, SYS_DiscountOfPreferential.UsingRangeID, RTRIM(SYS_DiscountOfPreferential.Privilege) as 优惠说明, SYS_DiscountOfPreferential.WhetherenableManagerPermissions as 是否启用经理权限, 
                  rtrim(SYS_AttributeDetails.AuttributeDetailsName) as 优惠类型, rtrim(SYS_AttributeDetails_1.AuttributeDetailsName) AS 计算方式, SYS_AttributeDetails_2.AttributeDetailsID, 
                  rtrim(SYS_AttributeDetails_2.AuttributeDetailsName) AS 计算类型, RTRIM(SYS_ProjectInformation.ProjectName) as 项目名称, rtrim(SYS_AttributeDetails_3.AuttributeDetailsName) AS 使用范围
 FROM         SYS_AttributeDetails INNER JOIN
                  SYS_DiscountOfPreferential ON SYS_AttributeDetails.AttributeDetailsID = SYS_DiscountOfPreferential.PreferentialTyoeID INNER JOIN
                  SYS_AttributeDetails AS SYS_AttributeDetails_1 ON SYS_DiscountOfPreferential.CaluculationID = SYS_AttributeDetails_1.AttributeDetailsID INNER JOIN
                  SYS_AttributeDetails AS SYS_AttributeDetails_2 ON SYS_DiscountOfPreferential.CaluculationTypeID = SYS_AttributeDetails_2.AttributeDetailsID INNER JOIN
                  SYS_ProjectInformation ON SYS_DiscountOfPreferential.ProjectID = SYS_ProjectInformation.ProjectID INNER JOIN
                  SYS_AttributeDetails AS SYS_AttributeDetails_3 ON SYS_DiscountOfPreferential.UsingRangeID = SYS_AttributeDetails_3.AttributeDetailsID
 WHERE       SYS_ProjectInformation.ProjectID=@ProjectID and  SYS_DiscountOfPreferential.CancelWhether=0                 
 end

 

第二步:逻辑层(BLL)相关代码

DALPublic.DALPublic myDALPublic = new DALPublic.DALPublic();


        [OperationContract]
        #region 查询下拉框数据
        public DataSet InsertPreferentialDetails_Load_BindingcboProjectName()
        {
            SqlParameter[] SQLCMDpas = { new SqlParameter("@type", SqlDbType.Char),
                                         
                                          };
            SQLCMDpas[0].Value = "InsertPreferentialDetails_Load_BindingcboProjectName";
            DataTable myDataTable = myDALPublic.DAL_SelectDB_Par("frmMarketManagement_SalesofPreferentialSettings", SQLCMDpas);
            DataSet myDataSet = new DataSet();
            myDataSet.Tables.Add(myDataTable);
            return myDataSet;
        }
        #endregion 

        [OperationContract]
        #region 查询下拉框数据
        public DataSet InsertPreferentialDetails_Load_BindingcboPreferentialType()
        {
            SqlParameter[] SQLCMDpas = { new SqlParameter("@type", SqlDbType.Char),
                                         
                                          };
            SQLCMDpas[0].Value = "InsertPreferentialDetails_Load_BindingcboPreferentialType";
            DataTable myDataTable = myDALPublic.DAL_SelectDB_Par("frmMarketManagement_SalesofPreferentialSettings", SQLCMDpas);
            DataSet myDataSet = new DataSet();
            myDataSet.Tables.Add(myDataTable);
            return myDataSet;
        }
        #endregion 

        [OperationContract]
        #region 查询下拉框数据
        public DataSet InsertPreferentialDetails_Load_BindingcboCalculation()
        {
            SqlParameter[] SQLCMDpas = { new SqlParameter("@type", SqlDbType.Char),
                                         
                                          };
            SQLCMDpas[0].Value = "InsertPreferentialDetails_Load_BindingcboCalculation";
            DataTable myDataTable = myDALPublic.DAL_SelectDB_Par("frmMarketManagement_SalesofPreferentialSettings", SQLCMDpas);
            DataSet myDataSet = new DataSet();
            myDataSet.Tables.Add(myDataTable);
            return myDataSet;
        }
        #endregion 

        [OperationContract]
        #region 查询下拉框数据
        public DataSet InsertPreferentialDetails_Load_BindingcboCalculatetheType()
        {
            SqlParameter[] SQLCMDpas = { new SqlParameter("@type", SqlDbType.Char),
                                         
                                          };
            SQLCMDpas[0].Value = "InsertPreferentialDetails_Load_BindingcboCalculatetheType";
            DataTable myDataTable = myDALPublic.DAL_SelectDB_Par("frmMarketManagement_SalesofPreferentialSettings", SQLCMDpas);
            DataSet myDataSet = new DataSet();
            myDataSet.Tables.Add(myDataTable);
            return myDataSet;
        }
        #endregion 


        [OperationContract]
        #region 查询下拉框数据
        public DataSet InsertPreferentialDetails_Load_BindingcboUsingRange()
        {
            SqlParameter[] SQLCMDpas = { new SqlParameter("@type", SqlDbType.Char),
                                         
                                          };
            SQLCMDpas[0].Value = "InsertPreferentialDetails_Load_BindingcboUsingRange";
            DataTable myDataTable = myDALPublic.DAL_SelectDB_Par("frmMarketManagement_SalesofPreferentialSettings", SQLCMDpas);
            DataSet myDataSet = new DataSet();
            myDataSet.Tables.Add(myDataTable);
            return myDataSet;
        }
        #endregion 

 

第三步:界面层(UIL)相关代码及说明

    public partial class frmMarketManagement_SalesOfPreferentialSettings : Form
    {
        frmMain frmmain;
        public frmMarketManagement_SalesOfPreferentialSettings(frmMain frm)
        {
            frmmain = frm;
            InitializeComponent();
        }

        BLL新锐房地产销售系统.MarketManagement.frmMarketManagement_SalesofPreferentialSettings.frmMarketManagement_SalesofPreferentialSettingsClient myfrmMarketManagement_SalesofPreferentialSettingsClient = new 
            BLL新锐房地产销售系统.MarketManagement.frmMarketManagement_SalesofPreferentialSettings.frmMarketManagement_SalesofPreferentialSettingsClient();

        private void frmMarketManagement_SalesOfPreferentialSettings_FormClosing(object sender, FormClosingEventArgs e)
        {
            frmmain.RemoveTabPage();
        }

        private void btnInsert_Click(object sender, EventArgs e)
        {
            frmMarketManagement_SalesofPreferentialSettings_InsertPreferentialDetails myfrmMarketManagement_SalesofPreferentialSettings_InsertPreferentialDetails = 
                new frmMarketManagement_SalesofPreferentialSettings_InsertPreferentialDetails(this);
            myfrmMarketManagement_SalesofPreferentialSettings_InsertPreferentialDetails.ShowDialog();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void frmMarketManagement_SalesOfPreferentialSettings_Load(object sender, EventArgs e)
        {
            dgvSalesPreferentialList.AutoGenerateColumns = false;
            DataTable dtProjectName = myfrmMarketManagement_SalesofPreferentialSettingsClient.InsertPreferentialDetails_Load_BindingcboProjectName().Tables[0];
            DataTable dtPreferentialType = myfrmMarketManagement_SalesofPreferentialSettingsClient.InsertPreferentialDetails_Load_BindingcboPreferentialType().Tables[0];
            DataRow dr = dtProjectName.NewRow();
            dr["ProjectID"] = 0;
            dr["项目名称"] = "全部";
            dtProjectName.Rows.InsertAt(dr,0);
            PublicMethod.SettingComboBox(cboProjectName, dtProjectName, "ProjectID", "项目名称", true);
            PublicMethod.SettingComboBox(cboPreferentialType, dtPreferentialType, "AttributeDetailsID", "优惠类型", true);
            DataTable dtCalculation = myfrmMarketManagement_SalesofPreferentialSettingsClient.InsertPreferentialDetails_Load_BindingcboCalculation().Tables[0];
            PublicMethod.SettingComboBox(cboCalculation, dtCalculation, "AttributeDetailsID", "计算方式", true);
            MultiSelect(intPreferentialType, intCalculation, strEffectiveDate, strEffectiveDate1, intProjectID);
        }

        private void btnSelect_Click(object sender, EventArgs e)
        {            
            MultiSelect(intPreferentialType, intCalculation, strEffectiveDate, strEffectiveDate1, intProjectID);            
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (dgvSalesPreferentialList.Rows.Count > 0)
            {
                int intDiscount =Convert.ToInt32(dgvSalesPreferentialList.CurrentRow.Cells["DiscountID"].Value);
                int intDeleteSuccess = myfrmMarketManagement_SalesofPreferentialSettingsClient.InsertPreferentialDetails_DeleteSalesOfPreferential(intDiscount);
                if (intDeleteSuccess > 0)
                {
                    MessageBox.Show("删除成功!!");
                    btnSelect_Click(null,null);
                }
                else
                {
                    MessageBox.Show("删除失败!!");
                }
            }
        }

        public void PubRefresh()
        {
            frmMarketManagement_SalesOfPreferentialSettings_Load(null,null);
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (dgvSalesPreferentialList.Rows.Count > 0)
            {
                PublicStaticClass.blPublicSwith = true;
                frmMarketManagement_SalesofPreferentialSettings_InsertPreferentialDetails myfrmMarketManagement_SalesofPreferentialSettings_InsertPreferentialDetails = new
                    frmMarketManagement_SalesofPreferentialSettings_InsertPreferentialDetails(this);
                myfrmMarketManagement_SalesofPreferentialSettings_InsertPreferentialDetails.ShowDialog();
            }
            else
            {
                MessageBox.Show("没有可修改的数据!!!");
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Pub_ckb_Click(object sender, EventArgs e)
        {
            CheckBox ckb = sender as CheckBox;
            if (ckb.Name == "ckbCalculation")
            {
                if (ckb.Checked)
                {
                    cboCalculation.Enabled = true;
                }
                else
                {
                    cboCalculation.Enabled = false;
                    intCalculation = 0;
                    MultiSelect(intPreferentialType, intCalculation, strEffectiveDate, strEffectiveDate1, intProjectID);
                }
            }
            if (ckb.Name == "ckbPreferentialType")
            {
                if (ckb.Checked)
                {
                    cboPreferentialType.Enabled = true;
                }
                else
                {
                    cboPreferentialType.Enabled = false;
                    intPreferentialType = 0;
                    MultiSelect(intPreferentialType, intCalculation, strEffectiveDate, strEffectiveDate1, intProjectID);
                }
            }
            if (ckb.Name == "ckbEffectiveDate")
            {
                if (ckb.Checked)
                {
                    dtpEffectiveDate.Enabled = true;
                    dtpEffectiveDate1.Enabled = true; 
                    string ss = dtpEffectiveDate.Text.ToString();
                    string sss = dtpEffectiveDate1.Text.ToString();
                }
                else
                {
                    dtpEffectiveDate.Enabled = false;
                    dtpEffectiveDate1.Enabled = false;
                    strEffectiveDate = "";
                    strEffectiveDate1 = "";
                    MultiSelect(intPreferentialType, intCalculation, strEffectiveDate, strEffectiveDate1, intProjectID);
                }
            }
        }

        int intPreferentialType = 0;
        int intCalculation = 0;
        string strEffectiveDate = "";
        string strEffectiveDate1 = "";
        int intProjectID = 0;
        bool bolRoomAllChecked = false;
         void MultiSelect(int intPreferentialType, int intCalculation, string strEffectiveDate, string strEffectiveDate1, int intProjectID)
        {
            DataTable dtSalesPreferentialMsg =  myfrmMarketManagement_SalesofPreferentialSettingsClient.Multi_Select_DiscountOfPreferential(intPreferentialType, intCalculation, strEffectiveDate, strEffectiveDate1, intProjectID).Tables[0];
            dgvSalesPreferentialList.DataSource = dtSalesPreferentialMsg;
         }

        private void cboPreferentialType_SelectionChangeCommitted(object sender, EventArgs e)
        {
            intPreferentialType = (int)cboPreferentialType.SelectedValue;
        }

        private void cboCalculation_SelectionChangeCommitted(object sender, EventArgs e)
        {
            intCalculation = (int)cboCalculation.SelectedValue;
        }

        private void Pub_dtp_ValueChanged(object sender, EventArgs e)
        {
            if (dtpEffectiveDate.Value > dtpEffectiveDate1.Value)
            {
                MessageBox.Show("亲,开始日期不能在结束日期之前的哦!!!","提示");
                dtpEffectiveDate.Value = dtpEffectiveDate1.Value;
                return;
            } 
            strEffectiveDate = dtpEffectiveDate.Text.ToString();
            strEffectiveDate1 = dtpEffectiveDate1.Text.ToString();
        }

        private void cboProjectName_SelectionChangeCommitted(object sender, EventArgs e)
        {
            intProjectID = (int)cboProjectName.SelectedValue;
        }

        private void dgvSalesPreferentialList_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            int intProjectID = (int)dgvSalesPreferentialList.CurrentRow.Cells["ProjectID"].Value;
            int intUsingRangeID = Convert.ToInt32(dgvSalesPreferentialList.CurrentRow.Cells["UsingRangeID"].Value);
            string strFloorGather = dgvSalesPreferentialList.CurrentRow.Cells["BuildingNumberIDGather"].Value.ToString();
            string strRoomResourceGather = dgvSalesPreferentialList.CurrentRow.Cells["UnitNumberIDGather"].Value.ToString();
            
            DataTable dtFloorNumber = myfrmMarketManagement_SalesofPreferentialSettingsClient.InsertPreferentialDetails_Load_BindingFloorNumber(intProjectID).Tables[0];
            string strCondition = "";
            switch (intUsingRangeID)
            {
                case 51:  //整个项目
                    bolRoomAllChecked = true;
                    BindingTvwNode_OnProject(dtFloorNumber);
                    tvwRoom.Nodes.Clear();
                    strCondition = BindingTvwFloor_Checked(strFloorGather);
                    BindingAllCheckedRoom(strCondition);
                    //tvwFloorNumber.Enabled = false;
                    //grbIncludeRoom.Enabled = false;
                    break;
                case 52:  //部分楼栋
                    bolRoomAllChecked = true;
                    BindingTvwNode(dtFloorNumber);
                    //grbIncludeRoom.Enabled = false;
                    tvwRoom.Nodes.Clear();
                    strCondition = BindingTvwFloor_Checked(strFloorGather);
                    BindingAllCheckedRoom(strCondition);
                    BindingTvwFloor_Checked(strFloorGather);
                    break;
                case 53:  //某些单元
                    bolRoomAllChecked = false;
                    BindingTvwNode(dtFloorNumber);
                    //grbIncludeRoom.Enabled = true;
                    tvwRoom.Nodes.Clear();
                    strCondition = BindingTvwFloor_Checked(strFloorGather);
                    BindingTvwRoomResource_Checked(strCondition, strRoomResourceGather);
                    break;
                case 54:  //某些房间
                    bolRoomAllChecked = false;
                    BindingTvwNode(dtFloorNumber);
                    //grbIncludeRoom.Enabled = true;
                    tvwRoom.Nodes.Clear();
                    strCondition = BindingTvwFloor_Checked(strFloorGather);
                    BindingTvwRoomResource_Checked(strCondition, strRoomResourceGather);
                    break;
            }
        }

        string BindingTvwFloor_Checked(string strFloorGather)
        {
            string strNewFloorGather = strFloorGather.Remove(strFloorGather.Length - 1);
            string[] strArrayFloorID = strNewFloorGather.Split(',');
            string strCondition = "";
            for (int intCount = 0; intCount < tvwFloorNumber.Nodes.Count; intCount++)
            {
                foreach (string strParameter in strArrayFloorID)
                {
                    if (strParameter == tvwFloorNumber.Nodes[intCount].Tag.ToString())
                    {
                        tvwFloorNumber.Nodes[intCount].Checked = true;
                        strCondition = strCondition + " FloorID=" + tvwFloorNumber.Nodes[intCount].Tag + " or";
                    }
                }
            }
            return strCondition;
        }

        void BindingAllCheckedRoom(string strCondition)
        {
            DataTable dtRoomNumber = new DataTable();
            dtRoomNumber = myfrmMarketManagement_SalesofPreferentialSettingsClient.InsertPreferentialDetails_Load_BindingRoomNumber().Tables[0];
            string strNewCondition = "";
            if (strCondition != "")
            {
                strNewCondition = strCondition.Remove(strCondition.Length - 3);
            }
            DataView dv = new DataView(dtRoomNumber);
            dv.RowFilter = strNewCondition;
            DataTable dt = dv.ToTable();
            BindingTvwRoomNode_AllChecked(dt);
        }

        DataTable dtAfter = new DataTable();
        void BindingTvwRoomResource_Checked(string strCondition, string strRoomResourceGather)
        {
            string strNewRoomResourceGather = strRoomResourceGather.Remove(strRoomResourceGather.Length - 1);
            string[] strArrayRoomResourceID = strNewRoomResourceGather.Split(',');
            DataTable dtRoomNumber = new DataTable();
            dtRoomNumber = myfrmMarketManagement_SalesofPreferentialSettingsClient.InsertPreferentialDetails_Load_BindingRoomNumber().Tables[0];
            string strNewCondition = "";
            if (strCondition != "")
            {
                strNewCondition = strCondition.Remove(strCondition.Length - 3);
            }
            DataView dv = new DataView(dtRoomNumber);
            dv.RowFilter = strNewCondition;
            dtAfter = dv.ToTable();
            BindingTvwRoomNode(dtAfter);
            for (int intCount = 0; intCount < tvwRoom.Nodes.Count; intCount++)
            {
                foreach (string strParameter in strArrayRoomResourceID)
                {
                    if (strParameter == tvwRoom.Nodes[intCount].Tag.ToString())
                    {
                        tvwRoom.Nodes[intCount].Checked = true;
                    }
                }
            }
        }

        public void BindingTvwNode(DataTable dtFloorNumber)
        {
            tvwFloorNumber.Enabled = true;
            tvwFloorNumber.Nodes.Clear();
            for (int i = 0; i < dtFloorNumber.Rows.Count; i++)//遍历绑定顶级节点
            {
                TreeNode tn = new TreeNode();//实例化节点
                tn.Text = dtFloorNumber.Rows[i]["楼栋号"].ToString();//指定节点文本
                tn.Tag = dtFloorNumber.Rows[i]["FloorID"];//绑定节点数据
                tvwFloorNumber.Nodes.Add(tn);//将节点添加到树控件                
            }
        }

        public void BindingTvwNode_OnProject(DataTable dtFloorNumber)
        {
            tvwFloorNumber.Nodes.Clear();
            for (int i = 0; i < dtFloorNumber.Rows.Count; i++)//遍历绑定顶级节点
            {
                TreeNode tn = new TreeNode();//实例化节点
                tn.Text = dtFloorNumber.Rows[i]["楼栋号"].ToString();//指定节点文本
                tn.Tag = dtFloorNumber.Rows[i]["FloorID"];//绑定节点数据
                tn.Checked = true;
                tvwFloorNumber.Nodes.Add(tn);//将节点添加到树控件                
            }
        }

        public void BindingTvwRoomNode(DataTable dt)
        {
            tvwRoom.Nodes.Clear();
            for (int i = 0; i < dt.Rows.Count; i++)//遍历绑定顶级节点
            {
                TreeNode tn = new TreeNode();//实例化节点
                tn.Text = dt.Rows[i]["FloorName"].ToString().Trim() + " - " + dt.Rows[i]["房间号"].ToString().Trim();//指定节点文本
                tn.Tag = dt.Rows[i]["RoomResourcesID"];//绑定节点数据
                tvwRoom.Nodes.Add(tn);//将节点添加到树控件                
            }
        }

        public void BindingTvwRoomNode_AllChecked(DataTable dt)
        {
            tvwRoom.Nodes.Clear();
            for (int i = 0; i < dt.Rows.Count; i++)//遍历绑定顶级节点
            {
                TreeNode tn = new TreeNode();//实例化节点
                tn.Text = dt.Rows[i]["FloorName"].ToString().Trim() + " - " + dt.Rows[i]["房间号"].ToString().Trim();//指定节点文本
                tn.Tag = dt.Rows[i]["RoomResourcesID"];//绑定节点数据
                tn.Checked = true;
                tvwRoom.Nodes.Add(tn);//将节点添加到树控件                
            }
        }

       



    }



2.增加优惠折扣



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

控件名称

说明

标注(Label)

控件可以在工具箱直接拖动至窗体,拖至窗体后右击属性可以修改控件的样式和各种属性,还可以编辑事件。

时间控件(DateTime)

树状图(TreeView)

文本(TextBox)

按钮(Button)

菜单(ToolStripMenuItem)

复选框(CheckBox)

工具栏(ToolStrip)

图片列表(ImageList)

表格(DataGridView)

 

功能实现:

第一步:数据库

1、表与关系


表1: 房间资源表(dbo.SYS_RoomResource)

Primary Key(主键):  RoomResourcesID

非主键ID值均是外键

列名

数据类型

默认值

Nulls?

说明

RoomResourcesID

int - Identity

 

No

房间资源ID

 

FloorID

int

 

Yes

楼栋信息表,楼栋ID

 

TheCodeModelID

int

 

Yes

属性明细表,代码模式ID

 

Number

nchar (10)

 

Yes

编号

 

UnitNumberID

int

 

Yes

单元表,单元ID

 

FloorStotey

nchar (10)

 

Yes

楼层

 

RoomCategoryID

int

 

Yes

属性明细表,房间类别ID

 

TowardID

int

 

Yes

属性明细表,朝向ID

 

DoorModelID

int

 

Yes

属性明细表,户型ID

 

RoomTypeID

int

 

Yes

属性明细表,房间类型ID

 

RoomLandScapeID

int

 

Yes

属性明细表,房间景观ID

 

RoomSpecialID

int

 

Yes

属性明细表,房间特殊ID

 

ConstructionArea

decimal (18, 2)

 

Yes

建筑面积

 

PricateArea

decimal (18, 2)

 

Yes

私有面积

 

PublicArea

decimal (18, 2)

 

Yes

公摊面积

 

Usage

decimal (18, 2)

 

Yes

使用率

 

TheUnitPrice

decimal (18, 2)

 

Yes

标价单价

 

BidPrice

decimal (18, 2)

 

Yes

标价总价

 

NumberOfPrice

nchar (10)

 

Yes

价格次数

 

SalesStatusID

int

((102))

Yes

属性明细表,销售状态ID

 

BriefNote

nchar (30)

 

Yes

简要备注

 

SchematicDiagram

image

 

Yes

示意图

 

Chart

image

 

Yes

效果图

 

 

表2: 楼栋信息表(dbo.SYS_FloorInformation)

Primary Key(主键):  FloorID

非主键ID值均是外键

(这里因为在这个表里边没有设置有默认值,所以没有默认值的那一列)

列名

数据类型

Nulls?

说明

FloorID

int - Identity

No

楼栋ID

 

ProjectID

int

Yes

项目信息表,项目ID

 

FloorStructureID

int

Yes

属性明细表,楼栋结构ID

 

OpenBatchID

int

Yes

属性明细表,开盘批次ID

 

LaunchSituationID

int

Yes

属性明细表,推出情况ID

 

OpeningSituationID

int

Yes

属性明细表,开盘情况ID

 

FloorLevelID

int

Yes

楼栋级别ID

 

SortNumber

nchar (10)

Yes

序号

 

FloorName

nchar (20)

Yes

楼栋名称

 

PropertyRightFloorName

nchar (20)

Yes

产权楼栋名称

 

FloorStorey

nchar (10)

Yes

楼栋层数

 

LaunchDate

datetime

Yes

推出日期

 

DoMortgageDate

datetime

Yes

具备办按揭日期

 

CapsDate

datetime

Yes

封顶日期

 

AccumulationFundDate

datetime

Yes

具备办公积金日期

 

ExpectedPayDate

datetime

Yes

预计交房日期

 

PropertyRightDate

datetime

Yes

具备办产权日期

 

MakingRoomDate

datetime

Yes

交房日期

 

表3: 项目信息表(dbo.SYS_ProjectInformation)

Primary Key(主键):  ProjectID

非主键ID值均是外键

 

列名

数据类型

默认值

Nulls?

说明

ProjectID

int - Identity

 

No

项目ID

 

SortNumber

int

 

Yes

排序号

 

ProjectAreaID

int

 

Yes

属性明细表,项目区域ID

 

Project_FatherlID

int

 

Yes

项目信息表,项目级别ID

 

ProjectName

nchar (20)

 

Yes

项目名称

 

PropertyRightProjectName

nchar (20)

 

Yes

产权项目名称

 

ProjectCompanyName

nchar (20)

 

Yes

项目公司名称

 

ProjectAddress

nchar (50)

 

Yes

项目座落地址

 

CaseWhether

bit

 

Yes

是否结案

 

CancelWhether

bit

((0))

Yes

有效否

 

表4: 折扣优惠表 (dbo. SYS_DiscountOfPreferential)

Primary Key(主键):  DiscountID

非主键ID值均是外键

列名

数据类型

默认值

Nulls?

DiscountID

int - Identity

 

No

ProjectID

int

 

Yes

BuildingNumberIDGather

nvarchar (4000)

 

Yes

UnitNumberIDGather

nvarchar (4000)

 

Yes

DiscountName

nchar (50)

 

Yes

SerialNumber

nchar (20)

 

Yes

EffectiveDate

datetime

 

Yes

ExpiryDate

datetime

 

Yes

PreferentialTyoeID

int

 

Yes

CaluculationID

int

 

Yes

CaluculationTypeID

int

 

Yes

Discount

decimal (18, 2)

 

Yes

DiscountSum

decimal (18, 2)

 

Yes

ASingleSetOfHighestDiscountAmount

decimal (18, 2)

 

Yes

TotalDiscount

decimal (18, 2)

 

Yes

UsingRangeID

int

 

Yes

Privilege

nchar (100)

 

Yes

WhetherenableManagerPermissions

bit

 

No

CancelWhether

bit

((0))

Yes

表5: 折扣优惠明细表 (dbo. SYS_DiscountOfPreferentialDetail)

Primary Key(主键):  DiscountOfPreferentialDetailID

非主键ID值均是外键

列名

数据类型

默认值

Nulls?

DiscountOfPreferentialDetailID

int - Identity

 

No

DiscountID

int

 

Yes

FloorID

int

 

Yes

RoomResourceID

int

 

Yes

RecordDate

datetime

 

Yes

IncalidOr

bit

((0))

Yes

表6: 属性明细表(dbo.SYS_AttributeDetails)

Primary Key(主键):  AttributeDetailsID

列名

数据类型

默认值

Nulls?

说明

AttributeDetailsID

int - Identity

 

No

属性明细ID

 

AuttributeSetID

int

 

Yes

属性集合表,属性集合ID

 

AuttributeDetailsName

nchar (10)

 

Yes

属性明细名称

 

EffectiveWhether

bit

((1))

Yes

有效否

 

 

2、具体的代码实现

第一步:数据库的存储过程

 

 if(@type='Multi_Select_DiscountOfPreferential')--不定条件查询折扣明细
 begin
 declare  @sql nvarchar(1000)=' where SYS_DiscountOfPreferential.CancelWhether=0 ' 
 if  @sqlPreferentialType   !='0'
     set @sql += ' and SYS_DiscountOfPreferential.PreferentialTyoeID = ' + RTRIM(@sqlPreferentialType) 
 if  @sqlCalculation  !='0'
     set @sql += ' and SYS_DiscountOfPreferential.CaluculationID = '  + RTRIM(@sqlCalculation) 
 if  @sqlEffectiveDate   !=''
     set @sql += ' and SYS_DiscountOfPreferential.EffectiveDate between ''' +  RTRIM(@sqlEffectiveDate)  + ''' and ''' + RTRIM(@sqlEffectiveDate1) +''''
 if  @sqlProjectID != '0'
     set @sql += ' and SYS_ProjectInformation.ProjectID = ' +  RTRIM(@sqlProjectID)  
 --select @sql
 exec( 
 'SELECT     SYS_DiscountOfPreferential.DiscountID, SYS_DiscountOfPreferential.ProjectID, rtrim(SYS_DiscountOfPreferential.BuildingNumberIDGather) as BuildingNumberIDGather, rtrim(SYS_DiscountOfPreferential.UnitNumberIDGather) as UnitNumberIDGather, RTRIM(SYS_DiscountOfPreferential.DiscountName) as 优惠名称, 
                  RTRIM(SYS_DiscountOfPreferential.SerialNumber) as 序号, SYS_DiscountOfPreferential.EffectiveDate as 有效时间, SYS_DiscountOfPreferential.ExpiryDate as 失效时间, SYS_DiscountOfPreferential.PreferentialTyoeID, SYS_DiscountOfPreferential.CaluculationID, 
                  SYS_DiscountOfPreferential.CaluculationTypeID, RTRIM(SYS_DiscountOfPreferential.Discount) as 优惠折扣, RTRIM(SYS_DiscountOfPreferential.DiscountSum) AS 优惠单价, RTRIM(SYS_DiscountOfPreferential.ASingleSetOfHighestDiscountAmount) as 单套最高优惠额, 
                  RTRIM(SYS_DiscountOfPreferential.TotalDiscount) as 优惠总价, SYS_DiscountOfPreferential.UsingRangeID, RTRIM(SYS_DiscountOfPreferential.Privilege) as 优惠说明, SYS_DiscountOfPreferential.WhetherenableManagerPermissions as 是否启用经理权限, 
                  rtrim(SYS_AttributeDetails.AuttributeDetailsName) as 优惠类型, rtrim(SYS_AttributeDetails_1.AuttributeDetailsName) AS 计算方式, SYS_AttributeDetails_2.AttributeDetailsID, 
                  rtrim(SYS_AttributeDetails_2.AuttributeDetailsName) AS 计算类型, RTRIM(SYS_ProjectInformation.ProjectName) as 项目名称, rtrim(SYS_AttributeDetails_3.AuttributeDetailsName) AS 使用范围
 FROM         SYS_AttributeDetails INNER JOIN
                  SYS_DiscountOfPreferential ON SYS_AttributeDetails.AttributeDetailsID = SYS_DiscountOfPreferential.PreferentialTyoeID INNER JOIN
                  SYS_AttributeDetails AS SYS_AttributeDetails_1 ON SYS_DiscountOfPreferential.CaluculationID = SYS_AttributeDetails_1.AttributeDetailsID INNER JOIN
                  SYS_AttributeDetails AS SYS_AttributeDetails_2 ON SYS_DiscountOfPreferential.CaluculationTypeID = SYS_AttributeDetails_2.AttributeDetailsID INNER JOIN
                  SYS_ProjectInformation ON SYS_DiscountOfPreferential.ProjectID = SYS_ProjectInformation.ProjectID INNER JOIN
                  SYS_AttributeDetails AS SYS_AttributeDetails_3 ON SYS_DiscountOfPreferential.UsingRangeID = SYS_AttributeDetails_3.AttributeDetailsID' +  @sql
                  
)
return          
 
 end
  
 
 if(@type='InsertPreferentialDetails_DeleteSalesOfPreferential')--修改销售优惠的有效否
 begin
 update   SYS_DiscountOfPreferential
 set    SYS_DiscountOfPreferential.CancelWhether=1
 WHERE      SYS_DiscountOfPreferential.DiscountID=@DiscountID
 end
 
 if(@type='InsertPreferentialDetails_btnSaveAndUpdate_Click_Update')--修改优惠明细
 begin
 update   SYS_DiscountOfPreferential
 set    ProjectID=@ProjectID, BuildingNumberIDGather=@BuildingNumberIDGather, UnitNumberIDGather=@UnitNumberIDGather, DiscountName=@DiscountName, SerialNumber=@SerialNumber, EffectiveDate=@EffectiveDate, 
                 ExpiryDate=@ExpiryDate, PreferentialTyoeID=@PreferentialTyoeID, CaluculationID=@CaluculationID, CaluculationTypeID=@CaluculationTypeID, Discount=@Discount, DiscountSum=@DiscountSum, 
                  ASingleSetOfHighestDiscountAmount=@ASingleSetOfHighestDiscountAmount, TotalDiscount=@TotalDiscount, UsingRangeID=@UsingRangeID, Privilege=@Privilege, 
                  WhetherenableManagerPermissions=@WhetherenableManagerPermissions
 WHERE      SYS_DiscountOfPreferential.DiscountID=@DiscountID
 end
 
 if(@type='InsertPreferentialDetails_Load_BindingFloorNumber')--查询楼栋信息
 begin
 SELECT     FloorID, Rtrim(FloorName) AS 楼栋号
 FROM         SYS_FloorInformation
 WHERE  SYS_FloorInformation.ProjectID=@ProjectID
 end
 
 if(@type='InsertPreferentialDetails_Load_BindingRoomNumber')--查询房源信息
 begin
 SELECT     SYS_RoomResources.RoomResourcesID, RTRIM(SYS_RoomResources.Number) AS 房间号, RTRIM(SYS_RoomResources.FloorStotey) AS 楼栋层数, SYS_FloorInformation.FloorName, 
              SYS_RoomResources.FloorID
 FROM         SYS_RoomResources INNER JOIN
              SYS_FloorInformation ON SYS_RoomResources.FloorID = SYS_FloorInformation.FloorID	
 end
 

 

第二步:逻辑层(BLL)相关代码

        [OperationContract]
        #region    修改   
        public int InsertPreferentialDetails_btnSaveAndUpdate_Click_Update(int intProjectID, string strBuildingNumberIDGather, string  strUnitNumberIDGather, string strDiscountName, string strSerialNumber, DateTime dtEffectiveDate, 
                    DateTime dtExpiryDate,int intPreferentialTyoeID,int intCaluculationID,int intCaluculationTypeID,decimal decDiscount,decimal decDiscountSum,
                     decimal decASingleSetOfHighestDiscountAmount, decimal decTotalDiscount, int intUsingRangeID, string strPrivilege, Boolean blWhetherenableManagerPermissions, int intDiscountID)
        {            
            SqlParameter[] SQLCMDpas = { new SqlParameter("@Type", SqlDbType.Char),
                                         new SqlParameter("@ProjectID", SqlDbType.Int),
                                         new SqlParameter("@BuildingNumberIDGather", SqlDbType.NVarChar),
                                         new SqlParameter("@UnitNumberIDGather", SqlDbType.NVarChar),
                                         new SqlParameter("@DiscountName", SqlDbType.Char),
                                         new SqlParameter("@SerialNumber", SqlDbType.Char),
                                         new SqlParameter("@EffectiveDate", SqlDbType.DateTime),
                                         new SqlParameter("@ExpiryDate", SqlDbType.DateTime),
                                         new SqlParameter("@PreferentialTyoeID", SqlDbType.Int),
                                         new SqlParameter("@CaluculationID", SqlDbType.Int),
                                         new SqlParameter("@CaluculationTypeID", SqlDbType.Int),
                                         new SqlParameter("@Discount", SqlDbType.Decimal),
                                         new SqlParameter("@DiscountSum", SqlDbType.Decimal),
                                         new SqlParameter("@ASingleSetOfHighestDiscountAmount", SqlDbType.Decimal),
                                         new SqlParameter("@TotalDiscount", SqlDbType.Decimal),
                                         new SqlParameter("@UsingRangeID", SqlDbType.Int),
                                         new SqlParameter("@Privilege", SqlDbType.Char),
                                         new SqlParameter("@WhetherenableManagerPermissions", SqlDbType.Bit),
                                         new SqlParameter("@DiscountID", SqlDbType.Int),
                                          };
            SQLCMDpas[0].Value = "InsertPreferentialDetails_btnSaveAndUpdate_Click_Update";
            SQLCMDpas[1].Value = intProjectID;
            SQLCMDpas[2].Value = strBuildingNumberIDGather;
            SQLCMDpas[3].Value = strUnitNumberIDGather;
            SQLCMDpas[4].Value = strDiscountName;
            SQLCMDpas[5].Value = strSerialNumber;
            SQLCMDpas[6].Value = dtEffectiveDate;
            SQLCMDpas[7].Value = dtExpiryDate;
            SQLCMDpas[8].Value = intPreferentialTyoeID;
            SQLCMDpas[9].Value = intCaluculationID;
            SQLCMDpas[10].Value = intCaluculationTypeID;
            SQLCMDpas[11].Value = decDiscount;
            SQLCMDpas[12].Value = decDiscountSum;
            SQLCMDpas[13].Value = decASingleSetOfHighestDiscountAmount;
            SQLCMDpas[14].Value = decTotalDiscount;
            SQLCMDpas[15].Value = intUsingRangeID;
            SQLCMDpas[16].Value = strPrivilege;
            SQLCMDpas[17].Value = blWhetherenableManagerPermissions;
            SQLCMDpas[18].Value = intDiscountID;
            return myDALPublic.DAL_OPTableDB_Par("frmMarketManagement_SalesofPreferentialSettings", SQLCMDpas);
        }
        #endregion


        [OperationContract]
        #region  根据项目ID查询销售优惠信息
        public DataSet InsertPreferentialDetails_btnSelect_Click(int intProjectID)
        {
            SqlParameter[] SQLCMDpas = { 
                                            new SqlParameter("@type", SqlDbType.Char),
                                            new SqlParameter("@ProjectID", SqlDbType.Int),
                                         
                                          };
            SQLCMDpas[0].Value = "InsertPreferentialDetails_btnSelect_Click";
            SQLCMDpas[1].Value = intProjectID;
            DataTable myDataTable = myDALPublic.DAL_SelectDB_Par("frmMarketManagement_SalesofPreferentialSettings", SQLCMDpas);
            DataSet myDataSet = new DataSet();
            myDataSet.Tables.Add(myDataTable);
            return myDataSet;
        }
        #endregion

        [OperationContract]
        #region  删除-修改作废否
        public int InsertPreferentialDetails_DeleteSalesOfPreferential(int intDiscountID)
        {
            SqlParameter[] SQLCMDpas = { 
                                            new SqlParameter("@type", SqlDbType.Char),
                                            new SqlParameter("@DiscountID", SqlDbType.Int),
                                         
                                          };
            SQLCMDpas[0].Value = "InsertPreferentialDetails_DeleteSalesOfPreferential";
            SQLCMDpas[1].Value = intDiscountID;
            return myDALPublic.DAL_OPTableDB_Par("frmMarketManagement_SalesofPreferentialSettings", SQLCMDpas);
        }
        #endregion


        [OperationContract]
        #region
        public DataSet InsertPreferentialDetails_btnSaveAndInsert_Click(int intProjectID, string strBuildingNumberIDGather, string strUnitNumberIDGather, string strDiscountName, string strSerialNumber, DateTime dtEffectiveDate,
                    DateTime dtExpiryDate, int intPreferentialTyoeID, int intCaluculationID, int intCaluculationTypeID, decimal decDiscount, decimal decDiscountSum,
                     decimal decASingleSetOfHighestDiscountAmount, decimal decTotalDiscount, int intUsingRangeID, string strPrivilege, Boolean blWhetherenableManagerPermissions)
        {
            //ProjectID, BuildingNumberID, UnitNumberID, DiscountName, SerialNumber, EffectiveDate, 
            //         ExpiryDate, PreferentialTyoeID, CaluculationID, CaluculationTypeID, Discount, DiscountSum, 
            //          ASingleSetOfHighestDiscountAmount, TotalDiscount, UsingRangeID, Privilege, WhetherenableManagerPermissions
            SqlParameter[] SQLCMDpas = { new SqlParameter("@Type", SqlDbType.Char),
                                         new SqlParameter("@ProjectID", SqlDbType.Int),
                                         new SqlParameter("@BuildingNumberIDGather", SqlDbType.NVarChar),
                                         new SqlParameter("@UnitNumberIDGather", SqlDbType.NVarChar),
                                         new SqlParameter("@DiscountName", SqlDbType.Char),
                                         new SqlParameter("@SerialNumber", SqlDbType.Char),
                                         new SqlParameter("@EffectiveDate", SqlDbType.DateTime),
                                         new SqlParameter("@ExpiryDate", SqlDbType.DateTime),
                                         new SqlParameter("@PreferentialTyoeID", SqlDbType.Int),
                                         new SqlParameter("@CaluculationID", SqlDbType.Int),
                                         new SqlParameter("@CaluculationTypeID", SqlDbType.Int),
                                         new SqlParameter("@Discount", SqlDbType.Decimal),
                                         new SqlParameter("@DiscountSum", SqlDbType.Decimal),
                                         new SqlParameter("@ASingleSetOfHighestDiscountAmount", SqlDbType.Decimal),
                                         new SqlParameter("@TotalDiscount", SqlDbType.Decimal),
                                         new SqlParameter("@UsingRangeID", SqlDbType.Int),
                                         new SqlParameter("@Privilege", SqlDbType.Char),
                                         new SqlParameter("@WhetherenableManagerPermissions", SqlDbType.Bit),
                                          };
            SQLCMDpas[0].Value = "InsertPreferentialDetails_btnSaveAndInsert_Click";
            SQLCMDpas[1].Value = intProjectID;
            SQLCMDpas[2].Value = strBuildingNumberIDGather;
            SQLCMDpas[3].Value = strUnitNumberIDGather;
            SQLCMDpas[4].Value = strDiscountName;
            SQLCMDpas[5].Value = strSerialNumber;
            SQLCMDpas[6].Value = dtEffectiveDate;
            SQLCMDpas[7].Value = dtExpiryDate;
            SQLCMDpas[8].Value = intPreferentialTyoeID;
            SQLCMDpas[9].Value = intCaluculationID;
            SQLCMDpas[10].Value = intCaluculationTypeID;
            SQLCMDpas[11].Value = decDiscount;
            SQLCMDpas[12].Value = decDiscountSum;
            SQLCMDpas[13].Value = decASingleSetOfHighestDiscountAmount;
            SQLCMDpas[14].Value = decTotalDiscount;
            SQLCMDpas[15].Value = intUsingRangeID;
            SQLCMDpas[16].Value = strPrivilege;
            SQLCMDpas[17].Value = blWhetherenableManagerPermissions;
            DataTable myDataTable = myDALPublic.DAL_SelectDB_Par("frmMarketManagement_SalesofPreferentialSettings", SQLCMDpas);
            DataSet myDataSet = new DataSet();
            myDataSet.Tables.Add(myDataTable);
            return myDataSet;
        }
        #endregion

        [OperationContract]
        #region  新增优惠明细
        public int btnSaveAndInsert_Click_InsertDetail(int intDiscountID, int intFloorID, int intRoomResourceID)
        {
            SqlParameter[] SQLCMDpas = { 
                                            new SqlParameter("@type", SqlDbType.Char),
                                            new SqlParameter("@DiscountID", SqlDbType.Int),
                                            new SqlParameter("@FloorID", SqlDbType.Int),
                                            new SqlParameter("@RoomResourceID", SqlDbType.Int),
                                         
                                          };
            SQLCMDpas[0].Value = "btnSaveAndInsert_Click_InsertDetail";
            SQLCMDpas[1].Value = intDiscountID;
            SQLCMDpas[2].Value = intFloorID;
            SQLCMDpas[3].Value = intRoomResourceID;
            return myDALPublic.DAL_OPTableDB_Par("frmMarketManagement_SalesofPreferentialSettings", SQLCMDpas);
        }
        #endregion

        [OperationContract]
        #region 查询下拉框数据
        public DataSet InsertPreferentialDetails_Load_BindingFloorNumber(int intProjectID)
        {
            SqlParameter[] SQLCMDpas = { 
                                           new SqlParameter("@type", SqlDbType.Char),
                                           new SqlParameter("@ProjectID", SqlDbType.Int),
                                          };
            SQLCMDpas[0].Value = "InsertPreferentialDetails_Load_BindingFloorNumber";
            SQLCMDpas[1].Value = intProjectID;
            DataTable myDataTable = myDALPublic.DAL_SelectDB_Par("frmMarketManagement_SalesofPreferentialSettings", SQLCMDpas);
            DataSet myDataSet = new DataSet();
            myDataSet.Tables.Add(myDataTable);
            return myDataSet;
        }
        #endregion 


        [OperationContract]
        #region 查询所有房间
        public DataSet InsertPreferentialDetails_Load_BindingRoomNumber()
        {
            SqlParameter[] SQLCMDpas = { 
                                           new SqlParameter("@type", SqlDbType.Char),
                                          };
            SQLCMDpas[0].Value = "InsertPreferentialDetails_Load_BindingRoomNumber";
            DataTable myDataTable = myDALPublic.DAL_SelectDB_Par("frmMarketManagement_SalesofPreferentialSettings", SQLCMDpas);
            DataSet myDataSet = new DataSet();
            myDataSet.Tables.Add(myDataTable);
            return myDataSet;
        }
        #endregion 
        
        [OperationContract]
        #region 不定条件查询
        public DataSet Multi_Select_DiscountOfPreferential(int intPreferentialType,int intCalculation,string strEffectiveDate,string  strEffectiveDate1,int intProjectID)
        {
            SqlParameter[] SQLCMDpas = { 
                                           new SqlParameter("@type", SqlDbType.Char),
                                           new SqlParameter("@sqlPreferentialType", SqlDbType.NVarChar),
                                           new SqlParameter("@sqlCalculation", SqlDbType.NVarChar),
                                           new SqlParameter("@sqlEffectiveDate", SqlDbType.NVarChar),
                                           new SqlParameter("@sqlEffectiveDate1", SqlDbType.NVarChar),
                                           new SqlParameter("@sqlProjectID", SqlDbType.NVarChar),
                                          };
            SQLCMDpas[0].Value = "Multi_Select_DiscountOfPreferential";
            SQLCMDpas[1].Value = intPreferentialType.ToString();
            SQLCMDpas[2].Value = intCalculation.ToString();
            SQLCMDpas[3].Value = strEffectiveDate;
            SQLCMDpas[4].Value = strEffectiveDate1;
            SQLCMDpas[5].Value = intProjectID.ToString();
            DataTable myDataTable = myDALPublic.DAL_SelectDB_Par("frmMarketManagement_SalesofPreferentialSettings", SQLCMDpas);
            DataSet myDataSet = new DataSet();
            myDataSet.Tables.Add(myDataTable);
            return myDataSet;
        }
        #endregion 

 

第三步:界面层(UIL)相关代码及说明

    public partial class frmMarketManagement_SalesofPreferentialSettings_InsertPreferentialDetails : Form
    {
        frmMarketManagement_SalesOfPreferentialSettings Frm;
        public frmMarketManagement_SalesofPreferentialSettings_InsertPreferentialDetails(frmMarketManagement_SalesOfPreferentialSettings frm)
        {
            Frm = frm;
            InitializeComponent();        
        }

        BLL新锐房地产销售系统.MarketManagement.frmMarketManagement_SalesofPreferentialSettings.frmMarketManagement_SalesofPreferentialSettingsClient myfrmMarketManagement_SalesofPreferentialSettingsClient = new 
            BLL新锐房地产销售系统.MarketManagement.frmMarketManagement_SalesofPreferentialSettings.frmMarketManagement_SalesofPreferentialSettingsClient();

        int intDiscountID = 0;
        bool bolRoomAllChecked = false;
        private void frmMarketManagement_SalesofPreferentialSettings_InsertPreferentialDetails_Load(object sender, EventArgs e)
        {
            DataTable dtProjectName=myfrmMarketManagement_SalesofPreferentialSettingsClient.InsertPreferentialDetails_Load_BindingcboProjectName().Tables[0];
            DataTable dtPreferentialType=myfrmMarketManagement_SalesofPreferentialSettingsClient.InsertPreferentialDetails_Load_BindingcboPreferentialType().Tables[0];
            DataTable dtCalculation=myfrmMarketManagement_SalesofPreferentialSettingsClient.InsertPreferentialDetails_Load_BindingcboCalculation().Tables[0];
            DataTable dtCalculatetheType=myfrmMarketManagement_SalesofPreferentialSettingsClient.InsertPreferentialDetails_Load_BindingcboCalculatetheType().Tables[0];
            DataTable dtUsingRange=myfrmMarketManagement_SalesofPreferentialSettingsClient.InsertPreferentialDetails_Load_BindingcboUsingRange().Tables[0];
            PublicMethod.SettingComboBox(cboCalculatetheType, dtCalculatetheType, "AttributeDetailsID", "计算类型", true);
            PublicMethod.SettingComboBox(cboCalculation, dtCalculation, "AttributeDetailsID", "计算方式", true);
            PublicMethod.SettingComboBox(cboProjectName, dtProjectName, "ProjectID", "项目名称", true);
            PublicMethod.SettingComboBox(cboPreferentialType, dtPreferentialType, "AttributeDetailsID", "优惠类型", true);
              PublicMethod.SettingComboBox(cboUsingRange, dtUsingRange, "AttributeDetailsID", "使用范围", true);
            string[] strArrayNumber = { "全部","1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16","17","18","19","20" };

            cboRoomNumber.DataSource = strArrayNumber;
            btnSaveAndInsert.Enabled = true;
            cboUsingRange_SelectionChangeCommitted(null, null);
            if (PublicStaticClass.blPublicSwith == true)
            {
                BindingOldMsg();
                PublicStaticClass.blPublicSwith = false;
            }
            else
                cboUsingRange_SelectionChangeCommitted(null, null);
            
            intProjectID = (int)cboProjectName.SelectedValue;
        }

        void BindingOldMsg()
        {
            intDiscountID = Convert.ToInt32(Frm.dgvSalesPreferentialList.CurrentRow.Cells["DiscountID"].Value);
            cboProjectName.SelectedValue = (int)Frm.dgvSalesPreferentialList.CurrentRow.Cells["ProjectID"].Value;
            cboCalculation.SelectedValue = (int)Frm.dgvSalesPreferentialList.CurrentRow.Cells["CaluculationID"].Value;
            cboPreferentialType.SelectedValue = (int)Frm.dgvSalesPreferentialList.CurrentRow.Cells["PreferentialTyoeID"].Value;
            cboCalculatetheType.SelectedValue = (int)Frm.dgvSalesPreferentialList.CurrentRow.Cells["CaluculationTypeID"].Value;
            cboUsingRange.SelectedValue = Convert.ToInt32(Frm.dgvSalesPreferentialList.CurrentRow.Cells["UsingRangeID"].Value);
            cboRoomNumber.SelectedIndex = 0;
            txtDiscount.Text = Frm.dgvSalesPreferentialList.CurrentRow.Cells["优惠折扣"].Value.ToString();
            txtDiscountAmount.Text = Frm.dgvSalesPreferentialList.CurrentRow.Cells["优惠单价"].Value.ToString();
            txtNameofPreferential.Text = Frm.dgvSalesPreferentialList.CurrentRow.Cells["优惠名称"].Value.ToString();
            txtPrivilege.Text = Frm.dgvSalesPreferentialList.CurrentRow.Cells["优惠说明"].Value.ToString();
            txtSerialNumber.Text = Frm.dgvSalesPreferentialList.CurrentRow.Cells["序号"].Value.ToString();
            txtSinglesetofhighestdiscountamount.Text = Frm.dgvSalesPreferentialList.CurrentRow.Cells["单套最高优惠额"].Value.ToString();
            txtTotalDiscount.Text = Frm.dgvSalesPreferentialList.CurrentRow.Cells["优惠总价"].Value.ToString();
            dtpEffectiveDate.Value = Convert.ToDateTime(Frm.dgvSalesPreferentialList.CurrentRow.Cells["有效时间"].Value);
            dtpExpiryDate.Value = Convert.ToDateTime(Frm.dgvSalesPreferentialList.CurrentRow.Cells["失效时间"].Value);
            btnSaveAndUpdate.Enabled = true;
            btnSaveAndInsert.Enabled = false;
            string strFloorGather = Frm.dgvSalesPreferentialList.CurrentRow.Cells["BuildingNumberIDGather"].Value.ToString();
            string strRoomResourceGather = Frm.dgvSalesPreferentialList.CurrentRow.Cells["UnitNumberIDGather"].Value.ToString();

            intProjectID = (int)Frm.dgvSalesPreferentialList.CurrentRow.Cells["ProjectID"].Value;
            int intUsingRangeID = Convert.ToInt32(Frm.dgvSalesPreferentialList.CurrentRow.Cells["UsingRangeID"].Value);
            dtFloorNumber = myfrmMarketManagement_SalesofPreferentialSettingsClient.InsertPreferentialDetails_Load_BindingFloorNumber(intProjectID).Tables[0];
            string strCondition = "";
            switch (intUsingRangeID)
            {
                case 51:  //整个项目
                    bolRoomAllChecked = true;
                    BindingTvwNode_OnProject(dtFloorNumber);
                    BinddtAfter();
                    btnScreening_Click(null,null);
                    tvwFloorNumber.Enabled = false;
                    grbIncludeRoom.Enabled = false;
                    strCondition = BindingTvwFloor_Checked(strFloorGather);
                    break;
                case 52:  //部分楼栋
                    bolRoomAllChecked = true;
                    BindingTvwNode(dtFloorNumber);
                    grbIncludeRoom.Enabled = false;
                    BinddtAfter();
                    btnScreening_Click(null,null);
                    tvwRoom.Nodes.Clear();
                    strCondition = BindingTvwFloor_Checked(strFloorGather);
                    break;
                case 53:  //某些单元
                    bolRoomAllChecked = false;
                    BindingTvwNode(dtFloorNumber);
                    grbIncludeRoom.Enabled = true;
                    tvwRoom.Nodes.Clear();
                    strCondition = BindingTvwFloor_Checked(strFloorGather);
                    BindingTvwRoomResource_Checked(strCondition, strRoomResourceGather);
                    break;
                case 54:  //某些房间
                    bolRoomAllChecked = false;
                    BindingTvwNode(dtFloorNumber);
                    grbIncludeRoom.Enabled = true;
                    tvwRoom.Nodes.Clear();
                    strCondition = BindingTvwFloor_Checked(strFloorGather);
                    BindingTvwRoomResource_Checked(strCondition, strRoomResourceGather);
                    break;
            }
        }

        void BinddtAfter()
        {
            DataTable dtRoomNumber = new DataTable();
            dtRoomNumber = myfrmMarketManagement_SalesofPreferentialSettingsClient.InsertPreferentialDetails_Load_BindingRoomNumber().Tables[0];
            string strCondition = "";
            string strNewCondition = "";
            for (int j = 0; j < tvwFloorNumber.Nodes.Count; j++)
            {
                if (tvwFloorNumber.Nodes[j].Checked == true)
                {
                    strCondition = strCondition + " FloorID=" + tvwFloorNumber.Nodes[j].Tag + " or";
                }
            }
            if (strCondition != "")
            {
                strNewCondition = strCondition.Remove(strCondition.Length - 3);
            }
            DataView dv = new DataView(dtRoomNumber);
            dv.RowFilter = strNewCondition;
            dtAfter = dv.ToTable();                
        }

        string BindingTvwFloor_Checked(string strFloorGather)
        {
            string strNewFloorGather = strFloorGather.Remove(strFloorGather.Length - 1);
            string[] strArrayFloorID = strNewFloorGather.Split(',');
            string strCondition = "";
            for (int intCount = 0; intCount < tvwFloorNumber.Nodes.Count; intCount++)
            {
                foreach (string strParameter in strArrayFloorID)
                {
                    if (strParameter == tvwFloorNumber.Nodes[intCount].Tag.ToString())
                    {
                        tvwFloorNumber.Nodes[intCount].Checked = true;
                        strCondition = strCondition + " FloorID=" + tvwFloorNumber.Nodes[intCount].Tag + " or";
                    }
                } 
            }
            return strCondition;
        }

        void BindingTvwRoomResource_Checked(string strCondition,string strRoomResourceGather)
        {
            string strNewRoomResourceGather = strRoomResourceGather.Remove(strRoomResourceGather.Length - 1);
            string[] strArrayRoomResourceID = strNewRoomResourceGather.Split(',');
            DataTable dtRoomNumber = new DataTable();
            dtRoomNumber = myfrmMarketManagement_SalesofPreferentialSettingsClient.InsertPreferentialDetails_Load_BindingRoomNumber().Tables[0];
            string strNewCondition = "";
            if (strCondition != "")
            {
                strNewCondition = strCondition.Remove(strCondition.Length - 3);
            }
            DataView dv = new DataView(dtRoomNumber);
            dv.RowFilter = strNewCondition;
            dtAfter = dv.ToTable();
            BindingTvwRoomNode(dtAfter);
            for (int intCount = 0; intCount < tvwRoom.Nodes.Count; intCount++)
            {
                foreach (string strParameter in strArrayRoomResourceID)
                {
                    if (strParameter == tvwRoom.Nodes[intCount].Tag.ToString())
                    {
                        tvwRoom.Nodes[intCount].Checked = true;
                    }
                }
            }
        }

        private void btnSaveAndInsert_Click(object sender, EventArgs e)
        {
            int intProjectID=Convert.ToInt32(cboProjectName.SelectedValue);
            string strDiscountName=txtNameofPreferential.Text.ToString().Trim();
            string strSerialNumber=txtSerialNumber.Text.ToString().Trim();
            DateTime dtEffectiveDate=dtpEffectiveDate.Value;
            DateTime dtExpiryDate=dtpExpiryDate.Value;
            int intPreferentialTyoeID=Convert.ToInt32(cboPreferentialType.SelectedValue);
            int intCaluculationID=Convert.ToInt32(cboCalculation.SelectedValue);
            int intCaluculationTypeID=Convert.ToInt32(cboCalculatetheType.SelectedValue);
            decimal decDiscount=Convert.ToDecimal(txtDiscount.Text.Trim());
            decimal decDiscountSum=Convert.ToDecimal(txtDiscountAmount.Text);
            decimal decASingleSetOfHighestDiscountAmount=Convert.ToDecimal(txtSinglesetofhighestdiscountamount.Text.Trim());
            decimal decTotalDiscount=Convert.ToDecimal(txtTotalDiscount.Text.Trim());
            int intUsingRangeID=Convert.ToInt32(cboUsingRange.SelectedValue);
            string strPrivilege = txtPrivilege.Text.ToString().Trim();
            Boolean blWhetherenableManagerPermissions=chkManagerLevelAuthorityCanOnlyBeEnabled.Checked;
            string[] strGatherArray = GetFloorIDGatherAndRoomIDGather();
            int intDiscount = Convert.ToInt32( myfrmMarketManagement_SalesofPreferentialSettingsClient.InsertPreferentialDetails_btnSaveAndInsert_Click(intProjectID, strGatherArray[0], strGatherArray[1], strDiscountName, strSerialNumber, dtEffectiveDate, 
                    dtExpiryDate,intPreferentialTyoeID,intCaluculationID,intCaluculationTypeID,decDiscount,decDiscountSum,
                     decASingleSetOfHighestDiscountAmount, decTotalDiscount, intUsingRangeID, strPrivilege, blWhetherenableManagerPermissions).Tables[0].Rows[0][0]) ;
            if (intDiscount > 0)
            {
                InsertDetail(intDiscount);
                MessageBox.Show("新增成功!!!");
                Frm.PubRefresh();
                this.Dispose();
            }
            else
            {
                MessageBox.Show("新增失败!!!");
            }
        }

        string[] GetFloorIDGatherAndRoomIDGather()
        {
            string[] strArray=new string[2];
            string strFloorIDGather = "";
            string strRoomIDGather = "";
            for (int FloorNode = 0; FloorNode < tvwFloorNumber.Nodes.Count; FloorNode++)
            {
                if (tvwFloorNumber.Nodes[FloorNode].Checked)
                {
                    strFloorIDGather += tvwFloorNumber.Nodes[FloorNode].Tag.ToString() + ",";
                }
            }
            try
            {
                for (int RoomNode = 0; RoomNode < tvwRoom.Nodes.Count; RoomNode++)
                {
                    if (tvwRoom.Nodes[RoomNode].Checked)
                    {
                        strRoomIDGather += tvwRoom.Nodes[RoomNode].Tag.ToString() + ",";
                    }
                }
            }
            catch { };
            strArray[0] = strFloorIDGather;
            strArray[1] = strRoomIDGather;
            return strArray;
        }

        void InsertDetail(int intDiscountID)//新增销售优惠明细
        {
            DataTable dtRoomNumber = myfrmMarketManagement_SalesofPreferentialSettingsClient.InsertPreferentialDetails_Load_BindingRoomNumber().Tables[0];
            int intUsingRange = (int)cboUsingRange.SelectedValue;
            string strCondition = "";
            switch (intUsingRange)
            {
                case 51:  //整个项目
                    for (int intNumber = 0; intNumber < tvwFloorNumber.Nodes.Count; intNumber++)
                    {
                        if (tvwFloorNumber.Nodes[intNumber].Checked == true)
                        {
                            strCondition =  " FloorID=" + tvwFloorNumber.Nodes[intNumber].Tag ;
                            DataView dv = new DataView(dtRoomNumber);
                            dv.RowFilter = strCondition;
                            DataTable dt = dv.ToTable();
                            if (dt.Rows.Count > 0)
                            {
                                for (int intCount = 0; intCount < dt.Rows.Count; intCount++)
                                {
                                    int intFloorID = (int)tvwFloorNumber.Nodes[intNumber].Tag;
                                    int intRoomResourceID = (int)dt.Rows[intCount]["RoomResourcesID"];
                                    myfrmMarketManagement_SalesofPreferentialSettingsClient.btnSaveAndInsert_Click_InsertDetail(intDiscountID, intFloorID, intRoomResourceID);
                                }
                            }
                        }
                    }
                    break;
                case 52:  //部分楼栋
                    for (int intNumber = 0; intNumber < tvwFloorNumber.Nodes.Count; intNumber++)
                    {
                        if (tvwFloorNumber.Nodes[intNumber].Checked == true)
                        {
                            strCondition = " FloorID=" + tvwFloorNumber.Nodes[intNumber].Tag;
                            DataView dv = new DataView(dtRoomNumber);
                            dv.RowFilter = strCondition;
                            DataTable dt = dv.ToTable();
                            if (dt.Rows.Count > 0)
                            {
                                for (int intCount = 0; intCount < dt.Rows.Count; intCount++)
                                {
                                    int intFloorID = (int)tvwFloorNumber.Nodes[intNumber].Tag;
                                    int intRoomResourceID = (int)dt.Rows[intCount]["RoomResourcesID"];
                                    myfrmMarketManagement_SalesofPreferentialSettingsClient.btnSaveAndInsert_Click_InsertDetail(intDiscountID, intFloorID, intRoomResourceID);
                                }
                            }
                        }
                    }
                    break;
                case 53:  //某些单元
                    for (int intNumber = 0; intNumber < tvwFloorNumber.Nodes.Count; intNumber++)
                    {
                        if (tvwFloorNumber.Nodes[intNumber].Checked == true)
                        {
                            strCondition = " FloorID=" + tvwFloorNumber.Nodes[intNumber].Tag;
                            DataView dv = new DataView(dtRoomNumber);
                            dv.RowFilter = strCondition;
                            DataTable dt = dv.ToTable();
                            if (dt.Rows.Count > 0)
                            {
                                for (int intCount = 0; intCount < dt.Rows.Count; intCount++)
                                {
                                    int intFloorID = (int)tvwFloorNumber.Nodes[intNumber].Tag;
                                    for (int NodeNumber = 0; NodeNumber < tvwRoom.Nodes.Count; NodeNumber++)
                                    {
                                        if (tvwRoom.Nodes[NodeNumber].Checked)
                                        {
                                            int intRoomResourceID = (int)tvwRoom.Nodes[NodeNumber].Tag;
                                            myfrmMarketManagement_SalesofPreferentialSettingsClient.btnSaveAndInsert_Click_InsertDetail(intDiscountID, intFloorID, intRoomResourceID);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    break;
                case 54:  //某些房间
                    for (int intNumber = 0; intNumber < tvwFloorNumber.Nodes.Count; intNumber++)
                    {
                        if (tvwFloorNumber.Nodes[intNumber].Checked == true)
                        {
                            strCondition = " FloorID=" + tvwFloorNumber.Nodes[intNumber].Tag;
                            DataView dv = new DataView(dtRoomNumber);
                            dv.RowFilter = strCondition;
                            DataTable dt = dv.ToTable();
                            if (dt.Rows.Count > 0)
                            {
                                for (int intCount = 0; intCount < dt.Rows.Count; intCount++)
                                {
                                    int intFloorID = (int)tvwFloorNumber.Nodes[intNumber].Tag;
                                    for (int NodeNumber = 0; NodeNumber < tvwRoom.Nodes.Count; NodeNumber++)
                                    {
                                        if (tvwRoom.Nodes[NodeNumber].Checked)
                                        {
                                            int intRoomResourceID = (int)tvwRoom.Nodes[NodeNumber].Tag;
                                            myfrmMarketManagement_SalesofPreferentialSettingsClient.btnSaveAndInsert_Click_InsertDetail(intDiscountID, intFloorID, intRoomResourceID);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    break;
            }
        }

        private void btnReturn_Click(object sender, EventArgs e)
        {
            this.Dispose();
            this.Close();
        }

        private void btnSaveAndUpdate_Click(object sender, EventArgs e)
        {
            int intProjectID = Convert.ToInt32(cboProjectName.SelectedValue);
            string strDiscountName = txtNameofPreferential.Text.ToString().Trim();
            string strSerialNumber = txtSerialNumber.Text.ToString().Trim();
            DateTime dtEffectiveDate = dtpEffectiveDate.Value;
            DateTime dtExpiryDate = dtpExpiryDate.Value;
            int intPreferentialTyoeID = Convert.ToInt32(cboPreferentialType.SelectedValue);
            int intCaluculationID = Convert.ToInt32(cboCalculation.SelectedValue);
            int intCaluculationTypeID = Convert.ToInt32(cboCalculatetheType.SelectedValue);
            decimal decDiscount = Convert.ToDecimal(txtDiscount.Text.Trim());
            decimal decDiscountSum = Convert.ToDecimal(txtDiscountAmount.Text);
            decimal decASingleSetOfHighestDiscountAmount = Convert.ToDecimal(txtSinglesetofhighestdiscountamount.Text.Trim());
            decimal decTotalDiscount = Convert.ToDecimal(txtTotalDiscount.Text.Trim());
            int intUsingRangeID = Convert.ToInt32(cboUsingRange.SelectedValue);
            string strPrivilege = txtPrivilege.Text.ToString().Trim();
            Boolean blWhetherenableManagerPermissions = chkManagerLevelAuthorityCanOnlyBeEnabled.Checked;
            string[] strGatherArray = GetFloorIDGatherAndRoomIDGather();
            int intSaveSuccess = myfrmMarketManagement_SalesofPreferentialSettingsClient.InsertPreferentialDetails_btnSaveAndUpdate_Click_Update(intProjectID, strGatherArray[0], strGatherArray[1], strDiscountName, strSerialNumber, dtEffectiveDate,
                    dtExpiryDate, intPreferentialTyoeID, intCaluculationID, intCaluculationTypeID, decDiscount, decDiscountSum,
                     decASingleSetOfHighestDiscountAmount, decTotalDiscount, intUsingRangeID, strPrivilege, blWhetherenableManagerPermissions,intDiscountID);
            if (intSaveSuccess > 0)
            {
                MessageBox.Show("修改成功!!!");
                btnSaveAndUpdate.Enabled = false;
                this.Dispose();
            }
            else
            {
                MessageBox.Show("修改失败!!!");
            }
        }

        DataTable dtAfter;
        private void tvwFloorNumber_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            DataTable dtRoomNumber = new DataTable();
            dtRoomNumber = myfrmMarketManagement_SalesofPreferentialSettingsClient.InsertPreferentialDetails_Load_BindingRoomNumber().Tables[0];
            string strCondition = "";
            string strNewCondition = "";
            for (int j = 0; j < tvwFloorNumber.Nodes.Count; j++)
            {
                if (tvwFloorNumber.Nodes[j].Checked == true)
                {
                    strCondition = strCondition + " FloorID=" + tvwFloorNumber.Nodes[j].Tag + " or";
                }
            }
            if (strCondition != "")
            {
                strNewCondition = strCondition.Remove(strCondition.Length - 3);
            }
            DataView dv = new DataView(dtRoomNumber);
            dv.RowFilter = strNewCondition;
            dtAfter = dv.ToTable();
            btnScreening_Click(null,null);   
        }

        public void BindingTvwNode_OnProject(DataTable dtFloorNumber)
        {
            tvwFloorNumber.Nodes.Clear();        
            for (int i = 0; i < dtFloorNumber.Rows.Count; i++)//遍历绑定顶级节点
            {
                TreeNode tn = new TreeNode();//实例化节点
                tn.Text = dtFloorNumber.Rows[i]["楼栋号"].ToString();//指定节点文本
                tn.Tag = dtFloorNumber.Rows[i]["FloorID"];//绑定节点数据
                tn.Checked = true;
                tvwFloorNumber.Nodes.Add(tn);//将节点添加到树控件                
            }
        }

        public void BindingTvwNode(DataTable dtFloorNumber)
        {
            tvwFloorNumber.Enabled = true ;
            tvwFloorNumber.Nodes.Clear();
            for (int i = 0; i < dtFloorNumber.Rows.Count; i++)//遍历绑定顶级节点
            {
                TreeNode tn = new TreeNode();//实例化节点
                tn.Text = dtFloorNumber.Rows[i]["楼栋号"].ToString();//指定节点文本
                tn.Tag = dtFloorNumber.Rows[i]["FloorID"];//绑定节点数据
                tvwFloorNumber.Nodes.Add(tn);//将节点添加到树控件                
            }
        }

        int intProjectID = 0;
        private void cboProjectName_DropDownClosed(object sender, EventArgs e)
        {
            intProjectID = (int)cboProjectName.SelectedValue;
            cboUsingRange_SelectionChangeCommitted(null,null);
        }

        #region 获取字符串里的某个字符
        string GetNumber(string str)
        {
            string[] strArray = new string[str.Length];
            string strAfter = "";
            for (int count = 0; count < str.Length; count++)
            {
                strArray[count] = str.ToArray()[count].ToString();
            }
            switch (str.Length)
            {
                case 3:
                    strAfter = strArray[1] + strArray[2];
                    break;
                case 4:
                    strAfter = strArray[2] + strArray[3];
                    break;
            }
            return strAfter;
        }
        #endregion

        private void btnScreening_Click(object sender, EventArgs e)
        {
            int intSelectedNodes = 0;
            for (int intCount = 0; intCount < tvwFloorNumber.Nodes.Count; intCount++)
            {
                if (tvwFloorNumber.Nodes[intCount].Checked)
                {
                    intSelectedNodes = (int)tvwFloorNumber.Nodes[intCount].Tag;
                    break;
                }
            }
            if (intSelectedNodes == 0)
            {
                tvwRoom.Nodes.Clear();
                return;
            }

            int intMaxFloorStorey = 0;
            chkFullRoomNumberSelect.Checked = false;
            string strCondition="";
            string strConditionNumber = "";
            string strConditionFloorStorey = "";
            string strNumber = cboRoomNumber.SelectedValue.ToString(); 
            if (dtAfter.Rows.Count == 0)
                return;
            if (dtAfter.Rows.Count > 0)
            {               
                for (int count = 0; count < dtAfter.Rows.Count; count++)
                {
                    if (Convert.ToInt32(dtAfter.Rows[count]["楼栋层数"]) > intMaxFloorStorey)
                        intMaxFloorStorey = Convert.ToInt32(dtAfter.Rows[count]["楼栋层数"]);
                }
            }
            if (txtFloorName.Text == "" || txtFloorNextName.Text == "")
            {
                strConditionFloorStorey = "";
                for (int BeginNumber = 1; BeginNumber <= intMaxFloorStorey; BeginNumber++)
                {
                    strConditionNumber = strConditionNumber + " 房间号=" + BeginNumber + (strNumber.Length > 1 ? strNumber : "0" + strNumber) + " or";
                }
            }
                           
            if (txtFloorName.Text == "" && txtFloorNextName.Text != "")
            {
                strConditionFloorStorey = " and 楼栋层数<=" + txtFloorNextName.Text;
                for (int BeginNumber = 1; BeginNumber <= Convert.ToInt32(txtFloorNextName.Text); BeginNumber++)
                {
                    strConditionNumber = strConditionNumber + " 房间号=" + BeginNumber + (strNumber.Length > 1 ? strNumber : "0" + strNumber) + " or";
                }
            }
            if (txtFloorName.Text != "" && txtFloorNextName.Text == "")
            {
                strConditionFloorStorey = " and 楼栋层数>=" + txtFloorName.Text;
                for (int BeginNumber = Convert.ToInt32(txtFloorName.Text); BeginNumber <= intMaxFloorStorey; BeginNumber++)
                {
                    strConditionNumber = strConditionNumber + " 房间号=" + BeginNumber + (strNumber.Length > 1 ? strNumber : "0" + strNumber) + " or";
                }
            }
            if (txtFloorName.Text != "" && txtFloorNextName.Text != "")
            {
                if ((Convert.ToInt32(txtFloorName.Text) - Convert.ToInt32(txtFloorNextName.Text)) > 0)
                {
                    MessageBox.Show("亲,输入的筛选开始楼层不能大于结束楼层的哦", "提示");
                    return;
                }
                strConditionFloorStorey = " and 楼栋层数<=" + txtFloorNextName.Text + " and 楼栋层数>=" + txtFloorName.Text;
                for (int BeginNumber = Convert.ToInt32(txtFloorName.Text); BeginNumber <= Convert.ToInt32(txtFloorNextName.Text); BeginNumber++)
                {
                    strConditionNumber = strConditionNumber + " 房间号=" + BeginNumber + (strNumber.Length > 1 ? strNumber : "0" + strNumber) + " or";
                }
            }
            if (strConditionNumber != "")
                strConditionNumber = strConditionNumber.Remove(strConditionNumber.Length - 3);
            strConditionNumber = " and (" + strConditionNumber + ")";
            if (cboRoomNumber.SelectedValue.ToString() == "全部")
            {
                BindingTvwRoomNode(dtAfter);
                strConditionNumber = "";
            }
            strCondition = " 1=1 " + strConditionFloorStorey + strConditionNumber;
            DataView dv = new DataView(dtAfter);
            dv.RowFilter = strCondition;
            DataTable dtLast = dv.ToTable();
            if (bolRoomAllChecked == true)
            {
                BindingTvwRoomNode_AllChecked(dtLast);
            }
            else
                BindingTvwRoomNode(dtLast);
        }

        public void BindingTvwRoomNode(DataTable dt)
        {
            tvwRoom.Nodes.Clear();
            for (int i = 0; i < dt.Rows.Count; i++)//遍历绑定顶级节点
            {
                TreeNode tn = new TreeNode();//实例化节点
                tn.Text = dt.Rows[i]["FloorName"].ToString().Trim() +" - "+ dt.Rows[i]["房间号"].ToString().Trim();//指定节点文本
                tn.Tag = dt.Rows[i]["RoomResourcesID"];//绑定节点数据
                tvwRoom.Nodes.Add(tn);//将节点添加到树控件                
            }
        }

        public void BindingTvwRoomNode_AllChecked(DataTable dt)
        {
            tvwRoom.Nodes.Clear();
            for (int i = 0; i < dt.Rows.Count; i++)//遍历绑定顶级节点
            {
                TreeNode tn = new TreeNode();//实例化节点
                tn.Text = dt.Rows[i]["FloorName"].ToString().Trim() + " - " + dt.Rows[i]["房间号"].ToString().Trim();//指定节点文本
                tn.Tag = dt.Rows[i]["RoomResourcesID"];//绑定节点数据
                tn.Checked = true;
                tvwRoom.Nodes.Add(tn);//将节点添加到树控件                
            }
        }
        
        private void txtFloorName_KeyPress(object sender, KeyPressEventArgs e)
        {
            PublicMethod.txt_KeyPress_OnlyNumber(e, txtFloorName);
        }

        private void txtFloorNextName_KeyPress(object sender, KeyPressEventArgs e)
        {
            PublicMethod.txt_KeyPress_OnlyNumber(e, txtFloorNextName);
        }

        private void chkFullRoomNumberSelect_CheckedChanged(object sender, EventArgs e)
        {
            if (chkFullRoomNumberSelect.Checked)
            {
                for (int nodeconut = 0; nodeconut < tvwRoom.Nodes.Count; nodeconut++)
                {
                    tvwRoom.Nodes[nodeconut].Checked = true;
                }
            }
        }

        DataTable dtFloorNumber = new DataTable();
        private void cboUsingRange_SelectionChangeCommitted(object sender, EventArgs e)
        {
            intProjectID = (int)cboProjectName.SelectedValue;
            dtFloorNumber = myfrmMarketManagement_SalesofPreferentialSettingsClient.InsertPreferentialDetails_Load_BindingFloorNumber(intProjectID).Tables[0];
            int intUsingRange = (int)cboUsingRange.SelectedValue;
            switch (intUsingRange)
            {
                case 51:  //整个项目
                    bolRoomAllChecked = true;
                    BindingTvwNode_OnProject(dtFloorNumber);
                    tvwRoom.Nodes.Clear();
                    BinddtAfter();
                    btnScreening_Click(null,null);
                    tvwFloorNumber.Enabled = false;
                    grbIncludeRoom.Enabled = false;
                    break;
                case 52:  //部分楼栋
                    bolRoomAllChecked = true;
                    BindingTvwNode(dtFloorNumber);
                    BinddtAfter();
                    btnScreening_Click(null,null);
                    grbIncludeRoom.Enabled = false;
                    tvwRoom.Nodes.Clear();
                    break;
                case 53:  //某些单元
                    bolRoomAllChecked = false;
                    BindingTvwNode(dtFloorNumber);
                    grbIncludeRoom.Enabled = true;
                    tvwRoom.Nodes.Clear();
                    break;
                case 54:  //某些房间
                    bolRoomAllChecked = false;
                    BindingTvwNode(dtFloorNumber);
                    grbIncludeRoom.Enabled = true;
                    tvwRoom.Nodes.Clear();
                    break;
            }
        }

        private void txtDiscount_KeyPress(object sender, KeyPressEventArgs e)
        {
            PublicMethod.pubPriceOrRate_KeyPress(sender, e);
        }

        private void txtDiscountAmount_KeyPress(object sender, KeyPressEventArgs e)
        {
            PublicMethod.pubPriceOrRate_KeyPress(sender, e);
        }

        private void txtSinglesetofhighestdiscountamount_KeyPress(object sender, KeyPressEventArgs e)
        {
            PublicMethod.pubPriceOrRate_KeyPress(sender, e);
        }

        private void txtTotalDiscount_KeyPress(object sender, KeyPressEventArgs e)
        {
            PublicMethod.pubPriceOrRate_KeyPress(sender, e);
        }

        private void txtSerialNumber_KeyPress(object sender, KeyPressEventArgs e)
        {
            PublicMethod.txt_KeyPress_OnlyNumber(e, txtSerialNumber);
        }
    }












以上内容仅供学习用途,如用于商业用途,后果自负!!!!!

























































  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值