王 垚
2020-11-30 7e3217866f07ee082c66b9f3bf57189c140aa86b
src/BLL/Demo.BillView/PRD/Pro_ScDayImport.cs
@@ -115,6 +115,27 @@
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            //根据生产订单号和物料查询是否存在明细
                            string sql = string.Format(@"/*dialect*/ SELECT T1.FBILLNO,T2.* FROM T_PRD_MO T1
LEFT JOIN T_PRD_MOENTRY T2 ON T1.FID = T2.FID
JOIN T_BD_MATERIAL T3 ON T2.FMATERIALID = T3.FMATERIALID
WHERE T1.FBILLNO = '{0}'  AND T3.FNUMBER = '{1}'", dt.Rows[i][1].ToString(), dt.Rows[i][5].ToString());
                            DataTable _dt = new DataTable();
                            _dt = DBServiceHelper.ExecuteDataSet(Context, sql).Tables[0];
                            string FLOT = "";//FLOT  批次
                            string FQTY = "";//FQTY 生产订单数量
                            string FBILLNO = "";//FBILLNO 原单号
                            if (_dt.Rows.Count > 0)
                            {
                                FLOT = _dt.Rows[0]["FLOT"].ToString();
                                FQTY = _dt.Rows[0]["FQTY"].ToString();
                                FBILLNO = _dt.Rows[0]["FBILLNO"].ToString();
                            }
                            //DynamicObject row = new DynamicObject(entity.DynamicObjectType);
                            this.Model.CreateNewEntryRow("FEntity");
                            this.Model.SetValue("FSEQ", i + 1, i);
@@ -130,14 +151,17 @@
                            this.Model.SetValue("FUnit", dt.Rows[i][8].ToString(), i);
                            this.Model.SetValue("FBatch", dt.Rows[i][9].ToString(), i);
                            this.Model.SetValue("FSalOrderCount", dt.Rows[i][10].ToString(), i);
                            this.Model.SetValue("FProOrderCount", dt.Rows[i][11].ToString(), i);
                            this.Model.SetValue("FCompleteSetCount", dt.Rows[i][12].ToString(), i);
                            this.Model.SetValue("FDeliveryDate", GetDateTime(Convert.ToInt32(dt.Rows[i][13].ToString())), i);
                            this.Model.SetValue("FDeliveryDate", ToDateTimeValue(dt.Rows[i][13].ToString()), i);
                            this.Model.SetValue("FOrderLevel", dt.Rows[i][14].ToString(), i);
                            this.Model.SetValue("FOrderQuantity", FQTY, i);
                            for (int j = 0; j <= 60; j++)
                            {
                                this.Model.SetValue("FT" + "" + j + "", dt.Rows[i][15 + j].ToString(), i);
                            }
                            //调用数量值更新
                            this.View.InvokeFieldUpdateService("FT0", i);
                        }
                    }
