FrmCosting.cs 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086
  1. using LYFZ.Software.MainBusiness.DoorCityProcess;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Windows.Forms;
  8. namespace LYFZ.Software.MainBusiness.StatisticalInquiry
  9. {
  10. public partial class FrmCosting : LYFZ.Software.UI.StatisticalInquiry.FrmCosting
  11. {
  12. private delegate void UpdateControl();
  13. public FrmCosting()
  14. {
  15. this.ucPagerEx1.EventPaging += ucPagerEx1_EventPaging;
  16. this.cmbtreevStoreName.ComboBoxTree_NodeMouseClick += CmbtreevStoreName_ComboBoxTree_NodeMouseClick;
  17. // 获取分店信息;
  18. LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.BindGroupStoreName( this.cmbtreevStoreName, StrGroupKeyCode: "retailProcess", StrKeyCode: "st013" );
  19. #region 新版本成本核算;
  20. // 初始化DataGridView;
  21. InitDataGridViewColumns( _listShowColumns, _listHideColumns );
  22. // checkbox;
  23. this.cb_pickup.CheckedChanged += Cb_pickup_CheckedChanged;
  24. // datagridview双击;
  25. this.dgv.CellDoubleClick += Dgv_CellDoubleClick;
  26. #endregion
  27. }
  28. private void Dgv_CellDoubleClick( object sender, DataGridViewCellEventArgs e )
  29. {
  30. // 参数校验;
  31. if ( e.RowIndex < 0 || e.RowIndex == this.dgv.RowCount )
  32. return;
  33. // 订单号;
  34. FrmCostDetail frmCostDetail = new FrmCostDetail( this.dgv.Rows[e.RowIndex], this._dataTable.Rows[e.RowIndex]["订单类型"].ToString() == "1" );
  35. frmCostDetail.ShowDialog();
  36. }
  37. private void Cb_pickup_CheckedChanged( object sender, EventArgs e )
  38. {
  39. this.PublicFunctionRows();
  40. }
  41. private void CmbtreevStoreName_ComboBoxTree_NodeMouseClick( object sender, TreeNodeMouseClickEventArgs e )
  42. {
  43. this.PublicFunctionRows();
  44. }
  45. /// <summary>
  46. /// 加载
  47. /// </summary>
  48. /// <param name="sender"></param>
  49. /// <param name="e"></param>
  50. protected override void FrmCosting_Shown( object sender, EventArgs e )
  51. {
  52. txtTimeStart.Text = SDateTime.Now.ToString( "yyyy-MM-dd" );
  53. txtTimeEnd.Text = Convert.ToDateTime( SDateTime.Now ).AddMonths( 1 ).AddSeconds( -1 ).ToString( "yyyy-MM-dd" );
  54. LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.BindComboBoxTreeView_DepartmentAndEmployee( this.txtTsorder_OpenSingle, IsFirstNodeNull: true );
  55. //绑定数据
  56. Bind();
  57. //导出
  58. btnExPort.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights( LYFZ.BLL.BLL_ErpUser.CurrentUserRights.CostingCompetence, CustomAttributes.OperatingAuthority.DataExport );
  59. ///控制统计查询成本核算的版本权
  60. //LYFZSS.SystemSpecterPossessed.ISystemSpecterPossessed.GetMySystemSpecter = LYFZSS.SystemSpecterType.SST_C;
  61. bool b = LYFZ.Software.MainBusiness.VersionControl.StaticVersion.UIFunctionVersion( VersionControl.VersionFunctionEnum.统计查询成本核算 );
  62. if ( !b )
  63. {
  64. btnClose_Click( null, null );
  65. }
  66. }
  67. /// <summary>
  68. /// 人员选择事件
  69. /// </summary>
  70. /// <param name="sender"></param>
  71. /// <param name="e"></param>
  72. protected override void txtTsorder_OpenSingle_ComboBoxTreeViewEx_TextChanged( object sender, TreeViewEventArgs e )
  73. {
  74. Bind();
  75. }
  76. /// <summary>
  77. /// 时间查询
  78. /// </summary>
  79. /// <param name="sender"></param>
  80. /// <param name="e"></param>
  81. protected override void btnSelect_Click( object sender, EventArgs e )
  82. {
  83. if ( string.IsNullOrEmpty( txtTimeStart.DateValue ) )
  84. {
  85. MessageBoxCustom.Show( "开始时间不能为空!" );
  86. return;
  87. }
  88. if ( string.IsNullOrEmpty( txtTimeEnd.DateValue ) )
  89. {
  90. MessageBoxCustom.Show( "结束时间不能为空!" );
  91. return;
  92. }
  93. //绑定数据
  94. Bind();
  95. }
  96. /// <summary>
  97. /// 导出
  98. /// </summary>
  99. /// <param name="sender"></param>
  100. /// <param name="e"></param>
  101. protected override void btnExPort_Click( object sender, EventArgs e )
  102. {
  103. dgv.ExportDataTable();
  104. }
  105. /// <summary>
  106. /// 关闭
  107. /// </summary>
  108. /// <param name="sender"></param>
  109. /// <param name="e"></param>
  110. protected override void btnClose_Click( object sender, EventArgs e )
  111. {
  112. this.Close();
  113. }
  114. /// <summary>
  115. /// 时间控件
  116. /// </summary>
  117. /// <param name="sender"></param>
  118. /// <param name="e"></param>
  119. protected override void txtTimeStart_Leave( object sender, EventArgs e )
  120. {
  121. if ( string.IsNullOrEmpty( this.txtTimeStart.DateValue ) )
  122. {
  123. MessageBoxCustom.Show( "开始时间格式输入错误" );
  124. txtTimeStart.DateValue = SDateTime.Now.ToString( "yyyy-MM" ) + "-01";
  125. }
  126. }
  127. /// <summary>
  128. ///
  129. /// </summary>
  130. /// <param name="sender"></param>
  131. /// <param name="e"></param>
  132. protected override void txtTimeStart_Enter( object sender, EventArgs e )
  133. {
  134. if ( string.IsNullOrEmpty( this.txtTimeStart.DateValue ) )
  135. {
  136. txtTimeStart.DateValue = SDateTime.Now.ToString( "yyyy-MM" ) + "-01";
  137. }
  138. }
  139. /// <summary>
  140. ///
  141. /// </summary>
  142. /// <param name="sender"></param>
  143. /// <param name="e"></param>
  144. protected override void txtTimeEnd_Leave( object sender, EventArgs e )
  145. {
  146. if ( string.IsNullOrEmpty( this.txtTimeEnd.DateValue ) )
  147. {
  148. MessageBoxCustom.Show( "结束时间格式输入错误" );
  149. txtTimeEnd.DateValue = Convert.ToDateTime( Convert.ToDateTime( SDateTime.Now.ToString( "yyyy-MM" ) + "-01" ).AddMonths( 1 ).AddSeconds( -1 ) ).ToString( "yyyy-MM-dd" );
  150. }
  151. }
  152. /// <summary>
  153. ///
  154. /// </summary>
  155. /// <param name="sender"></param>
  156. /// <param name="e"></param>
  157. protected override void txtTimeEnd_Enter( object sender, EventArgs e )
  158. {
  159. if ( string.IsNullOrEmpty( this.txtTimeEnd.DateValue ) )
  160. {
  161. txtTimeEnd.DateValue = Convert.ToDateTime( Convert.ToDateTime( SDateTime.Now.ToString( "yyyy-MM" ) + "-01" ).AddMonths( 1 ).AddSeconds( -1 ) ).ToString( "yyyy-MM-dd" );
  162. }
  163. }
  164. LYFZ.BLL.BLL_FinancialStatements FinancialStatementsbll = new BLL.BLL_FinancialStatements();
  165. LYFZ.BLL.BLL_ErpOrderProductList OrderProductListbll = new BLL.BLL_ErpOrderProductList();
  166. LYFZ.BLL.BLL_ErpWeddingService WeddingServicebll = new BLL.BLL_ErpWeddingService();
  167. LYFZ.BLL.BLL_ErpPlusPickItems PlusPickItemsbll = new BLL.BLL_ErpPlusPickItems();
  168. LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder();
  169. void PublicFunctionRows()
  170. {
  171. PublicFunctionRowsEx();
  172. return;
  173. this.dgv.Rows.Clear();
  174. string StrWhere = "Ord_Class = '1'";
  175. if ( !string.IsNullOrEmpty( this.txtOrd_Number.Text.Trim() ) )
  176. {
  177. 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() + "%')";
  178. }
  179. else
  180. {
  181. StrWhere += PublicCodeClasses.GetDateTime( "订单时间", txtTimeStart.Text, txtTimeEnd.Text );
  182. }
  183. if ( !string.IsNullOrEmpty( txtTsorder_OpenSingle.Text.Trim() ) )
  184. {
  185. StrWhere += " And 接单人编号 like '%" + txtTsorder_OpenSingle.Tag.ToString().Trim() + "%' ";
  186. }
  187. StrWhere += LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetGroupQueryWhere( this.cmbtreevStoreName, "Ord_DividedShop" );
  188. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod( delegate ( object obj, BackgroundWorker backgroundWorker )
  189. {
  190. backgroundWorker.ReportProgress( 0, "正在获取数据 ..." );
  191. string StrTableName = "( " +
  192. "select Ord_Number,Ord_SinceOrderNumber,Ord_Class,Ord_DividedShop,Cus_Name AS 客户姓名,Cus_Name_py AS 客户拼音,Cus_Telephone AS 客户电话," +
  193. "case when Ord_SinceOrderNumber <> '' then Ord_SinceOrderNumber else Ord_Number end AS 订单号,Ord_CreateDatetime AS 订单时间," +
  194. "(Ord_SeriesPrice+ " +
  195. "case when (select Count(ID) AS CountID from tb_ErpPlusPickItems where Plu_OrdNumber = Ord_Number) > 0 then " +
  196. " 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 " +
  197. " else 0 end) AS 套系价格, " +
  198. "(select stuff((select ',' + OrdPe_OrdersPerson from tb_ErpOrdersPerson where OrdPe_OrderNumber = Ord_Number for xml path('')),1,1,'')) as 接单人编号, " +
  199. "(select stuff((select ',' + dbo.fn_CheckUserIDGetUserName(OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber = Ord_Number for xml path('')),1,1,'')) as 接单人, " +
  200. "(isnull((select sum(OPlist_CostPrice * OPlist_ProdQuantity) from tb_ErpOrderProductList where OPlist_Type = '1' And OPlist_OrderNumber = Ord_Number),0) + " +
  201. "isnull((select sum(Ws_ProdCostPrice * Ws_ProdQuantity) from tb_ErpWeddingService where Ws_Number = Ord_Number),0) + " +
  202. "isnull((select sum(Ordpg_CostPrice) from tb_ErpOrdersPhotography where Ordpg_Number = Ord_Number),0) + " +
  203. "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 套系成本 " +
  204. "from tb_ErpOrder Left Join tempTB_AggregationCustomer on Ord_Number = GP_OrderNumber " +
  205. ") as tb ";
  206. string StrColumnName = "Ord_Number,订单号,客户姓名,客户电话,接单人,套系价格,套系成本";
  207. DataTable dt = orbll.GetView_Custom( StrTableName, StrWhere: StrWhere, ShowColumnName: StrColumnName ).Tables[0];
  208. if ( dt.Rows.Count > 0 )
  209. {
  210. string StrWhere2 = "";
  211. for ( int i = 0; i < dt.Rows.Count; i++ )
  212. {
  213. StrWhere2 += "'" + dt.Rows[i]["Ord_Number"].ToString().Trim() + "',";
  214. }
  215. 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( ',' ) + ") " +
  216. "UNION ALL " +
  217. "select Ws_Number AS 订单号,Ws_ProdName AS 商品名称,Ws_ProdCostPrice AS 商品单价,Ws_ProdQuantity AS 商品数量 from tb_ErpWeddingService where Ws_Number in (" + StrWhere2.TrimEnd( ',' ) + ") " +
  218. "UNION ALL " +
  219. "select Ordpg_Number AS 订单号,Ordpg_Sights AS 商品名称,Ordpg_CostPrice AS 商品单价,1 AS 商品数量 from tb_ErpOrdersPhotography where Ordpg_Number in (" + StrWhere2.TrimEnd( ',' ) + ") ";
  220. DataTable tbl = orbll.GetView_Custom( StrTableName2 ).Tables[0];
  221. DataTable tblPlus = orbll.GetView_Custom( "tb_ErpPlusPickItems", StrWhere: "Plu_OrdNumber in (" + StrWhere2.TrimEnd( ',' ) + ")", ShowColumnName: "Plu_OrdNumber,Plu_Goods,Plu_GoodsCosts" ).Tables[0];
  222. backgroundWorker.ReportProgress( 0, "正在绑定数据 ..." );
  223. for ( int i = 0; i < tblPlus.Rows.Count; i++ )
  224. {
  225. try
  226. {
  227. string[] StrArray1 = tblPlus.Rows[i]["Plu_Goods"].ToString().Trim().Split( ',' );
  228. string[] StrArray2 = tblPlus.Rows[i]["Plu_GoodsCosts"].ToString().Trim().Split( ',' );
  229. for ( int j = 0; j < StrArray1.Length; j++ )
  230. {
  231. DataRow newRow = tbl.NewRow();
  232. newRow["订单号"] = tblPlus.Rows[i]["Plu_OrdNumber"].ToString().Trim();
  233. newRow["商品名称"] = StrArray1[j].ToString().Trim();
  234. if ( j < StrArray2.Length )
  235. {
  236. newRow["商品单价"] = StrArray2[j].ToString().Trim();
  237. }
  238. else
  239. {
  240. newRow["商品单价"] = "0";
  241. }
  242. newRow["商品数量"] = 1;
  243. tbl.Rows.Add( newRow );
  244. }
  245. }
  246. catch { }
  247. }
  248. try
  249. {
  250. this.Invoke( new UpdateControl( delegate ()
  251. {
  252. #region 绑定订单
  253. //总售价
  254. decimal TotalPrice = 0;
  255. //总成本
  256. decimal TotalCost = 0;
  257. for ( int i = 0; i < dt.Rows.Count; i++ )
  258. {
  259. DataRow[] dtRows = tbl.Select( "订单号 = '" + dt.Rows[i]["Ord_Number"].ToString().Trim() + "'" );
  260. DataGridViewRow dgvr = new DataGridViewRow();
  261. DataGridViewCell cell = null;
  262. cell = new DataGridViewTextBoxCell();
  263. cell.Value = dt.Rows[i]["订单号"].ToString().Trim();
  264. dgvr.Cells.Add( cell );
  265. cell = new DataGridViewTextBoxCell();
  266. cell.Value = dt.Rows[i]["客户姓名"].ToString().Trim();
  267. dgvr.Cells.Add( cell );
  268. cell = new DataGridViewTextBoxCell();
  269. cell.Value = dt.Rows[i]["客户电话"].ToString().Trim();
  270. dgvr.Cells.Add( cell );
  271. cell = new DataGridViewTextBoxCell();
  272. cell.Value = dt.Rows[i]["接单人"].ToString().Trim();
  273. dgvr.Cells.Add( cell );
  274. cell = new DataGridViewTextBoxCell();
  275. cell.Value = dt.Rows[i]["套系价格"].ToString().Trim();
  276. dgvr.Cells.Add( cell );
  277. TotalPrice += Convert.ToDecimal( dt.Rows[i]["套系价格"] );
  278. cell = new DataGridViewTextBoxCell();
  279. cell.Value = dt.Rows[i]["套系成本"].ToString().Trim();
  280. dgvr.Cells.Add( cell );
  281. TotalCost += Convert.ToDecimal( dt.Rows[i]["套系成本"] );
  282. if ( dtRows.Length > 0 )
  283. {
  284. cell = new DataGridViewTextBoxCell();
  285. cell.Value = dtRows[0]["商品名称"].ToString().Trim();
  286. dgvr.Cells.Add( cell );
  287. cell = new DataGridViewTextBoxCell();
  288. cell.Value = dtRows[0]["商品单价"].ToString().Trim();
  289. dgvr.Cells.Add( cell );
  290. cell = new DataGridViewTextBoxCell();
  291. cell.Value = dtRows[0]["商品数量"].ToString().Trim();
  292. dgvr.Cells.Add( cell );
  293. }
  294. else
  295. {
  296. for ( int j = 0; j < 3; j++ )
  297. {
  298. cell = new DataGridViewTextBoxCell();
  299. cell.Value = "";
  300. dgvr.Cells.Add( cell );
  301. }
  302. }
  303. this.dgv.Rows.Add( dgvr );
  304. #region 绑定商品数据
  305. for ( int j = 1; j < dtRows.Length; j++ )
  306. {
  307. dgvr = new DataGridViewRow();
  308. for ( int k = 0; k < 6; k++ )
  309. {
  310. cell = new DataGridViewTextBoxCell();
  311. cell.Value = "";
  312. dgvr.Cells.Add( cell );
  313. }
  314. cell = new DataGridViewTextBoxCell();
  315. cell.Value = dtRows[j]["商品名称"].ToString().Trim();
  316. dgvr.Cells.Add( cell );
  317. cell = new DataGridViewTextBoxCell();
  318. cell.Value = dtRows[j]["商品单价"].ToString().Trim();
  319. dgvr.Cells.Add( cell );
  320. cell = new DataGridViewTextBoxCell();
  321. cell.Value = dtRows[j]["商品数量"].ToString().Trim();
  322. dgvr.Cells.Add( cell );
  323. this.dgv.Rows.Add( dgvr );
  324. }
  325. #endregion
  326. }
  327. #endregion
  328. #region 合计项目
  329. //单数
  330. this.lblSingular.Text = dt.Rows.Count.ToString();
  331. //总售价
  332. this.lblTotalPrice.Text = TotalPrice.ToString( "N2" );
  333. //总成本
  334. this.lbltotalCost.Text = TotalCost.ToString( "N2" );
  335. //毛利
  336. this.lblGrossProfit.Text = ( Convert.ToDecimal( this.lblTotalPrice.Text ) - Convert.ToDecimal( this.lbltotalCost.Text ) ).ToString( "N2" );
  337. //毛利率 ((总售价-总成本)/总售价)*100
  338. if ( Convert.ToDecimal( this.lblSingular.Text ) == 0 )
  339. {
  340. this.lblGrossMargin.Text = "100%";
  341. }
  342. else
  343. {
  344. if ( Convert.ToDecimal( this.lblTotalPrice.Text ) != Convert.ToDecimal( "0" ) )
  345. {
  346. this.lblGrossMargin.Text = ( ( ( Convert.ToDecimal( this.lblTotalPrice.Text ) - Convert.ToDecimal( this.lbltotalCost.Text ) ) / Convert.ToDecimal( this.lblTotalPrice.Text ) ) * 100 ).ToString( "N2" ) + "%";
  347. }
  348. else
  349. {
  350. this.lblGrossMargin.Text = "0%";
  351. }
  352. }
  353. //平均售价
  354. if ( Convert.ToDecimal( lblSingular.Text ) == 0 )
  355. {
  356. this.lblAverageSellingPrice.Text = "0.00";
  357. }
  358. else
  359. {
  360. this.lblAverageSellingPrice.Text = ( Convert.ToDecimal( this.lblTotalPrice.Text ) / Convert.ToInt32( this.lblSingular.Text ) ).ToString( "N2" );
  361. }
  362. //平均成本
  363. if ( Convert.ToDecimal( lblSingular.Text ) == 0 )
  364. {
  365. this.lblAverageCost.Text = "0.00";
  366. }
  367. else
  368. {
  369. this.lblAverageCost.Text = ( Convert.ToDecimal( this.lbltotalCost.Text ) / Convert.ToInt32( this.lblSingular.Text ) ).ToString( "N2" );
  370. }
  371. //平均毛利
  372. if ( Convert.ToDecimal( lblSingular.Text ) == 0 )
  373. {
  374. this.lblAverageGrossProfit.Text = "0.00";
  375. }
  376. else
  377. {
  378. this.lblAverageGrossProfit.Text = ( Convert.ToDecimal( this.lblGrossProfit.Text ) / Convert.ToInt32( this.lblSingular.Text ) ).ToString( "N2" );
  379. }
  380. #endregion
  381. } ) );
  382. }
  383. catch ( Exception e )
  384. {
  385. }
  386. }
  387. } );
  388. }
  389. #region 新版本成本核算;
  390. IEnumerable<DataRow> _rows = null;
  391. DataTable _dataTable = null;
  392. string _listNullColumn = "订单号, 接单人, 顾客姓名, 顾客电话, 套系名称, 套系价格";
  393. string _listShowColumns = "订单号, 接单人, 顾客姓名, 顾客电话, 套系名称, 套系价格, 拍摄景点, 商品成本, 服务成本, 景点成本, 加挑总价, 加挑成本";
  394. string _listHideColumns = "自定义单号,订单类型,订单类别,订单日期,分店编号,顾客拼音,取件状态,取件时间";
  395. void PublicFunctionRowsEx()
  396. {
  397. _dataTable = null;
  398. this.dgv.Rows.Clear();
  399. this.lblSingular.Text = "0";
  400. this.lblTotalPrice.Text = "0";
  401. this.lbltotalCost.Text = "0";
  402. this.lblGrossProfit.Text = "0";
  403. this.lblGrossMargin.Text = "0%";
  404. this.lblAverageSellingPrice.Text = "0.00";
  405. this.lblAverageGrossProfit.Text = "0.00";
  406. LYFZ.DAL.CostAccounting costAccounting = new DAL.CostAccounting();
  407. // 获取分店编号;
  408. string branchId = null;
  409. if ( LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.IsGroupEdition )
  410. branchId = this.cmbtreevStoreName.Tag.ToString().Trim();
  411. string clerkId = null;
  412. if ( !string.IsNullOrEmpty( txtTsorder_OpenSingle.Text.Trim() ) )
  413. clerkId = txtTsorder_OpenSingle.Tag.ToString().Trim();
  414. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod( delegate ( object obj, BackgroundWorker backgroundWorker )
  415. {
  416. backgroundWorker.ReportProgress( 0, "正在获取数据 ..." );
  417. // 获取成本核算数据集;
  418. _dataTable = costAccounting.GetCostAccountingEx( this.cb_pickup.Checked, txtTimeStart.Value, txtTimeEnd.Value, branchId, clerkId, txtOrd_Number.Text );
  419. } );
  420. if ( _dataTable == null )
  421. return;
  422. _rows = from pp in _dataTable.AsEnumerable() select pp;
  423. this.dgv.RowCount = _dataTable.Rows.Count;
  424. // 订单总数;
  425. int nOrderCount = _rows.GroupBy( e => e.Field<string>( "订单号" ) ).Count();
  426. // 订单总售价;
  427. decimal TotalPrice = _rows.Select( e => e.Field<decimal>( "套系价格" ) ).Sum() +
  428. _rows.Select( e => e.Field<decimal>( "加挑总价" ) ).Sum();
  429. // 订单总成本;
  430. decimal TotalCost = _rows.Select( e => e.Field<decimal>( "商品成本" ) ).Sum() +
  431. _rows.Select( e => e.Field<decimal>( "服务成本" ) ).Sum() +
  432. _rows.Select( e => e.Field<decimal>( "景点成本" ) ).Sum() +
  433. _rows.Select( e => e.Field<decimal>( "加挑成本" ) ).Sum();
  434. #region 合计项目
  435. //单数;
  436. this.lblSingular.Text = nOrderCount.ToString();
  437. //总售价;
  438. this.lblTotalPrice.Text = TotalPrice.ToString( "N2" );
  439. //总成本;
  440. this.lbltotalCost.Text = TotalCost.ToString( "N2" );
  441. //毛利;
  442. this.lblGrossProfit.Text = ( TotalPrice - TotalCost ).ToString( "N2" );
  443. //毛利率 ((总售价-总成本)/总售价)*100;
  444. if ( nOrderCount == 0 )
  445. {
  446. this.lblGrossMargin.Text = "100%";
  447. }
  448. else
  449. {
  450. if ( TotalPrice != Convert.ToDecimal( "0" ) )
  451. this.lblGrossMargin.Text = ( ( ( TotalPrice - TotalCost ) / TotalPrice ) * 100 ).ToString( "N2" ) + "%";
  452. else
  453. this.lblGrossMargin.Text = "0%";
  454. }
  455. //平均售价;
  456. if ( nOrderCount == 0 )
  457. this.lblAverageSellingPrice.Text = "0.00";
  458. else
  459. this.lblAverageSellingPrice.Text = ( TotalPrice / nOrderCount ).ToString( "N2" );
  460. //平均成本;
  461. if ( nOrderCount == 0 )
  462. this.lblAverageCost.Text = "0.00";
  463. else
  464. this.lblAverageCost.Text = ( TotalCost / nOrderCount ).ToString( "N2" );
  465. //平均毛利;
  466. if ( nOrderCount == 0 )
  467. this.lblAverageGrossProfit.Text = "0.00";
  468. else
  469. this.lblAverageGrossProfit.Text = ( ( TotalPrice - TotalCost ) / nOrderCount ).ToString( "N2" );
  470. #endregion
  471. }
  472. /// <summary>
  473. /// 初始化DataGridView列;
  474. /// </summary>
  475. void InitDataGridViewColumns( string strColumns /*逗号分隔*/, string strHideFields = ""/*逗号分隔*/, bool IsSortMode = false )
  476. {
  477. DataGridViewTextBoxColumn column = null;
  478. if ( !string.IsNullOrEmpty( strColumns ) )
  479. {
  480. // 有必须的话, 清空之前的列头信息;
  481. this.dgv.Rows.Clear();
  482. this.dgv.Columns.Clear();
  483. List<string> listColumns = strColumns.Split( ',' ).ToList();
  484. List<string> listHideFields = strHideFields.Split( ',' ).ToList();
  485. for ( int i = 0; i < listColumns.Count; i++ )
  486. {
  487. column = new DataGridViewTextBoxColumn();
  488. column.ReadOnly = true;
  489. column.Name = listColumns[i].Trim();
  490. column.HeaderText = listColumns[i].Trim();
  491. // 是否有隐藏列;
  492. if ( listHideFields.Contains( listColumns[i].Trim() ) )
  493. column.Visible = false;
  494. // 是否排序;
  495. if ( IsSortMode )
  496. column.SortMode = DataGridViewColumnSortMode.Automatic;
  497. this.dgv.Columns.Add( column );
  498. }
  499. this.dgv.ColumnHeadersHeight = 25;
  500. this.dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  501. }
  502. // 虚拟模式显示数据;
  503. this.dgv.VirtualMode = true;
  504. this.dgv.CellValueNeeded += Dgv_CellValueNeeded;
  505. }
  506. private void Dgv_CellValueNeeded( object sender, DataGridViewCellValueEventArgs e )
  507. {
  508. // 参数校验;
  509. if ( _dataTable == null || 0 == _dataTable.Rows.Count || e.RowIndex == _dataTable.Rows.Count )
  510. return;
  511. // 当前行;
  512. DataGridViewRow dgrCurrent = this.dgv.Rows[e.RowIndex];
  513. if ( e.RowIndex != 0 && _dataTable.Rows[e.RowIndex]["订单号"].Equals( _dataTable.Rows[e.RowIndex - 1]["订单号"] ) )
  514. {// 同一订单的;
  515. // 上一行颜色;
  516. DataGridViewRow dgrLast = this.dgv.Rows[e.RowIndex - 1];
  517. dgrCurrent.Tag = dgrLast.Tag;
  518. if ( dgrCurrent.DefaultCellStyle.BackColor != dgrLast.DefaultCellStyle.BackColor )
  519. dgrCurrent.DefaultCellStyle.BackColor = dgrLast.DefaultCellStyle.BackColor;
  520. // 如果是不显示的列字段, 退出;
  521. if ( _listNullColumn.Contains( this.dgv.Columns[e.ColumnIndex].Name.Trim() ) )
  522. return;
  523. if ( this.dgv.Columns[e.ColumnIndex].Name.Trim() != "StrIsAddColumnsNull" )
  524. e.Value = _dataTable.Rows[e.RowIndex][this.dgv.Columns[e.ColumnIndex].Name.Trim()].ToString();
  525. }
  526. else
  527. {// 下一订单的;
  528. dgrCurrent.Tag = _dataTable.Rows[e.RowIndex]["订单号"];
  529. if ( this.dgv.Columns[e.ColumnIndex].Name.Trim() != "StrIsAddColumnsNull" )
  530. e.Value = _dataTable.Rows[e.RowIndex][this.dgv.Columns[e.ColumnIndex].Name.Trim()].ToString();
  531. // 订单行是否更色;
  532. if ( e.RowIndex != 0 )
  533. {// 非第一行;
  534. DataGridViewRow dgrLast = this.dgv.Rows[e.RowIndex - 1];
  535. if ( dgrLast.DefaultCellStyle.BackColor == System.Drawing.Color.PowderBlue )
  536. dgrCurrent.DefaultCellStyle.BackColor = System.Drawing.Color.PapayaWhip;
  537. else
  538. dgrCurrent.DefaultCellStyle.BackColor = System.Drawing.Color.PowderBlue;
  539. }
  540. else
  541. {// 第一行时;
  542. dgrCurrent.DefaultCellStyle.BackColor = System.Drawing.Color.PowderBlue;
  543. }
  544. }
  545. }
  546. #endregion
  547. DataTable dtProductList = null;
  548. DataTable dtWeddingService = null;
  549. DataTable dtPlusPickItems = null;
  550. /// <summary>
  551. /// 绑定数据
  552. /// </summary>
  553. public void Bind()
  554. {
  555. PublicFunctionRows();
  556. //this.ucPagerEx1.PageCurrent = 1;
  557. //this.ucPagerEx1.PageSize = 200;
  558. //this.ucPagerEx1.Bind();
  559. }
  560. /// <summary>
  561. /// 画分页
  562. /// </summary>
  563. /// <param name="e"></param>
  564. /// <returns></returns>
  565. private int ucPagerEx1_EventPaging( UCPager.EventPagingArg e )
  566. {
  567. //总售价
  568. decimal TotalPrice = 0;
  569. //总成本
  570. decimal totalCost = 0;
  571. LYFZ.UCPager.PageData pageData = new LYFZ.UCPager.PageData();
  572. this.dgv.Rows.Clear();
  573. DataTable dt = new DataTable();
  574. string StrWhere = "";
  575. #region 查询条件
  576. if ( txtTsorder_OpenSingle.Text.Trim() == "" )
  577. {
  578. if ( string.IsNullOrEmpty( txtOrd_Number.Text.Trim() ) )
  579. {
  580. StrWhere = " ord_class='1' " + PublicCodeClasses.GetDateTime( "Ord_CreateDatetime", txtTimeStart.Text, txtTimeEnd.Text );
  581. }
  582. else
  583. {
  584. 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 + "%')";
  585. }
  586. }
  587. else
  588. {
  589. if ( string.IsNullOrEmpty( txtOrd_Number.Text.Trim() ) )
  590. {
  591. StrWhere = " ord_class='1' and Ord_OrdersPersonID like '%" + txtTsorder_OpenSingle.Tag.ToString() + "%' " + PublicCodeClasses.GetDateTime( "Ord_CreateDatetime", txtTimeStart.Text, txtTimeEnd.Text );
  592. }
  593. else
  594. {
  595. 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 );
  596. }
  597. }
  598. #endregion
  599. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod( delegate ( object obj, BackgroundWorker backgroundWorker )
  600. {
  601. pageData.TableName = "Vw_Customer_PaymentOrders";
  602. pageData.PageIndex = this.ucPagerEx1.PageCurrent;
  603. pageData.PageSize = this.ucPagerEx1.PageSize;
  604. pageData.QueryCondition = StrWhere.ToString();
  605. 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";
  606. pageData.OrderStr = "ID desc";
  607. DataSet da = pageData.QueryDataTable();
  608. dt = da.Tables[0];
  609. if ( dt.Rows.Count > 0 )
  610. {
  611. if ( dtProductList == null )
  612. {
  613. dtProductList = OrderProductListbll.GetAllList().Tables[0];
  614. }
  615. if ( dtWeddingService == null )
  616. {
  617. dtWeddingService = WeddingServicebll.GetAllList().Tables[0];
  618. }
  619. if ( dtPlusPickItems == null )
  620. {
  621. dtPlusPickItems = PlusPickItemsbll.GetAllList().Tables[0];
  622. }
  623. this.Invoke( new UpdateControl( delegate ()
  624. {
  625. for ( int t = 0; t < dt.Rows.Count; t++ )
  626. {
  627. #region 获取订单
  628. DataGridViewRow dgvr = new DataGridViewRow();
  629. DataGridViewCell cell = null;
  630. //订单号
  631. cell = new DataGridViewTextBoxCell();
  632. if ( !string.IsNullOrEmpty( dt.Rows[t]["Ord_SinceOrderNumber"].ToString() ) )
  633. {
  634. cell.Value = dt.Rows[t]["Ord_SinceOrderNumber"].ToString();
  635. }
  636. else
  637. {
  638. cell.Value = dt.Rows[t]["Ord_Number"].ToString();
  639. }
  640. dgvr.Cells.Add( cell );
  641. //姓名
  642. cell = new DataGridViewTextBoxCell();
  643. cell.Value = dt.Rows[t]["Cus_Name"].ToString().Trim();
  644. dgvr.Cells.Add( cell );
  645. //电话
  646. cell = new DataGridViewTextBoxCell();
  647. cell.Value = dt.Rows[t]["Cus_Telephone"].ToString();
  648. dgvr.Cells.Add( cell );
  649. //接单人
  650. cell = new DataGridViewTextBoxCell();
  651. cell.Value = dt.Rows[t]["Ord_OrdersPerson"].ToString();
  652. dgvr.Cells.Add( cell );
  653. // 售价
  654. decimal SJ = FinancialStatementsbll.GetSellingPrice( dt.Rows[t]["Ord_Number"].ToString(), "", "" );
  655. cell = new DataGridViewTextBoxCell();
  656. cell.Value = SJ.ToString( "N2" );
  657. dgvr.Cells.Add( cell );
  658. //合计售价
  659. TotalPrice += SJ;
  660. // 成本
  661. decimal CB = FinancialStatementsbll.GetCostsPrice( dt.Rows[t]["Ord_Number"].ToString(), "", "" );
  662. cell = new DataGridViewTextBoxCell();
  663. cell.Value = CB.ToString( "N2" );
  664. dgvr.Cells.Add( cell );
  665. totalCost += CB;
  666. //商品名称
  667. cell = new DataGridViewTextBoxCell();
  668. DataRow[] dtProductList2 = dtProductList.Select( "OPlist_OrderNumber='" + dt.Rows[t]["Ord_Number"].ToString() + "' and OPlist_Type='2'" );
  669. if ( dtProductList2.Length > 0 )
  670. {
  671. cell.Value = dtProductList2[0]["OPlist_ProdName"].ToString();
  672. }
  673. else
  674. {
  675. cell.Value = "";
  676. }
  677. dgvr.Cells.Add( cell );
  678. //单价
  679. cell = new DataGridViewTextBoxCell();
  680. if ( dtProductList2.Length > 0 )
  681. {
  682. cell.Value = dtProductList2[0]["OPlist_CostPrice"].ToString().Trim();
  683. }
  684. else
  685. {
  686. cell.Value = "";
  687. }
  688. dgvr.Cells.Add( cell );
  689. //数量
  690. cell = new DataGridViewTextBoxCell();
  691. if ( dtProductList2.Length > 0 )
  692. {
  693. cell.Value = dtProductList2[0]["OPlist_ProdQuantity"].ToString();
  694. }
  695. else
  696. {
  697. cell.Value = "";
  698. }
  699. dgvr.Cells.Add( cell );
  700. this.dgv.Rows.Add( dgvr );
  701. #endregion
  702. #region 获取订单套系商品
  703. dtProductList2 = dtProductList.Select( "OPlist_OrderNumber='" + dt.Rows[t]["Ord_Number"].ToString() + "' and OPlist_Type='1'" );
  704. if ( dtProductList2.Length > 0 )
  705. {
  706. for ( int t1 = 1; t1 < dtProductList2.Length; t1++ )
  707. {
  708. dgvr = new DataGridViewRow();
  709. cell = null;
  710. //订单号
  711. cell = new DataGridViewTextBoxCell();
  712. cell.Value = "";
  713. dgvr.Cells.Add( cell );
  714. //姓名
  715. cell = new DataGridViewTextBoxCell();
  716. cell.Value = "";
  717. dgvr.Cells.Add( cell );
  718. //电话
  719. cell = new DataGridViewTextBoxCell();
  720. cell.Value = "";
  721. dgvr.Cells.Add( cell );
  722. //接单人
  723. cell = new DataGridViewTextBoxCell();
  724. cell.Value = "";
  725. dgvr.Cells.Add( cell );
  726. // 售价
  727. cell = new DataGridViewTextBoxCell();
  728. cell.Value = "";
  729. dgvr.Cells.Add( cell );
  730. // 成本
  731. cell = new DataGridViewTextBoxCell();
  732. cell.Value = "";
  733. dgvr.Cells.Add( cell );
  734. //商品名称
  735. cell = new DataGridViewTextBoxCell();
  736. cell.Value = dtProductList2[t1]["OPlist_ProdName"].ToString();
  737. dgvr.Cells.Add( cell );
  738. //单价
  739. cell = new DataGridViewTextBoxCell();
  740. cell.Value = dtProductList2[t1]["OPlist_CostPrice"].ToString();
  741. dgvr.Cells.Add( cell );
  742. //数量
  743. cell = new DataGridViewTextBoxCell();
  744. cell.Value = dtProductList2[t1]["OPlist_ProdQuantity"].ToString();
  745. dgvr.Cells.Add( cell );
  746. this.dgv.Rows.Add( dgvr );
  747. }
  748. }
  749. #endregion
  750. #region 获取服务商品
  751. DataRow[] dtWeddingService2 = dtWeddingService.Select( "Ws_Number='" + dt.Rows[t]["Ord_Number"].ToString() + "'" );
  752. if ( dtWeddingService2.Length > 0 )
  753. {
  754. for ( int t2 = 0; t2 < dtWeddingService2.Length; t2++ )
  755. {
  756. dgvr = new DataGridViewRow();
  757. cell = null;
  758. //订单号
  759. cell = new DataGridViewTextBoxCell();
  760. cell.Value = "";
  761. dgvr.Cells.Add( cell );
  762. //姓名
  763. cell = new DataGridViewTextBoxCell();
  764. cell.Value = "";
  765. dgvr.Cells.Add( cell );
  766. //电话
  767. cell = new DataGridViewTextBoxCell();
  768. cell.Value = "";
  769. dgvr.Cells.Add( cell );
  770. //接单人
  771. cell = new DataGridViewTextBoxCell();
  772. cell.Value = "";
  773. dgvr.Cells.Add( cell );
  774. // 售价
  775. cell = new DataGridViewTextBoxCell();
  776. cell.Value = "";
  777. dgvr.Cells.Add( cell );
  778. //成本
  779. cell = new DataGridViewTextBoxCell();
  780. cell.Value = "";
  781. dgvr.Cells.Add( cell );
  782. //商品名称
  783. cell = new DataGridViewTextBoxCell();
  784. cell.Value = dtWeddingService2[t2]["Ws_ProdName"].ToString();
  785. dgvr.Cells.Add( cell );
  786. //单价
  787. cell = new DataGridViewTextBoxCell();
  788. cell.Value = dtWeddingService2[t2]["Ws_ProdCostPrice"].ToString();
  789. dgvr.Cells.Add( cell );
  790. //数量
  791. cell = new DataGridViewTextBoxCell();
  792. cell.Value = dtWeddingService2[t2]["Ws_ProdQuantity"].ToString();
  793. dgvr.Cells.Add( cell );
  794. this.dgv.Rows.Add( dgvr );
  795. }
  796. }
  797. #endregion
  798. #region 获取后期收款加挑物品
  799. DataRow[] dtPlusPickItems2 = dtPlusPickItems.Select( "Plu_OrdNumber='" + dt.Rows[t]["Ord_Number"].ToString() + "'" );
  800. if ( dtPlusPickItems2.Length > 0 )
  801. {
  802. for ( int t3 = 0; t3 < dtPlusPickItems2.Length; t3++ )
  803. {
  804. string[] Plu_Goods = dtPlusPickItems2[t3]["Plu_Goods"].ToString().Split( ',' );
  805. string[] Plu_GoodsCosts = dtPlusPickItems2[t3]["Plu_GoodsCosts"].ToString().Split( ',' );
  806. for ( int y = 0; y < Plu_Goods.Length; y++ )
  807. {
  808. #region
  809. dgvr = new DataGridViewRow();
  810. cell = null;
  811. //订单号
  812. cell = new DataGridViewTextBoxCell();
  813. cell.Value = "";
  814. dgvr.Cells.Add( cell );
  815. //姓名
  816. cell = new DataGridViewTextBoxCell();
  817. cell.Value = "";
  818. dgvr.Cells.Add( cell );
  819. //女电话
  820. cell = new DataGridViewTextBoxCell();
  821. cell.Value = "";
  822. dgvr.Cells.Add( cell );
  823. //接单人
  824. cell = new DataGridViewTextBoxCell();
  825. cell.Value = "";
  826. dgvr.Cells.Add( cell );
  827. #region 售价
  828. cell = new DataGridViewTextBoxCell();
  829. cell.Value = "";
  830. dgvr.Cells.Add( cell );
  831. #endregion
  832. #region 成本
  833. //获取套系商品
  834. cell = new DataGridViewTextBoxCell();
  835. cell.Value = "";
  836. dgvr.Cells.Add( cell );
  837. #endregion
  838. //商品名称
  839. cell = new DataGridViewTextBoxCell();
  840. cell.Value = Plu_Goods[y].ToString();
  841. dgvr.Cells.Add( cell );
  842. //单价
  843. cell = new DataGridViewTextBoxCell();
  844. cell.Value = Convert.ToDecimal( Plu_GoodsCosts[y] ).ToString( "N2" );
  845. dgvr.Cells.Add( cell );
  846. //数量
  847. cell = new DataGridViewTextBoxCell();
  848. cell.Value = "1";
  849. dgvr.Cells.Add( cell );
  850. this.dgv.Rows.Add( dgvr );
  851. #endregion
  852. }
  853. }
  854. }
  855. #endregion
  856. #region 获取订单景点
  857. if ( dt.Rows[t]["Ord_Type"].ToString().Trim() != "1" )
  858. {
  859. DataTable dtPhotography = orbll.GetView_Custom( "tb_ErpOrdersPhotography", StrWhere: "Ordpg_Number = '" + dt.Rows[t]["Ord_Number"].ToString().Trim() + "'", ShowColumnName: "Ordpg_Sights,Ordpg_CostPrice" ).Tables[0];
  860. if ( dtPhotography.Rows.Count > 0 )
  861. {
  862. for ( int i = 0; i < dtPhotography.Rows.Count; i++ )
  863. {
  864. dgvr = new DataGridViewRow();
  865. cell = null;
  866. //订单号
  867. cell = new DataGridViewTextBoxCell();
  868. cell.Value = "";
  869. dgvr.Cells.Add( cell );
  870. //姓名
  871. cell = new DataGridViewTextBoxCell();
  872. cell.Value = "";
  873. dgvr.Cells.Add( cell );
  874. //电话
  875. cell = new DataGridViewTextBoxCell();
  876. cell.Value = "";
  877. dgvr.Cells.Add( cell );
  878. //接单人
  879. cell = new DataGridViewTextBoxCell();
  880. cell.Value = "";
  881. dgvr.Cells.Add( cell );
  882. cell = new DataGridViewTextBoxCell();
  883. cell.Value = "";
  884. dgvr.Cells.Add( cell );
  885. //获取套系商品
  886. cell = new DataGridViewTextBoxCell();
  887. cell.Value = "";
  888. dgvr.Cells.Add( cell );
  889. //商品名称
  890. cell = new DataGridViewTextBoxCell();
  891. cell.Value = dtPhotography.Rows[i]["Ordpg_Sights"].ToString();
  892. dgvr.Cells.Add( cell );
  893. //单价
  894. cell = new DataGridViewTextBoxCell();
  895. cell.Value = dtPhotography.Rows[i]["Ordpg_CostPrice"].ToString();
  896. dgvr.Cells.Add( cell );
  897. //数量
  898. cell = new DataGridViewTextBoxCell();
  899. cell.Value = "1";
  900. dgvr.Cells.Add( cell );
  901. this.dgv.Rows.Add( dgvr );
  902. }
  903. }
  904. }
  905. #endregion
  906. }
  907. #region 合计项目
  908. //单数
  909. this.lblSingular.Text = dt.Rows.Count.ToString();
  910. //总售价
  911. this.lblTotalPrice.Text = TotalPrice.ToString( "N2" );
  912. //总成本
  913. this.lbltotalCost.Text = totalCost.ToString( "N2" );
  914. //毛利
  915. this.lblGrossProfit.Text = ( Convert.ToDecimal( this.lblTotalPrice.Text ) - Convert.ToDecimal( this.lbltotalCost.Text ) ).ToString( "N2" );
  916. //毛利率 ((总售价-总成本)/总售价)*100
  917. if ( Convert.ToDecimal( this.lblSingular.Text ) == 0 )
  918. {
  919. this.lblGrossMargin.Text = "100%";
  920. }
  921. else
  922. {
  923. if ( Convert.ToDecimal( this.lblTotalPrice.Text ) != Convert.ToDecimal( "0" ) )
  924. {
  925. this.lblGrossMargin.Text = ( ( ( Convert.ToDecimal( this.lblTotalPrice.Text ) - Convert.ToDecimal( this.lbltotalCost.Text ) ) / Convert.ToDecimal( this.lblTotalPrice.Text ) ) * 100 ).ToString( "N2" ) + "%";
  926. }
  927. else
  928. {
  929. this.lblGrossMargin.Text = "0%";
  930. }
  931. }
  932. //平均售价
  933. if ( Convert.ToDecimal( lblSingular.Text ) == 0 )
  934. {
  935. this.lblAverageSellingPrice.Text = "0.00";
  936. }
  937. else
  938. {
  939. this.lblAverageSellingPrice.Text = ( Convert.ToDecimal( this.lblTotalPrice.Text ) / Convert.ToInt32( this.lblSingular.Text ) ).ToString( "N2" );
  940. }
  941. //平均成本
  942. if ( Convert.ToDecimal( lblSingular.Text ) == 0 )
  943. {
  944. this.lblAverageCost.Text = "0.00";
  945. }
  946. else
  947. {
  948. this.lblAverageCost.Text = ( Convert.ToDecimal( this.lbltotalCost.Text ) / Convert.ToInt32( this.lblSingular.Text ) ).ToString( "N2" );
  949. }
  950. //平均毛利
  951. if ( Convert.ToDecimal( lblSingular.Text ) == 0 )
  952. {
  953. this.lblAverageGrossProfit.Text = "0.00";
  954. }
  955. else
  956. {
  957. this.lblAverageGrossProfit.Text = ( Convert.ToDecimal( this.lblGrossProfit.Text ) / Convert.ToInt32( this.lblSingular.Text ) ).ToString( "N2" );
  958. }
  959. #endregion
  960. } ) );
  961. }
  962. } );
  963. try
  964. {
  965. dgv.ClearSelection();
  966. this.ucPagerEx1.TbDataSource = dt;
  967. }
  968. catch
  969. {
  970. }
  971. return pageData.TotalCount;
  972. }
  973. }
  974. }