Проблема с функциональностью StringBuilder - PullRequest
0 голосов
/ 14 апреля 2020
private ResponseDTO SyncPODetails(PODTO po)
        {
            //TODO Take string builder here and  append values from loop to this string builder 
            string query = "";
            try
            {
                query = "insert into " + ConfigurationManager.AppSettings["dbUser"] + ".PODetail(WHSEID,POKEY,POLINENUMBER,STORERKEY,SKU,SKUDESCRIPTION,QTYORDERED,QTYADJUSTED,QTYRECEIVED,PACKKEY,UNITPRICE,UOM,EFFECTIVEDATE,FORTE_FLAG,ITEM_NUMBER,SKU_WGT,SKU_CUBE,SKU_HGT,UNIT_COST,UNIT_SHIP,SUSR1,SUSR2,QTYREJECTED,STATUS,QCAUTOADJUST,QCREQUIRED,ADDDATE,ADDWHO,EDITDATE,EDITWHO,ITEMPRICEREF,POPLANID,LOADPLANQTY,ORDERKEY,ORDERLINENUMBER,ASSIGNEDQTY,SUPPLIERRECEIVEDQTY,SUPPLIERRECEIPTDATE,QTYPOPULATED,ORDEREDQTY)"
          + " 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 };
            }
        }
...