Winform開(kāi)發(fā)框架之客戶關(guān)系管理系統(tǒng)(CRM)的報(bào)價(jià)單和銷售單的處理

在前面介紹了很多CRM相關(guān)的界面和實(shí)現(xiàn)思路的隨筆文章,本篇繼續(xù)介紹一下系統(tǒng)中用到的一些經(jīng)驗(yàn)和技巧片段。本篇隨筆主要介紹客戶關(guān)系管理系統(tǒng)(CRM)的報(bào)價(jià)單和銷售單的處理界面效果,使用列表內(nèi)置的選擇代替彈出對(duì)話框選擇產(chǎn)品的方式,實(shí)現(xiàn)報(bào)價(jià)單和銷售單的產(chǎn)品列表快速選擇。

1、功能界面效果展示

我們知道,在很多列表的內(nèi)容輸入中,很多都使用內(nèi)置的列表選擇方式代替彈出式對(duì)話框的選擇方式,在我研究了解的很多個(gè)CRM系統(tǒng)中,報(bào)價(jià)單和銷售單都基本上是采用這種內(nèi)置的選擇方式,為了適應(yīng)業(yè)界的標(biāo)準(zhǔn)習(xí)慣,我在我的系統(tǒng)中也使用了這種方式,新建報(bào)價(jià)單界面如下所示。



新建銷售訂單界面如下所示。


報(bào)價(jià)單或者銷售單,一般有狀態(tài)的區(qū)分,為了方便展示各種狀態(tài),可以通過(guò)不同的背景色進(jìn)行區(qū)分,并且單據(jù)通過(guò)分頁(yè)控件進(jìn)行分頁(yè)展示,以達(dá)到更好的效率,如下所示。



報(bào)價(jià)單列表界面如下所示。



其中報(bào)價(jià)單可以直接生成銷售訂單,在報(bào)價(jià)單的列表上右鍵菜單彈出“轉(zhuǎn)化為銷售訂單”即可實(shí)現(xiàn)該功能。

2、實(shí)現(xiàn)控件界面的設(shè)計(jì)步驟

首先我們介紹內(nèi)嵌式的GridControl,實(shí)現(xiàn)實(shí)現(xiàn)數(shù)據(jù)的快速錄入和選擇的操作。在這個(gè)GridControl控件的設(shè)計(jì)視圖里面,需要增加一些在界面上綁定的列,并綁定相關(guān)的FieldName字段。另外,我們把產(chǎn)品名稱設(shè)計(jì)為可以通過(guò)彈出列表選擇的方式,因此需要修改它的ColumnEdit編輯控件為SeachLookupEdit控件,如下界面所示的控件。



調(diào)整后的GridControl的設(shè)計(jì)界面如下所示。



然后需要在設(shè)計(jì)窗口的Repository選項(xiàng)卡界面中的In-place Editor Repository的設(shè)計(jì)模塊里面進(jìn)行調(diào)整,如下所示。

通過(guò)設(shè)置控件的顯示成員(DisplayMemeber)和值成員(ValueMember)即可實(shí)現(xiàn)數(shù)據(jù)的顯示和綁定。


3、實(shí)現(xiàn)控件界面的代碼處理

通過(guò)第二步的界面配置,我們指定了GridControl的列表展示效果,但是真正需要運(yùn)行起來(lái),還需要通過(guò)代碼進(jìn)行數(shù)據(jù)的動(dòng)態(tài)綁定和處理,才能正常使用。

public partial class FrmEditQuotation : BaseEditForm
{
    private QuotationInfo tempInfo = new QuotationInfo();

    /// <summary>
    /// 所屬客戶ID
    /// </summary>
    public string CustomerID { get; set; }

    public FrmEditQuotation()
    {
        InitializeComponent();
        
        //綁定所有在用的產(chǎn)品信息
        this.repositoryItemSearchLookUpEdit1.DataSource = BLLFactory<Product>.Instance.GetAllInUsed();
        //對(duì)控件列編輯控件的預(yù)處理
        this.gridView1.ShowingEditor += new CancelEventHandler(gridView1_ShowingEditor);
        //控件列編輯控件的值變化的處理
        this.gridView1.CellValueChanged += new DevExpress.XtraGrid.Views.Base.CellValueChangedEventHandler(gridView1_CellValueChanged);
    }

另外,我們?cè)诮壎〝?shù)據(jù)的時(shí)候,必須綁定GridControl的控件數(shù)據(jù)源,如下代碼所示。

/// <summary>
/// 數(shù)據(jù)顯示的函數(shù)
/// </summary>
public override void DisplayData()
{
    InitDictItem();//數(shù)據(jù)字典加載(公用)
    
    if (!string.IsNullOrEmpty(ID))
    {
       ................................     
    }
    else
    {
        ............................... 
    }

    this.gridControl1.DataSource = GetDetailTable();//綁定訂單詳細(xì)列表

    SetAttachInfo(tempInfo);
}
/// <summary>
/// 綁定明細(xì)信息
/// </summary>
/// <returns></returns>
public DataTable GetDetailTable()
{
    string columnString = "ID,ProductName,ProductNo,MaterialCode,ProductType,Specification,Model,Unit,SalePrice|decimal,Quantity|int,Note,ExpireDate|DateTime";
    DataTable dt = DataTableHelper.CreateTable(columnString);
    if (!string.IsNullOrEmpty(ID))
    {
        List<QuotationDetailInfo> list = BLLFactory<QuotationDetail>.Instance.FindByOrderNo(this.txtHandNo.Text);
        DataRow dr = null;
        foreach (QuotationDetailInfo info in list)
        {
            dr = dt.NewRow();
            dr["ID"] = info.ID;
            dr["ProductName"] = info.Product_ID;
            dr["ProductNo"] = info.ProductNo;
            dr["MaterialCode"] = info.MaterialCode;
            dr["ProductType"] = info.ProductType;
            dr["Specification"] = info.Specification;
            dr["Model"] = info.Model;
            dr["Unit"] = info.Unit;
            dr["SalePrice"] = info.SalePrice;
            dr["Quantity"] = info.Quantity;
            dr["Note"] = info.Note;
            if (info.ExpireDate > Convert.ToDateTime("1900-1-1"))
            {
                dr["ExpireDate"] = info.ExpireDate;
            }
            dt.Rows.Add(dr);
        }
    }
    return dt;
}

