Beispiel #1
0
        private async void onClick(object sender, RoutedEventArgs e)
        {
            Button save = (Button)sender;

            save.IsEnabled = false;
            string data = "";

            if (Url.Text != "")
            {
                data += "url=" + Url.Text;
            }
            else
            {
                data += "text=" + Text.Text;
            }

            //sendRequest(data);
            AppSettings settings = new AppSettings();
            String      message  = await SendToReaderAPI.sendDoc(settings.UserName, settings.Password, Url.Text, Author.Text, Title.Text, Text.Text);

            if (message == "Operatoin successful!")
            {
                clearData();
            }
            else if (message.Substring(0, "Not Found".Length) == "Not Found")
            {
                string url = message.Substring("Not Found:".Length);
                try
                {
                    W2RTask task = new W2RTask();
                    task._uri = url;


                    TaskDataContext dataContext = new TaskDataContext(TaskDataContext.DBConnectionString);
                    Table <W2RTask> table       = dataContext.GetTable <W2RTask>();
                    table.InsertOnSubmit(task);

                    dataContext.SubmitChanges();
                    message = "Document will be sent when phone connects to network";
                    clearData();
                }
                catch (DbException exp)
                {
                    string strUniqueConstErr = "A duplicate value cannot be inserted into a unique index.";
                    if (strUniqueConstErr == exp.Message.Substring(0, strUniqueConstErr.Length))
                    {
                        message = "This url is already queued";
                        clearData();
                    }
                    else
                    {
                        message = exp.Message;
                    }
                }
            }

            // Inform user with appropriate message
            MessageBox.Show(message, "Compose", MessageBoxButton.OK);
            save.IsEnabled = true;
        }