StringBuilder功能问题

问题描述 投票:0回答:1

私人响应DTO SyncPODetails(PODTO po){// TODO在这里使用字符串构建器,并将循环中的值附加到此字符串构建器字符串查询=“”;尝试{query =“插入到” + ConfigurationManager.AppSettings [“ dbUser”] +“ .PODetail(WHSEID,POKEY,POLINENUMBER,STORERKEY,SKU,SKUDESCRIPTION,QTYORDERED,QTYADJUSTED,QTYRECEIVED,PACKKEY,UNITPRICE,UOM,EFFECTIVEAGATE,FORTE_FL SKU_WGT,SKU_CUBE,SKU_HGT,UNIT_COST,UNIT_SHIP,SUSR1,SUSR2,QTY拒绝,状态,QCAUTOADJUST,QCREQUIRED,ADDWHO,EDITDATE,EDITWHO,ITEMPRICEREF,POPLANID,LOADPLANQTYDERPTYQUETTYPID ”+“ values('LMRWHS1','{0}','{1}','KGL','{2}','{3}',{4},0.00,0.00,'{5}', {6},'{7}','{8}','I',0,{9},{10},0.00,{11},0.00,'{12}','{13}', 0.00,0,0,0,'{14}','{15}','{16}','{17}','{18}','{19}',0.00,'{20} ','{21}',0.00,0.00,'{22}',0.00,0.00);“;

            //ar n = "";
            foreach (var pd in po.POdetails)
            {
                n = n + pd.NSN;
                //TODO:remove the query here and keep it out of loop i.e before the loop 
                //TODO: Remove this select is not required 
               //query= query + "select max(SERIALKEY) SERIALKEY from " + ConfigurationManager.AppSettings["dbUser"] + ".PODetail";
                query = string.Format(query,
                    po.POKey,
                    pd.POLineNumber,
                    pd.NSN,
                    pd.NSNDescription,
                    pd.OpenQuantity,//pd.PalletQuantities.Sum(x => x.PalletQuantity),
                    "STD",
                    pd.UnitPrice,
                    pd.UOM,
                    po.CreatedDate.ToString("MM-dd-yyyy hh:mm:ss tt"),
                    pd.STDGROSSWGT,
                    "0",
                    pd.UnitPrice,
                   pd.AgreementRefNo,
                    "DRY",
                    po.CreatedDate.ToString("MM-dd-yyyy hh:mm:ss tt"),
                    pd.CreatedByName,
                    po.UpdatedDate.Year < 1990 ? null : po.UpdatedDate.ToString("MM-dd-yyyy hh:mm:ss tt"),
                    pd.UpdatedByName,
                    pd.ITEMPRICEREF,
                    po.PlanNo,
                    pd.WMSOrderKey,
                    pd.CustomerOrderLineNo,
                    po.VendorDeliveryDate.ToString("MM-dd-yyyy")
                    );
                LogHelper.LogInfo(query);
                // TODO: Remove this 
                var result = ExecuteNonQuery(ConnectionStringCPRD, query);
            }
            LogHelper.LogInfo(n);
            //TODO: Execute the string builder here like this ExecuteNonQuery(ConnectionStringCPRD, query);  
            return new ResponseDTO { Status = true, Message = "PO  Synced sucessfully", SingleResponse = po.Id };
        }
        catch (Exception ex)
        {
            RevereseSync(po);
            LogHelper.LogError("Sync PO Details" + query, ex);
            return new ResponseDTO { Status = false, Message = "PO  not synced sucessfully", SingleResponse = po.Id };
        }
    }
string builder
1个回答
0
投票

私人响应DTO SyncPODetails(PODTO po){// TODO在这里使用字符串构建器,并将循环中的值附加到此字符串构建器字符串查询=“”;尝试{query =“插入到” + ConfigurationManager.AppSettings [“ dbUser”] +“ .PODetail(WHSEID,POKEY,POLINENUMBER,STORERKEY,SKU,SKUDESCRIPTION,QTYORDERED,QTYADJUSTED,QTYRECEIVED,PACKKEY,UNITPRICE,UOM,EFFECTIVEAGATE,FORTE_FL SKU_WGT,SKU_CUBE,SKU_HGT,UNIT_COST,UNIT_SHIP,SUSR1,SUSR2,QTY拒绝,状态,QCAUTOADJUST,QCREQUIRED,ADDWHO,EDITDATE,EDITWHO,ITEMPRICEREF,POPLANID,LOADPLANQTYDERPTYQUETTYPID ”+“ values('LMRWHS1','{0}','{1}','KGL','{2}','{3}',{4},0.00,0.00,'{5}', {6},'{7}','{8}','I',0,{9},{10},0.00,{11},0.00,'{12}','{13}', 0.00,0,0,0,'{14}','{15}','{16}','{17}','{18}','{19}',0.00,'{20} ','{21}',0.00,0.00,'{22}',0.00,0.00);“;

            //ar n = "";
            foreach (var pd in po.POdetails)
            {
                n = n + pd.NSN;
                //TODO:remove the query here and keep it out of loop i.e before the loop 
                //TODO: Remove this select is not required 
               //query= query + "select max(SERIALKEY) SERIALKEY from " + ConfigurationManager.AppSettings["dbUser"] + ".PODetail";
                query = string.Format(query,
                    po.POKey,
                    pd.POLineNumber,
                    pd.NSN,
                    pd.NSNDescription,
                    pd.OpenQuantity,//pd.PalletQuantities.Sum(x => x.PalletQuantity),
                    "STD",
                    pd.UnitPrice,
                    pd.UOM,
                    po.CreatedDate.ToString("MM-dd-yyyy hh:mm:ss tt"),
                    pd.STDGROSSWGT,
                    "0",
                    pd.UnitPrice,
                   pd.AgreementRefNo,
                    "DRY",
                    po.CreatedDate.ToString("MM-dd-yyyy hh:mm:ss tt"),
                    pd.CreatedByName,
                    po.UpdatedDate.Year < 1990 ? null : po.UpdatedDate.ToString("MM-dd-yyyy hh:mm:ss tt"),
                    pd.UpdatedByName,
                    pd.ITEMPRICEREF,
                    po.PlanNo,
                    pd.WMSOrderKey,
                    pd.CustomerOrderLineNo,
                    po.VendorDeliveryDate.ToString("MM-dd-yyyy")
                    );
                LogHelper.LogInfo(query);
                // TODO: Remove this 
                var result = ExecuteNonQuery(ConnectionStringCPRD, query);
            }
            LogHelper.LogInfo(n);
            //TODO: Execute the string builder here like this ExecuteNonQuery(ConnectionStringCPRD, query);  
            return new ResponseDTO { Status = true, Message = "PO  Synced sucessfully", SingleResponse = po.Id };
        }
        catch (Exception ex)
        {
            RevereseSync(po);
            LogHelper.LogError("Sync PO Details" + query, ex);
            return new ResponseDTO { Status = false, Message = "PO  not synced sucessfully", SingleResponse = po.Id };
        }
    }
© www.soinside.com 2019 - 2024. All rights reserved.