コード例 #1
0
ファイル: DatabaseInstance.cs プロジェクト: a864610877/src
        public int Delete <T>(T item, string tableName)
        {
            var       inserter = new DeleteCommandBuilder <T>(_database, Connection, tableName, Transaction);
            DbCommand command  = inserter.Build(item);

            return(command.ExecuteNonQuery());
        }
コード例 #2
0
    public void Build_Generates_Command_With_Parameters()
    {
        // Arrange
        var input = new DeleteCommandBuilder()
                    .From("MyTable")
                    .Where("Field1 = @Field1")
                    .And("Field2 = @Field2")
                    .And("Field3 = @Field3")
                    .AppendParameters(new { Field1 = "Value1", Field2 = "Value2", Field3 = "Value3" });

        // Act
        var actual = input.Build();

        // Assert
        actual.Operation.Should().Be(Abstractions.DatabaseOperation.Delete);
        actual.CommandText.Should().Be("DELETE FROM MyTable WHERE Field1 = @Field1 AND Field2 = @Field2 AND Field3 = @Field3");
        actual.CommandParameters.Should().BeAssignableTo <IDictionary <string, object> >();
        var parameters = actual.CommandParameters as IDictionary <string, object>;

        if (parameters != null)
        {
            parameters.Should().HaveCount(3);
            parameters.Keys.Should().BeEquivalentTo(new[] { "Field1", "Field2", "Field3" });
            parameters.Values.Should().BeEquivalentTo(new[] { "Value1", "Value2", "Value3" });
        }
    }
コード例 #3
0
        protected void dgvVenderList_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string sql             = "delete from Vendor where vendor_id = '" + ((Label)dgvVenderList.Rows[e.RowIndex].Cells[0].FindControl("Label1")).Text + "'";
            DeleteCommandBuilder u = new DeleteCommandBuilder();

            u.ExecuteNonQuery(sql);
            dgvVenderList.DataSource = getAllVendor("");
            dgvVenderList.DataBind();
        }
コード例 #4
0
ファイル: EntityWriter.cs プロジェクト: jej666/Skeleton
        private int DeleteCommand(TEntity entity)
        {
            EnsureEntityIdExists(entity);

            var builder = new DeleteCommandBuilder <TEntity>(
                _metadataProvider, entity);

            return(_database.Execute(builder.SqlCommand));
        }
コード例 #5
0
    public void Build_Throws_When_TableName_Is_Missing()
    {
        // Arrange
        var input = new DeleteCommandBuilder();

        // Act & Assert
        input.Invoking(x => x.Build())
        .Should().Throw <InvalidOperationException>()
        .WithMessage("table name is missing");
    }
コード例 #6
0
        //if (e.Row.RowType != DataControlRowType.DataRow)
        //    {
        //        return;
        //    }
        //    DataRowView drv = e.Row.DataItem as DataRowView;

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int    id                = e.RowIndex;
            string userId            = GridView1.Rows[id].Cells[1].Text;
            string sqldel            = "delete from shatter_Parts_Password where userid = '" + userId + "'";
            DeleteCommandBuilder dcb = new DeleteCommandBuilder();

            dcb.ExecuteNonQuery(sqldel);
            Response.Redirect("UserManage.aspx");
        }
コード例 #7
0
        protected void gvShowData_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string id    = (gvShowData.Rows[e.RowIndex].Cells[0].FindControl("hfId") as HiddenField).Value;
            string sql   = "delete from BarCodeRecords where id ='" + id + "'";
            int    count = new DeleteCommandBuilder().ExecuteNonQuery(sql);

            if (count != 0)
            {
                btnSearch_Click(sender, e as EventArgs);
            }
        }
コード例 #8
0
        private async Task <int> DeleteCommand(TEntity entity)
        {
            EnsureEntityIdExists(entity);

            var builder = new DeleteCommandBuilder <TEntity>(
                _metadataProvider, entity);

            return(await _database.ExecuteAsync(
                       builder.SqlCommand)
                   .ConfigureAwait(false));
        }
