Dev blog

C# Developer and a Geek

neisep

EN guide till EAN koder Del 2

Här kommer en exempel kod som jag skrivit för att ta fram kontrolsiffran för EAN-13 och EAN-8

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
    private string GetCheckSum(string barcode)
    {
        StringBuilder sb = new StringBuilder();
        if (barcode.Length < 12)
        {
            for (int i = 0; i < 13 - barcode.Length; i++)
            {
                sb.Append("0");
            }
        }
        string tempbarcode = sb.Append(barcode).ToString();
        double totalSum = 0.0;
        for (int j = 0; j < tempbarcode.Length - 1; j++)
        {
            int eanCode = Convert.ToUInt16(tempbarcode[j].ToString());
            totalSum += (double)((j % 2 == 0) ? eanCode : (3 * eanCode));
        }
        return (Math.Ceiling(totalSum / 10.0) * 10.0 - totalSum).ToString();
    }

Nästa del tar vi och går igenom viktartiklar eller viktean.

EN guide till EAN koder Del 1

EAN står för Europa artikel nummer översatt från European article number det är ett sätt att hantera koder, EAN kallas nummera Gtin som står för Global trade item number kan vara bra att veta om du skulle komma i kontakt med gtin-13 som alltså är ean-13.

Det finns fler typer än bara EAN men i europa är EAN vanligast och därför väljer jag att skriva om just EAN-8 och EAN-13 i första hand eftersom EAN-8 är egentligen mindre version av EAN-13.

Så hur är EAN-13 uppdelat jo det ser ut så här:


LandskodProducentartikelnummerkontrollsiffra
7310350109906
Första 2 sifforna är landskoden, de 5 andra sifforna är producentens den tilldelas av Sveriges ansvarige myndighet/organisation, nästa 5 siffror är producentens artikel nummer och sista siffran är kontroll siffran.

Men de finns faktiskt fler ean koder som innehåller 13 siffror som exempelvis vikt artiklar eller visste du tillexempel att tidningar har en egen streckkod serie för att få ut priset på tidningen de står alltså i själva ean koden hur mycket den kostar.

Men vikt ean och ean koder för tidningar kommer jag skriva om så småning om.

Uträckning av kontrollsiffran

Du räknar ut kontrollsiffran genom att först summera varannan siffra från höger sida, som i vårt fall då blir det:
3+0+5+1+9+0=18
7 1 3 0 0 9
Sedan tar du summan gånger 3 så här

18 x 3 =54

Summera sedan dom resterande siffrorna som du hoppade över så här

7+1+3+0+0+9 =20

Sedan lägger vi ihop dessa två summor alltså så här

54+20 =74

Så nu behöver du ta total summan minus närmsta högre tiotal de vill säga 80

80-74=6 alltså är det då kontrollsiffra 6

Det kommer komma en Del 2 med exempel kod för hur vi kan hantera EAN koden på ett enkelt sätt i vår kod.
Hur som helst nu bör du ha en viss förståelse för hur EAN 13 och 8 är uppbyggt.



Norway

Well this Year i went to Norway at first i did not know if i wanted to share this on this website and i thought to myself why not.

Everything has not to be about C# and programming so i share my trip to Norway during this summer, it was a really awesome trip my friend learn me a lot it is crazy going from a super comfortable life style going to a trip to watch mountain and the nature basically, Completely something im not used to for example use a toilet…. there was no toilet really and we take so much stuff for granted even a shower was like something we did not have you had to take a bath in the water from the mountains it was interesting not really that hard.

But it was an awesome experience making food was another thing that was abit different but it was fun and i must say during the whole trip i never felt so alive before it was.

This is one of the top of the mountain

We went from place to place to see new things up in Norway i was amazed how beautiful the environment was over there, not exactly what i am used to. This was an lifetime experience i hope to make much more exp like this in the future only thing is the time it does not exists for now.

Went to a creek the water was blue really beautiful you could feel the air how freash everything felt, anyway this creek was soo cold i did not wanna go there for a swim because it was to cold for me, but my friend went for a very was swim 🙂

I remember one other thing that was very different they had a lot of sheep’s and cows there was going free so our camp got visitor from the cows and sheep’s it was pretty fun, my friend did not even use a tent he slept under the stars but he got woke up by the interested cows. It was crazy but very amusing experience i really hope to get the time todo it again sometime.

One of the best trips in my entire life that is for sure so much things to see and so much stuff to experience kind of a good way to relax somewhere were the phone or the computer meant absolutely nothing.

Anything new yet no?

Well right now i have been busy learning but that never change thought, but i been looking into open source project too help out on.
Specific interested in Storj but currently have to wait for V3 of the protocol until i can do anything more because they will change a lot of things in API and functions, anyway Storj is a cloud storage such as AWS but much cheaper.
Storj is unfortunately still in testing so should not be used for any kind of production environment, but it is really interesting to play around with.

So meanwhile i wait for V3 i gone try to take a vacation and focus on health seems like a good idea to me.

I hope everyone get a awesome summer enjoy.

Best regards Jimmie Aka NeiSep

How too use Tasks and progressbar in .net

Everybody know how nice Task can be to work with, but did you know there is actually a interface for using a progressbar.
I will show you how to use it and how to implement it and make use of it.

First of we start with write a class i called it ProgressClass with a int this will contain our reported progress.
You can extend this class to contain anything you like that has todo with the progress reporting for example maybe you want to set Max value to your progressbar you could do this with an extra field in ProgressClass if you like to.
But lets focus on reporting the progress only.

1
2
3
4
public class ProgressClass
{
     public int Progress { get; set; }
}

next up we need code for our progress and in C# there is already a class for this under System namespace called Progress that has an EventHandler called ProgressChanged that is what we need.
Lets take a look at the example code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
private void Init()
{
var progress = new Progress<ProgressClass>();
progress.ProgressChanged += Progress_Changed;
StartTask(progress);
}

private void StartTask(IProgress<ProgressClass> progress)
{
    Task myTask = Task.Run(() =>
    {
        try
        {
                     for (int i = 0; i < 100; i++)
                     {
                        progress.Report(new ProgressClass { Progress = i+1 });
                        Thread.Sleep(100);
                     }
        }
        catch (Exception crap)
        {
            //Handle Exceptions!
        }
    });
}

private void Progress_Changed(object sender, ProgressClass e)
{
     MyProgressBar.Value = e.Progress;
}

So this is a very easy implementation to use a Progressbar for your .net application.

Have a nice weekened

Working on a small utility to push emails to apis

Lately been working on a small utility to push emails to any kind of api, anyone can create a api integration in the software.

You get all the information from the software and for now we have support for OsTicket api, but i will look into to add support for Katak support to, but there is probobly plenty more to work on also, such as attachment im pretty sure thats not completed either yet.

Good thing is that this is my first open source software the source code is on github: https://github.com/neisep/emailpipe

The code is yet little bit messy but im working to clean it up and move stuff around, feel free too modify or help out on it if you wish.

 

 

Who remember FastTracker 2?

You probobly aren’t familier with FastTracker 2 well anyway it is a tracker software were you basicly write your music.

it looks like this:

Who said you couldn’t program music right, i find it very inspiring so much talent out there.

C# relay server

Created a small small relay server, right now it only works with text and the concept is that a client connect too a server with a key and password to connect to another server.

So basicly this will replace my old junkie Support tool later on.

But we will see