123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086 |
- using LYFZ.Software.MainBusiness.DoorCityProcess;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Linq;
- using System.Windows.Forms;
- namespace LYFZ.Software.MainBusiness.StatisticalInquiry
- {
- public partial class FrmCosting : LYFZ.Software.UI.StatisticalInquiry.FrmCosting
- {
- private delegate void UpdateControl();
- public FrmCosting()
- {
- this.ucPagerEx1.EventPaging += ucPagerEx1_EventPaging;
- this.cmbtreevStoreName.ComboBoxTree_NodeMouseClick += CmbtreevStoreName_ComboBoxTree_NodeMouseClick;
- // 获取分店信息;
- LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.BindGroupStoreName( this.cmbtreevStoreName, StrGroupKeyCode: "retailProcess", StrKeyCode: "st013" );
- #region 新版本成本核算;
- // 初始化DataGridView;
- InitDataGridViewColumns( _listShowColumns, _listHideColumns );
- // checkbox;
- this.cb_pickup.CheckedChanged += Cb_pickup_CheckedChanged;
- // datagridview双击;
- this.dgv.CellDoubleClick += Dgv_CellDoubleClick;
- #endregion
- }
- private void Dgv_CellDoubleClick( object sender, DataGridViewCellEventArgs e )
- {
- // 参数校验;
- if ( e.RowIndex < 0 || e.RowIndex == this.dgv.RowCount )
- return;
- // 订单号;
- FrmCostDetail frmCostDetail = new FrmCostDetail( this.dgv.Rows[e.RowIndex], this._dataTable.Rows[e.RowIndex]["订单类型"].ToString() == "1" );
- frmCostDetail.ShowDialog();
- }
- private void Cb_pickup_CheckedChanged( object sender, EventArgs e )
- {
- this.PublicFunctionRows();
- }
- private void CmbtreevStoreName_ComboBoxTree_NodeMouseClick( object sender, TreeNodeMouseClickEventArgs e )
- {
- this.PublicFunctionRows();
- }
- /// <summary>
- /// 加载
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void FrmCosting_Shown( object sender, EventArgs e )
- {
- txtTimeStart.Text = SDateTime.Now.ToString( "yyyy-MM-dd" );
- txtTimeEnd.Text = Convert.ToDateTime( SDateTime.Now ).AddMonths( 1 ).AddSeconds( -1 ).ToString( "yyyy-MM-dd" );
- LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.BindComboBoxTreeView_DepartmentAndEmployee( this.txtTsorder_OpenSingle, IsFirstNodeNull: true );
- //绑定数据
- Bind();
- //导出
- btnExPort.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights( LYFZ.BLL.BLL_ErpUser.CurrentUserRights.CostingCompetence, CustomAttributes.OperatingAuthority.DataExport );
- ///控制统计查询成本核算的版本权
- //LYFZSS.SystemSpecterPossessed.ISystemSpecterPossessed.GetMySystemSpecter = LYFZSS.SystemSpecterType.SST_C;
- bool b = LYFZ.Software.MainBusiness.VersionControl.StaticVersion.UIFunctionVersion( VersionControl.VersionFunctionEnum.统计查询成本核算 );
- if ( !b )
- {
- btnClose_Click( null, null );
- }
- }
- /// <summary>
- /// 人员选择事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void txtTsorder_OpenSingle_ComboBoxTreeViewEx_TextChanged( object sender, TreeViewEventArgs e )
- {
- Bind();
- }
- /// <summary>
- /// 时间查询
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void btnSelect_Click( object sender, EventArgs e )
- {
- if ( string.IsNullOrEmpty( txtTimeStart.DateValue ) )
- {
- MessageBoxCustom.Show( "开始时间不能为空!" );
- return;
- }
- if ( string.IsNullOrEmpty( txtTimeEnd.DateValue ) )
- {
- MessageBoxCustom.Show( "结束时间不能为空!" );
- return;
- }
- //绑定数据
- Bind();
- }
- /// <summary>
- /// 导出
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void btnExPort_Click( object sender, EventArgs e )
- {
- dgv.ExportDataTable();
- }
- /// <summary>
- /// 关闭
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void btnClose_Click( object sender, EventArgs e )
- {
- this.Close();
- }
- /// <summary>
- /// 时间控件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void txtTimeStart_Leave( object sender, EventArgs e )
- {
- if ( string.IsNullOrEmpty( this.txtTimeStart.DateValue ) )
- {
- MessageBoxCustom.Show( "开始时间格式输入错误" );
- txtTimeStart.DateValue = SDateTime.Now.ToString( "yyyy-MM" ) + "-01";
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void txtTimeStart_Enter( object sender, EventArgs e )
- {
- if ( string.IsNullOrEmpty( this.txtTimeStart.DateValue ) )
- {
- txtTimeStart.DateValue = SDateTime.Now.ToString( "yyyy-MM" ) + "-01";
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void txtTimeEnd_Leave( object sender, EventArgs e )
- {
- if ( string.IsNullOrEmpty( this.txtTimeEnd.DateValue ) )
- {
- MessageBoxCustom.Show( "结束时间格式输入错误" );
- txtTimeEnd.DateValue = Convert.ToDateTime( Convert.ToDateTime( SDateTime.Now.ToString( "yyyy-MM" ) + "-01" ).AddMonths( 1 ).AddSeconds( -1 ) ).ToString( "yyyy-MM-dd" );
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void txtTimeEnd_Enter( object sender, EventArgs e )
- {
- if ( string.IsNullOrEmpty( this.txtTimeEnd.DateValue ) )
- {
- txtTimeEnd.DateValue = Convert.ToDateTime( Convert.ToDateTime( SDateTime.Now.ToString( "yyyy-MM" ) + "-01" ).AddMonths( 1 ).AddSeconds( -1 ) ).ToString( "yyyy-MM-dd" );
- }
- }
- LYFZ.BLL.BLL_FinancialStatements FinancialStatementsbll = new BLL.BLL_FinancialStatements();
- LYFZ.BLL.BLL_ErpOrderProductList OrderProductListbll = new BLL.BLL_ErpOrderProductList();
- LYFZ.BLL.BLL_ErpWeddingService WeddingServicebll = new BLL.BLL_ErpWeddingService();
- LYFZ.BLL.BLL_ErpPlusPickItems PlusPickItemsbll = new BLL.BLL_ErpPlusPickItems();
- LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder();
- void PublicFunctionRows()
- {
- PublicFunctionRowsEx();
- return;
- this.dgv.Rows.Clear();
- string StrWhere = "Ord_Class = '1'";
- if ( !string.IsNullOrEmpty( this.txtOrd_Number.Text.Trim() ) )
- {
- StrWhere += " And (Ord_Number like '%" + this.txtOrd_Number.Text.Trim() + "%' or Ord_SinceOrderNumber like '%" + this.txtOrd_Number.Text.Trim() + "%' or 客户姓名 like '%" + this.txtOrd_Number.Text.Trim() + "%' or 客户拼音 like '%" + this.txtOrd_Number.Text.Trim() + "%' or 客户电话 like '%" + this.txtOrd_Number.Text.Trim() + "%')";
- }
- else
- {
- StrWhere += PublicCodeClasses.GetDateTime( "订单时间", txtTimeStart.Text, txtTimeEnd.Text );
- }
- if ( !string.IsNullOrEmpty( txtTsorder_OpenSingle.Text.Trim() ) )
- {
- StrWhere += " And 接单人编号 like '%" + txtTsorder_OpenSingle.Tag.ToString().Trim() + "%' ";
- }
- StrWhere += LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetGroupQueryWhere( this.cmbtreevStoreName, "Ord_DividedShop" );
- LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod( delegate ( object obj, BackgroundWorker backgroundWorker )
- {
- backgroundWorker.ReportProgress( 0, "正在获取数据 ..." );
- string StrTableName = "( " +
- "select Ord_Number,Ord_SinceOrderNumber,Ord_Class,Ord_DividedShop,Cus_Name AS 客户姓名,Cus_Name_py AS 客户拼音,Cus_Telephone AS 客户电话," +
- "case when Ord_SinceOrderNumber <> '' then Ord_SinceOrderNumber else Ord_Number end AS 订单号,Ord_CreateDatetime AS 订单时间," +
- "(Ord_SeriesPrice+ " +
- "case when (select Count(ID) AS CountID from tb_ErpPlusPickItems where Plu_OrdNumber = Ord_Number) > 0 then " +
- " case when (select sum(case when Plu_GoodsCosts <> '' then convert(decimal(10,2),dbo.fn_GetSumArray(Plu_GoodsCosts)) else 0 end) from tb_ErpPlusPickItems where Plu_OrdNumber = Ord_Number) is null then 0 else (select sum(case when Plu_GoodsCosts <> '' then convert(decimal(10,2),dbo.fn_GetSumArray(Plu_GoodsCosts)) else 0 end) from tb_ErpPlusPickItems where Plu_OrdNumber = Ord_Number) end " +
- " else 0 end) AS 套系价格, " +
- "(select stuff((select ',' + OrdPe_OrdersPerson from tb_ErpOrdersPerson where OrdPe_OrderNumber = Ord_Number for xml path('')),1,1,'')) as 接单人编号, " +
- "(select stuff((select ',' + dbo.fn_CheckUserIDGetUserName(OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber = Ord_Number for xml path('')),1,1,'')) as 接单人, " +
- "(isnull((select sum(OPlist_CostPrice * OPlist_ProdQuantity) from tb_ErpOrderProductList where OPlist_Type = '1' And OPlist_OrderNumber = Ord_Number),0) + " +
- "isnull((select sum(Ws_ProdCostPrice * Ws_ProdQuantity) from tb_ErpWeddingService where Ws_Number = Ord_Number),0) + " +
- "isnull((select sum(Ordpg_CostPrice) from tb_ErpOrdersPhotography where Ordpg_Number = Ord_Number),0) + " +
- "isnull((select sum(case when Plu_GoodsCosts <> '' then convert(decimal(10,2),dbo.fn_GetSumArray(Plu_GoodsCosts)) else 0 end) from tb_ErpPlusPickItems where Plu_OrdNumber = Ord_Number),0)) AS 套系成本 " +
- "from tb_ErpOrder Left Join tempTB_AggregationCustomer on Ord_Number = GP_OrderNumber " +
- ") as tb ";
- string StrColumnName = "Ord_Number,订单号,客户姓名,客户电话,接单人,套系价格,套系成本";
- DataTable dt = orbll.GetView_Custom( StrTableName, StrWhere: StrWhere, ShowColumnName: StrColumnName ).Tables[0];
- if ( dt.Rows.Count > 0 )
- {
- string StrWhere2 = "";
- for ( int i = 0; i < dt.Rows.Count; i++ )
- {
- StrWhere2 += "'" + dt.Rows[i]["Ord_Number"].ToString().Trim() + "',";
- }
- string StrTableName2 = "select OPlist_OrderNumber AS 订单号,OPlist_ProdName AS 商品名称,OPlist_CostPrice AS 商品单价,OPlist_ProdQuantity AS 商品数量 from tb_ErpOrderProductList where OPlist_Type = '1' And OPlist_OrderNumber in (" + StrWhere2.TrimEnd( ',' ) + ") " +
- "UNION ALL " +
- "select Ws_Number AS 订单号,Ws_ProdName AS 商品名称,Ws_ProdCostPrice AS 商品单价,Ws_ProdQuantity AS 商品数量 from tb_ErpWeddingService where Ws_Number in (" + StrWhere2.TrimEnd( ',' ) + ") " +
- "UNION ALL " +
- "select Ordpg_Number AS 订单号,Ordpg_Sights AS 商品名称,Ordpg_CostPrice AS 商品单价,1 AS 商品数量 from tb_ErpOrdersPhotography where Ordpg_Number in (" + StrWhere2.TrimEnd( ',' ) + ") ";
- DataTable tbl = orbll.GetView_Custom( StrTableName2 ).Tables[0];
- DataTable tblPlus = orbll.GetView_Custom( "tb_ErpPlusPickItems", StrWhere: "Plu_OrdNumber in (" + StrWhere2.TrimEnd( ',' ) + ")", ShowColumnName: "Plu_OrdNumber,Plu_Goods,Plu_GoodsCosts" ).Tables[0];
- backgroundWorker.ReportProgress( 0, "正在绑定数据 ..." );
- for ( int i = 0; i < tblPlus.Rows.Count; i++ )
- {
- try
- {
- string[] StrArray1 = tblPlus.Rows[i]["Plu_Goods"].ToString().Trim().Split( ',' );
- string[] StrArray2 = tblPlus.Rows[i]["Plu_GoodsCosts"].ToString().Trim().Split( ',' );
- for ( int j = 0; j < StrArray1.Length; j++ )
- {
- DataRow newRow = tbl.NewRow();
- newRow["订单号"] = tblPlus.Rows[i]["Plu_OrdNumber"].ToString().Trim();
- newRow["商品名称"] = StrArray1[j].ToString().Trim();
- if ( j < StrArray2.Length )
- {
- newRow["商品单价"] = StrArray2[j].ToString().Trim();
- }
- else
- {
- newRow["商品单价"] = "0";
- }
- newRow["商品数量"] = 1;
- tbl.Rows.Add( newRow );
- }
- }
- catch { }
- }
- try
- {
- this.Invoke( new UpdateControl( delegate ()
- {
- #region 绑定订单
- //总售价
- decimal TotalPrice = 0;
- //总成本
- decimal TotalCost = 0;
- for ( int i = 0; i < dt.Rows.Count; i++ )
- {
- DataRow[] dtRows = tbl.Select( "订单号 = '" + dt.Rows[i]["Ord_Number"].ToString().Trim() + "'" );
- DataGridViewRow dgvr = new DataGridViewRow();
- DataGridViewCell cell = null;
- cell = new DataGridViewTextBoxCell();
- cell.Value = dt.Rows[i]["订单号"].ToString().Trim();
- dgvr.Cells.Add( cell );
- cell = new DataGridViewTextBoxCell();
- cell.Value = dt.Rows[i]["客户姓名"].ToString().Trim();
- dgvr.Cells.Add( cell );
- cell = new DataGridViewTextBoxCell();
- cell.Value = dt.Rows[i]["客户电话"].ToString().Trim();
- dgvr.Cells.Add( cell );
- cell = new DataGridViewTextBoxCell();
- cell.Value = dt.Rows[i]["接单人"].ToString().Trim();
- dgvr.Cells.Add( cell );
- cell = new DataGridViewTextBoxCell();
- cell.Value = dt.Rows[i]["套系价格"].ToString().Trim();
- dgvr.Cells.Add( cell );
- TotalPrice += Convert.ToDecimal( dt.Rows[i]["套系价格"] );
- cell = new DataGridViewTextBoxCell();
- cell.Value = dt.Rows[i]["套系成本"].ToString().Trim();
- dgvr.Cells.Add( cell );
- TotalCost += Convert.ToDecimal( dt.Rows[i]["套系成本"] );
- if ( dtRows.Length > 0 )
- {
- cell = new DataGridViewTextBoxCell();
- cell.Value = dtRows[0]["商品名称"].ToString().Trim();
- dgvr.Cells.Add( cell );
- cell = new DataGridViewTextBoxCell();
- cell.Value = dtRows[0]["商品单价"].ToString().Trim();
- dgvr.Cells.Add( cell );
- cell = new DataGridViewTextBoxCell();
- cell.Value = dtRows[0]["商品数量"].ToString().Trim();
- dgvr.Cells.Add( cell );
- }
- else
- {
- for ( int j = 0; j < 3; j++ )
- {
- cell = new DataGridViewTextBoxCell();
- cell.Value = "";
- dgvr.Cells.Add( cell );
- }
- }
- this.dgv.Rows.Add( dgvr );
- #region 绑定商品数据
- for ( int j = 1; j < dtRows.Length; j++ )
- {
- dgvr = new DataGridViewRow();
- for ( int k = 0; k < 6; k++ )
- {
- cell = new DataGridViewTextBoxCell();
- cell.Value = "";
- dgvr.Cells.Add( cell );
- }
- cell = new DataGridViewTextBoxCell();
- cell.Value = dtRows[j]["商品名称"].ToString().Trim();
- dgvr.Cells.Add( cell );
- cell = new DataGridViewTextBoxCell();
- cell.Value = dtRows[j]["商品单价"].ToString().Trim();
- dgvr.Cells.Add( cell );
- cell = new DataGridViewTextBoxCell();
- cell.Value = dtRows[j]["商品数量"].ToString().Trim();
- dgvr.Cells.Add( cell );
- this.dgv.Rows.Add( dgvr );
- }
- #endregion
- }
- #endregion
- #region 合计项目
- //单数
- this.lblSingular.Text = dt.Rows.Count.ToString();
- //总售价
- this.lblTotalPrice.Text = TotalPrice.ToString( "N2" );
- //总成本
- this.lbltotalCost.Text = TotalCost.ToString( "N2" );
- //毛利
- this.lblGrossProfit.Text = ( Convert.ToDecimal( this.lblTotalPrice.Text ) - Convert.ToDecimal( this.lbltotalCost.Text ) ).ToString( "N2" );
- //毛利率 ((总售价-总成本)/总售价)*100
- if ( Convert.ToDecimal( this.lblSingular.Text ) == 0 )
- {
- this.lblGrossMargin.Text = "100%";
- }
- else
- {
- if ( Convert.ToDecimal( this.lblTotalPrice.Text ) != Convert.ToDecimal( "0" ) )
- {
- this.lblGrossMargin.Text = ( ( ( Convert.ToDecimal( this.lblTotalPrice.Text ) - Convert.ToDecimal( this.lbltotalCost.Text ) ) / Convert.ToDecimal( this.lblTotalPrice.Text ) ) * 100 ).ToString( "N2" ) + "%";
- }
- else
- {
- this.lblGrossMargin.Text = "0%";
- }
- }
- //平均售价
- if ( Convert.ToDecimal( lblSingular.Text ) == 0 )
- {
- this.lblAverageSellingPrice.Text = "0.00";
- }
- else
- {
- this.lblAverageSellingPrice.Text = ( Convert.ToDecimal( this.lblTotalPrice.Text ) / Convert.ToInt32( this.lblSingular.Text ) ).ToString( "N2" );
- }
- //平均成本
- if ( Convert.ToDecimal( lblSingular.Text ) == 0 )
- {
- this.lblAverageCost.Text = "0.00";
- }
- else
- {
- this.lblAverageCost.Text = ( Convert.ToDecimal( this.lbltotalCost.Text ) / Convert.ToInt32( this.lblSingular.Text ) ).ToString( "N2" );
- }
- //平均毛利
- if ( Convert.ToDecimal( lblSingular.Text ) == 0 )
- {
- this.lblAverageGrossProfit.Text = "0.00";
- }
- else
- {
- this.lblAverageGrossProfit.Text = ( Convert.ToDecimal( this.lblGrossProfit.Text ) / Convert.ToInt32( this.lblSingular.Text ) ).ToString( "N2" );
- }
- #endregion
- } ) );
- }
- catch ( Exception e )
- {
- }
- }
- } );
- }
- #region 新版本成本核算;
- IEnumerable<DataRow> _rows = null;
- DataTable _dataTable = null;
- string _listNullColumn = "订单号, 接单人, 顾客姓名, 顾客电话, 套系名称, 套系价格";
- string _listShowColumns = "订单号, 接单人, 顾客姓名, 顾客电话, 套系名称, 套系价格, 拍摄景点, 商品成本, 服务成本, 景点成本, 加挑总价, 加挑成本";
- string _listHideColumns = "自定义单号,订单类型,订单类别,订单日期,分店编号,顾客拼音,取件状态,取件时间";
- void PublicFunctionRowsEx()
- {
- _dataTable = null;
- this.dgv.Rows.Clear();
- this.lblSingular.Text = "0";
- this.lblTotalPrice.Text = "0";
- this.lbltotalCost.Text = "0";
- this.lblGrossProfit.Text = "0";
- this.lblGrossMargin.Text = "0%";
- this.lblAverageSellingPrice.Text = "0.00";
- this.lblAverageGrossProfit.Text = "0.00";
- LYFZ.DAL.CostAccounting costAccounting = new DAL.CostAccounting();
- // 获取分店编号;
- string branchId = null;
- if ( LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.IsGroupEdition )
- branchId = this.cmbtreevStoreName.Tag.ToString().Trim();
- string clerkId = null;
- if ( !string.IsNullOrEmpty( txtTsorder_OpenSingle.Text.Trim() ) )
- clerkId = txtTsorder_OpenSingle.Tag.ToString().Trim();
- LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod( delegate ( object obj, BackgroundWorker backgroundWorker )
- {
- backgroundWorker.ReportProgress( 0, "正在获取数据 ..." );
- // 获取成本核算数据集;
- _dataTable = costAccounting.GetCostAccountingEx( this.cb_pickup.Checked, txtTimeStart.Value, txtTimeEnd.Value, branchId, clerkId, txtOrd_Number.Text );
- } );
- if ( _dataTable == null )
- return;
- _rows = from pp in _dataTable.AsEnumerable() select pp;
- this.dgv.RowCount = _dataTable.Rows.Count;
- // 订单总数;
- int nOrderCount = _rows.GroupBy( e => e.Field<string>( "订单号" ) ).Count();
- // 订单总售价;
- decimal TotalPrice = _rows.Select( e => e.Field<decimal>( "套系价格" ) ).Sum() +
- _rows.Select( e => e.Field<decimal>( "加挑总价" ) ).Sum();
- // 订单总成本;
- decimal TotalCost = _rows.Select( e => e.Field<decimal>( "商品成本" ) ).Sum() +
- _rows.Select( e => e.Field<decimal>( "服务成本" ) ).Sum() +
- _rows.Select( e => e.Field<decimal>( "景点成本" ) ).Sum() +
- _rows.Select( e => e.Field<decimal>( "加挑成本" ) ).Sum();
- #region 合计项目
- //单数;
- this.lblSingular.Text = nOrderCount.ToString();
- //总售价;
- this.lblTotalPrice.Text = TotalPrice.ToString( "N2" );
- //总成本;
- this.lbltotalCost.Text = TotalCost.ToString( "N2" );
- //毛利;
- this.lblGrossProfit.Text = ( TotalPrice - TotalCost ).ToString( "N2" );
- //毛利率 ((总售价-总成本)/总售价)*100;
- if ( nOrderCount == 0 )
- {
- this.lblGrossMargin.Text = "100%";
- }
- else
- {
- if ( TotalPrice != Convert.ToDecimal( "0" ) )
- this.lblGrossMargin.Text = ( ( ( TotalPrice - TotalCost ) / TotalPrice ) * 100 ).ToString( "N2" ) + "%";
- else
- this.lblGrossMargin.Text = "0%";
- }
- //平均售价;
- if ( nOrderCount == 0 )
- this.lblAverageSellingPrice.Text = "0.00";
- else
- this.lblAverageSellingPrice.Text = ( TotalPrice / nOrderCount ).ToString( "N2" );
- //平均成本;
- if ( nOrderCount == 0 )
- this.lblAverageCost.Text = "0.00";
- else
- this.lblAverageCost.Text = ( TotalCost / nOrderCount ).ToString( "N2" );
- //平均毛利;
- if ( nOrderCount == 0 )
- this.lblAverageGrossProfit.Text = "0.00";
- else
- this.lblAverageGrossProfit.Text = ( ( TotalPrice - TotalCost ) / nOrderCount ).ToString( "N2" );
- #endregion
- }
- /// <summary>
- /// 初始化DataGridView列;
- /// </summary>
- void InitDataGridViewColumns( string strColumns /*逗号分隔*/, string strHideFields = ""/*逗号分隔*/, bool IsSortMode = false )
- {
- DataGridViewTextBoxColumn column = null;
- if ( !string.IsNullOrEmpty( strColumns ) )
- {
- // 有必须的话, 清空之前的列头信息;
- this.dgv.Rows.Clear();
- this.dgv.Columns.Clear();
- List<string> listColumns = strColumns.Split( ',' ).ToList();
- List<string> listHideFields = strHideFields.Split( ',' ).ToList();
- for ( int i = 0; i < listColumns.Count; i++ )
- {
- column = new DataGridViewTextBoxColumn();
- column.ReadOnly = true;
- column.Name = listColumns[i].Trim();
- column.HeaderText = listColumns[i].Trim();
- // 是否有隐藏列;
- if ( listHideFields.Contains( listColumns[i].Trim() ) )
- column.Visible = false;
- // 是否排序;
- if ( IsSortMode )
- column.SortMode = DataGridViewColumnSortMode.Automatic;
- this.dgv.Columns.Add( column );
- }
- this.dgv.ColumnHeadersHeight = 25;
- this.dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
- }
- // 虚拟模式显示数据;
- this.dgv.VirtualMode = true;
- this.dgv.CellValueNeeded += Dgv_CellValueNeeded;
- }
- private void Dgv_CellValueNeeded( object sender, DataGridViewCellValueEventArgs e )
- {
- // 参数校验;
- if ( _dataTable == null || 0 == _dataTable.Rows.Count || e.RowIndex == _dataTable.Rows.Count )
- return;
- // 当前行;
- DataGridViewRow dgrCurrent = this.dgv.Rows[e.RowIndex];
- if ( e.RowIndex != 0 && _dataTable.Rows[e.RowIndex]["订单号"].Equals( _dataTable.Rows[e.RowIndex - 1]["订单号"] ) )
- {// 同一订单的;
- // 上一行颜色;
- DataGridViewRow dgrLast = this.dgv.Rows[e.RowIndex - 1];
- dgrCurrent.Tag = dgrLast.Tag;
- if ( dgrCurrent.DefaultCellStyle.BackColor != dgrLast.DefaultCellStyle.BackColor )
- dgrCurrent.DefaultCellStyle.BackColor = dgrLast.DefaultCellStyle.BackColor;
- // 如果是不显示的列字段, 退出;
- if ( _listNullColumn.Contains( this.dgv.Columns[e.ColumnIndex].Name.Trim() ) )
- return;
- if ( this.dgv.Columns[e.ColumnIndex].Name.Trim() != "StrIsAddColumnsNull" )
- e.Value = _dataTable.Rows[e.RowIndex][this.dgv.Columns[e.ColumnIndex].Name.Trim()].ToString();
- }
- else
- {// 下一订单的;
- dgrCurrent.Tag = _dataTable.Rows[e.RowIndex]["订单号"];
- if ( this.dgv.Columns[e.ColumnIndex].Name.Trim() != "StrIsAddColumnsNull" )
- e.Value = _dataTable.Rows[e.RowIndex][this.dgv.Columns[e.ColumnIndex].Name.Trim()].ToString();
- // 订单行是否更色;
- if ( e.RowIndex != 0 )
- {// 非第一行;
- DataGridViewRow dgrLast = this.dgv.Rows[e.RowIndex - 1];
- if ( dgrLast.DefaultCellStyle.BackColor == System.Drawing.Color.PowderBlue )
- dgrCurrent.DefaultCellStyle.BackColor = System.Drawing.Color.PapayaWhip;
- else
- dgrCurrent.DefaultCellStyle.BackColor = System.Drawing.Color.PowderBlue;
- }
- else
- {// 第一行时;
- dgrCurrent.DefaultCellStyle.BackColor = System.Drawing.Color.PowderBlue;
- }
- }
- }
- #endregion
- DataTable dtProductList = null;
- DataTable dtWeddingService = null;
- DataTable dtPlusPickItems = null;
- /// <summary>
- /// 绑定数据
- /// </summary>
- public void Bind()
- {
- PublicFunctionRows();
- //this.ucPagerEx1.PageCurrent = 1;
- //this.ucPagerEx1.PageSize = 200;
- //this.ucPagerEx1.Bind();
- }
- /// <summary>
- /// 画分页
- /// </summary>
- /// <param name="e"></param>
- /// <returns></returns>
- private int ucPagerEx1_EventPaging( UCPager.EventPagingArg e )
- {
- //总售价
- decimal TotalPrice = 0;
- //总成本
- decimal totalCost = 0;
- LYFZ.UCPager.PageData pageData = new LYFZ.UCPager.PageData();
- this.dgv.Rows.Clear();
- DataTable dt = new DataTable();
- string StrWhere = "";
- #region 查询条件
- if ( txtTsorder_OpenSingle.Text.Trim() == "" )
- {
- if ( string.IsNullOrEmpty( txtOrd_Number.Text.Trim() ) )
- {
- StrWhere = " ord_class='1' " + PublicCodeClasses.GetDateTime( "Ord_CreateDatetime", txtTimeStart.Text, txtTimeEnd.Text );
- }
- else
- {
- StrWhere = " ord_class='1' " + PublicCodeClasses.GetDateTime( "Ord_CreateDatetime", txtTimeStart.Text, txtTimeEnd.Text ) + " and (Ord_Number like '%" + txtOrd_Number.Text + "%' or Ord_SinceOrderNumber like '%" + txtOrd_Number.Text + "%')";
- }
- }
- else
- {
- if ( string.IsNullOrEmpty( txtOrd_Number.Text.Trim() ) )
- {
- StrWhere = " ord_class='1' and Ord_OrdersPersonID like '%" + txtTsorder_OpenSingle.Tag.ToString() + "%' " + PublicCodeClasses.GetDateTime( "Ord_CreateDatetime", txtTimeStart.Text, txtTimeEnd.Text );
- }
- else
- {
- StrWhere = " ord_class='1' and Ord_OrdersPersonID like '%" + txtTsorder_OpenSingle.Tag.ToString() + "%' and (Ord_Number like '%" + txtOrd_Number.Text + "%' or Ord_SinceOrderNumber like '%" + txtOrd_Number.Text + "%')" + PublicCodeClasses.GetDateTime( "Ord_CreateDatetime", txtTimeStart.Text, txtTimeEnd.Text );
- }
- }
- #endregion
- LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod( delegate ( object obj, BackgroundWorker backgroundWorker )
- {
- pageData.TableName = "Vw_Customer_PaymentOrders";
- pageData.PageIndex = this.ucPagerEx1.PageCurrent;
- pageData.PageSize = this.ucPagerEx1.PageSize;
- pageData.QueryCondition = StrWhere.ToString();
- pageData.QueryFieldName = " ID,Ord_Number,Ord_DividedShop,Ord_Type,Ord_SeriesName,Ord_SeriesPrice,Ord_Class,GP_OrderNumber,GP_CustomerGroupID,Cus_Name,Cus_Name_py,Cus_Telephone,Ord_OrdersPersonID,Ord_OrdersPerson,Ord_CreateDatetime,PickupStatusCount,Ord_SinceOrderNumber";
- pageData.OrderStr = "ID desc";
- DataSet da = pageData.QueryDataTable();
- dt = da.Tables[0];
- if ( dt.Rows.Count > 0 )
- {
- if ( dtProductList == null )
- {
- dtProductList = OrderProductListbll.GetAllList().Tables[0];
- }
- if ( dtWeddingService == null )
- {
- dtWeddingService = WeddingServicebll.GetAllList().Tables[0];
- }
- if ( dtPlusPickItems == null )
- {
- dtPlusPickItems = PlusPickItemsbll.GetAllList().Tables[0];
- }
- this.Invoke( new UpdateControl( delegate ()
- {
- for ( int t = 0; t < dt.Rows.Count; t++ )
- {
- #region 获取订单
- DataGridViewRow dgvr = new DataGridViewRow();
- DataGridViewCell cell = null;
- //订单号
- cell = new DataGridViewTextBoxCell();
- if ( !string.IsNullOrEmpty( dt.Rows[t]["Ord_SinceOrderNumber"].ToString() ) )
- {
- cell.Value = dt.Rows[t]["Ord_SinceOrderNumber"].ToString();
- }
- else
- {
- cell.Value = dt.Rows[t]["Ord_Number"].ToString();
- }
- dgvr.Cells.Add( cell );
- //姓名
- cell = new DataGridViewTextBoxCell();
- cell.Value = dt.Rows[t]["Cus_Name"].ToString().Trim();
- dgvr.Cells.Add( cell );
- //电话
- cell = new DataGridViewTextBoxCell();
- cell.Value = dt.Rows[t]["Cus_Telephone"].ToString();
- dgvr.Cells.Add( cell );
- //接单人
- cell = new DataGridViewTextBoxCell();
- cell.Value = dt.Rows[t]["Ord_OrdersPerson"].ToString();
- dgvr.Cells.Add( cell );
- // 售价
- decimal SJ = FinancialStatementsbll.GetSellingPrice( dt.Rows[t]["Ord_Number"].ToString(), "", "" );
- cell = new DataGridViewTextBoxCell();
- cell.Value = SJ.ToString( "N2" );
- dgvr.Cells.Add( cell );
- //合计售价
- TotalPrice += SJ;
- // 成本
- decimal CB = FinancialStatementsbll.GetCostsPrice( dt.Rows[t]["Ord_Number"].ToString(), "", "" );
- cell = new DataGridViewTextBoxCell();
- cell.Value = CB.ToString( "N2" );
- dgvr.Cells.Add( cell );
- totalCost += CB;
- //商品名称
- cell = new DataGridViewTextBoxCell();
- DataRow[] dtProductList2 = dtProductList.Select( "OPlist_OrderNumber='" + dt.Rows[t]["Ord_Number"].ToString() + "' and OPlist_Type='2'" );
- if ( dtProductList2.Length > 0 )
- {
- cell.Value = dtProductList2[0]["OPlist_ProdName"].ToString();
- }
- else
- {
- cell.Value = "";
- }
- dgvr.Cells.Add( cell );
- //单价
- cell = new DataGridViewTextBoxCell();
- if ( dtProductList2.Length > 0 )
- {
- cell.Value = dtProductList2[0]["OPlist_CostPrice"].ToString().Trim();
- }
- else
- {
- cell.Value = "";
- }
- dgvr.Cells.Add( cell );
- //数量
- cell = new DataGridViewTextBoxCell();
- if ( dtProductList2.Length > 0 )
- {
- cell.Value = dtProductList2[0]["OPlist_ProdQuantity"].ToString();
- }
- else
- {
- cell.Value = "";
- }
- dgvr.Cells.Add( cell );
- this.dgv.Rows.Add( dgvr );
- #endregion
- #region 获取订单套系商品
- dtProductList2 = dtProductList.Select( "OPlist_OrderNumber='" + dt.Rows[t]["Ord_Number"].ToString() + "' and OPlist_Type='1'" );
- if ( dtProductList2.Length > 0 )
- {
- for ( int t1 = 1; t1 < dtProductList2.Length; t1++ )
- {
- dgvr = new DataGridViewRow();
- cell = null;
- //订单号
- cell = new DataGridViewTextBoxCell();
- cell.Value = "";
- dgvr.Cells.Add( cell );
- //姓名
- cell = new DataGridViewTextBoxCell();
- cell.Value = "";
- dgvr.Cells.Add( cell );
- //电话
- cell = new DataGridViewTextBoxCell();
- cell.Value = "";
- dgvr.Cells.Add( cell );
- //接单人
- cell = new DataGridViewTextBoxCell();
- cell.Value = "";
- dgvr.Cells.Add( cell );
- // 售价
- cell = new DataGridViewTextBoxCell();
- cell.Value = "";
- dgvr.Cells.Add( cell );
- // 成本
- cell = new DataGridViewTextBoxCell();
- cell.Value = "";
- dgvr.Cells.Add( cell );
- //商品名称
- cell = new DataGridViewTextBoxCell();
- cell.Value = dtProductList2[t1]["OPlist_ProdName"].ToString();
- dgvr.Cells.Add( cell );
- //单价
- cell = new DataGridViewTextBoxCell();
- cell.Value = dtProductList2[t1]["OPlist_CostPrice"].ToString();
- dgvr.Cells.Add( cell );
- //数量
- cell = new DataGridViewTextBoxCell();
- cell.Value = dtProductList2[t1]["OPlist_ProdQuantity"].ToString();
- dgvr.Cells.Add( cell );
- this.dgv.Rows.Add( dgvr );
- }
- }
- #endregion
- #region 获取服务商品
- DataRow[] dtWeddingService2 = dtWeddingService.Select( "Ws_Number='" + dt.Rows[t]["Ord_Number"].ToString() + "'" );
- if ( dtWeddingService2.Length > 0 )
- {
- for ( int t2 = 0; t2 < dtWeddingService2.Length; t2++ )
- {
- dgvr = new DataGridViewRow();
- cell = null;
- //订单号
- cell = new DataGridViewTextBoxCell();
- cell.Value = "";
- dgvr.Cells.Add( cell );
- //姓名
- cell = new DataGridViewTextBoxCell();
- cell.Value = "";
- dgvr.Cells.Add( cell );
- //电话
- cell = new DataGridViewTextBoxCell();
- cell.Value = "";
- dgvr.Cells.Add( cell );
- //接单人
- cell = new DataGridViewTextBoxCell();
- cell.Value = "";
- dgvr.Cells.Add( cell );
- // 售价
- cell = new DataGridViewTextBoxCell();
- cell.Value = "";
- dgvr.Cells.Add( cell );
- //成本
- cell = new DataGridViewTextBoxCell();
- cell.Value = "";
- dgvr.Cells.Add( cell );
- //商品名称
- cell = new DataGridViewTextBoxCell();
- cell.Value = dtWeddingService2[t2]["Ws_ProdName"].ToString();
- dgvr.Cells.Add( cell );
- //单价
- cell = new DataGridViewTextBoxCell();
- cell.Value = dtWeddingService2[t2]["Ws_ProdCostPrice"].ToString();
- dgvr.Cells.Add( cell );
- //数量
- cell = new DataGridViewTextBoxCell();
- cell.Value = dtWeddingService2[t2]["Ws_ProdQuantity"].ToString();
- dgvr.Cells.Add( cell );
- this.dgv.Rows.Add( dgvr );
- }
- }
- #endregion
- #region 获取后期收款加挑物品
- DataRow[] dtPlusPickItems2 = dtPlusPickItems.Select( "Plu_OrdNumber='" + dt.Rows[t]["Ord_Number"].ToString() + "'" );
- if ( dtPlusPickItems2.Length > 0 )
- {
- for ( int t3 = 0; t3 < dtPlusPickItems2.Length; t3++ )
- {
- string[] Plu_Goods = dtPlusPickItems2[t3]["Plu_Goods"].ToString().Split( ',' );
- string[] Plu_GoodsCosts = dtPlusPickItems2[t3]["Plu_GoodsCosts"].ToString().Split( ',' );
- for ( int y = 0; y < Plu_Goods.Length; y++ )
- {
- #region
- dgvr = new DataGridViewRow();
- cell = null;
- //订单号
- cell = new DataGridViewTextBoxCell();
- cell.Value = "";
- dgvr.Cells.Add( cell );
- //姓名
- cell = new DataGridViewTextBoxCell();
- cell.Value = "";
- dgvr.Cells.Add( cell );
- //女电话
- cell = new DataGridViewTextBoxCell();
- cell.Value = "";
- dgvr.Cells.Add( cell );
- //接单人
- cell = new DataGridViewTextBoxCell();
- cell.Value = "";
- dgvr.Cells.Add( cell );
- #region 售价
- cell = new DataGridViewTextBoxCell();
- cell.Value = "";
- dgvr.Cells.Add( cell );
- #endregion
- #region 成本
- //获取套系商品
- cell = new DataGridViewTextBoxCell();
- cell.Value = "";
- dgvr.Cells.Add( cell );
- #endregion
- //商品名称
- cell = new DataGridViewTextBoxCell();
- cell.Value = Plu_Goods[y].ToString();
- dgvr.Cells.Add( cell );
- //单价
- cell = new DataGridViewTextBoxCell();
- cell.Value = Convert.ToDecimal( Plu_GoodsCosts[y] ).ToString( "N2" );
- dgvr.Cells.Add( cell );
- //数量
- cell = new DataGridViewTextBoxCell();
- cell.Value = "1";
- dgvr.Cells.Add( cell );
- this.dgv.Rows.Add( dgvr );
- #endregion
- }
- }
- }
- #endregion
- #region 获取订单景点
- if ( dt.Rows[t]["Ord_Type"].ToString().Trim() != "1" )
- {
- DataTable dtPhotography = orbll.GetView_Custom( "tb_ErpOrdersPhotography", StrWhere: "Ordpg_Number = '" + dt.Rows[t]["Ord_Number"].ToString().Trim() + "'", ShowColumnName: "Ordpg_Sights,Ordpg_CostPrice" ).Tables[0];
- if ( dtPhotography.Rows.Count > 0 )
- {
- for ( int i = 0; i < dtPhotography.Rows.Count; i++ )
- {
- dgvr = new DataGridViewRow();
- cell = null;
- //订单号
- cell = new DataGridViewTextBoxCell();
- cell.Value = "";
- dgvr.Cells.Add( cell );
- //姓名
- cell = new DataGridViewTextBoxCell();
- cell.Value = "";
- dgvr.Cells.Add( cell );
- //电话
- cell = new DataGridViewTextBoxCell();
- cell.Value = "";
- dgvr.Cells.Add( cell );
- //接单人
- cell = new DataGridViewTextBoxCell();
- cell.Value = "";
- dgvr.Cells.Add( cell );
- cell = new DataGridViewTextBoxCell();
- cell.Value = "";
- dgvr.Cells.Add( cell );
- //获取套系商品
- cell = new DataGridViewTextBoxCell();
- cell.Value = "";
- dgvr.Cells.Add( cell );
- //商品名称
- cell = new DataGridViewTextBoxCell();
- cell.Value = dtPhotography.Rows[i]["Ordpg_Sights"].ToString();
- dgvr.Cells.Add( cell );
- //单价
- cell = new DataGridViewTextBoxCell();
- cell.Value = dtPhotography.Rows[i]["Ordpg_CostPrice"].ToString();
- dgvr.Cells.Add( cell );
- //数量
- cell = new DataGridViewTextBoxCell();
- cell.Value = "1";
- dgvr.Cells.Add( cell );
- this.dgv.Rows.Add( dgvr );
- }
- }
- }
- #endregion
- }
- #region 合计项目
- //单数
- this.lblSingular.Text = dt.Rows.Count.ToString();
- //总售价
- this.lblTotalPrice.Text = TotalPrice.ToString( "N2" );
- //总成本
- this.lbltotalCost.Text = totalCost.ToString( "N2" );
- //毛利
- this.lblGrossProfit.Text = ( Convert.ToDecimal( this.lblTotalPrice.Text ) - Convert.ToDecimal( this.lbltotalCost.Text ) ).ToString( "N2" );
- //毛利率 ((总售价-总成本)/总售价)*100
- if ( Convert.ToDecimal( this.lblSingular.Text ) == 0 )
- {
- this.lblGrossMargin.Text = "100%";
- }
- else
- {
- if ( Convert.ToDecimal( this.lblTotalPrice.Text ) != Convert.ToDecimal( "0" ) )
- {
- this.lblGrossMargin.Text = ( ( ( Convert.ToDecimal( this.lblTotalPrice.Text ) - Convert.ToDecimal( this.lbltotalCost.Text ) ) / Convert.ToDecimal( this.lblTotalPrice.Text ) ) * 100 ).ToString( "N2" ) + "%";
- }
- else
- {
- this.lblGrossMargin.Text = "0%";
- }
- }
- //平均售价
- if ( Convert.ToDecimal( lblSingular.Text ) == 0 )
- {
- this.lblAverageSellingPrice.Text = "0.00";
- }
- else
- {
- this.lblAverageSellingPrice.Text = ( Convert.ToDecimal( this.lblTotalPrice.Text ) / Convert.ToInt32( this.lblSingular.Text ) ).ToString( "N2" );
- }
- //平均成本
- if ( Convert.ToDecimal( lblSingular.Text ) == 0 )
- {
- this.lblAverageCost.Text = "0.00";
- }
- else
- {
- this.lblAverageCost.Text = ( Convert.ToDecimal( this.lbltotalCost.Text ) / Convert.ToInt32( this.lblSingular.Text ) ).ToString( "N2" );
- }
- //平均毛利
- if ( Convert.ToDecimal( lblSingular.Text ) == 0 )
- {
- this.lblAverageGrossProfit.Text = "0.00";
- }
- else
- {
- this.lblAverageGrossProfit.Text = ( Convert.ToDecimal( this.lblGrossProfit.Text ) / Convert.ToInt32( this.lblSingular.Text ) ).ToString( "N2" );
- }
- #endregion
- } ) );
- }
- } );
- try
- {
- dgv.ClearSelection();
- this.ucPagerEx1.TbDataSource = dt;
- }
- catch
- {
- }
- return pageData.TotalCount;
- }
- }
- }
|