コード例 #9
0
        protected void gvAddData_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            string D_id    = (gvAddData.Rows[e.RowIndex].FindControl("hfDetailId") as HiddenField).Value;
            string c       = "select Bill_id from tmp_pk_detail where Detail_id ='" + D_id + "'";
            string bill_id = new SelectCommandBuilder().ExecuteDataTable(c).Rows[0][0].ToString();
            string sql1    = "delete from tmp_pk_detail where Detail_id ='" + D_id + "'";
            int    count   = new DeleteCommandBuilder().ExecuteNonQuery(sql1);
            string dsql    = "SELECT COUNT(*) AS COUNTa FROM tmp_pk_detail where Bill_id = '" + bill_id + "'";
            int    p       = Convert.ToInt32(new SelectCommandBuilder().ExecuteScalar(dsql));

            if (p == 0)
            {
                string sqlc = "delete from tmp_pk_bill where Bill_id = '" + bill_id + "'";
                count += new DeleteCommandBuilder().ExecuteNonQuery(sqlc);
            }
            if (count != 0)
            {
                string    sql = @"SELECT a.Bill_id,a.Detail_id,goods.goods_name,goods.spec,goods.cz, goods.ys,goods.goods_unit,a.pch,a.hwh as 'hwh',a.Qty,a.price,customer_name = (select cc.customer_name  
						from prd_dictate bb,batch aa,customer cc,xsht dd where aa.dictate_id = bb.dictate_id and aa.batch_id = a.batch_id and bb.order_id = dd.xsht_id and dd.customer_id = cc.customer_id )
                        FROM tmp_pk_detail a,goods,sccj WHERE ( goods.sccj_id *= sccj.sccj_id) and ( a.Goods_id = goods.goods_id )and  a.bill_id='" + ViewState["billId"].ToString().Trim() + "'";
                DataTable dt  = new SelectCommandBuilder().ExecuteDataTable(sql);
                aList.Clear();
                if (dt != null && dt.Rows.Count != 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        AddData a = new AddData()
                        {
                            id            = dt.Rows[i]["Detail_id"].ToString(),
                            pm            = dt.Rows[i]["goods_name"].ToString(),
                            spec          = dt.Rows[i]["spec"].ToString(),
                            cz            = dt.Rows[i]["cz"].ToString(),
                            ys            = dt.Rows[i]["ys"].ToString(),
                            goods_unit    = dt.Rows[i]["goods_unit"].ToString(),
                            pch           = dt.Rows[i]["pch"].ToString(),
                            hwh           = dt.Rows[i]["hwh"].ToString(),
                            pdsl          = dt.Rows[i]["qty"].ToString() == "" ? "0.00" : Convert.ToDecimal(dt.Rows[i]["qty"]).ToString("0.##"),
                            Price         = dt.Rows[i]["price"].ToString() == "" ? "0.00" : Convert.ToDecimal(dt.Rows[i]["price"]).ToString("0.##"),
                            total         = dt.Rows[i]["price"].ToString() == "" ? "0.00" : (Convert.ToDecimal(dt.Rows[i]["qty"]) * Convert.ToDecimal(dt.Rows[i]["price"])).ToString("0.##"),
                            customer_name = dt.Rows[i]["customer_name"].ToString()
                        };
                        aList.Add(a);
                    }
                }
                gvAddData.DataSource = aList;
                gvAddData.DataBind();
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "focus", "<script>alert('删除失败!')</script>");
            }
        }
コード例 #10
0
        protected void gvDetail_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string sql = "delete from BarCodeRecords where id = '" + gvDetail.Rows[e.RowIndex].Cells[2].Text.Trim() + "'";
            int    o   = new DeleteCommandBuilder().ExecuteNonQuery(sql);

            if (o > 0)
            {
                gvShowData_SelectedIndexChanged(sender, e as EventArgs);
            }
            else
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "<script>alert('取消失败')</script>", false);
            }
        }
