Make ConterSale with Serial Numbers

Hi, I have a custom code about CounterSale and i can not create a new row on SelectedSerialNumbers and the invoice is 0

here my Custom Code:

  	    SalesOrderAdapter SO = new SalesOrderAdapter(this.oTrans);
             SO.BOConnect();

			int OrderNum=int.Parse(rowSelected.Cells[3].Value.ToString());
			int CustNum=int.Parse(rowSelected.Cells[5].Value.ToString());
			string Correo=rowSelected.Cells[7].Value.ToString();
			SO.GetByID(OrderNum);

			bool bout=false;
			bool ODirecto=true;
			string outs="";
			string PackNum = "";
			string EpicError = "";
			string rMess = "";
		    string NegInv = string.Empty;
		    string NegInvQty = string.Empty;
		    int InvoiceNum = 0;
		    SO.ValidateInvQty(OrderNum, out NegInv, out NegInvQty);
			Guid wsid = Guid.NewGuid();
			SO.GetSelectSerialNumbersParams("4710947659556-9","APTZ","GENERAL",1,"",wsid);

//GetByID
//GetAttributes
//GetAttributesForExtensionTable
//GetSerialNumFormat

			string A,B,C;
bool D=false;

			 SelectedSerialNumbersAdapter  SN =  new SelectedSerialNumbersAdapter(this.oTrans);
             SN.BOConnect();


			SN.GetSerialNumFormat("4710947659556-9","","",0,"Zapopan");

			SN.GetNextSN("4710947659556-9","","",0,"Zapopan",out A,out B,out C,out D);



			Ice.Lib.Searches.SearchOptions opts = new Ice.Lib.Searches.SearchOptions(Ice.Lib.Searches.SearchMode.AutoSearch);
			opts.DataSetMode = Ice.Lib.Searches.DataSetMode.ListDataSet;
			string whereClause = "Company = 'ON02' and PartNum = '4710947659556-9' and WarehouseCode = 'APTZ' and BinNum = 'GENERAL' and SNStatus = 'INVENTORY' and PCID = ''";
			opts.NamedSearch.WhereClauses.Add("SerialNo",whereClause);
			bool MorePages = false;

			 SerialNoAdapter  SNO =  new SerialNoAdapter(this.oTrans);
             SNO.BOConnect();

			SNO.GetList(opts,out MorePages);
			
          DataRow Row = SO.SalesOrderData.SelectedSerialNumbers.NewRow();   
//SO.SalesOrderData.SelectedSerialNumbers Row= SO.SalesOrderData.SelectedSerialNumbers.NewRow();
Row.BeginEdit();
Row["Company"]="ON02";
Row["PartNum"]="4710947659556-9";
Row["SerialNumber"]="00000000000000000007";
Row["Scrapped"]="False";
Row["Voided"]="False";
Row["SNBaseNumber"]="00000000000000000007";
//Row["PassedInspection"]="False";
//Row["Deselected"]="False";
//Row["PreventDeselect"]="False";
//Row["KRowBLbrAction"]="0";
//Row["NotSavedToDB"]="True";
Row["RowMod"]="A";
Row.EndEdit();

  SO.SalesOrderData.SelectedSerialNumbers.Rows.Add(Row);

			SO.ValidateSNs();


		    SO.CheckCustomerCreditLimit(OrderNum, CustNum, out bout, out outs);
		    //for (int i = 0; i < (Adap.SalesOrderData.OrderDtl.Rows.Count - 1); i++)
		    //{
			int i = 0;

			foreach(DataRow dr in SO.SalesOrderData.OrderDtl.Rows)
			{		      
		        SO.SalesOrderData.Tables["OrderDtl"].Rows[i].BeginEdit();
		        SO.SalesOrderData.OrderDtl[i]["ProcessCounterSale"] = true;
		        SO.SalesOrderData.OrderDtl[i]["RowMod"] = "U";
		        SO.SalesOrderData.Tables["OrderDtl"].Rows[i].EndEdit();
		        //SO.MasterUpdate(true, true, "OrderDtl", CustNum, OrderNum, false, out bout, out outs, out outs, out EpicError, out outs, out outs);
				i++;
		    }



		SO.ValidateSNs();

		    SO.ProcessCounterSale(OrderNum, true, ODirecto, true, "STOP", out PackNum, out InvoiceNum, out EpicError);

		    SO.Update();

GetSelectSerialNumbersParams will return a dataset with only a single row of parameters needed to select serial numbers.

This dataset is then passed to another serial entry form.

I think it would be best to do a client trace for a regular order with serial numbers and then try to replicate the process for Counter Sales.

Unfortunately I’m not really familiar with serial numbers.