protected void btInsert_Click(object sender, EventArgs e)
 {
     if (MyDataSource.Insert() >= 1)
     {
         Response.Write("<script>alert('添加成功')</script>");
     }
 }
Beispiel #2
0
    private void CreateMenuItems()
    {
        MyDataSource data = new MyDataSource();

        Menu.DataSource = data;
        Menu.DataBind();
    }
 protected void btDelete_Click(object sender, EventArgs e)
 {
     if (MyDataSource.Delete() >= 1)
     {
         Response.Write("<script>alert('删除成功')</script>");
     }
 }
        /// <summary>
        /// Verify field names against database. Combines the ability to add and remove
        /// fields from Database.
        /// </summary><returns>true if modified, false if not needed, throws exception if fail</returns>
        public bool VerifyOrCreateAndRemoveFields(bool createTableIfMissing = true)
        {
            VerifyOrCreateClassFieldsInDbTable(createTableIfMissing);
            var dbAllFieldNames = _dbFieldNames.ToArray().ToList();

            dbAllFieldNames.Add(IDField);
            var extraDbFieldNames = GetDbFieldNames().Except(dbAllFieldNames).ToArray();

            if (extraDbFieldNames.Length == 0)
            {
                return(false);
            }
            var  sb         = new StringBuilder();
            bool firstField = true;

            foreach (var fieldName in extraDbFieldNames)
            {
                if (firstField)
                {
                    sb.Append(",");
                }
                sb.Append(fieldName);
                sb.Append(" ");
                firstField = false;
            }

            MyDataSource.ExecuteSql($"alter table {TableName} drop {sb}");

            return(true);
        }
Beispiel #5
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.Main);

            var button = FindViewById <Button>(Resource.Id.MyButton);

            button.Click += (s, e) => {
                var ds = new MyDataSource();
                ds.Authenticate().ContinueWith(
                    t =>
                {
                    var isauth = t.Result;
                    if (isauth)
                    {
                        var result = ds.QueryDataSoruce <DsParams>("your dataset", new DsParams {
                            qty = 2
                        }).Result;
                        System.Diagnostics.Debug.WriteLine(result.ToString());
                    }
                }
                    );
            };
        }
Beispiel #6
0
    protected void cbCars_ItemsRequestedByFilterCondition(object source, DevExpress.Web.ASPxEditors.ListEditItemsRequestedByFilterConditionEventArgs e)
    {
        var data  = MyDataSource.GetData(cbLocation.Text);
        var query = from r in data where r.Text.StartsWith(e.Filter) select r;

        cbCars.DataSource = query.Skip(e.BeginIndex).Take(e.EndIndex - e.BeginIndex + 1);
        cbCars.DataBind();
    }
Beispiel #7
0
        protected void Button3_Click(object sender, EventArgs e)
        {
            int i = MyDataSource.Delete();

            if (i == 1)
            {
                message.Text = "Profile Deleted Successfully !";
            }
        }
