Example #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBox1.Text))
            {
                MessageBox.Show("定价不能为空!");
                textBox1.Focus();
                return;
            }
            IDictionary <string, string> parameters = new Dictionary <string, string>();

            parameters.Add("isbn", label7.Text);
            parameters.Add("fixedPrice", textBox1.Text);
            parameters.Add("name", label9.Text);
            parameters.Add("press", ("" == label8.Text) ? "无" : label8.Text);
            parameters.Add("author", ("" == label10.Text)? "无" : label10.Text);
            string gbookid;

            if (yg.InsertNewBookInfo(parameters, out gbookid))
            {
                YouGeWinformApi.Localbookinfo lbi = new YouGeWinformApi.Localbookinfo();
                lbi.author     = label10.Text;
                lbi.fixedprice = textBox1.Text;
                lbi.guid       = gbookid;
                lbi.imgpath    = "";
                lbi.isbn       = label7.Text;
                lbi.name       = label9.Text;
                lbi.press      = label8.Text;
                if (ygw.InsertNewBookInfo(lbi, out gbookid))
                {
                    MessageBox.Show("添加成功,重新搜索即可查到");
                    return;
                }
            }
            MessageBox.Show("添加失败,请在网络状态良好的情况下重试");
            MyOperation.DebugPrint("复制图书信息失败,请在网络状态良好的情况下重试");
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBox1.Text))
            {
                MessageBox.Show("请输入书名");
                textBox1.Focus();
                return;
            }

            if (string.IsNullOrEmpty(textBox2.Text))
            {
                MessageBox.Show("请输入作者");
                textBox2.Focus();
                return;
            }

            if (string.IsNullOrEmpty(textBox3.Text))
            {
                MessageBox.Show("请输入出版社");
                textBox3.Focus();
                return;
            }

            if (string.IsNullOrEmpty(textBox4.Text))
            {
                MessageBox.Show("请输入定价");
                textBox4.Focus();
                return;
            }

            if (string.IsNullOrEmpty(textBox5.Text))
            {
                MessageBox.Show("请输入ISBN");
                textBox5.Focus();
                return;
            }

            IDictionary <string, string> parameters = new Dictionary <string, string>();

            parameters.Add("isbn", textBox5.Text);
            parameters.Add("fixedPrice", textBox4.Text);
            parameters.Add("name", textBox1.Text);
            parameters.Add("press", textBox3.Text);
            parameters.Add("author", textBox2.Text);
            string gbookid;

            if (yg.InsertNewBookInfo(parameters, out gbookid))
            {
                YouGeWinformApi.Localbookinfo lbi = new YouGeWinformApi.Localbookinfo();
                lbi.author     = textBox2.Text;
                lbi.fixedprice = textBox4.Text;
                lbi.guid       = gbookid;
                lbi.imgpath    = "";
                lbi.isbn       = textBox5.Text;
                lbi.name       = textBox1.Text;
                lbi.press      = textBox3.Text;
                if (ygw.InsertNewBookInfo(lbi, out gbookid))
                {
                    MessageBox.Show("添加成功,重新搜索即可查到");
                    this.Dispose();
                    return;
                }
            }
            MessageBox.Show("添加失败,请在网络状态良好的情况下重试");
            MyOperation.DebugPrint("添加图书信息失败,请在网络状态良好的情况下重试");
        }
Example #3
0
        public DataTable SearchBookinfoByIsbn(string isbn)
        {
            DataTable dt = ygw.SearchBookinfoByIsbn(isbn);

            if (dt.Rows.Count > 0)
            {
                //如果本地已经有图书信息,就直接返回给用户
                return(dt);
            }
            //本地没有图书信息,从主数据库取信息
            dt = new DataTable();
            //初始化dt结构
            dt.Columns.Add("id", System.Type.GetType("System.Int32"));
            dt.Columns.Add("name", System.Type.GetType("System.String"));
            dt.Columns.Add("press", System.Type.GetType("System.String"));
            dt.Columns.Add("isbn", System.Type.GetType("System.String"));
            dt.Columns.Add("price", System.Type.GetType("System.String"));
            dt.Columns.Add("author", System.Type.GetType("System.String"));
            try
            {
                JObject jo;
                if (yg.SearchBookinfoByIsbn(isbn, out jo))
                {
                    YouGeWinformApi.Localbookinfo lbi = new YouGeWinformApi.Localbookinfo();
                    lbi.author     = jo["data"]["author"].ToString();
                    lbi.fixedprice = jo["data"]["fixedPrice"].ToString();
                    lbi.guid       = jo["data"]["id"].ToString();;
                    lbi.imgpath    = jo["data"]["imgpath"].ToString();
                    lbi.isbn       = jo["data"]["isbn"].ToString();
                    lbi.name       = jo["data"]["name"].ToString();
                    lbi.press      = jo["data"]["press"].ToString();
                    //如果从主数据库取到了图书信息,那么就写入本地数据库
                    string newid;
                    if (ygw.InsertNewBookInfo(lbi, out newid))
                    {
                        //写入成功之后,将dt变量赋值并返回
                        DataRow dr = dt.NewRow();
                        dr["id"]     = Convert.ToInt32(newid);
                        dr["name"]   = lbi.name;
                        dr["press"]  = lbi.press;
                        dr["isbn"]   = lbi.isbn;
                        dr["price"]  = lbi.fixedprice;
                        dr["author"] = lbi.author;
                        dt.Rows.Add(dr);
                        return(dt);
                    }
                    else
                    {
                        return(dt);
                    }
                }
                else
                {
                    return(dt);
                }
            }
            catch
            {
                //异常返回不一定是错误,jo对象解析完毕也会走到这里
                return(dt);
            }
        }