using LYFZ.Model; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Windows.Forms; namespace LYFZ.Software.MainBusiness.DecisionAssistant.SetSmallForm { public partial class AnalyzedOrderDetailSmallForm : UI.DecisionAssistant.SetSmallForm.AnalyzedOrderDetailSmallForm { LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder(); public AnalyzedOrderDetailSmallForm() { InitializeComponent(); this.Load += AnalyzedOrderDetailSmallForm_Load; } void AnalyzedOrderDetailSmallForm_Load(object sender, EventArgs e) { this.btn_Export.Click += btn_Export_Click; } void btn_Export_Click(object sender, EventArgs e) { this.gridViewDetail.ExportDataTable(); } void SetDataTablePaymentNull( DataTable DataTableDb) { foreach(DataRow dr in DataTableDb.Rows) { if(DataTableDb.Columns.Contains("付款方式")) { if (string.IsNullOrEmpty(dr["付款方式"].ToString())) { dr["付款方式"] = ""; } } } } public void BindDataGridView(ModelImagePostionAction modelImagePostionAction) { DataTable DataTableDb = orbll.GetView_Custom(modelImagePostionAction.SqlData).Tables[0]; SetDataTablePaymentNull(DataTableDb); BindDataGridView(modelImagePostionAction, DataTableDb); } public void BindDataGridView2(ModelImagePostionAction modelImagePostionAction) { DataSet ds=orbll.GetView_Custom(modelImagePostionAction.SqlData); DataTable DataTableDb = ds.Tables[0]; DataTable DataTableDb1 = ds.Tables[1]; SetDataTablePaymentNull(DataTableDb); SetDataTablePaymentNull(DataTableDb1); for (int j = 0; j < DataTableDb.Rows.Count; j++) { DataRow dr = DataTableDb.Rows[j]; if (dr["OrdersPerson"].ToString().Trim().Length != dr["OrdersPerson"].ToString().Trim().Replace(",", "").Length) { string[] StrArrayPerson = dr["OrdersPerson"].ToString().Trim().Split(','); if (StrArrayPerson[0].Trim() == modelImagePostionAction.ColumType) { dr["订单号"] = dr["订单号"] + "(主门市)"; } else { dr["订单号"] = dr["订单号"] + "(副门市)"; } } else { dr["订单号"] = dr["订单号"] + "(主门市)"; } } for (int j = 0; j < DataTableDb1.Rows.Count; j++) { DataRow tempDataRow = DataTableDb1.Rows[j]; DataRow dataRow = DataTableDb.NewRow(); foreach (DataColumn header in DataTableDb1.Columns) { if (header.ColumnName == "订单号") { dataRow[header.ColumnName] = tempDataRow[header.ColumnName] + "(二销)"; } else { dataRow[header.ColumnName] = tempDataRow[header.ColumnName]; } } DataTableDb.Rows.Add(dataRow); } DataTableDb.Columns.Remove("OrdersPerson"); BindDataGridView(modelImagePostionAction, DataTableDb); this.Width = 850; } public void BindDataGridView3(ModelImagePostionAction modelImagePostionAction) { DataSet ds = orbll.GetView_Custom(modelImagePostionAction.SqlData); DataTable DataTableDb = ds.Tables[0]; SetDataTablePaymentNull(DataTableDb); List strWhereList = new List(); string strWhere = ""; foreach(DataRow dr in DataTableDb.Rows) { if(!strWhereList.Contains(Convert.ToString(dr["摄影师"].ToString()))) { strWhereList.Add(dr["摄影师"].ToString()); } if (!strWhereList.Contains(Convert.ToString(dr["摄影助理"].ToString()))) { strWhereList.Add(dr["摄影助理"].ToString()); } if (!strWhereList.Contains(Convert.ToString(dr["化妆师"].ToString()))) { strWhereList.Add(dr["化妆师"].ToString()); } if (!strWhereList.Contains(Convert.ToString(dr["化妆助理"].ToString()))) { strWhereList.Add(dr["化妆助理"].ToString()); } if (!strWhereList.Contains(Convert.ToString(dr["引导师"]))) { strWhereList.Add(dr["引导师"].ToString()); } if (!strWhereList.Contains(Convert.ToString(dr["引导助理"]))) { strWhereList.Add(dr["引导助理"].ToString()); } } LYFZ.BLL.BLL_ErpUser userBll = new BLL.BLL_ErpUser(); DataTable userTb = userBll.GetList(" User_EmployeeID in ('" + string.Join("','", strWhereList.ToArray()) + "') ").Tables[0]; foreach(DataRow dr in DataTableDb.Rows) { if(!string.IsNullOrEmpty(Convert.ToString(dr["摄影师"]))) { DataRow[] tempUserRow = userTb.Select( " User_EmployeeID ='"+dr["摄影师"].ToString()+"' "); if(tempUserRow.Length>0) { dr["摄影师"] = tempUserRow[0]["User_Name"].ToString(); } } if (!string.IsNullOrEmpty(Convert.ToString(dr["摄影助理"]).ToString())) { DataRow[] tempUserRow = userTb.Select(" User_EmployeeID ='" + dr["摄影助理"].ToString() + "' "); if (tempUserRow.Length > 0) { dr["摄影助理"] = tempUserRow[0]["User_Name"].ToString(); } } if (!string.IsNullOrEmpty(Convert.ToString(dr["化妆师"]).ToString())) { DataRow[] tempUserRow = userTb.Select(" User_EmployeeID ='" + dr["化妆师"].ToString() + "' "); if (tempUserRow.Length > 0) { dr["化妆师"] = tempUserRow[0]["User_Name"].ToString(); } } if (!string.IsNullOrEmpty(Convert.ToString(dr["化妆助理"]).ToString())) { DataRow[] tempUserRow = userTb.Select(" User_EmployeeID ='" + dr["化妆助理"].ToString() + "' "); if (tempUserRow.Length > 0) { dr["化妆助理"] = tempUserRow[0]["User_Name"].ToString(); } } if (!string.IsNullOrEmpty(Convert.ToString(dr["引导师"]).ToString())) { DataRow[] tempUserRow = userTb.Select(" User_EmployeeID ='" + dr["引导师"].ToString() + "' "); if (tempUserRow.Length > 0) { dr["引导师"] = tempUserRow[0]["User_Name"].ToString(); } } if (!string.IsNullOrEmpty(Convert.ToString(dr["引导助理"]).ToString())) { DataRow[] tempUserRow = userTb.Select(" User_EmployeeID ='" + dr["引导助理"].ToString() + "' "); if (tempUserRow.Length > 0) { dr["引导助理"] = tempUserRow[0]["User_Name"].ToString(); } } if (!string.IsNullOrEmpty(Convert.ToString(dr["重拍责任人"]).ToString())) { DataRow[] tempUserRow = userTb.Select(" User_EmployeeID in ('" + dr["重拍责任人"].ToString() + "') "); string userName = ""; foreach (DataRow tempUser in tempUserRow) { if(!string.IsNullOrEmpty(userName)) { userName += ","; } userName += tempUser["User_Name"].ToString(); } if (tempUserRow.Length > 0) { dr["重拍责任人"] = userName; } } } BindDataGridView(modelImagePostionAction, DataTableDb); } void BindDataGridView(ModelImagePostionAction modelImagePostionAction, DataTable DataTableDb) { Dictionary dicList = new Dictionary(); if (string.IsNullOrEmpty(modelImagePostionAction.OrdType)) { this.Text = modelImagePostionAction.OrdTitle; } else { this.Text = modelImagePostionAction.OrdTitle + " (" + modelImagePostionAction.OrdType + ")"; } foreach (DataColumn columText in DataTableDb.Columns) { this.gridViewDetail.Columns.Add(columText.ColumnName, columText.ColumnName); if(columText.ColumnName=="订单号") { this.gridViewDetail.Columns[0].Width = 160; } } string ordNumber = ""; bool bNowData = false; List payTotalValue = new List(); foreach (DataRow dr in DataTableDb.Rows) { if (modelImagePostionAction.OrdTitle.Equals("营收分析")) { if (ordNumber != dr["订单号"].ToString_s()) { bNowData = false; ordNumber = dr["订单号"].ToString_s(); payTotalValue = new List(); payTotalValue.Add(Convert.ToDecimal(dr["实收"])); } else { bNowData = true; payTotalValue.Add(Convert.ToDecimal(dr["实收"])); } } int rowIndex = this.gridViewDetail.Rows.Add(); if (modelImagePostionAction.OrdTitle.Equals("营收分析") ) { this.gridViewDetail.Rows[rowIndex].Cells["余款"].Value = Convert.ToDecimal(dr["业绩"]) - Convert.ToDecimal(dr["实收"]); } foreach (DataColumn columText in DataTableDb.Columns) { if (modelImagePostionAction.OrdTitle.Equals("营收分析") && columText.ColumnName.Equals("余款")&& !bNowData) { continue; } this.gridViewDetail.Rows[rowIndex].Cells[columText.ColumnName].Value = dr[columText.ColumnName]; if (modelImagePostionAction.OrdTitle.Equals("营收分析") ) { if (bNowData) { if (!columText.ColumnName.Equals("付款方式") && !columText.ColumnName.Equals("实收") ) { this.gridViewDetail.Rows[rowIndex].Cells[columText.ColumnName].Value = ""; } decimal totalValue = payTotalValue.Sum(); //for (int i = 0; i < payTotalValue.Count; i++) //{ this.gridViewDetail.Rows[rowIndex - (payTotalValue.Count-1)].Cells["余款"].Value = Convert.ToDecimal(dr["业绩"]) - totalValue; //} } } /*if (dr[columText.ColumnName] != null) { if (IsNumeric(dr[columText.ColumnName].ToString())) { if (!dicList.ContainsKey(columText.ColumnName)) { if (string.IsNullOrEmpty(dr[columText.ColumnName].ToString())) { dr[columText.ColumnName] = "0"; } dicList.Add(columText.ColumnName, Convert.ToDecimal(dr[columText.ColumnName].ToString())); } else { if (string.IsNullOrEmpty(dr[columText.ColumnName].ToString())) { dr[columText.ColumnName] = "0"; } dicList[columText.ColumnName] += Convert.ToDecimal(dr[columText.ColumnName].ToString()); } } }*/ } } Dictionary pluAmountList = new Dictionary(); foreach(DataGridViewRow row in gridViewDetail.Rows) { foreach(DataGridViewColumn colum in gridViewDetail.Columns) { if (IsNumeric(row.Cells[colum.Name].Value.ToString())) { if (!dicList.ContainsKey(colum.Name)) { if (!string.IsNullOrEmpty(row.Cells[colum.Name].Value.ToString())) { dicList.Add(colum.Name, Convert.ToDecimal(row.Cells[colum.Name].Value.ToString())); //row.Cells[colum.Name].Value = "0"; } } else { if (!string.IsNullOrEmpty(row.Cells[colum.Name].Value.ToString())) { decimal tempValue = 0; if (decimal.TryParse(row.Cells[colum.Name].Value.ToString(), out tempValue)) { dicList[colum.Name] += Convert.ToDecimal(row.Cells[colum.Name].Value.ToString()); //row.Cells[colum.Name].Value = "0"; } } } if(colum.Name=="加挑金额") { if (gridViewDetail.Columns.Contains("订单号")) { if(!pluAmountList.ContainsKey(row.Cells["订单号"].Value.ToString_s())) { pluAmountList.Add(row.Cells["订单号"].Value.ToString_s(), Convert.ToDecimal(row.Cells["加挑金额"].Value.ToString_s())); } } } } } } if(dicList.ContainsKey("加挑金额")) { dicList["加挑金额"] = pluAmountList.Values.Sum(); } string msg = ""; foreach (string key in dicList.Keys) { if (!string.IsNullOrEmpty(msg)) { msg += " "; } msg += key + ":" + dicList[key]; } labelMsg.Text = msg; } public bool IsNumeric(string value) { return Regex.IsMatch(value, @"^[+-]?\d*[.]?\d*$"); } } }