Beispiel #8
0
 protected void cbCars_ItemRequestedByValue(object source, DevExpress.Web.ASPxEditors.ListEditItemRequestedByValueEventArgs e)
 {
     if (e.Value != null && e.Value is int)
     {
         var data  = MyDataSource.GetData(cbLocation.Text);
         var query = from r in data where r.Value == (int)e.Value select r;
         cbCars.DataSource = query;
         cbCars.DataBind();
     }
 }
        /// <summary>
        /// Get the names of the columns as defined in the database
        /// </summary>
        /// <returns></returns>
        public string[] GetDbFieldNames()
        {
            string sql         = "select Top 1 * from " + TableName;
            var    reader      = MyDataSource.ExecuteReader(sql);
            var    schemaTable = reader.GetSchemaTable();

            MyDataSource.DisposeReader(reader);
            return((from dr in schemaTable?.Rows.Cast <DataRow>()
                    select dr["ColumnName"].ToString()).ToArray());
        }
        /// <summary>
        /// Add missing fields to database that are found in record class.
        /// </summary><returns>true if changed, false if no need to change, throw exceptions on errors</returns>
        public bool VerifyOrCreateClassFieldsInDbTable(bool createTableIfMissing = true)
        {
            if (createTableIfMissing && !MyDataSource.GetDataTableNames().Contains(TableName))
            {
                CreateDataTable();
                return(true);
            }
            // field name exceptions, index matches location in fieldInfos
            var missingDbFieldNames = _dbFieldNames.Except(GetDbFieldNames()).ToArray();

            if (missingDbFieldNames.Length == 0)
            {
                return(false);
            }
            try {
                var  sb         = new StringBuilder();
                bool firstField = true;
                foreach (var dbFieldName in missingDbFieldNames)
                {
                    if (!firstField)
                    {
                        sb.Append(",");
                    }

                    int    fiIndex = _dbFieldNames.IndexOf(dbFieldName);
                    string fixDbFn = dbFieldName;

                    int fnSepIdx = fixDbFn.IndexOf(".[", StringComparison.Ordinal);
                    if (MyDataSource is DataFileSource dfSrc && dfSrc.FileType != DataFileType.Access2007 &&
                        dfSrc.FileType != DataFileType.AccessMdb && fnSepIdx >= 0)
                    {
                        fixDbFn = fixDbFn.Substring(fnSepIdx + 2, fixDbFn.Length - fnSepIdx - 3);
                    }
                    sb.Append(fixDbFn);
                    sb.Append(" ");
                    sb.Append(FieldInfoToSqlType(_fieldInfos[fiIndex]));
                    firstField = false;
                }

                MyDataSource.ExecuteSql($"alter table {TableName} add {sb}");
            } catch  {
                //on fail remove all fieldInfos not contained in database.
                foreach (var dbFieldName in missingDbFieldNames)
                {
                    int fiIndex = _dbFieldNames.IndexOf(dbFieldName);
                    _fieldInfos.RemoveAt(fiIndex);
                    _dbFieldNames.RemoveAt(fiIndex);
                }

                throw;
            }

            return(true);
        }
Beispiel #11
0
        protected void Button2_Click(object sender, EventArgs e)
        {
            DataView  dataView = (DataView)MyDataSource.Select(DataSourceSelectArguments.Empty);
            DataTable table    = dataView.ToTable();

            TextBox1.Text = table.Rows[0].ItemArray[1].ToString();
            TextBox2.Text = table.Rows[0].ItemArray[2].ToString();
            TextBox3.Text = table.Rows[0].ItemArray[3].ToString();
            TextBox4.Text = table.Rows[0].ItemArray[5].ToString();
            TextBox5.Text = table.Rows[0].ItemArray[4].ToString();
            TextBox6.Text = table.Rows[0].ItemArray[6].ToString();
        }
Beispiel #12
0
 public void MyDataBind()
 {
     Text = new StringBuilder();
     foreach (PropertyInfo p in MyDataSource.GetType().GetProperties())
     {
         Text.Append(string.Format("<b>{0}</b>", p.Name));
         Text.Append(":");
         if (p.GetIndexParameters() == null || p.GetIndexParameters().Length == 0)
         {
             Text.Append(p.GetValue(MyDataSource, null));
         }
         Text.Append("<br />");
     }
 }
