Exemplo n.º 1
0
        private void qg_button1_Click(object sender, EventArgs e)
        {
            if (!ValidateOK())
            {
                ISBN_text_Validating(ISBN_text, null);
                name_text_Validating(name_text, null);
                dj_text_Validating(dj_text, null);
                data1_text_Validating(data1_text, null);
                pressaaa_text_Validating(pressaaa_text, null);
                typeaaa_text_Validating(typeaaa_text, null);
                sl_text_Validating(sl_text, null);
                return;
            }
            //if (ISBN_text.Text.Trim() == "")
            //{
            //    MessageBox.Show("请输入ISBN号!");
            //    return;
            //}
            //if (name_text.Text.Trim() == "")
            //{
            //    MessageBox.Show("请输入书名!");
            //    return;
            //}
            //if (dj_text.Text.Trim() == "" || !dj_text.Text.IsDecimal() || dj_text.Text.ToDecimal() < 0)
            //{
            //    MessageBox.Show("单价不正常!");
            //    return;
            //}
            //if (pressaaa_text.Text.Trim() == "")
            //{
            //    MessageBox.Show("请输入出版社!");
            //    return;
            //}
            //if (typeaaa_text.Text.Trim() == "")
            //{
            //    MessageBox.Show("请输入图书类别!");
            //    return;
            //}
            //if (sl_text.Text.Trim() == "" || !sl_text.Text.IsInt() || sl_text.Text.ToInt() < 0)
            //{
            //    MessageBox.Show("册数不正常!");
            //    return;
            //}

            string    sqlstring = "";
            DataTable dt;

            sqlstring = "select ISBN号,书名 from booksall where ID!=" + bookid + " and ISBN号='" + ISBN_text.Text.Trim() + "'";
            dt        = return_select(sqlstring);
            if (dt.Rows.Count > 0)
            {
                string temp1 = "";
                temp1 = temp1 + "\rISBN号:" + dt.Rows[0]["ISBN号"].ToString();
                temp1 = temp1 + "\r书名:" + dt.Rows[0]["书名"].ToString();


                MessageBox.Show("数据库中已经存在以下ISBN号的图书" + temp1 + "\r无法修改!");
                return;
            }



            string pressidtempid = "0";
            string press1temp1   = pressaaa_text.Text.Trim();
            string presspytemp1  = MyPinYin.GetFirst(press1temp1);//

            sqlstring = "select ID from press where 出版社='" + press1temp1.Trim() + "'";
            dt        = return_select(sqlstring);
            if (dt.Rows.Count <= 0)
            {
                sqlstring = "insert into press(出版社,拼音) values ('" + press1temp1.Trim() + "','" + presspytemp1 + "')";
                insert_update_delete(sqlstring);
                sqlstring = "select ID from press where 出版社='" + press1temp1.Trim() + "'";
                dt        = return_select(sqlstring);
            }
            pressidtempid = dt.Rows[0]["ID"].ToString();

            string typeidtempid = "0";
            string type1temp1   = typeaaa_text.Text.Trim();
            string typepytemp1  = MyPinYin.GetFirst(type1temp1);//

            sqlstring = "select ID from types where 图书类别='" + type1temp1.Trim() + "'";
            dt        = return_select(sqlstring);
            if (dt.Rows.Count <= 0)
            {
                sqlstring = "insert into types(图书类别,拼音) values ('" + type1temp1.Trim() + "','" + typepytemp1 + "')";
                insert_update_delete(sqlstring);
                sqlstring = "select ID from types where 图书类别='" + type1temp1.Trim() + "'";
                dt        = return_select(sqlstring);
            }
            typeidtempid = dt.Rows[0]["ID"].ToString();


            sqlstring = "select ID from booksall where 出版社ID=" + pressidtempid + " and 书名='" + name_text.Text.Trim() + "'";
            sqlstring = sqlstring + " and ID!=" + bookid;
            dt        = return_select(sqlstring);
            if (dt.Rows.Count > 0)
            {
                string temp1 = "";
                temp1 = temp1 + "\rISBN号:" + dt.Rows[0]["ISBN号"].ToString();
                temp1 = temp1 + "\r书名:" + name_text.Text.Trim();
                temp1 = temp1 + "\r出版社:" + pressaaa_text.Text.Trim();

                DialogResult dr = MessageBox.Show("数据库中已经存在以下图书目录?\r" + temp1 + "\r是否确定修改?", "提示", MessageBoxButtons.OKCancel);
                if (dr == DialogResult.Cancel)
                {
                    return;
                }
            }

            string namebytemp1 = MyPinYin.GetFirst(name_text.Text.Trim());

            sqlstring = "update booksall set ISBN号='" + ISBN_text.Text.Trim() + "',书名='" + name_text.Text.Trim() + "',拼音='" + namebytemp1 + "'"
                        + ",单价=" + dj_text.Text + ",出版社ID=" + pressidtempid + ",类别ID=" + typeidtempid + ",册数=" + sl_text.Text
                        + ",出版日期=(convert(varchar(10),'" + data1_text.Value.ToShortDateString().ToString() + "',120))"
                        + " where ID=" + bookid;
            insert_update_delete(sqlstring);

            booksall frm1 = (booksall)this.Owner;
            //frm1.auto();
            DataTable owner_dt = frm1.grid_datasource();

            DataRow[] rows = owner_dt.Select("ID=" + bookid);
            rows[0]["ISBN号"] = ISBN_text.Text.Trim();
            rows[0]["书名"]    = name_text.Text.Trim();
            rows[0]["单价"]    = dj_text.Text.Trim();
            rows[0]["出版社ID"] = pressidtempid;
            rows[0]["类别ID"]  = typeidtempid;
            rows[0]["册数"]    = sl_text.Text.Trim();
            rows[0]["出版日期"]  = data1_text.Value.ToShortDateString().ToString();
            rows[0]["出版社"]   = pressaaa_text.Text.Trim();
            rows[0]["图书类别"]  = typeaaa_text.Text.Trim();

            Close();
        }