コード例 #11
0
        protected void gvShowData_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string sql = "delete from BarCodeRecords where goods_name = '" + gvShowData.Rows[e.RowIndex].Cells[3].Text.Trim() + "' and create_date BETWEEN CONVERT(DATETIME,'" + txtStartDate.Text + @"', 102) AND CONVERT(DATETIME, '" + txtEndDate.Text + @"', 102)";
            int    o   = new DeleteCommandBuilder().ExecuteNonQuery(sql);

            if (o > 0)
            {
                btnSearch_Click(sender, e as EventArgs);
            }
            else
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "<script>alert('取消失败')</script>", false);
            }
        }
コード例 #12
0
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            int c = new DeleteCommandBuilder(constr, "").ExecuteNonQuery("delete from goods_tmp where goods_id = '" + ViewState["id"].ToString() + "'");

            if (c != 0)
            {
                Response.Write("<script>alert('删除成功!')</script>");
                dgvList.DataSource = getConfirmGoodsList(ViewState["id"].ToString());
                dgvList.DataBind();
            }
            else
            {
                Response.Write("<script>alert('删除失败!')</script>");
            }
        }
コード例 #13
0
 protected void ButtonDelete_Click(object sender, EventArgs e)
 {
     if (TextBoxPwd.Text.Equals("123456"))
     {
         string id = Request.QueryString["id"];
         DeleteCommandBuilder dcb = new DeleteCommandBuilder();
         string sql = "delete  from shatter_Parts where id = " + id + "";
         dcb.ExecuteNonQuery(sql);
         Response.Redirect("index.aspx");
     }
     else
     {
         Response.Write("<script>alert('密码不正确')</script>");
     }
 }
コード例 #14
0
    public void Build_Generates_Command_Without_Where_Statement()
    {
        // Arrange
        var input = new DeleteCommandBuilder().From("MyTable");

        // Act
        var actual = input.Build();

        // Assert
        actual.Operation.Should().Be(Abstractions.DatabaseOperation.Delete);
        actual.CommandText.Should().Be("DELETE FROM MyTable");
        actual.CommandParameters.Should().BeAssignableTo <IDictionary <string, object> >();
        var parameters = actual.CommandParameters as IDictionary <string, object>;

        parameters.Should().BeEmpty();
    }
コード例 #15
0
    public void Build_Generates_Command_With_OutputValues()
    {
        // Arrange
        var input = new DeleteCommandBuilder()
                    .From("MyTable")
                    .Where("Field1 = @Field1")
                    .And("Field2 = @Field2")
                    .And("Field3 = @Field3")
                    .AddOutputFields("Field1", "Field2");

        // Act
        var actual = input.Build();

        // Assert
        actual.Operation.Should().Be(Abstractions.DatabaseOperation.Delete);
        actual.CommandText.Should().Be("DELETE FROM MyTable OUTPUT Field1, Field2 WHERE Field1 = @Field1 AND Field2 = @Field2 AND Field3 = @Field3");
    }
コード例 #16
0
        public void Build_WithDeleteSubOptionsWithFilePath_ReturnsDeleteCommandWithFilePath()
        {
            // Arrange
            var deleteSubOptions = new DeleteSubOptions();

            deleteSubOptions.FilePath = new List <string> {
                "TestFilePath"
            };

            // Act
            var result = new DeleteCommandBuilder().Build(deleteSubOptions);

            // Assert
            Assert.IsInstanceOf <DeleteCommand>(result);
            var deleteCommand = result as DeleteCommand;

            Assert.AreEqual("TestFilePath", deleteCommand.FilePath);
        }
コード例 #17
0
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (ddlMode_Type.SelectedItem.Value == "0")
            {
                return;
            }
            string sql   = "delete from Mode_type where Mode_type_id = " + ddlMode_Type.SelectedItem.Value + "";
            int    count = new DeleteCommandBuilder().ExecuteNonQuery(sql);

            if (count != 0)
            {
                getType();
                ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", "<script>alert('删除成功!')</script>");
            }
            else
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", "<script>alert('删除失败!')</script>");
            }
        }
