我有它由特定任務xml
節點的字符串,項目列表的字符串,我通過這兩項任務和項目列表進行迭代,並調用另一個功能並通過任務和項目列表,但它給了我一個錯誤best overloaded method and it has some invalid argument
。我假設它是一個類型轉換錯誤。如何將字符串類型轉換爲任務型
這裏是我的代碼:
private void addtask(object sender,RoutedEventArgs e)
{
foreach (object item in tasklistBox.Items)
{
var listBoxItem = tasklistBox.ItemContainerGenerator.ContainerFromItem(item);
var myContentPresenter = FindVisualChild<ContentPresenter>(listBoxItem);
var myDataTemplate = myContentPresenter.ContentTemplate;
var mydata = (System.Windows.Controls.Label)myDataTemplate.FindName("tasklabel", myContentPresenter);
var xmlElement = (XmlElement)mydata.Content;
//System.Windows.Forms.MessageBox.Show(xmlElement.InnerText);
foreach (Harvest_Project item1 in Globals._globalController.harvestManager._PROJECTLIST)
{
Globals._globalController.harvestManager.assignTaskToProject(xmlElement.InnerText,item1);
}
}
}
和另一類我打電話的功能:
public void assignTaskToProject(Harvest_Task task, Harvest_Project project)
{
Console.WriteLine("Assigning Task to Project");
string assignXML = "<task>" +
"<id type=\"integer\">" + task._id + "</id> " +
"</task>";
sendPOSTRequest(uri + _GETALLPROJECTS + "/" + project._id + "/task_assignments", assignXML);
}
的Harvest_Task
類是在這裏:
private bool _billable_by_default;
private bool _deactivated;
private float _default_hourly_rate=0;
public int _id { get; set; }
private bool _is_default;
public string _name { get; set; }
private DateTime _created_at;
private DateTime _updated_at;
private XmlNode _node;
public Harvest_Task()
{ }
public Harvest_Task(XmlNode node)
{
this._node = node;
this._name = node.SelectSingleNode("name").InnerText;
this._created_at = Harvest_Base.storeTime(node.SelectSingleNode("created-at").InnerText);
this._updated_at = Harvest_Base.storeTime(node.SelectSingleNode("updated-at").InnerText);
this._is_default = bool.Parse(node.SelectSingleNode("is-default").InnerText);
this._deactivated = bool.Parse(node.SelectSingleNode("deactivated").InnerText);
float.TryParse(node.SelectSingleNode("default-hourly-rate").InnerText,out this._default_hourly_rate);
this._id = int.Parse(node.SelectSingleNode("id").InnerText);
}
public Harvest_Task(string name, float defaultHourlyRate)
{
this._name = name;
this._default_hourly_rate = defaultHourlyRate;
}
public string createXMLAddEntry()
{
string returnXML = "<task>" +
"<billable-by-default type=\"boolean\">true</billable-by-default>" +
"<default-hourly-rate type=\"decimal\">"+this._default_hourly_rate+"</default-hourly-rate>" +
"<is-default type=\"boolean\">true</is-default>" +
"<name>" + this._name + "</name> " +
"</task>";
return returnXML;
}
的Harvest_Project
類在這裏
public string _name { get; set; }
private DateTime _over_budget_notified_at;
private bool _billable;
private DateTime _created_at;
private bool _active;
private enum _bill_by { Tasks, People, none };
public int _client_id = 0;
private string _code;
private string _notes;
private enum _budget_by { project, project_cost, task, person, none };
private float _budget = 0; //Budget in hrs
private DateTime _latest_record_at;
private DateTime _earliest_record_at;
private int _fees = 0;
public int _id { get; set; }
private DateTime _updated_at;
private XmlNode _node;
public int getId() { return this._id; }
public Harvest_Project(XmlNode node)
{
this._node = node;
this._name = node.SelectSingleNode("name").InnerText;
this._created_at = storeTime(node.SelectSingleNode("created-at").InnerText);
this._updated_at = storeTime(node.SelectSingleNode("updated-at").InnerText);
this._over_budget_notified_at = storeTime(node.SelectSingleNode("over-budget-notified-at").InnerText);
this._latest_record_at = storeTime(node.SelectSingleNode("hint-latest-record-at").InnerText);
this._earliest_record_at = storeTime(node.SelectSingleNode("hint-earliest-record-at").InnerText);
this._billable = bool.Parse(node.SelectSingleNode("billable").InnerText);
try
{
this._id = Convert.ToInt32(getXmlNode("id", node));
this._client_id = Convert.ToInt32(getXmlNode("client-id", node));
this._budget = float.Parse(getXmlNode("budget", node));
this._fees = Convert.ToInt32(getXmlNode("fees", node));
}
catch (OverflowException e)
{
Console.WriteLine("The number cannot fit in an Int32.");
}
catch (FormatException e)
{
Console.WriteLine("The string is not a valid integer");
}
this._code = node.SelectSingleNode("code").InnerText;
this._notes = node.SelectSingleNode("notes").InnerText;
}
此功能有Harvest_task
和Harvest_Project
類,我打電話這個功能,但無法呼叫。此行給出錯誤
Globals._globalController.harvestManager.assignTaskToProject(xmlElement.InnerText,item1);
要使用哪種轉換?我堅持
任何幫助嗎?謝謝
你可以分享你的XML爲XMLELEMENT和Harvest_Task類? – pushpraj
@pushpraj是的,我將分享類和XML文件中的圖像 – Safwan
你的XML似乎缺少這是在'assignTaskToProject'方法所需的'id'。它是正確的XML?此外,我發現它很難混淆檢索xmlElement的方式,這對你是否正確? – pushpraj