Exemplo n.º 2
0
        private void qg_button1_Click(object sender, EventArgs e)
        {
            monthCalendar1.Visible = false;

            if (!ValidateOK())
            {
                ISBN_text_Validating(ISBN_text, null);
                name_text_Validating(name_text, null);
                dj_text_Validating(dj_text, null);
                data1_text_Validating(data1_text, null);
                pressaaa_text_Validating(pressaaa_text, null);
                typeaaa_text_Validating(typeaaa_text, null);
                sl_text_Validating(sl_text, null);
                return;
            }


            //if (ISBN_text.Text.Trim() == "")
            //{
            //    MessageBox.Show("请输入ISBN号!");
            //    return;
            //}
            //if (name_text.Text.Trim() == "")
            //{
            //    MessageBox.Show("请输入书名!");
            //    return;
            //}
            //if (dj_text.Text.Trim()=="" || !dj_text.Text.IsDecimal()|| dj_text.Text.ToDecimal()<0)
            //{
            //    MessageBox.Show("单价不正常!");
            //    return;
            //}
            //if (pressaaa_text.Text.Trim() == "")
            //{
            //    MessageBox.Show("请输入出版社!");
            //    return;
            //}
            //if (typeaaa_text.Text.Trim() == "")
            //{
            //    MessageBox.Show("请输入图书类别!");
            //    return;
            //}
            //if (sl_text.Text.Trim()=="" || !sl_text.Text.IsInt() || sl_text.Text.ToInt()<0)
            //{
            //    MessageBox.Show("册数不正常!");
            //    return;
            //}

            string  isbnstring  = ISBN_text.Text.Trim();
            string  namestring  = name_text.Text.Trim();
            decimal djtemp1     = dj_text.Value;
            string  pressstring = pressaaa_text.Text.Trim();

            string  typestring = typeaaa_text.Text.Trim();
            decimal sltemp1    = sl_text.Value;

            string    sqlstring = "";
            DataTable dt;

            sqlstring = "select *,出版社=isnull((select 出版社 from press where ID=b.出版社ID),'') from booksall b where ISBN号='" + isbnstring + "'";
            dt        = return_select(sqlstring);
            if (dt.Rows.Count > 0)
            {
                string temp1 = "\rISBN号:" + isbnstring;
                temp1 = temp1 + "\r 书名:" + dt.Rows[0]["书名"].ToString();
                temp1 = temp1 + "\r 出版社:" + dt.Rows[0]["出版社"].ToString();

                MessageBox.Show("图书目录表中已经存在相同的ISBN号" + temp1 + "\r 请修改ISBN号!");
                return;
            }


            string pressidtempid = "0";
            string press1temp1   = pressaaa_text.Text.Trim();
            string presspytemp1  = MyPinYin.GetFirst(press1temp1);//

            sqlstring = "select ID from press where 出版社='" + press1temp1.Trim() + "'";
            dt        = return_select(sqlstring);
            if (dt.Rows.Count <= 0)
            {
                sqlstring = "insert into press(出版社,拼音) values ('" + press1temp1.Trim() + "','" + presspytemp1 + "')";
                insert_update_delete(sqlstring);
                sqlstring = "select ID from press where 出版社='" + press1temp1.Trim() + "'";
                dt        = return_select(sqlstring);
            }
            pressidtempid = dt.Rows[0]["ID"].ToString();

            string typeidtempid = "0";
            string type1temp1   = typeaaa_text.Text.Trim();
            string typepytemp1  = MyPinYin.GetFirst(type1temp1);//

            sqlstring = "select ID from types where 图书类别='" + type1temp1.Trim() + "'";
            dt        = return_select(sqlstring);
            if (dt.Rows.Count <= 0)
            {
                sqlstring = "insert into types(图书类别,拼音) values ('" + type1temp1.Trim() + "','" + typepytemp1 + "')";
                insert_update_delete(sqlstring);
                sqlstring = "select ID from types where 图书类别='" + type1temp1.Trim() + "'";
                dt        = return_select(sqlstring);
            }
            typeidtempid = dt.Rows[0]["ID"].ToString();


            sqlstring = "select * from booksall where 出版社ID=" + pressidtempid + " and 书名='" + name_text.Text.Trim() + "'";
            dt        = return_select(sqlstring);
            if (dt.Rows.Count > 0)
            {
                string temp1 = "";
                temp1 = temp1 + "\rISBN号:" + dt.Rows[0]["ISBN号"].ToString();
                temp1 = temp1 + "\r书名:" + name_text.Text.Trim();
                temp1 = temp1 + "\r出版社:" + pressaaa_text.Text.Trim();


                DialogResult dr = MessageBox.Show("数据库中已经存在以下图书目录?" + temp1 + "\r是否继续增加?", "提示", MessageBoxButtons.OKCancel);
                if (dr == DialogResult.Cancel)
                {
                    return;
                }
            }

            string namebytemp1 = MyPinYin.GetFirst(name_text.Text.Trim());

            sqlstring = "insert into booksall(ISBN号,书名,拼音,单价,出版社ID,类别ID,册数,出版日期"
                        + ") values ("
                        + "'" + ISBN_text.Text.Trim() + "','" + name_text.Text.Trim() + "','" + namebytemp1 + "'," + dj_text.Text + "," + pressidtempid + "," + typeidtempid + "," + sl_text.Text + ""
                        + ",(convert(varchar(10),'" + data1_text.Value.ToShortDateString().ToString() + "',120))"
                        + ")";
            insert_update_delete(sqlstring);

            sqlstring = "select max(ID) ID from booksall where ISBN号='" + isbnstring.Trim() + "'";
            dt        = return_select(sqlstring);
            string bookidtempid = "0";

            if (dt.Rows.Count > 0)
            {
                bookidtempid = dt.Rows[0]["ID"].ToString();
            }

            #region 执行父窗体的命令
            booksall  frm1     = (booksall)this.Owner;
            DataTable owner_dt = frm1.grid_datasource();
            DataRow   row      = owner_dt.NewRow();
            row["ID"]    = bookidtempid;
            row["ISBN号"] = ISBN_text.Text.Trim();
            row["书名"]    = name_text.Text.Trim();
            row["单价"]    = dj_text.Text;
            row["出版社ID"] = pressidtempid;
            row["出版社"]   = pressaaa_text.Text.Trim();
            row["类别ID"]  = typeidtempid;
            row["图书类别"]  = typeaaa_text.Text.Trim();
            row["册数"]    = sl_text.Text;
            row["出版日期"]  = data1_text.Value.ToShortDateString().ToString();
            row["金额"]    = Math.Round(dj_text.Value * sl_text.Value, 2);
            frm1.grid_add(row);
            #endregion

            auto();
            auto_tag();
            //booksall frm1 = (booksall)this.Owner;
            //frm1.auto();

            ////((booksall)Parent).auto();
            //if ((this.MdiParent != null) && (this.MdiParent is booksall))
            //    (this.MdiParent as booksall).auto();
            //Close();
        }