Exemplo n.º 1
0
 /// <summary>
 /// 执行SQL
 /// </summary>
 public void Commit(Microsoft.Practices.EnterpriseLibrary.Data.Database dbinstance)
 {
     if (_buf.Length > 0 && dbinstance != null)
     {
         dbinstance.ExecuteNonQuery(System.Data.CommandType.Text, _buf.ToString());
     }
 }
Exemplo n.º 2
0
        private void GvList_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                DataGridViewColumn column = GvList.Columns[e.ColumnIndex];
                var id        = GvList.Rows[e.RowIndex].Cells["id"].Value.ToString();
                var ProjectNo = GvList.Rows[e.RowIndex].Cells["ProjectNo"].Value.ToString();
                var PartNo    = GvList.Rows[e.RowIndex].Cells["PartNo"].Value.ToString();
                var PartName  = GvList.Rows[e.RowIndex].Cells["PartName"].Value.ToString();

                if (column is DataGridViewButtonColumn)
                {
                    var temp = column as DataGridViewButtonColumn;

                    if (temp.DefaultCellStyle.NullValue.ToString() == "删除")
                    {
                        if (MessageBox.Show("确定要删除数据吗 ?删除数据将不可恢复!", "Confirm Message", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                        {
                            SqlParameter[] p = new SqlParameter[] {
                                new SqlParameter("@MeasReportID", id),
                            };

                            var dbc = db.GetStoredProcCommand("DeleteMeasurementReports");
                            dbc.Parameters.AddRange(p);
                            var number = db.ExecuteNonQuery(dbc);
                            if (number > 0)
                            {
                                GvBind();
                            }
                            else
                            {
                                MessageBox.Show("删除失败");
                            }
                        }
                    }
                    else if (temp.DefaultCellStyle.NullValue.ToString() == "查询")
                    {
                        FrmIndex1 _FrmIndex1 = new FrmIndex1(int.Parse(id), ProjectNo, PartNo, PartName);
                        _FrmIndex1.Show();
                    }
                    else
                    {
                        MessageBox.Show("未知响应事件");
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 选中页码上传图片
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtYM.Text.Trim()))
            {
                MessageBox.Show("页码不能为空!");
                return;
            }
            //创建一个对话框对象
            OpenFileDialog ofd = new OpenFileDialog();

            //为对话框设置标题
            ofd.Title = "请选择上传的图片";
            //设置筛选的图片格式
            ofd.Filter = "图片格式|*.jpg";
            //设置是否允许多选
            ofd.Multiselect = false;
            //如果你点了“确定”按钮
            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                //获得文件的完整路径(包括名字后后缀)
                string filePath = ofd.FileName;
                int    position = filePath.LastIndexOf("\\");
                //从完整路径中截取出来文件名“1.jpg”
                string fileName = filePath.Substring(position + 1);
                Byte[] bytes    = GetContent(filePath);

                MemoryStream ms = new MemoryStream(bytes);

                //测点信息表上传图片
                string    strMeasPageID  = GetMeasPageID(comboBox1.SelectedValue.ToString(), comboBox2.SelectedValue.ToString(), txtYM.Text.Trim());
                string    strSqlMeasPage = " update MeasurementPages set MeasPageImage=@Picture " + " where MeasPageID=" + strMeasPageID;
                DbCommand dbc            = db.GetSqlStringCommand(strSqlMeasPage);
                db.AddInParameter(dbc, "@Picture", DbType.AnsiString, bytes);
                int ipa = db.ExecuteNonQuery(dbc);
                this.pictureBox1.Image = Image.FromStream(ms);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Execute the non query like insert, delete and update.
        /// </summary>
        /// <param name="command"></param>
        /// <returns>Numbers of rows affected.</returns>
        public static int ExecuteNonQuery(DbCommand command)
        {
            int rowsAffected = 0;

            try
            {
                Microsoft.Practices.EnterpriseLibrary.Data.Database db = DBSelector.Instance.GetDataBase;
                rowsAffected = db.ExecuteNonQuery(command);
            }
            catch (Exception ex)
            {
                VaaaN.MLFF.Libraries.CommonLibrary.Logger.Log.WriteGeneralLog("Failed to execute non query." + ex.Message);
                throw ex;
            }

            return rowsAffected;
        }
Exemplo n.º 5
0
        private void GvList_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                DataGridViewColumn column = GvList.Columns[e.ColumnIndex];
                var id = GvList.Rows[e.RowIndex].Cells["id"].Value.ToString();

                if (column is DataGridViewButtonColumn)
                {
                    var temp = column as DataGridViewButtonColumn;

                    if (temp.DefaultCellStyle.NullValue.ToString() == "处理")
                    {
                        if (MessageBox.Show("你确定要设置成已经处理吗!", "Confirm Message", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                        {
                            SqlParameter[] p = new SqlParameter[] {
                                new SqlParameter("@id", id),
                            };

                            var dbc = db.GetSqlStringCommand("UPDATE [dbo].[Warnings] SET [DoTime] = getdate(),[status] = 1 WHERE id=@id");
                            dbc.Parameters.AddRange(p);
                            var number = db.ExecuteNonQuery(dbc);
                            if (number > 0)
                            {
                                bind();
                            }
                            else
                            {
                                MessageBox.Show("提交数据失败");
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("未知响应事件");
                    }
                }
            }
        }
Exemplo n.º 6
0
        public IHttpActionResult PostMeasureData(MeasureData measureData)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            var day1 = measureData.checktime.ToString("yyyy-MM-dd");

            //var t1 = checktime(day1);
            //var t2 = checktime(day2);

            string sql = @"
                delete from [TestData] where [TestData_PointSetting_ID] = {0} and TestData_User='******' and [TestData_Date] = '{1}'
            ";

            var ttt = string.Format(sql, measureData.PointId, day1, measureData.Username);

            var ds = _db.ExecuteNonQuery(CommandType.Text, ttt);


            string insert = @"
            INSERT INTO [dbo].[TestData]
            ([TestData_PointSetting_ID]
            ,[TestData_Value1]
            ,[TestData_Value2]
            ,[TestData_Value3]
            ,[TestData_Value4]
            ,[TestData_Value5]
            ,[TestData_Value6]
            ,[TestData_Value7]
            ,[TestData_Value8]
            ,[TestData_Value9]
            ,[TestData_Value10]
            ,[TestData_User]
            ,[TestData_SubmitTime]
            ,[TestData_Date]
            ,[TestData_UpperTolerance]
            ,[TestData_LowerTolerance]
            )
            VALUES
            ({0}
            ,'{1}'
            ,'{2}'
            ,'{3}'
            ,'{4}'
            ,'{5}'
            ,'{6}'
            ,'{7}'
            ,'{8}'
            ,'{9}'
            ,'{10}'
            ,'{11}'
            ,getdate()
            ,'{12}'
            ,{13}
            ,{14}
            );
            ";

            var temp = string.Format(insert, measureData.PointId,
                                     measureData.Value1,
                                     measureData.Value2,
                                     measureData.Value3,
                                     measureData.Value4,
                                     measureData.Value5,

                                     measureData.Value6,
                                     measureData.Value7,
                                     measureData.Value8,
                                     measureData.Value9,
                                     measureData.Value10,

                                     measureData.Username,
                                     measureData.checktime.ToString("yyyy-MM-dd"),
                                     string.IsNullOrWhiteSpace(measureData.UpperTolerance) ? "null" : measureData.UpperTolerance,
                                     string.IsNullOrWhiteSpace(measureData.LowerTolerance) ? "null" : measureData.LowerTolerance

                                     );

            _db.ExecuteNonQuery(CommandType.Text, temp);



            //var model = db.MeasureDatas.Where(
            //    b => b.ProjectName == measureData.ProjectName
            //    && b.ProductName == measureData.ProductName
            //    && b.TargetName == measureData.TargetName
            //    && b.MeasurePoint == measureData.MeasurePoint
            //    && b.Direction == measureData.Direction
            //    && b.Username == measureData.Username
            //    && b.Timestamp > t1
            //    && b.Timestamp < t2
            //    );

            //if (null != model)
            //{
            //    db.MeasureDatas.RemoveRange(model);
            //}

            //db.MeasureDatas.Add(measureData);
            //db.SaveChanges();

            ServiceReference1.WCFServiceClient client = new ServiceReference1.WCFServiceClient();
            client.StartStatic(ServiceReference1.SourceType.Standard);


            return(CreatedAtRoute("DefaultApi", new { id = measureData.Id }, measureData));
        }
Exemplo n.º 7
0
        private void dgvList_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                DataGridViewColumn column = dgvList.Columns[e.ColumnIndex];
                if (column is DataGridViewButtonColumn)
                {
                    var temp = column as DataGridViewButtonColumn;

                    if (temp.DefaultCellStyle.NullValue.ToString() == "上传")
                    {
                        DataGridViewRow Row = dgvList.Rows[e.RowIndex];

                        var cel1 = Row.Cells["Value1"].Value ?? "";
                        var cel2 = Row.Cells["Value2"].Value ?? "";
                        var cel3 = Row.Cells["Value3"].Value ?? "";
                        var cel4 = Row.Cells["Value4"].Value ?? "";
                        var cel5 = Row.Cells["Value5"].Value ?? "";

                        var cel6  = Row.Cells["Value6"].Value ?? "";
                        var cel7  = Row.Cells["Value7"].Value ?? "";
                        var cel8  = Row.Cells["Value8"].Value ?? "";
                        var cel9  = Row.Cells["Value9"].Value ?? "";
                        var cel10 = Row.Cells["Value10"].Value ?? "";


                        var id = Row.Cells["ID"].Value ?? "";



                        SqlParameter[] p = new SqlParameter[] {
                            new SqlParameter("@Value1", cel1),
                            new SqlParameter("@Value2", cel2),
                            new SqlParameter("@Value3", cel3),
                            new SqlParameter("@Value4", cel4),
                            new SqlParameter("@Value5", cel5),


                            new SqlParameter("@Value6", cel6),
                            new SqlParameter("@Value7", cel7),
                            new SqlParameter("@Value8", cel8),
                            new SqlParameter("@Value9", cel9),
                            new SqlParameter("@Value10", cel10),

                            new SqlParameter("@id", id)
                        };

                        var dbc = db.GetSqlStringCommand("UPDATE [dbo].[MeasureDatas] SET [Value1] = @Value1,[Value2] = @Value2,[Value3] = @Value3,[Value4] = @Value4,[Value5] = @Value5,[Value6] = @Value6,[Value7] = @Value7,[Value8] = @Value8,[Value9] = @Value9,[Value10] = @Value10 WHERE ID=@ID");
                        dbc.Parameters.AddRange(p);
                        var number = db.ExecuteNonQuery(dbc);
                        if (number > 0)
                        {
                            MessageBox.Show("修改成功");
                        }
                        else
                        {
                            MessageBox.Show("删除失败");
                        }
                    }
                }
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// Execute an SQL command (statement) and return the number of rows affected
 /// </summary>
 public int ExecuteNonQuery(DbCommand com)
 {
     Log.Debug("\tSQL Command: " + com.CommandText);
     return(Db.ExecuteNonQuery(com));
 }