Friday, 20 May 2016

XPO Snippets

Session s = new Session();
            s.ConnectionString = "Data Source=(local);Initial Catalog=NORTHWND;Integrated Security=True";
            int i = Convert.ToInt32(s.ExecuteScalar("select count(*) from products where UnitPrice>@price AND ProductName LIKE @prodName", new string[] { "@price","@prodName" }, new object[] { 10,"A%" }));
            MessageBox.Show(i.ToString());
            s.ExecuteNonQuery("UPDATE Products SET ProductName='a_'+ProductName WHERE UnitPrice>@price AND ProductName LIKE 'A%'", new string[] { "@price" }, new object[] { 10 });
            SelectedData sd = s.ExecuteQuery("select * from products where UnitPrice>@price AND ProductName LIKE 'A%'", new string[] { "@price" }, new object[] { 10 });
            MessageBox.Show(sd.ResultSet[0].Rows[0].Values[1].ToString());

Tuesday, 15 March 2016

C# Code Snippets

Return number only from text
private string GetNumbers(string input)
{
    return new string(input.Where(c => char.IsDigit(c)).ToArray());
}


Read CSV file

static List ReadCSV(string filename)
{
  return File.ReadLines(filename)
          //.Skip(1)
          .Where(s => s != "")
          .Select(s => s.Split(new[] { ',' }))
          .Select(a => new Result
           {
              OrgFN = a[0],
              NewFN = a[2],
              Barcode = a[1]
           })
           .ToList();
}



Or can use this:
http://www.codeproject.com/Articles/12170/FileHelpers-v-Delimited-CSV-or-Fixed-Data-Impor

Saturday, 12 March 2016

Install Mono and MonoDevelop

Add additional package repositories. First add the Mono Project GPG signing key by typing in the (remote or local) command prompt
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF

Then type
echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
for the first repository. Now enter
echo "deb http://download.mono-project.com/repo/debian wheezy-apache24-compat main" | sudo tee -a /etc/apt/sources.list.d/mono-xamarin.list
for the second repository.
Once added, we need to execute the sudo apt-get update and sudo apt-get upgrade commands again. Cool, now we are finally ready to install Mono: enter
sudo apt-get install mono-complete

When prompted hit enter or Y to confirm the installation of the complete Mono framework. Give it some time to complete, it takes like 5 minutes.

Link

Friday, 15 January 2016

Interesting Links

API

How To Consume a WebAPI with RestSharp

Cross Platform Development

http://www.reactnative.com/

Swagger

Library

MassMail.NET
PC Control

XAF

https://documentation.devexpress.com/#eXpressAppFramework/CustomDocument113054

How to: Map a Database View to a Persistent Class


How to deploy the OData security service in the Cloud for further use by a mobile DevExtreme client



Raspberry Pi
Raspberry Pi Articles
Wired Watershed
Raspberry Pi Touch Screen
Reverse SSH scripts
Reverse SSH scripts 1
Reverse tunnel without autossh
RPi Display
People counting
Stomx - Image processing workflow
Enclosure

Misc

SMS Service
Database Synchronisation - SymmetricDS
Metl - Web-based integration platform

XAF Notes

Add Button to a detail view - link

DomainObject Attributes

TextArea and Hide from ListView
[Size(SizeAttribute.Unlimited), VisibleInListView(true)]
       
XAF Display Label
[XafDisplayName("")]

[Association("FileLog-DonorFileRecords"), Aggregated]

https://documentation.devexpress.com/#CoreLibraries/CustomDocument2127
The retrieved collection of persistent objects can also be filtered. Use its XPBaseCollection.Filter property to apply the desired filter.

Criteria

https://documentation.devexpress.com/#CoreLibraries/CustomDocument2038

Validation Rule
https://documentation.devexpress.com/#eXpressAppFramework/CustomDocument113008

Rule to prevent record being deleted when there is record in the collection
[RuleRequiredField(DefaultContexts.Delete, InvertResult = true, CustomMessageTemplate = "The {TargetPropertyName} collection is not empty")]
        public XPCollection<WBSMapping> WBSMappings

        {
            get
            {
                return GetCollection<WBSMapping>("WBSMappings");
            }
        }


