123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337 |
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace LYFZ.Software.MainBusiness.StatisticalInquiry
- {
- public class FrmOrderTakingStatus : LYFZ.Software.UI.StatisticalInquiry.FrmOrderTakingStatus
- {
- private delegate void UpdateControl();
-
- public FrmOrderTakingStatus()
- {
- ///赋予初始值
- dtpStart.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
- dtpEnd.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
- cb_OrderedStatus.SelectedIndex = 0;
- ///查询
- this.btnQuery.Click += BtnQuery_Click;
- this.btn_Export.Click += Btn_Export_Click;
- LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.BindGroupStoreName(this.cmbtreevStoreName, StrGroupKeyCode: "retailProcess", StrKeyCode: "st007");
- ///显示
- this.Shown += FrmOrderTakingStatus_Shown;
-
- }
- private void Btn_Export_Click(object sender, EventArgs e)
- {
- dgvOrderBeen.ExportDataTable();
- }
- private void BtnQuery_Click(object sender, EventArgs e)
- {
- ///搜索数据
- BindOrderDataList();
- }
- private void FrmOrderTakingStatus_Shown(object sender, EventArgs e)
- {
- BtnQuery_Click(null, null);
- }
- void BindOrderDataList()
- {
- LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate (object obj, System.ComponentModel.BackgroundWorker backgroundWorker)
- {
- string statusText = cb_OrderedStatus.Text;
- if (statusText=="未拍照")
- {
- statusText = "NotOrdered";
- }
- else if (statusText == "拍照中")
- {
- statusText = "Ordering";
- }
- else
- {
- statusText = "Ordered";
- }
- this.dgvOrderBeen.Rows.Clear();
- Dictionary<string, List<dynamic>> childOrderList = new Dictionary<string, List<dynamic>>();
- decimal sValue = 0;
- decimal aValue = 0;
- decimal yValue = 0;
- decimal pValue = 0;
- decimal arValue = 0;
- Dictionary<string, int> dicOrderList = new Dictionary<string, int>();
- dicOrderList.Add(OrderTypeName("0"), 0);
- dicOrderList.Add(OrderTypeName("1"), 0);
- dicOrderList.Add(OrderTypeName("2"), 0);
- dicOrderList.Add(OrderTypeName("3"), 0);
- dicOrderList.Add(OrderTypeName("4"), 0);
- List<string> ordNumberList = new List<string>();
- DataTable dtList = GetServiceData(statusText,ref childOrderList,ref ordNumberList,ref dicOrderList,ref sValue,ref aValue,ref yValue,ref pValue,ref arValue);
- if (dtList.Rows.Count > 0)
- {
- this.Invoke(new UpdateControl(delegate ()
- {
- ///绑定DataGridView
- for (int t = 0; t < dtList.Rows.Count; t++)
- {
- DataRow drData = dtList.Rows[t];
- BindDataGridViewData(drData, statusText);
- }
- this.dgvOrderBeen.ClearSelection();
- txtTotalAmount.Text = sValue.ToString("0.00");
- txtPickUpAmount.Text = aValue.ToString("0.00");
- txt_TotalAllAmount.Text = yValue.ToString("0.00");
- txtTotalCollection.Text = pValue.ToString("0.00");
- txtTotalArrears.Text = arValue.ToString("0.00");
- string statusTempText = "";
- int totalCount = 0;
- foreach(string key in dicOrderList.Keys)
- {
- totalCount += dicOrderList[key];
- if (dicOrderList[key] > 0)
- {
- statusTempText += key + ":" + dicOrderList[key] + " ";
- }
- }
- lblCount.Text = "订单数:"+ totalCount + " \r\n "+ statusTempText;
- }));
- }
- else
- {
- this.Invoke(new UpdateControl(delegate ()
- {
- txtTotalAmount.Text = sValue.ToString("0.00");
- txtPickUpAmount.Text = aValue.ToString("0.00");
- txt_TotalAllAmount.Text = yValue.ToString("0.00");
- txtTotalCollection.Text = pValue.ToString("0.00");
- txtTotalArrears.Text = arValue.ToString("0.00");
- lblCount.Text = "订单数:0";
- }));
- }
- });
- }
- /// <summary>
- /// 获取数据集合数据
- /// </summary>
- /// <param name="statusText"></param>
- /// <returns></returns>
- DataTable GetServiceData(string statusText,ref Dictionary<string, List<dynamic>> childOrderList,
- ref List<string> ordNumberList, ref Dictionary<string, int> dicOrderList
- ,ref decimal sValue, ref decimal aValue, ref decimal yValue, ref decimal pValue, ref decimal arValue)
- {
- string shopCode = LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetGroupQueryWhere(this.cmbtreevStoreName, "Ord_DividedShop");
- System.Data.DataTable dtList = BLL.BLL_ErpOrderView.GetData_OrdersNotBeenOrdered(shopCode, dtpStart.Value, dtpEnd.Value, statusText);
- ///儿童订单次数等级总值
- Dictionary<string, decimal> dicOrderValue = new Dictionary<string, decimal>();
-
- ///数据处理
- for (int t = 0; t < dtList.Rows.Count; t++)
- {
- DataRow drData = dtList.Rows[t];
-
- BindChildDataBySign(drData, ref childOrderList,ref dicOrderValue);
- if (!ordNumberList.Contains(drData["Ord_Number"].ToString())
- &&
- ((statusText == "NotOrdered" && drData["StatusCount"].ToString() == "0")
- || (statusText == "Ordered" && Convert.ToInt32(drData["StatusCount"].ToString()) > 0 && Convert.ToInt32(drData["StatusCount"].ToString()) == Convert.ToInt32(drData["PhotoCount"].ToString()))
- || (statusText == "Ordering" && Convert.ToInt32(drData["StatusCount"].ToString()) > 0 && Convert.ToInt32(drData["StatusCount"].ToString())< Convert.ToInt32(drData["PhotoCount"].ToString()))))
- {
- sValue += Convert.ToDecimal(drData["Ord_SeriesPrice"]);
- aValue += Convert.ToDecimal(drData["TwoSales"]);
- yValue += Convert.ToDecimal(drData["TotalValue"]);
- pValue += Convert.ToDecimal(drData["payAmount"]);
- arValue += Convert.ToDecimal(drData["ArrearsAmount"]);
- ordNumberList.Add(drData["Ord_Number"].ToString());
- dicOrderList[OrderTypeName(drData["Ord_Type"].ToString())]++;
- }
- }
- foreach(string ordNumber in childOrderList.Keys)
- {
- decimal totalValue = dicOrderValue[ordNumber];
- foreach(dynamic dyObj in childOrderList[ordNumber])
- {
- List<DataRow> drDataList = dtList.AsEnumerable().Where(p => p.Field<string>("Ordpg_ViceNumber") == dyObj.ViceNumber).ToList();
- if(drDataList.Count>0)
- {
- if (totalValue > 0)
- {
- decimal TCValue = 0;
- decimal.TryParse(dyObj.TCValue, out TCValue);
- drDataList[0]["Ord_SeriesPrice"] = ((Convert.ToDecimal(dyObj.SeriesPrice) / (totalValue)) * TCValue).ToString("0.00");
- }
- }
- }
- }
- return dtList;
- }
- /// <summary>
- /// 绑定DataGridView行数据
- /// </summary>
- /// <param name="drData">数据集数据</param>
- /// <param name="statusText">订单类型</param>
- void BindDataGridViewData(DataRow drData,string statusText)
- {
- #region 获取月报表
- DataGridViewRow dgvr = new DataGridViewRow();
- DataGridViewCell cell = null;
- //单号
- cell = new DataGridViewTextBoxCell();
- cell.Value = drData["Ord_Number"].ToString();
- dgvr.Cells.Add(cell);
- //场景好
- cell = new DataGridViewTextBoxCell();
- cell.Value = drData["Ordpg_ViceNumber"].ToString();
- dgvr.Cells.Add(cell);
- //订单号
- cell = new DataGridViewTextBoxCell();
- cell.Value = drData["Ord_SinceOrderNumber"].ToString();
- dgvr.Cells.Add(cell);
- //订单类型
- cell = new DataGridViewTextBoxCell();
- cell.Value = OrderTypeName(drData["Ord_Type"].ToString());
- dgvr.Cells.Add(cell);
- //开单人
- cell = new DataGridViewTextBoxCell();
- cell.Value = drData["Ord_OrderPersonName"].ToString();
- dgvr.Cells.Add(cell);
- //客户名称
- cell = new DataGridViewTextBoxCell();
- cell.Value = drData["Cus_Name"].ToString();
- dgvr.Cells.Add(cell);
- //客户名称
- cell = new DataGridViewTextBoxCell();
- cell.Value = drData["Cus_Telephone"].ToString();
- dgvr.Cells.Add(cell);
- //拍摄场景
- string sightName = drData["Ords_SightsName"].ToString();
- string[] sightNameList = sightName.Split(',');
- string strSightName = "";
- foreach (string sightText in sightNameList)
- {
- if (strSightName != "")
- {
- strSightName += ",";
- }
- strSightName += sightText.Split('-')[0];
- }
- cell = new DataGridViewTextBoxCell();
- cell.Value = strSightName;
- dgvr.Cells.Add(cell);
- //套系名称
- cell = new DataGridViewTextBoxCell();
- cell.Value = drData["Ord_SeriesName"].ToString();
- dgvr.Cells.Add(cell);
- //拍照情况
- cell = new DataGridViewTextBoxCell();
- cell.Value = drData["Ordered"].ToString();
- dgvr.Cells.Add(cell);
- //订单套系金额
- cell = new DataGridViewTextBoxCell();
- cell.Value = drData["Ord_SeriesPrice"].ToString();
- dgvr.Cells.Add(cell);
- //欠款金额
- cell = new DataGridViewTextBoxCell();
- cell.Value = drData["ArrearsAmount"].ToString();
- dgvr.Cells.Add(cell);
- //业绩金额
- cell = new DataGridViewTextBoxCell();
- cell.Value = drData["TotalValue"].ToString();
- dgvr.Cells.Add(cell);
- //加挑金额
- cell = new DataGridViewTextBoxCell();
- cell.Value = drData["TwoSales"].ToString();
- dgvr.Cells.Add(cell);
- //已付款额
- cell = new DataGridViewTextBoxCell();
- cell.Value = drData["payAmount"].ToString();
- dgvr.Cells.Add(cell);
- if (statusText == "NotOrdered" && drData["StatusCount"].ToString() == "0")
- {
- this.dgvOrderBeen.Rows.Add(dgvr);
- }
- else if (statusText == "Ordered" && Convert.ToInt32(drData["StatusCount"].ToString()) > 0 && Convert.ToInt32(drData["StatusCount"].ToString()) == Convert.ToInt32(drData["PhotoCount"].ToString()))
- {
- this.dgvOrderBeen.Rows.Add(dgvr);
- }
- else if (statusText == "Ordering" && Convert.ToInt32(drData["StatusCount"].ToString()) > 0 && Convert.ToInt32(drData["StatusCount"].ToString()) < Convert.ToInt32(drData["PhotoCount"].ToString()))
- {
- this.dgvOrderBeen.Rows.Add(dgvr);
- }
- #endregion
- }
- public void BindChildDataBySign(DataRow drData,ref Dictionary<string,List<dynamic>> childOrderList,ref Dictionary<string, decimal> dicOrderValue)
- {
- if (drData["Ord_Type"].ToString() == "1")
- {
- dynamic dyObj = new System.Dynamic.ExpandoObject();
- dyObj.ViceNumber = drData["Ordpg_ViceNumber"].ToString();
- dyObj.TCValue = drData["Ords_SightsName"].ToString().Split('-')[1];
- dyObj.SeriesPrice = drData["Ord_SeriesPrice"].ToString();
-
- if (childOrderList.ContainsKey(drData["Ord_Number"].ToString()))
- {
- childOrderList[drData["Ord_Number"].ToString()].Add(dyObj);
- decimal tcValue = 0;
- decimal.TryParse(drData["Ords_SightsName"].ToString().Split('-')[1],out tcValue);
- dicOrderValue[drData["Ord_Number"].ToString()] += tcValue;
- }
- else
- {
- List<dynamic> dicDynamicList = new List<dynamic>();
- dicDynamicList.Add(dyObj);
- childOrderList.Add(drData["Ord_Number"].ToString(), dicDynamicList);
- decimal tcValue = 0;
- decimal.TryParse(drData["Ords_SightsName"].ToString().Split('-')[1], out tcValue);
- dicOrderValue.Add(drData["Ord_Number"].ToString(), tcValue);
- }
- }
- }
- /// <summary>
- /// 订单类型
- /// </summary>
- /// <param name="typeCode"></param>
- /// <returns></returns>
- string OrderTypeName(string typeCode)
- {
- switch(typeCode)
- {
- case "0":return "婚纱订单";
- case "1": return "儿童订单";
- case "2": return "写真订单";
- case "3": return "服务订单";
- case "4": return "婚庆订单";
- default : return "";
- }
- }
- }
- }
|