Beispiel #1
0
        public static int UpdateFinalWaste(Entity.FinalWaste 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("@FWID",     DBTypeConverter.ConvertCsTypeToOriginDBType(entity.FWID.GetType().ToString()),     entity.FWID,     32),
                    dbFactory.MakeInParam("@LogID",    DBTypeConverter.ConvertCsTypeToOriginDBType(entity.LogID.GetType().ToString()),    entity.LogID,    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),
                    dbFactory.MakeInParam("@Status",   DBTypeConverter.ConvertCsTypeToOriginDBType(entity.Status.GetType().ToString()),   entity.Status, 32)
                };
                iReturn = db.ExecuteNonQueryTrans(trans, CommandType.StoredProcedure, "proc_FinalWaste_Update", prams);
                thelper.CommitTransaction(trans);
                iReturn = 1;
            }
            catch (Exception ex)
            {
                thelper.RollTransaction(trans);
                iReturn = 0;
            }
            finally
            {
                db.Conn.Close();
            }
            return(iReturn);
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="DealID">    </param>
        /// <returns></returns>
        public static List <Entity.FinalWaste> GetFinalWaste(int LogID)
        {
            List <Entity.FinalWaste> list      = new List <Entity.FinalWaste>();
            DBOperatorBase           db        = new DataBase();
            IDBTypeElementFactory    dbFactory = db.GetDBTypeElementFactory();

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

            if (msg != "")
            {
                Alert.Show(msg);
                return;
            }
            else
            {
                int iReturn = 0;
                try
                {
                    Entity.FinalWasteLog entity = new Entity.FinalWasteLog();
                    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   = FDate.SelectedDate;
                    entity.IYear      = DateTime.Now.Year;
                    entity.Number     = DAL.FinalWasteLog.GetMaxNumber(entity.IYear) + 1;
                    int Number = DAL.FinalWasteLog.GetCount(entity.DateTime) + 1;
                    entity.LogNumber = int.Parse(GenerateLogNumberEx(entity.DateTime.Value, Number.ToString()));
                    //entity.LogNumber = int.Parse(GenerateLogNumber(entity.IYear, entity.Number.ToString()));
                    entity.Status = 1;
                    entity.UserID = int.Parse(drop_Man.SelectedValue.Trim());
                    if (string.IsNullOrEmpty(sGuid))
                    {
                        //Add
                        List <Dictionary <string, object> > newAddedList2 = Grid2.GetNewAddedList();
                        List <Entity.FinalWaste>            Adds2         = new List <Entity.FinalWaste>();
                        for (int i = 0; i < newAddedList2.Count; i++)
                        {
                            Entity.FinalWaste add = new Entity.FinalWaste();
                            add.Result   = decimal.Parse(newAddedList2[i]["Result2"].ToString());
                            add.ItemCode = DAL.Waste.GetWasteCodeByName(newAddedList2[i]["WasteName2"].ToString());
                            Adds2.Add(add);
                        }

                        iReturn = DAL.FinalWasteLog.AddFinalWasteLogEntity(entity, Adds2);
                    }
                    else
                    {
                        //Update
                        entity.LogID = int.Parse(sGuid);

                        List <int> deletedRows2           = Grid2.GetDeletedList();
                        List <Entity.FinalWaste> Deletes2 = new List <Entity.FinalWaste>();
                        foreach (int rowIndex in deletedRows2)
                        {
                            Entity.FinalWaste delete = new Entity.FinalWaste();
                            delete.FWID = Convert.ToInt32(Grid2.DataKeys[rowIndex][1]);
                            Deletes2.Add(delete);
                        }


                        Dictionary <int, Dictionary <string, object> > modifiedDict2 = Grid2.GetModifiedDict();
                        List <Entity.FinalWaste> Updates2 = new List <Entity.FinalWaste>();
                        foreach (int rowIndex in modifiedDict2.Keys)
                        {
                            Entity.FinalWaste update = new Entity.FinalWaste();
                            update.FWID     = Convert.ToInt32(Grid2.DataKeys[rowIndex][1]);
                            update.ItemCode = DAL.Waste.GetWasteCodeByName(Grid2.DataKeys[rowIndex][2].ToString());
                            update.Result   = decimal.Parse(Grid2.DataKeys[rowIndex][3].ToString());
                            update.Status   = 1;
                            Updates2.Add(update);
                        }

                        List <Dictionary <string, object> > newAddedList2 = Grid2.GetNewAddedList();
                        List <Entity.FinalWaste>            Adds2         = new List <Entity.FinalWaste>();
                        for (int i = 0; i < newAddedList2.Count; i++)
                        {
                            Entity.FinalWaste add = new Entity.FinalWaste();
                            add.Result   = decimal.Parse(newAddedList2[i]["Result2"].ToString());
                            add.ItemCode = DAL.Waste.GetWasteCodeByName(newAddedList2[i]["WasteName2"].ToString());
                            Adds2.Add(add);
                        }
                        iReturn = DAL.FinalWasteLog.UpdateFinalWasteLogEntity(entity, Adds2, Updates2, Deletes2);
                    }
                }
                catch (Exception ex)
                {
                }
                finally
                {
                }
                if (iReturn == 1)
                {
                    Alert.ShowInTop(" 保存成功!", MessageBoxIcon.Information);
                    //            PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
                }
                else
                {
                    Alert.ShowInTop(" 保存失败!", MessageBoxIcon.Warning);
                }
            }
            #endregion
        }