Beispiel #13
0
    //删除文件
    public static string mDeleteFile(string mPath)
    {
        string res = null;

        if (System.IO.File.Exists(Path.GetFullPath(mPath)))
        {
            File.Delete(Path.GetFullPath(mPath));
            MyDataSource.PrintLogs("删除文件" + mPath);
        }
        else
        {
            MyDataSource.PrintLogs("删除图片:图片文件不存在");
            res = "文件路径不存在";
        }
        return(res);
    }
        public void Fill()
        {
            if (this.isFilled)
            {
                return;
            }

            MyDataSource source = new MyDataSource();

            foreach (DataRow row in source.RecordsSet.Tables["DateTable"].Rows)
            {
                this.SourceCollection.Add(new DateEntity(row));
            }

            this.isFilled = true;
        }
        public override void Run()
        {
            StartTime = DateTime.Parse("01/01/2008", CultureInfo.InvariantCulture);
            EndTime   = DateTime.Now.Date - TimeSpan.FromDays(5);

            var ds = new MyDataSource();

            AddDataSource(ds);

            foreach (var s in SimTimes)
            {
                _plotter.SelectChart(Name, "date");
                _plotter.SetX(SimTime[0]);
                _plotter.Plot(ds.Instrument.Name, ds.Instrument.Close[0]);
            }
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var ds = new MyDataSource();

            ds.Authenticate().ContinueWith(
                t =>
            {
                var isauth = t.Result;
                if (isauth)
                {
                    var result = ds.QueryDataSoruce <DsParams>("getTellagoVacationsfff", new DsParams {
                        qty = 2
                    }).Result;
                    System.Diagnostics.Debug.WriteLine(result.ToString());
                }
            }
                );
        }
        public int[] GetIDs(bool sortByID = false)
        {
            if (string.IsNullOrEmpty(IDField))
            {
                return(null);
            }

            var sql    = "select " + IDField + " from " + TableName + (sortByID ? " order by " + IDField + " asc;" : "");
            var r      = MyDataSource.ExecuteReader(sql);
            var result = new List <int>();

            while (r.Read())
            {
                var id = r.GetInt32(0);
                result.Add(id);
            }

            MyDataSource.DisposeReader(r);
            return(result.ToArray());
        }
        public TField[] GetFieldDistinctValues <TField>(string fieldName, bool sort = false)
        {
            var fi = typeof(T).GetField(fieldName);

            if (fi == null)
            {
                throw new Exception("FieldName doesn't match any public field in type");
            }
            int fiIndex = _fieldInfos.IndexOf(fi);
            var dbFn    = _dbFieldNames[fiIndex];
            var sql     = $"select distinct {dbFn} from {TableName}" + (sort ? $" order by {dbFn} asc;" : "");
            var r       = MyDataSource.ExecuteReader(sql);
            var result  = new List <TField>();

            while (r.Read())
            {
                var vO = r[0];
                result.Add((TField)vO);
            }
            MyDataSource.DisposeReader(r);
            return(result.ToArray());
        }
