Exemple #1
0
        public static int UpdateMonitorResult(Entity.MonitorResult entity)
        {
            int                   iReturn   = 0;
            DBOperatorBase        db        = new DataBase();
            IDBTypeElementFactory dbFactory = db.GetDBTypeElementFactory();
            SqlTransactionHelper  thelper   = new SqlTransactionHelper(DAL.Config.con);
            IDbTransaction        trans     = thelper.StartTransaction();

            try
            {
                IDbDataParameter[] prams =
                {
                    dbFactory.MakeInParam("@ResultID",  DBTypeConverter.ConvertCsTypeToOriginDBType(entity.ResultID.GetType().ToString()),  entity.ResultID,  32),
                    dbFactory.MakeInParam("@MonitorID", DBTypeConverter.ConvertCsTypeToOriginDBType(entity.MonitorID.GetType().ToString()), entity.MonitorID, 32),
                    dbFactory.MakeInParam("@ItemCode",  DBTypeConverter.ConvertCsTypeToOriginDBType(entity.ItemCode.GetType().ToString()),  entity.ItemCode,  20),
                    dbFactory.MakeInParam("@Result",    DBTypeConverter.ConvertCsTypeToOriginDBType(entity.Result.GetType().ToString()),    entity.Result, 10)
                };
                iReturn = db.ExecuteNonQueryTrans(trans, CommandType.StoredProcedure, "proc_MonitorResult_Update", prams);
                thelper.CommitTransaction(trans);
                iReturn = 1;
            }
            catch (Exception ex)
            {
                thelper.RollTransaction(trans);
                iReturn = 0;
            }
            finally
            {
                db.Conn.Close();
            }
            return(iReturn);
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ResultID">    </param>
        /// <returns></returns>
        public static Entity.MonitorResult GetMonitorResultByID(int ResultID)
        {
            Entity.MonitorResult  entity    = null;
            DBOperatorBase        db        = new DataBase();
            IDBTypeElementFactory dbFactory = db.GetDBTypeElementFactory();

            try
            {
                IDataReader dataReader = db.ExecuteReader(Config.con, CommandType.Text, "Select * from [MonitorResult] where ResultID='" + ResultID + "'", null);
                while (dataReader.Read())
                {
                    entity           = new Entity.MonitorResult();
                    entity.ResultID  = DataHelper.ParseToInt(dataReader["ResultID"].ToString());
                    entity.MonitorID = DataHelper.ParseToInt(dataReader["MonitorID"].ToString());
                    entity.ItemCode  = dataReader["ItemCode"].ToString();
                    entity.Result    = decimal.Parse(dataReader["Result"].ToString());
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                db.Conn.Close();
            }
            return(entity);
        }
        protected void btn_save_Click(object sender, EventArgs e)
        {
            string msg = checkInput();

            if (msg != "")
            {
                Alert.Show(msg);
                return;
            }
            else
            {
                int iReturn = 0;
                try
                {
                    Entity.Monitor entity = new Entity.Monitor();
                    entity.PositionID    = int.Parse(drop_PositionName.SelectedValue);
                    entity.CreateDate    = DateTime.Now;
                    entity.UpdateDate    = DateTime.Now;
                    entity.CreateUser    = Request.Cookies["Cookies"].Values["UserName"].ToString();
                    entity.UpdateUser    = Request.Cookies["Cookies"].Values["UserName"].ToString();
                    entity.DateTime      = Date.SelectedDate;
                    entity.AnalysisManID = int.Parse(hf_AnalysisID.Text.Trim());
                    entity.Status        = 1;

                    if (string.IsNullOrEmpty(sGuid))
                    {
                        //Add


                        //List<Entity.MonitorResult> results = new List<Entity.MonitorResult>();
                        //foreach (GridRow gr in Grid1.Rows)
                        //{
                        //    Entity.MonitorResult result = new Entity.MonitorResult();
                        //    result.ItemCode = DAL.MonitorItem.GetItemCodeByName(gr.DataKeys[2].ToString());
                        //    result.Result = decimal.Parse(gr.DataKeys[3].ToString());
                        //    results.Add(result);
                        //}
                        List <Dictionary <string, object> > newAddedList = Grid1.GetNewAddedList();
                        List <Entity.MonitorResult>         Adds         = new List <Entity.MonitorResult>();
                        for (int i = 0; i < newAddedList.Count; i++)
                        {
                            Entity.MonitorResult add = new Entity.MonitorResult();
                            add.Result   = decimal.Parse(newAddedList[i]["Result"].ToString());
                            add.ItemCode = DAL.MonitorItem.GetItemCodeByName(newAddedList[i]["ItemName"].ToString());
                            Adds.Add(add);
                        }
                        iReturn = DAL.Monitor.AddMonitorEntity(entity, Adds);

                        //iReturn = DAL.Monitor.AddMonitorEntity(entity, results);
                    }
                    else
                    {
                        //Update
                        entity.MonitorID = int.Parse(sGuid);
                        List <int> deletedRows = Grid1.GetDeletedList();
                        List <Entity.MonitorResult> Deletes = new List <Entity.MonitorResult>();
                        foreach (int rowIndex in deletedRows)
                        {
                            Entity.MonitorResult delete = new Entity.MonitorResult();
                            delete.ResultID = Convert.ToInt32(Grid1.DataKeys[rowIndex][0]);
                            Deletes.Add(delete);
                        }


                        Dictionary <int, Dictionary <string, object> > modifiedDict = Grid1.GetModifiedDict();
                        List <Entity.MonitorResult> Updates = new List <Entity.MonitorResult>();
                        foreach (int rowIndex in modifiedDict.Keys)
                        {
                            Entity.MonitorResult update = new Entity.MonitorResult();
                            update.ResultID = Convert.ToInt32(Grid1.DataKeys[rowIndex][0]);
                            update.ItemCode = DAL.MonitorItem.GetItemCodeByName(Grid1.DataKeys[rowIndex][1].ToString());
                            update.Result   = decimal.Parse(Grid1.DataKeys[rowIndex][2].ToString());
                            Updates.Add(update);
                        }

                        List <Dictionary <string, object> > newAddedList = Grid1.GetNewAddedList();
                        List <Entity.MonitorResult>         Adds         = new List <Entity.MonitorResult>();
                        for (int i = 0; i < newAddedList.Count; i++)
                        {
                            Entity.MonitorResult add = new Entity.MonitorResult();
                            add.Result   = decimal.Parse(newAddedList[i]["Result"].ToString());
                            add.ItemCode = DAL.MonitorItem.GetItemCodeByName(newAddedList[i]["ItemName"].ToString());
                            Adds.Add(add);
                        }
                        iReturn = DAL.Monitor.UpdateMonitorEntity(entity, Adds, Deletes, Updates);
                    }
                }
                catch (Exception ex)
                {
                }
                finally
                {
                }
                if (iReturn == 1)
                {
                    Alert.ShowInTop(" 保存成功!", MessageBoxIcon.Information);
                    //            PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
                }
                else
                {
                    Alert.ShowInTop(" 保存失败!", MessageBoxIcon.Warning);
                }
            }
            #endregion
        }