Sum in BO
public decimal TotalAmount
{
      get
      {
                object result = Session.Evaluate(typeof(ApplicationMain), CriteriaOperator.Parse("Sum(AmountL)"), CriteriaOperator.Parse("FileSource.Oid = ?", Oid));
                decimal res = Convert.ToDecimal(result);
                return res;
      }
}

        public bool IsNewRecord
        {
            get
            {
                return Session.IsNewObject(this);
            }
        }


//Disable all Delete button
https://documentation.devexpress.com/#eXpressAppFramework/CustomDocument112728

        protected override void OnActivated()
        {
            base.OnActivated();
            // Perform various tasks depending on the target View.
            DeleteObjectsViewController deleteController =
                Frame.GetController<DeleteObjectsViewController>();
            if (deleteController != null)
            {
                deleteController.Active["Deactivation in code"] = true;
                //    !(View.ObjectTypeInfo.Type == typeof(PostingPeriod));
            }
       }


Show Popup Windows
             var spc = View.CurrentObject as SpecialProjectClosure;
            //IObjectSpace iosp = XPObjectSpace.FindObjectSpaceByObject(refund);
            var iosp = Application.CreateObjectSpace();
            var chooseobj = iosp.CreateObject<ApplicationMain>();
            DetailView dv = Application.CreateDetailView(iosp, chooseobj);
            dv.ViewEditMode = ViewEditMode.Edit;
            ShowViewParameters svp = new ShowViewParameters();
            svp.Context = TemplateContext.PopupWindow;
            svp.CreateAllControllers = true;
            svp.TargetWindow = TargetWindow.NewModalWindow;
            svp.CreatedView = dv;
            DialogController dc = Application.CreateController<DialogController>();
            dc.SaveOnAccept = false;
            dc.Accepting += dc_AcceptingRecordSelect; // This is an event handler. The dc_Accepting will be executed when Accepting event happens (user click OK button of the window)
            dc.Tag = spc; // pass the current db connection so that we can use it inside the accepting function
            svp.Controllers.Add(dc);

Show Popup Windows from Action Button
            var refund = View.CurrentObject as Refund;
            //IObjectSpace iosp = XPObjectSpace.FindObjectSpaceByObject(refund);
            var iosp = Application.CreateObjectSpace();
            var chooseobj = iosp.CreateObject<ChooseApplicationMain>();
            chooseobj.DonatingWBS = iosp.GetObject(refund.DonatingWBS);
            DetailView dv = Application.CreateDetailView(iosp, chooseobj);
            dv.ViewEditMode = ViewEditMode.Edit;
            e.ShowViewParameters.Context = TemplateContext.PopupWindow;
            e.ShowViewParameters.CreateAllControllers = true;
            e.ShowViewParameters.TargetWindow = TargetWindow.NewModalWindow;
            e.ShowViewParameters.CreatedView = dv;
            DialogController dc = Application.CreateController<DialogController>();
            dc.SaveOnAccept = false;
            dc.Accepting += dc_AcceptingRecordSelect; // This is an event handler. The dc_Accepting will be executed when Accepting event happens (user click OK button of the window)
            dc.Tag = refund; // pass the current db connection so that we can use it inside the accepting function
            e.ShowViewParameters.Controllers.Add(dc);


Permission

Boolean isEditingGranted = DataManipulationRight.CanEdit(View, View.CurrentObject, LinkToListViewController.FindCollectionSource(Frame));
editAction.Active[isGrantedToEditKey] = isEditingGranted;


Master Detail
- To avoid saving of Master record while adding or editing Child record, assign e.ObjectSpace to View.ObjectSpace during ObjectCreating event


XPObjectSpace.FindObjectSpaceByObject Method

Use XAF Module library in Non-XAF application
  BarcodeApp app = new BarcodeApp();
  app.ConnectionString = connectionString;
  app.ApplicationName = "DAS";
  app.Modules.Add(new DAS.Module.DASModule());
  app.Setup();