/// <summary>
        /// 从UltraGrid中获取数值,并返回dataset.
        /// </summary>
        /// <param name="grid"></param>
        /// <returns>UltraGrid中的数据</returns>
        public static DataSet_detail GetGridDataSet(UltraWebGrid grid)
        {
            if (grid.Rows.Count < 1) return null;

            DataSet_detail ds = new DataSet_detail();
            DataSet_detail.TProjectTypeDetailRow dsRow;

            foreach (UltraGridRow row in grid.Bands[0].Grid.Rows)
            {
                if (row.DataChanged != DataChanged.Modified) continue;

                int ShopID = Int32.Parse(row.Cells.FromKey("ShopID").Value.ToString());
                int StatTypeID = Int32.Parse(row.Cells.FromKey("StatTypeID").Value.ToString());
                int ProjectTypeClassID = Int32.Parse(row.Cells.FromKey("ProjectTypeClassID").Value.ToString());
                int ProjectTypeID = Int32.Parse(row.Cells.FromKey("ProjectTypeID").Value.ToString());
                int StatYear = Int32.Parse(row.Cells.FromKey("StatYear").Value.ToString());

                for (int i = 1; i <= 12; i++)
                {
                    if (false == row.Cells[i + 2].DataChanged) continue;//从第三列开始是一月、二月、三月……

                    dsRow = ds.TProjectTypeDetail.NewTProjectTypeDetailRow();

                    dsRow["ShopID"] = ShopID;
                    dsRow["StatTypeID"] = StatTypeID;
                    dsRow["ProjectTypeClassID"] = ProjectTypeClassID;
                    dsRow["ProjectTypeID"] = ProjectTypeID;
                    dsRow["ProjectTypeDate"] = DateTime.Parse(StatYear.ToString() + "-" + i.ToString());
                    dsRow["ProjectTypeQty"] = Decimal.Parse(row.Cells[i + 2].Value.ToString());

                    ds.Tables[0].Rows.Add(dsRow);
                }
            }

            int records = ds.Tables[0].Rows.Count;

            return ds;
        }
Esempio n. 2
0
        /// <summary>
        /// 将Grid中的修改数据,更新到数据库中
        /// </summary>
        /// <param name="ds">从Grid上获取的数据</param>
        /// <returns>成功更新的行数</returns>
        public static int UpdateDBAccess(DataSet_detail ds)
        {
            if (ds == null || ds.Tables[0].Rows.Count < 1) return 0;

            Database db = DatabaseFactory.CreateDatabase();

            // Establish our Insert, Delete, and Update commands
            DbCommand insertCommand = db.GetStoredProcCommand("_business_AddStatData");
            db.AddInParameter(insertCommand, "ShopID", DbType.Int32, "ShopID", DataRowVersion.Current);
            db.AddInParameter(insertCommand, "StatTypeID", DbType.Int32, "StatTypeID", DataRowVersion.Current);
            db.AddInParameter(insertCommand, "ProjectTypeClassID", DbType.Int32, "ProjectTypeClassID", DataRowVersion.Current);
            db.AddInParameter(insertCommand, "ProjectTypeID", DbType.Int32, "ProjectTypeID", DataRowVersion.Current);
            db.AddInParameter(insertCommand, "ProjectTypeDate", DbType.DateTime, "ProjectTypeDate", DataRowVersion.Current);
            db.AddInParameter(insertCommand, "ProjectTypeQty", DbType.Decimal, "ProjectTypeQty", DataRowVersion.Current);

            DbCommand deleteCommand = db.GetStoredProcCommand("_business_DeleteStatData");
            db.AddInParameter(deleteCommand, "ShopID", DbType.Int32, "ShopID", DataRowVersion.Current);
            db.AddInParameter(deleteCommand, "StatTypeID", DbType.Int32, "StatTypeID", DataRowVersion.Current);
            db.AddInParameter(deleteCommand, "ProjectTypeClassID", DbType.Int32, "ProjectTypeClassID", DataRowVersion.Current);
            db.AddInParameter(deleteCommand, "ProjectTypeID", DbType.Int32, "ProjectTypeID", DataRowVersion.Current);
            db.AddInParameter(deleteCommand, "ProjectTypeDate", DbType.DateTime, "ProjectTypeDate", DataRowVersion.Current);

            DbCommand updateCommand = db.GetStoredProcCommand("_business_UpdateStatData");
            db.AddInParameter(updateCommand, "ShopID", DbType.Int32, "ShopID", DataRowVersion.Current);
            db.AddInParameter(updateCommand, "StatTypeID", DbType.Int32, "StatTypeID", DataRowVersion.Current);
            db.AddInParameter(updateCommand, "ProjectTypeClassID", DbType.Int32, "ProjectTypeClassID", DataRowVersion.Current);
            db.AddInParameter(updateCommand, "ProjectTypeID", DbType.Int32, "ProjectTypeID", DataRowVersion.Current);
            db.AddInParameter(updateCommand, "ProjectTypeDate", DbType.DateTime, "ProjectTypeDate", DataRowVersion.Current);
            db.AddInParameter(updateCommand, "ProjectTypeQty", DbType.Decimal, "ProjectTypeQty", DataRowVersion.Current);

            // Submit the DataSet, capturing the number of rows that were affected
            int rowsAffected = db.UpdateDataSet(ds, "TProjectTypeDetail", insertCommand, updateCommand,
                                                deleteCommand, UpdateBehavior.Standard);

            return rowsAffected;
        }