Beispiel #19
0
        public static void Async2b_Events()
        {
            MyDataSource src = null;

            src.DataAvailable += (o, e) =>
            {
                if (cond(e.Data))
                {
                    var y = f(e.Data);
                    if (cond2(y))
                    {
                        RaiseTransformedDataAvailable(y);
                    }
                }
            };

            // now consumers interested in the filtered, transformed data attach
            // to Streams.TransformedDataAvailable instead of MyDataSource.DataAvailable

            // Notice that we can't return the event itself because events aren't first
            // class citizens.
        }
        private void getCarouselData()
        {
            var item = new ShowcaseImagesModel
            {
                showcaseImage = "Image1.jpg"
            };
            var item2 = new ShowcaseImagesModel
            {
                showcaseImage = "Image3.jpg"
            };

            MyDataSource.Add(item);
            MyDataSource.Add(item2);
            MyDataSource.Add(item);
            MyDataSource.Add(item2);
            MyDataSource.Add(item);
            MyDataSource.Add(item2);
            MyDataSource.Add(item);
            MyDataSource.Add(item2);
            MyDataSource.Add(item);
            MyDataSource.Add(item2);
        }
		public static void update (Page p)
		{
			LiteralControl lcb = new LiteralControl (HtmlDiff.BEGIN_TAG);
			LiteralControl lce = new LiteralControl (HtmlDiff.END_TAG);
			ObjectDataSourceView view;
			GridView grid = new GridView ();
			MyDataSource ds = new MyDataSource ();
			ds.ID = "ObjectDataSource1";
			ds.TypeName = "MonoTests.System.Web.UI.WebControls.DataSourceObject";
			
			ds.SelectMethod = "Select";
			ds.DeleteMethod = "Delete";
			ds.InsertMethod = "Insert";
			ds.UpdateMethod = "Update";

			Parameter p1 = new Parameter ("ID", TypeCode.String);
			Parameter p2 = new Parameter ("FName", TypeCode.String);
			Parameter p3 = new Parameter ("LName", TypeCode.String);

			ds.UpdateParameters.Add (p1);
			ds.UpdateParameters.Add (p2);
			ds.UpdateParameters.Add (p3);

			grid.ID = "Grid";
			grid.DataSourceID = "ObjectDataSource1";
			p.Form.Controls.Add (lcb);
			p.Form.Controls.Add (ds);
			p.Form.Controls.Add (grid);
			p.Form.Controls.Add (lce);
			view = (ObjectDataSourceView) ds.DoGetView ("defaultView");
			view.Updating += new ObjectDataSourceMethodEventHandler (Event);

			DataSourceObject.InitDS ();

			Hashtable table = new Hashtable ();
			table.Add ("ID", "1001");
			table.Add ("FName", "Yonik");
			table.Add ("LName", "Laim");
			view.Update (null, table, null);
			Assert.AreEqual (true, view.CanUpdate, "CanUpdate");
			Assert.AreEqual ("Update", view.UpdateMethod, "UpdateMethod");
			Assert.AreEqual (3, view.UpdateParameters.Count, "UpdateParameters.Count");
			Assert.AreEqual ("ID", view.UpdateParameters[0].Name, "UpdateParametersName#1");
			Assert.AreEqual ("FName", view.UpdateParameters[1].Name, "UpdateParametersName#2");
			Assert.AreEqual ("LName", view.UpdateParameters[2].Name, "UpdateParametersName#3");
			ObjectDataSourceViewTest.Eventassert ("Update event has not fired");
		}
		public static void selectcount (Page p)
		{
			// This method will render grid view with paging 
			// Note : ObjectDataSource will return page counter 5 hard coded

			LiteralControl lcb = new LiteralControl (HtmlDiff.BEGIN_TAG);
			LiteralControl lce = new LiteralControl (HtmlDiff.END_TAG);
			ObjectDataSourceView view;
			GridView grid = new GridView ();
			MyDataSource ds = new MyDataSource ();
			ds.ID = "ObjectDataSource2";
			ds.EnablePaging = true;
			ds.TypeName = "MonoTests.System.Web.UI.WebControls.DataSourceObject";
			ds.SelectMethod = "Select";
			ds.SelectCountMethod = "SelectCount";


			grid.ID = "Grid";
			grid.DataKeyNames = new string[] { "ID" };
			grid.DataSourceID = "ObjectDataSource2";
			grid.AllowPaging = true;
			grid.PageSize = 1;

			p.Form.Controls.Add (lcb);
			p.Form.Controls.Add (ds);
			p.Form.Controls.Add (grid);
			p.Form.Controls.Add (lce);
			view = (ObjectDataSourceView) ds.DoGetView ("DefaultView");
			Assert.IsTrue (view.CanRetrieveTotalRowCount, "CanRetrieveTotalRowCount");
		}
		public static void select (Page p)
		{
			LiteralControl lcb = new LiteralControl (HtmlDiff.BEGIN_TAG);
			LiteralControl lce = new LiteralControl (HtmlDiff.END_TAG);
			ObjectDataSourceView view;
			GridView grid = new GridView ();
			MyDataSource ds = new MyDataSource ();
			ds.ID = "ObjectDataSource2";
			ds.TypeName = "MonoTests.System.Web.UI.WebControls.DataSourceObject";
			ds.SelectMethod = "Select";

			grid.ID = "Grid";
			grid.DataKeyNames = new string[] { "ID" };
			grid.DataSourceID = "ObjectDataSource2";
			p.Form.Controls.Add (lcb);
			p.Form.Controls.Add (ds);
			p.Form.Controls.Add (grid);
			p.Form.Controls.Add (lce);
			view = (ObjectDataSourceView) ds.DoGetView ("DefaultView");
			view.Selecting += new ObjectDataSourceSelectingEventHandler (view_Selecting);

			DataSourceObject.InitDS ();

			DataView view1 = (DataView) view.Select (new DataSourceSelectArguments ());
			Assert.AreEqual (1, view1.Count, "SelectedRowsCount");
			Assert.AreEqual (1001, view1[0].Row["ID"], "SelectedRowsValue#1");
			Assert.AreEqual ("Mahesh", view1[0].Row["FName"], "SelectedRowsValue#2");
			Assert.AreEqual ("Chand", view1[0].Row["LName"], "SelectedRowsValue#3");
			ObjectDataSourceViewTest.Eventassert ("Select event has not fired");
		}
		public void ViewState ()
		{
			// Note :
			// IStateManager implementation allows public access to control state
			// Nothing added to viewstate

			ObjectDataSourceView view;
			MyDataSource ds = new MyDataSource ();

			ds.ID = "ObjectDataSource2";
			ds.TypeName = "MonoTests.System.Web.UI.WebControls.DataSourceObject";
			ds.SelectMethod = "Select";
			ds.SelectCountMethod = "SelectCount";

			view = (ObjectDataSourceView) ds.DoGetView ("DefaultView");
			((IStateManager) view).TrackViewState ();

			view.ConflictDetection = ConflictOptions.CompareAllValues;
			view.ConvertNullToDBNull = true;
			view.DataObjectTypeName = "test";
			view.DeleteMethod = "test";
			view.EnablePaging = true;
			view.InsertMethod = "test";
			view.FilterExpression = "test";
			view.MaximumRowsParameterName = "test";
			view.SelectCountMethod = "test";
			view.SelectMethod = "test";
			view.OldValuesParameterFormatString = "test";
			view.StartRowIndexParameterName = "test";
			view.TypeName = "test";
			view.UpdateMethod = "test";

			object state = ((IStateManager) view).SaveViewState ();
			Assert.IsNull (state, "ViewState#1");

			ObjectDataSourceView copy = new ObjectDataSourceView (ds, "DefaultView", null);
			((IStateManager) copy).LoadViewState (state);

		}
		public void ViewStateSupport () 
		{
			ObjectDataSourceView view;
			MyDataSource ds = new MyDataSource ();

			ds.ID = "ObjectDataSource2";
			ds.TypeName = "MonoTests.System.Web.UI.WebControls.DataSourceObject";
			ds.SelectMethod = "Select";
			ds.SelectCountMethod = "SelectCount";

			view = (ObjectDataSourceView) ds.DoGetView ("DefaultView");
			((IStateManager) view).TrackViewState ();

			Parameter p1 = new Parameter ("test", TypeCode.String);

			Assert.IsTrue (((IStateManager) view).IsTrackingViewState, "IsTrackingViewState");
			Assert.IsTrue (((IStateManager) view.FilterParameters).IsTrackingViewState, "FilterParameters.IsTrackingViewState");
			Assert.IsTrue (((IStateManager) view.SelectParameters).IsTrackingViewState, "SelecteParameters.IsTrackingViewState");
			Assert.IsFalse (((IStateManager) view.DeleteParameters).IsTrackingViewState, "DeleteParameters.IsTrackingViewState");
			Assert.IsFalse (((IStateManager) view.InsertParameters).IsTrackingViewState, "InsertParameters.IsTrackingViewState");
			Assert.IsFalse (((IStateManager) view.UpdateParameters).IsTrackingViewState, "UpdateParameters.IsTrackingViewState");

			object state = ((IStateManager) view).SaveViewState ();
			Assert.IsNull (state, "view ViewState not null");

			view.DeleteParameters.Add (p1);
			view.InsertParameters.Add (p1);
			//view.UpdateParameters.Add (p1);

			state = ((IStateManager) view).SaveViewState ();
			Assert.IsNull (state, "view ViewState not null");

			view.FilterParameters.Add (p1);
			//view.SelectParameters.Add (p1);

			state = ((IStateManager) view).SaveViewState ();
			Assert.IsNotNull (state, "view ViewState not null");

			state = ((IStateManager) view.FilterParameters).SaveViewState ();
			Assert.IsNotNull (state, "FilterParamenters ViewState not null");
			state = ((IStateManager) view.SelectParameters).SaveViewState ();
			Assert.IsNull (state, "SelectParameters ViewState not null");

			state = ((IStateManager) view.DeleteParameters).SaveViewState ();
			Assert.IsNotNull (state, "DeleteParameters ViewState not null");
			state = ((IStateManager) view.InsertParameters).SaveViewState ();
			Assert.IsNotNull (state, "InsertParameters ViewState not null");
			state = ((IStateManager) view.UpdateParameters).SaveViewState ();
			Assert.IsNull (state, "UpdateParameters ViewState not null");
		}
		public static void DataGrid1_UpdateCommand (object source, DataGridCommandEventArgs e) 
		{
			DataGrid DataGrid1 = (DataGrid) source;
			MyDataSource ds = new MyDataSource ();
			TextBox edittedName = (TextBox) e.Item.Cells [1].Controls [0];
			ds.UpdateItem (e.Item.DataSetIndex, Int32.Parse (e.Item.Cells [0].Text), edittedName.Text);
			DataGrid1.EditItemIndex = -1;
			DataGrid1.DataBind ();
		}
		public static void DataGrid1_DeleteCommand (object source, DataGridCommandEventArgs e) 
		{
			DataGrid DataGrid1 = (DataGrid) source;
			MyDataSource ds = new MyDataSource ();
			ds.DeleteItem (e.Item.DataSetIndex);
			DataGrid1.DataBind ();
		}