コード例 #18
0
    public void Can_Clear_And_Rebuild()
    {
        // Arrange
        var input = new DeleteCommandBuilder()
                    .From("MyTable")
                    .Where("Field = @Field")
                    .AppendParameter("Field", "Value");

        // Act
        var actual = input.Clear().From("MyTable2").Build();

        // Assert
        actual.Operation.Should().Be(Abstractions.DatabaseOperation.Delete);
        actual.CommandText.Should().Be("DELETE FROM MyTable2");
        actual.CommandParameters.Should().BeAssignableTo <IDictionary <string, object> >();
        var parameters = actual.CommandParameters as IDictionary <string, object>;

        parameters.Should().BeEmpty();
    }
コード例 #19
0
        protected void gvAddData_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            //Page.ClientScript.RegisterStartupScript(this.GetType(), "focus", "<script>alert('" + (gvAddData.Rows[e.RowIndex].FindControl("HiddenField1") as HiddenField).Value + "')</script>");
            string D_id    = (gvAddData.Rows[e.RowIndex].FindControl("hfDetailId") as HiddenField).Value;
            string c       = "select Bill_id from pd_detail where Detail_id ='" + D_id + "'";
            string bill_id = new SelectCommandBuilder().ExecuteDataTable(c).Rows[0][0].ToString();
            string sql1    = "delete from pd_detail where Detail_id ='" + D_id + "'";
            int    count   = new DeleteCommandBuilder().ExecuteNonQuery(sql1);
            string dsql    = "SELECT COUNT(*) AS COUNTa FROM pd_detail where Bill_id = '" + bill_id + "'";
            int    p       = Convert.ToInt32(new SelectCommandBuilder().ExecuteScalar(dsql));

            if (p == 0)
            {
                string sqlc = "delete from pd where Bill_id = '" + bill_id + "'";
                count += new DeleteCommandBuilder().ExecuteNonQuery(sqlc);
            }
            if (count != 0)
            {
                string    sql = @"SELECT a.Bill_id,
                             a.prd_Batch_id,
                             a.materials_id,
                             a.Qty,
                             a.Pch,
                             a.Detail_id,
                             a.yxq,
                             a.PDate,
                             a.Price,
                             a.is_can_sale,
                             materials.name,
                             materials.spec,
                             vendor.vendor_name,
                             materials.unit,
                             materials.name,
		                     materials.select_code,
			                 materials.texture,
			                 materials.color,
			                 a.hwh,
			                 a.is_new,
                             total = Isnull((a.Price*a.Qty),0)
                        FROM pd_detail a,
                             materials,
                             vendor
                       WHERE ( materials.sccj_id *= vendor.vendor_id) and
                             ( a.materials_id = materials.id ) and
			                    a.bill_id ='"             + ViewState["billId"].ToString().Trim() + "'";
                DataTable dt  = new SelectCommandBuilder().ExecuteDataTable(sql);
                aList.Clear();
                if (dt != null && dt.Rows.Count != 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        AddData a = new AddData()
                        {
                            id            = dt.Rows[i]["Detail_id"].ToString(),
                            pm            = dt.Rows[i]["name"].ToString(),
                            spec          = dt.Rows[i]["spec"].ToString(),
                            cz            = dt.Rows[i]["texture"].ToString(),
                            ys            = dt.Rows[i]["color"].ToString(),
                            goods_unit    = dt.Rows[i]["unit"].ToString(),
                            pch           = dt.Rows[i]["pch"].ToString(),
                            hwh           = dt.Rows[i]["hwh"].ToString(),
                            pdsl          = Convert.ToDecimal(dt.Rows[i]["qty"]).ToString("0.##"),
                            Price         = dt.Rows[i]["price"].ToString() == "" ? "0.00" : Convert.ToDecimal(dt.Rows[i]["price"]).ToString("0.##"),
                            total         = dt.Rows[i]["price"].ToString() == "" ? "0.00" : (Convert.ToDecimal(dt.Rows[i]["qty"]) * Convert.ToDecimal(dt.Rows[i]["price"])).ToString("0.##"),
                            customer_name = dt.Rows[i]["vendor_name"].ToString()
                        };
                        aList.Add(a);
                    }
                }
                gvAddData.DataSource = aList;
                gvAddData.DataBind();
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "focus", "<script>alert('删除失败!')</script>");
            }
        }