I'm filling data inside an object with c# but I don't know how to return this object.
I create an object named ArasOrder and fill in the data and I want to return the ArasOrder object.
how can I do this.
public class ArasDeneme
{
public static void aras()
{
var ArasService = new ArasTEST.Service();
var ArasGonderi = new ArasTEST.ShippingOrder();
var ArasOrder = new ArasTEST.Order();
var parametreler = ArasKargoTEST.ParametreGet();
var newentegrationcode = "";
foreach (var item in parametreler)
{
var encode = entegrationcode();
var YeniGelenDesi = DesiHesabi(item.WebSiparisNo);
var yeniteminyeri = item.TeminYeri;
newentegrationcode = 123+ "" + encode;
ArasOrder.UserName = "";
ArasOrder.Password = "";
ArasOrder.ReceiverName = item.KargoAdSoyad;
ArasOrder.ReceiverPhone1 = item.KargoTelefon;
ArasOrder.ReceiverCityName = item.KargoIlAdi;
ArasOrder.ReceiverTownName = item.KargoIlceAdi;
ArasOrder.ReceiverAddress = item.KargoAdres;
ArasOrder.TradingWaybillNumber = item.WebSiparisNo;
ArasOrder.PieceCount = "1";
ArasOrder.IntegrationCode = newentegrationcode;
ArasOrder.PayorTypeCode = "1";
ArasOrder.IsWorldWide = "0";
ArasOrder.IsCod = "0";
ArasOrder.VolumetricWeight = YeniGelenDesi;
ArasOrder.SenderAccountAddressId = "1071";
ArasTEST.PieceDetail[] ArasPieceDetails = new ArasTEST.PieceDetail[1];
PieceDetail ArasPieceDetail1 = new PieceDetail();
ArasPieceDetail1.BarcodeNumber = newentegrationcode;
ArasPieceDetail1.VolumetricWeight = YeniGelenDesi;
ArasPieceDetail1.Weight = "1";
ArasPieceDetail1.Description = "";
ArasPieceDetails[0] = ArasPieceDetail1;
ArasOrder.PieceDetails = ArasPieceDetails;
var ArasOrderInfo = new ArasTEST.Order[1];
ArasOrderInfo[0] = ArasOrder;
var takipNoResult = ArasService.SetOrder("", "", "");
var ArasOrderResultInfo = takipNoResult[0];
var SonucKodu = takipNoResult[0].ResultCode;
var SonucMesaji = takipNoResult[0].ResultMessage;
var SonucInvoiceKey = takipNoResult[0].InvoiceKey;
}
}
}
You should define the return type and return the instance.
public static ArasTEST aras()
{
// insert code here...
return ArasOrder;
}
Change void to ArasDeneme return type.
Then call like:
var ad = ArasDeneme.aras();
Related
In a list i have 4 rows and I am try to get all the rows of the list but it is giving only one row, how to get all the rows of the list.
I have tried below code
public async Task<ResponseUserModel> get()
{
List<ResponseUserModel> responseUsers = new List<ResponseUserModel>();
using (nae2sasqld0003Entities context = new nae2sasqld0003Entities())
{
var listt = context.Producers.Select(all => all).ToList();
foreach (var item in listt)
{
responseUsers.Add(new ResponseUserModel
{
ProducerName = item.ProducerName,
ResidentState = item.ResidentState,
ResidentCity = item.ResidentCity,
ProducerStatus = item.ProducerStatus,
ProducerCode = item.ProducerCode,
MasterCode = item.MasterCode,
NationalCode = item.NationalCode,
LegacyChubbCodes = item.LegacyChubbCodes,
LegacyPMSCode = item.LegacyPMSCode,
ProducingBranchCode = item.ProducingBranchCode,
CategoryCode = item.CategoryCode
});
}
return responseUsers;
}
}
please let me know where i to fix the issue
Use list to return all:
List<ResponseUserModel> responseUsers = new List<ResponseUserModel>();
then
foreach (var item in listt)
{
responseUsers.Add(new ResponseUserModel
{
ProducerName = item.ProducerName,
ResidentState = item.ResidentState,
ResidentCity = item.ResidentCity,
ProducerStatus = item.ProducerStatus,
ProducerCode = item.ProducerCode,
MasterCode = item.MasterCode,
NationalCode = item.NationalCode,
LegacyChubbCodes = item.LegacyChubbCodes,
LegacyPMSCode = item.LegacyPMSCode,
ProducingBranchCode = item.ProducingBranchCode,
CategoryCode = item.CategoryCode
});
}
return responseUsers;
Note: change return type of the method to IList<ResponseUserModel>
or in this way
using (var context = new nae2sasqld0003Entities())
{
return context.Producers.Select(item =>
new ResponseUserModel
{
ProducerName = item.ProducerName,
ResidentState = item.ResidentState,
ResidentCity = item.ResidentCity,
ProducerStatus = item.ProducerStatus,
ProducerCode = item.ProducerCode,
MasterCode = item.MasterCode,
NationalCode = item.NationalCode,
LegacyChubbCodes = item.LegacyChubbCodes,
LegacyPMSCode = item.LegacyPMSCode,
ProducingBranchCode = item.ProducingBranchCode,
CategoryCode = item.CategoryCode
}).ToList();
}
I am trying to save the entity data using General methods of lightswitch, which is Updating. Below is the following code. I am not able to figure out what I am missing. There is no error in the code or in the UI. Its just that nothing gets saved.
partial void viewFamilyProcessDatas_Updating(viewFamilyProcessData entity)
{
var AutoAddMissingListing = entity.AutoAddMissingListing;
var AutoAddOddLots = entity.AutoAddOddLots;
var DefaultFilterValue = entity.DefaultFilterValue;
var ExcludeZeroNumberOfUnits = entity.ExcludeZeroNumberOfUnits;
//objFamilyProcessData.FamilyID = entity.FamilyID;
var IgnoreForPricing = entity.IgnoreForPricing;
var LimitEndDate = entity.LimitEndDate;
var OffsetFromMaxAsAtDate = entity.OffsetFromMaxAsAtDate;
var PrefilterConstituents = entity.PrefilterConstituents;
var TimeDataExpires = entity.TimeDataExpires;
entity.AutoAddMissingListing = AutoAddMissingListing;
entity.AutoAddOddLots = AutoAddOddLots;
entity.DefaultFilterValue = DefaultFilterValue;
entity.ExcludeZeroNumberOfUnits = ExcludeZeroNumberOfUnits;
entity.IgnoreForPricing = IgnoreForPricing;
entity.LimitEndDate = LimitEndDate;
entity.OffsetFromMaxAsAtDate = OffsetFromMaxAsAtDate;
entity.PrefilterConstituents = PrefilterConstituents;
entity.TimeDataExpires = TimeDataExpires;
//this.DataWorkspace.SolaDBServerData.Details.DiscardChanges();
entity.Details.DiscardChanges();
}
The solution to this finally came to this:
partial void vwFamilyProcessDatas_Updating(vwFamilyProcessData entity)
{
if(entity.Details.EntityState.ToString() == "Modified")
{
var AutoAddMissingListing = entity.AutoAddMissingListing;
var AutoAddOddLots = entity.AutoAddOddLots;
var DefaultFilterValue = entity.DefaultFilterValue;
var ExcludeZeroNumberOfUnits = entity.ExcludeZeroNumberOfUnits;
var IgnoreForPricing = entity.IgnoreForPricing;
var LimitEndDate = entity.LimitEndDate;
var OffsetFromMaxAsAtDate = entity.OffsetFromMaxAsAtDate;
var PrefilterConstituents = entity.PrefilterConstituents;
var TimeDataExpires = entity.TimeDataExpires;
tblFamily objFamily = tblFamilies.Where(f => f.FamilyID == entity.FamilyID).Single();
objFamily.AutoAddMissingListing = AutoAddMissingListing;
objFamily.AutoAddOddLots = AutoAddOddLots;
objFamily.DefaultFilterValue = DefaultFilterValue;
objFamily.ExcludeZeroNumberOfUnits = ExcludeZeroNumberOfUnits;
objFamily.IgnoreForPricing = IgnoreForPricing;
objFamily.LimitEndDate = LimitEndDate;
objFamily.OffsetFromMaxAsAtDate = OffsetFromMaxAsAtDate;
objFamily.PrefilterConstituents = PrefilterConstituents;
objFamily.TimeDataExpires = TimeSpan.Parse(TimeDataExpires);
entity.Details.DiscardChanges();
}}
i am programming in BHO for IE.i have create a button.I want to call a method in that button click.how to call it.
here my code:
htmlFormCollection = objDocument.getElementsByTagName("*");
if (htmlFormCollection.length > 0)
{
foreach (IHTMLElement ihtmlCollectionClass in htmlFormCollection)
{
htmlElementsCollection = (IHTMLElementCollection)ihtmlCollectionClass.all;
foreach (IHTMLElement ihtmlBtnAddClass in htmlElementsCollection)
{
if (ihtmlBtnAddClass.className == "n1tfz")
{
if (flagVal)
{
IHTMLDOMNode divNode = (IHTMLDOMNode)ihtmlBtnAddClass;
var tbl = objDocument.createElement("table");
var tblBody = objDocument.createElement("tbody");
var tabr = objDocument.createElement("tr");
var tabd = objDocument.createElement("td");
var newDiv=objDocument.createElement("div");
newDiv.setAttribute("id","innerdiv11");
var Encryptbutton = objDocument.createElement("input");
Encryptbutton.setAttribute("type", "button");
Encryptbutton.setAttribute("value", "Encrypt");
Encryptbutton.setAttribute("id", "Encr1");
Encryptbutton.style.backgroundColor = "#4d90fe";
Encryptbutton.style.border = "#4787ed";
Encryptbutton.style.color = "White";
Encryptbutton.style.fontSize = "11px";
Encryptbutton.style.fontFamily = "arial,sans-serif";
Encryptbutton.style.width = "47pt";
//Encryptbutton.onclick = ComposeEncrypt();
//Encryptbutton.click();
IHTMLDOMNode newDivVal = (IHTMLDOMNode)newDiv;
IHTMLDOMNode tabdVal = (IHTMLDOMNode)tabd;
IHTMLDOMNode tabrVal = (IHTMLDOMNode)tabr;
IHTMLDOMNode tblBodyVal = (IHTMLDOMNode)tblBody;
IHTMLDOMNode tblVal = (IHTMLDOMNode)tbl;
newDivVal.appendChild((IHTMLDOMNode)Encryptbutton);
tabdVal.appendChild((IHTMLDOMNode)newDivVal);
tabrVal.appendChild((IHTMLDOMNode)tabdVal);
tblBodyVal.appendChild((IHTMLDOMNode)tabrVal);
tblVal.appendChild((IHTMLDOMNode)tblBodyVal);
IHTMLDOMNode divNode1 = (IHTMLDOMNode)ihtmlBtnAddClass;
IHTMLElement head = (IHTMLElement)((IHTMLElementCollection)objDocument.all.tags("head")).item(null, 0);
divNode.insertBefore((IHTMLDOMNode)Encryptbutton, divNode.firstChild);
//Encryptbutton.InvokeMember("click");
flagVal = false;
}
}
if (!flagVal)
break;
}
}
}
method:
public void myfunc()
{
Messgebox.show("hai");
}
i want to call myfunc() in Encryptbutton click event.How to call it.
Thanks
Sanju
i got it.
HTMLButtonElementEvents_Event htmlButtonEvent = Encryptbutton1 as HTMLButtonElementEvents_Event;
htmlButtonEvent.onclick += new HTMLButtonElementEvents_onclickEventHandler(ComposeEncrypt_onclick);
method:
bool ComposeEncrypt_onclick()
{
MessageBox.show("hai");
}
I have made a ajax post and stringifyed my json and send the data to my controller method:
The data that the controller recieves looks like this:
"[\"0041300201\",1610612764,\"WAS\",\"Washington\",2772,\"Trevor Ariza\",\"F\",\"\",\"37:20\",7,10,0.7,6,6,1,2,4,0.5,1,5,6,2,1,0,0,3,22,18]"
My controller method:
public void addBoxScore(string playerstats)
{
Games gamestats = new Games();
gamestats.GAME_ID = playerstats[0];
gamestats.TEAM_ID = playerstats[1];
gamestats.TEAM_ABBREVIATION = playerstats[2].ToString();
gamestats.TEAM_CITY = playerstats[3].ToString();
gamestats.PLAYER_ID = playerstats[4];
gamestats.PLAYER_NAME = playerstats[5].ToString();
gamestats.START_POSITION = playerstats[6].ToString();
gamestats.COMMENT = playerstats[7].ToString();
gamestats.MIN = playerstats[8];
gamestats.FGM = playerstats[9];
gamestats.FGA = playerstats[10];
gamestats.FG_PCT = playerstats[11];
gamestats.FGTHREEM = playerstats[12];
gamestats.FGTHREEA = playerstats[13];
gamestats.FGTHREE_PCT = playerstats[14];
gamestats.FTM = playerstats[15];
gamestats.FTA = playerstats[16];
gamestats.FT_PCT = playerstats[17];
gamestats.OREB = playerstats[18];
gamestats.DREB = playerstats[19];
gamestats.REB = playerstats[20];
gamestats.AST = playerstats[21];
gamestats.STL = playerstats[22];
gamestats.BLK = playerstats[23];
gamestats.TO = playerstats[24];
gamestats.PF = playerstats[25];
gamestats.PTS = playerstats[26];
gamestats.PLUS_MINUS = playerstats[27];
}
When i do this the gamestats.Game_ID becomes "91" instead of "0041300201" as i wanted it to be.
Please use this array or list of string instead of only strings. like this
public void addBoxScore(string[] playerstats)
private void Updated_ModRecFGA()
{
try
{
DRFGAModifiedRecord TABLE = new DRFGAModifiedRecord();
foreach (ArrayFunc Row in ArrayFunc.QueryResult)
{
foreach (ArrayFunc Row2 in ArrayFunc.QueryResult1)
{
TABLE.RecordDocID = Row.FGACol1;
TABLE.DRNo = Row.FGACol2;
TABLE.DDNum = Row.FGACol3;
TABLE.LineNumber = Row.FGACol4;
TABLE.Itemnmbr = Row2.updItemCode;
TABLE.Itemdesc = Row2.updItemDesc;
TABLE.Pallet = Row2.updPallets;
TABLE.BagsNo = Row2.updBagsNo;
TABLE.TotalLoaded = Row2.updTotalKgs;
TABLE.PostStat = Row2.updPostStat;
TABLE.ProdCode = Row2.updProdcode;
TABLE.VariantCode = Row2.updVariantCode;
TABLE.DateModify = DateTime.Now.ToShortDateString();
TABLE.TimeModify = DateTime.Now.ToShortTimeString();
TABLE.UserModify = "Mik";//GlobalvarClass.LogUser;
TABLE.ReasonModify = GlobalvarClass.GetModReasOnDR;
TABLE.FileType = "New";
saveREC(TABLE);
gfunc.MsgBox("Saved", 1);
}
}
ArrayFunc.QueryResult.Clear();
ArrayFunc.QueryResult1.Clear();
GlobalvarClass.GetModReasOnDR = string.Empty;
}
catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); }
}
Is there another proper way to use this kind of code something like this to avoid duplicate? I know it duplicate because of two foreach statement
Just combine the two using linq. Remember to include using System.Linq; in your using clause.
var results = ArrayFunc.QueryResult.SelectMany(l1 => ArrayFunc.QueryResult1, (l1, l2) =>
new DRFGAModifiedRecord
{
RecordDocID = l1.FGACol1,
DRNo = l1.FGACol2,
DDNum = l1.FGACol3,
LineNumber = l1.FGACol4,
Itemnmbr = l2.updItemCode,
Itemdesc = l2.updItemDesc,
Pallet = l2.updPallets,
BagsNo = l2.updBagsNo,
TotalLoaded = l2.updTotalKgs,
PostStat = l2.updPostStat,
ProdCode = l2.updProdcode,
VariantCode = l2.updVariantCode,
DateModify = DateTime.Now.ToShortDateString(),
TimeModify = DateTime.Now.ToShortTimeString(),
UserModify = "Mik",//GlobalvarClass.LogUser
ReasonModify = GlobalvarClass.GetModReasOnDR,
FileType = "New"
}).ToList();
foreach (row in results)
{
saveREC(row);
gfunc.MsgBox("Saved", 1);
}
Alternatively you can do it with a query expression:
var result = (from l1 in ArrayFunc.QueryResult
from l2 in ArrayFunc.QueryResult1
select new DRFGAModifiedRecord { RecordDocID = l1.FGACol1 ... }).ToList();