其中注意上面的紅色的代碼,在產(chǎn)品名稱的列上綁定的值是產(chǎn)品ID,而非產(chǎn)品名稱即可。
另外,上面代碼提到的CellValueChanged事件是當(dāng)列表選定后,在該行的其他列上顯示數(shù)據(jù)的操作,如果沒(méi)有選擇,則清空相關(guān)的單元格內(nèi)容,具體代碼如下所示。

private void gridView1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
{
    if (e.Column.FieldName == "ProductName")
    {
        ProductInfo info = BLLFactory<Product>.Instance.FindByID(e.Value.ToString());
        if (info != null)
        {
            this.gridView1.SetRowCellValue(e.RowHandle, "ProductNo", info.HandNo);
            this.gridView1.SetRowCellValue(e.RowHandle, "MaterialCode", info.MaterialCode);
            this.gridView1.SetRowCellValue(e.RowHandle, "ProductType", info.ProductType);
            this.gridView1.SetRowCellValue(e.RowHandle, "Specification", info.Specification);
            this.gridView1.SetRowCellValue(e.RowHandle, "Model", info.Model);
            this.gridView1.SetRowCellValue(e.RowHandle, "Unit", info.Unit);
            this.gridView1.SetRowCellValue(e.RowHandle, "SalePrice", info.SalePrice);
        }
        else
        {
            this.gridView1.SetRowCellValue(e.RowHandle, "ProductNo", DBNull.Value);
            this.gridView1.SetRowCellValue(e.RowHandle, "MaterialCode", DBNull.Value);
            this.gridView1.SetRowCellValue(e.RowHandle, "ProductType", DBNull.Value);
            this.gridView1.SetRowCellValue(e.RowHandle, "Specification", DBNull.Value);
            this.gridView1.SetRowCellValue(e.RowHandle, "Model", DBNull.Value);
            this.gridView1.SetRowCellValue(e.RowHandle, "Unit", DBNull.Value);
            this.gridView1.SetRowCellValue(e.RowHandle, "SalePrice", DBNull.Value);

            this.gridView1.SetRowCellValue(e.RowHandle, "Quantity", DBNull.Value);
            this.gridView1.SetRowCellValue(e.RowHandle, "Note", DBNull.Value);
            this.gridView1.SetRowCellValue(e.RowHandle, "ExpireDate", DBNull.Value);
        }
    }
}

最后就是在表單保存的時(shí)候,更新相關(guān)的主表數(shù)據(jù)后,接著保存相關(guān)的報(bào)價(jià)單明細(xì)或者訂單明細(xì)即可,如下面的紅色部分代碼所示。

/// <summary>
/// 新增狀態(tài)下的數(shù)據(jù)保存
/// </summary>
/// <returns></returns>
public override bool SaveAddNew()
{
    QuotationInfo info = tempInfo;
    SetInfo(info);
    info.Creator = LoginUserInfo.Name;
    info.CreateTime = DateTime.Now;

    try
    {
        #region 新增數(shù)據(jù)

        bool succeed = BLLFactory<Quotation>.Instance.Insert(info);
        if (succeed)
        {
            //可添加其他關(guān)聯(lián)操作
            SaveDetail();

            return true;
        }
        #endregion
    }
    catch (Exception ex)
    {
        LogTextHelper.Error(ex);
        MessageDxUtil.ShowError(ex.Message);
    }
    return false;
}

4、列表單元格背景顏色變化的處理

剛才在1小節(jié)里面提到報(bào)價(jià)單或者銷售單,一般有狀態(tài)的區(qū)分,為了方便展示各種狀態(tài),可以通過(guò)不同的背景色進(jìn)行區(qū)分,如下所示。



上面這種效果如何實(shí)現(xiàn)的呢,一般通過(guò)增加對(duì)RowCellStyle的處理即可,具體代碼如下所示。

void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
{
    if (e.Column.FieldName == "OrderStatus" || e.Column.FieldName == "HandNo")
    {
        //待處理  處理中 已完成
        string status = this.winGridViewPager1.gridView1.GetRowCellValue(e.RowHandle, "OrderStatus").ToString();
        Color color = Color.White;
        if (status == "處理中")
        {
            e.Appearance.BackColor = Color.Yellow;
            e.Appearance.BackColor2 = Color.LightCyan;
        }
        if (status == "發(fā)貨中")
        {
            e.Appearance.BackColor = Color.Purple;
            e.Appearance.BackColor2 = Color.LightCyan;
        }
        if (status == "已取消")
        {
            e.Appearance.BackColor = Color.Red;
            e.Appearance.BackColor2 = Color.LightCyan;
        }
        else if (status == "已完成")
        {
            e.Appearance.BackColor = Color.Green;
            e.Appearance.BackColor2 = Color.LightCyan;
        }
    }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容