@@ -202,6 +226,17 @@
                    return;
                }
                foreach (DynamicObject current in entityDataObjoct)
                {
                    if (Convert.ToInt32(current["FNoScheduled"]) < 0)
                        _result += "序号:" + Convert.ToString(current["SEQ"]) + ",日计划总数量超出生产订单数量";
                }
                if (_result != "")
                {
                    this.View.ShowErrMessage(_result);
                    return;
                }
                foreach (DynamicObject current in entityDataObjoct)
                {
@@ -222,6 +257,7 @@
                    string FLOT = "";//FLOT  批次
                    string FQTY = "";//FQTY 生产订单数量
                    string FBILLNO = "";//FBILLNO 原单号 
                    if (dt.Rows.Count > 0)
                    {
                        FID = dt.Rows[0]["FID"].ToString();
@@ -236,7 +272,7 @@
                    jsonRoot.Add("Creator", "");
                    jsonRoot.Add("NeedUpDateFields", new JArray());
                    jsonRoot.Add("NeedReturnFields", new JArray());
                    jsonRoot.Add("IsDeleteEntry", "false");
                    jsonRoot.Add("IsDeleteEntry", "true");
                    jsonRoot.Add("SubSystemId", "");
                    jsonRoot.Add("IsVerifyBaseDataField", "");
@@ -254,6 +290,12 @@
                    jsonModel.Add("FPRDMOMAINID", FID); ;//源单主内码
                    jsonModel.Add("FPRDMOENTYID", FENTRYID); ;//源单子内码
                    jsonModel.Add("FOrderQuantity", current["FOrderQuantity"].ToString()); ;//生产订单数量
                    jsonModel.Add("FDayPlanQuantity", current["FDayPlanQuantity"].ToString()); ;//日计划数量
                    jsonModel.Add("FNoScheduled", current["FNoScheduled"].ToString()); ;//未排数量
                    JObject jsonFHMaterID = new JObject();
                    jsonFHMaterID.Add("FNumber", (current["FMatrailId"] as DynamicObject)["Number"].ToString());
@@ -266,17 +308,17 @@
                        jsonModel.Add("FHPRDORGID", jsonFHPRDORGID);//FHMaterID 生产组织
                    }
                    if (Convert.ToString(current["FProductWorkShopId_Id"]) != "0")
                    if (Convert.ToString(current["FResourcesId_Id"]) != "0")
                    {
                        JObject jsonFProductWorkShopId = new JObject();
                        jsonFProductWorkShopId.Add("FNumber", (current["FProductWorkShopId"] as DynamicObject)["Number"].ToString());
                        jsonFProductWorkShopId.Add("FNumber", (current["FResourcesId"] as DynamicObject)["Number"].ToString());
                        jsonModel.Add("FHSourceID", jsonFProductWorkShopId);//FHSourceID  生产车间
                    }
                    if (Convert.ToString(current["FResourcesId_Id"]) != "0")
                    if (Convert.ToString(current["FProductWorkShopId_Id"]) != "0")
                    {
                        JObject jsonFResourcesId = new JObject();
                        jsonFResourcesId.Add("FNumber", (current["FResourcesId"] as DynamicObject)["Number"].ToString());
                        jsonFResourcesId.Add("FNumber", (current["FProductWorkShopId"] as DynamicObject)["Number"].ToString());
                        jsonModel.Add("FHWorkShopID", jsonFResourcesId);//FHWorkShopID  生产资源
                    }
                    JArray Entry = new JArray();
@@ -308,12 +350,11 @@
                        if (saveIsSuc == "TRUE")
                        {
                            string FDayPlanBillNo = saveObj["Result"]["ResponseStatus"]["SuccessEntitys"]["Number"].ToString();
                            string FDayPlanID = saveObj["Result"]["ResponseStatus"]["SuccessEntitys"]["Id"].ToString();
                            string FDayPlanBillNo = saveObj["Result"]["Number"].ToString();
                            string FDayPlanID = saveObj["Result"]["Id"].ToString();
                            //this.Model.SetValue("FDayPlanBillNo", FDayPlanBillNo, Convert.ToString(current["SEQ"]));//
                            // this.Model.SetValue("FDayPlanID", FDayPlanID, Convert.ToString(current["SEQ"]));//
                            this.Model.SetValue("FDayPlanBillNo", FDayPlanBillNo, Convert.ToInt32(current["SEQ"]) - 1);//
                            this.Model.SetValue("FDayPlanID", FDayPlanID, Convert.ToInt32(current["SEQ"]) - 1);//
                            this.View.ShowMessage("导入成功");
@@ -337,8 +378,8 @@
                            string FDayPlanBillNo = saveObj["Result"]["Number"].ToString();
                            string FDayPlanID = saveObj["Result"]["Id"].ToString();
                            //this.Model.SetValue("FDayPlanBillNo", FDayPlanBillNo, Convert.ToString(current["SEQ"]));//
                            // this.Model.SetValue("FDayPlanID", FDayPlanID, Convert.ToString(current["SEQ"]));//
                            this.Model.SetValue("FDayPlanBillNo", FDayPlanBillNo, Convert.ToInt32(current["SEQ"]) - 1);//
                            this.Model.SetValue("FDayPlanID", FDayPlanID, Convert.ToInt32(current["SEQ"]) - 1);//
                            this.View.ShowMessage("导入成功");
@@ -351,7 +392,7 @@
                        }
                    }
                    this.View.UpdateView();
                }
@@ -366,6 +407,53 @@
        /// <summary>
        /// 数字转换时间格式
        /// </summary>
        /// <param name="timeStr">数字,如:42095.7069444444/0.650694444444444</param>
        /// <returns>日期/时间格式</returns>
        private string ToDateTimeValue(string strNumber)
        {
            if (!string.IsNullOrWhiteSpace(strNumber))
            {
                Decimal tempValue;
                //先检查 是不是数字;
                if (Decimal.TryParse(strNumber, out tempValue))
                {
                    //天数,取整
                    int day = Convert.ToInt32(Math.Truncate(tempValue));
                    //这里也不知道为什么. 如果是小于32,则减1,否则减2
                    //日期从1900-01-01开始累加
                    // day = day < 32 ? day - 1 : day - 2;
                    DateTime dt = new DateTime(1900, 1, 1).AddDays(day < 32 ? (day - 1) : (day - 2));
                    //小时:减掉天数,这个数字转换小时:(* 24)
                    Decimal hourTemp = (tempValue - day) * 24;//获取小时数
                                                              //取整.小时数
                    int hour = Convert.ToInt32(Math.Truncate(hourTemp));
                    //分钟:减掉小时,( * 60)
                    //这里舍入,否则取值会有1分钟误差.
                    Decimal minuteTemp = Math.Round((hourTemp - hour) * 60, 2);//获取分钟数
                    int minute = Convert.ToInt32(Math.Truncate(minuteTemp));
                    //秒:减掉分钟,( * 60)
                    //这里舍入,否则取值会有1秒误差.
                    Decimal secondTemp = Math.Round((minuteTemp - minute) * 60, 2);//获取秒数
                    int second = Convert.ToInt32(Math.Truncate(secondTemp));
                    //时间格式:00:00:00
                    string resultTimes = string.Format("{0}:{1}:{2}",
                            (hour < 10 ? ("0" + hour) : hour.ToString()),
                            (minute < 10 ? ("0" + minute) : minute.ToString()),
                            (second < 10 ? ("0" + second) : second.ToString()));
                    if (day > 0)
                        return string.Format("{0} {1}", dt.ToString("yyyy-MM-dd"), resultTimes);
                    else
                        return resultTimes;
                }
            }
            return string.Empty;
        }
    }