This term "Stringly Typed" were coined from codinghorror site here. It is described as "an implementation that needlessly relies on strings when programmer & refactor friendly options are available". Now, have you ever think that you can replace almost every data type, even functions / methods with string? If not, then you can see it here.
A site contains programming and software engineering articles, mainly focused at application architecture and design. Almost all of the articles are written in C# (C-Sharp) language.
Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts
Code Smell : Array-based Data Model
In OOP, you have classes to define your data model. Your class can be passed between methods and even other classes as well, making it very flexible to be used, and at the same time still keeping the data structure. It is nice isn't it? Unfortunately, there are a group of programmers who like array-based data model more rather than modeling using classes.
If you find those group working for medium-high complexity projects, quickly demoted them, and exclude them from the socialization. If you find yourself doing the same thing, quickly go to nearest worship place and atone your sin, then begin to start a new life. Is it that bad? Yes it is. Why? Here we go:
If you find those group working for medium-high complexity projects, quickly demoted them, and exclude them from the socialization. If you find yourself doing the same thing, quickly go to nearest worship place and atone your sin, then begin to start a new life. Is it that bad? Yes it is. Why? Here we go:
What does Clean Code meant to you?
The very basic question
It is the very basic question for middle-level programmer (professional programmer with advanced skill but not yet a master). It has already been discussed maybe for decades in several discussion forums. Some of the source I had found is:- Stack overflow question
- Linked in discussion - As Technology Becomes More Complex, Design Becomes More Important
- My Linked in discussion
However we arrived to the basic question, what is a clean code actually? This is purely my opinion about clean code.
Programming Idealism, Avoiding Hungarian Notation
Hungarian Notation
From wikipedia, hungarian notation is an identifier naming convention in computer programming, in which the name of a variable or function indicates its type or intended use. There are two types of Hungarian notation: Systems Hungarian notation and Apps Hungarian notation.System Hungarian is intended to emphasize the variable's type. It is extremely useful in interpret / dynamic language such as javascript or php, and useless at all in static programming language. Especially in compiled oop language such as Java and C#, where data contract and type casting is the major problem, it has no benefit at all.
Apps Hungarian is intended to describe the functionality of given variable, regardless of it's type. As Joel Spoolsky has been explained in his article, there are some variable that is prone to error, even though already has compiled-type checking. One of his example is between unsafe and safe string (encoded html tags for example), in which the type is same but serve different purpose.
The article is posted at 2005. It means it already there for more than 7 years around. Given current ability of compiler and programming language, what can we do to improve the design?
Problem
There lies one and only one problem in Joel's solution, that is the code can still pass compilation phase. As stated by Mark Seeman in his article, faster feedback means less costs to correct errors. Ideally, it is the best when we can get all the system's error during compilation phase, but it mostly impossible for some reasons (such as parsing error or business rule error, in which cannot be caught by compiler). In short, you need to create compile error as much as possible to catch wrong code, rather than getting run time exceptions.
The Proposed Design
Using Joel's example for safe and unsafe string, we need to create a design where we can handle safe and unsafe string which can give compile error. By using C# syntax, as usual for oop language, first I define some classes. The class is for unsafe string.
public class DecodedHtmlString
{
public DecodedHtmlString(string decodedString)
{
this.decodedString = decodedString;
}
private string decodedString;
public override string ToString()
{
return decodedString;
}
}
Simple enough. It gives no benefit but gives you a self-documenting data type. The class represent a html string in a decoded way, and no encoding happen here. Next, for the safe (encoded string).
public class EncodedHtmlString
{
public EncodedHtmlString(DecodedHtmlString decodedString)
{
this.encodedString = System.Web.HttpUtility.HtmlEncode(decodedString.ToString());
}
private string encodedString;
public override string ToString()
{
return encodedString;
}
}
Again, a self explaining class accepting encoded string from a decoded string. Now we want to make both of the classes communicate each other. We have several options such as type casting or static parsing, which is easy enough in C# that I won't explain. In here I will do constructor injection and To type casting instead. For the DecodedHtmlString, we add a constructor and ToEncodedHtmlString method:
public DecodedHtmlString(EncodedHtmlString encodedString)
{
this.decodedString = System.Web.HttpUtility.HtmlDecode(encodedString.ToString());
}
public EncodedHtmlString ToEncodedHtmlString()
{
return new EncodedHtmlString(this);
}
And for the EncodedHtmlString side:
public static EncodedHtmlString FromEncodedString(string encodedString)
{
EncodedHtmlString result = new EncodedHtmlString();
result.encodedString = encodedString;
}
public DecodedHtmlString ToDecodedHtmlString()
{
return new DecodedHtmlString(this);
}
Consumer
Let's see from consumer point of view:string unsafeString = Request.Forms["CUSTOM_INPUT"]; // input from form string safeString = System.Web.HttpUtility.HtmlEncode(unsafeString); // encoded safe string for reference DecodedHtmlString decoded; EncodedHtmlString encoded; // initial creation decoded = new DecodedHtmlString(unsafeString); // correct encoded = EncodedHtmlString.FromEncodedString(safeString); //correct // type casting encoded = decoded.ToEncodedHtmlString(); // correct encoded = new EncodedHtmlString(decoded); // also correct decoded = encoded.ToDecodedHtmlString(); // correct decoded = new DecodedHtmlString(encoded); // also correct // wrong initial creation decoded = new DecodedHtmlString(safeString); // wrong encoded = EncodedHtmlString.FromEncodedString(unsafeString); //wrong // to primitive unsafeString = decoded.ToString(); // correct safeString = encoded.ToString(); // correct // wrong to primitive unsafeString = encoded.ToString(); // wrong safeString = decoded.ToString(); // wrong
We got 4 possible wrong code, that is from primitive and to primitive parameter assignment, and for other scenarios it is correct. Now let's see whether we can exploit the data type validation with parameter accepting data type.
public void WriteToDatabase(EncodedHtmlString encoded)
{
string encodedString = encoded.ToString();
// doing with encodedString
}
WriteToDatabase(unsafeString); // compile error WriteToDatabase(safeString); // compile error WriteToDatabase(decoded); // compile error WriteToDatabase(encoded); // correct
Now we got 3 compile error and one correct code. If you favor to get a compile error, it is an improvement since now you can protect myself from 3 possible parameter assignment errors. And if you carefully using the two data types instead of passing from primitive string, it will be fine. The only two things that can pass the compile error is when casting to primitive, or from primitive.
But hey, isn't most of the operation (at least safe and unsafe string) is using primitive type? If we take account Response.Write and Database operations, it is very clear that most of the critical operation is using primitive type. (even for url, etc). Moreover, we add 2 more classes for this design.
Conclusion
We can get the design where we will receive compile error instead of run time error or buggy code. However, we still cannot get one hundred percent buggy-code free with this design, and most of the operations are error-prone here. Additionally, it introduces two dependent classes as well, making it more tight coupling.In the end, it is still the framework's support that do the decide. If the framework support the Encoded and Decoded datatype by default, and suggesting you to use the datatype instead of primitives, maybe it is worth it. However, with current framework design, it is very unlikely for this design to give decent benefit.
Design, don't Code Yet
Why - Risk at Development
As a programmer, sometimes I doubt whether I should wasting time to think and design about the application that I will develop or not. As a single programmer-architect, there are some self-defined projects where I usually start by code first or by design first. Logically, they should have produced the same result, thinking that the developer and the architect is the same person. Practically, I'm surprised that the project started with code first is tend to have more risk and more likely to be stopped than the one by design-first.So, logic does not apply here? Yes it is. The reason is basically that the developer is human. and they will likely get bored because of several reasons:
- The project does not has exact requirement and scope
- The project does not has exact release strategy
- The project is most likely isn't needed by the user
The project does not has exact requirement and scope
Once, I have tried to create a so-called "ideal-best" application. The application should be able to handle many kind of business process. That application will be free of bug, easily extendable and has good architecture foundation. And the application can work as both transaction handling or event high level management reporting tools.
It sounds like a good plan at the beginning, however with such a big regards I need to drop the development because I got bored during developing it. It has no exact scope, no exact plan about what I must develop, what I must validate, how is the process after doing this and that, etc. The scope is growing and growing each day I think about the application, and the development cannot follow the planning growth. You have not target to accomplish, and caused you to loss interest in the development.
The project does not has exact release strategy
What I mean about the term of release strategy here is a strategy about how to deliver the application. It consist of release date, the audience and the platform target. It may has more details than that such as how to replace the current running application without breaking, or how to not breaking other applications which is dependent to it; but it's regarding what kind of application that want to be delivered.
Having no release date deadline (target) can affect the development scope, since you will think like "I have unlimited time to develop this" or "I can add this and that feature before delivering the application, since the release date isn't being decided".
Lack of audience target can also affect the scope, because you will try to create an application that can be used by any level of management (transaction level or event advanced-level ad-hoc reporting).
Lack of platform target can demoralize your development. You will be haunted by thoughts such as "will it works well in firefox, chrome, or IE?" or "will it works in other-windows operating system?". Thoughts like that will drag your development, because you will be bugged by how you will check them each time you make a modification. Don't be bugged by it!
The project is most likely isn't needed by the user
Any project needed by the user should has estimated release date. In terms of user, the faster the deliver date, the better. Sometimes you may think that this kind of application/enhancement will not be needed by the user. It can be because you can do manipulation to the database directly. This kind of thought can demoralize the development, since you don't know exactly how your application can give good benefits to the user. Don't develop any kind of application which won't be needed. Or if it will, don't ever think that the workaround (direct manipulation) can be the replacement of the application.
Conclusion
Always design your application first before do code. No matter how skillful programmer you are, the risk of not having the application designed beforehand is high. It can makes your effort go waste, and you got nothing from it, except wondering why this is happening. If you cannot do the design, as someone who is good at it. Asking experts in each field, for example accountant during finance application design or a headmaster during education application design. It can give you clear vision about what kind of application you want to develop, and the functionality.
Separation of Model in Design Pattern
Before talking about model, you can read about what is the "model" thing in MVC design pattern explanation. The simple explanation about model (my interpretation, don't use it in exams) is something which represent the structure of data, and possess the logic to get and/or modify the data.
Usually, model's logic can be integrated with the controller (or view model), and the structure itself can be represented using data sets (for database, or xml documents for xml). So in most cases, developers really can ignore model and integrated it with the controller itself. So why is it needed to separate the model?
If we said about small application, it will be okay to ignore model, and integrate it with the controller at all. But what if we talk about large applications? It will be hell if we use data sets or xml documents itself. A slight change with the data structure, and you must search for every controller which used that data. Yeah I already said every controller, and if the application has so many controller, it will be a pain.
Not only that, in additional model can hold some logic that bound to data, so every controller used the data can have same behavior of the logic. Let's say that a request has some mechanics like discounts or so. Instead of put the logic in controller or database, we can put it in model. So in summary, I will say that the model is quite a handy tool for data management.
Usually, model's logic can be integrated with the controller (or view model), and the structure itself can be represented using data sets (for database, or xml documents for xml). So in most cases, developers really can ignore model and integrated it with the controller itself. So why is it needed to separate the model?
If we said about small application, it will be okay to ignore model, and integrate it with the controller at all. But what if we talk about large applications? It will be hell if we use data sets or xml documents itself. A slight change with the data structure, and you must search for every controller which used that data. Yeah I already said every controller, and if the application has so many controller, it will be a pain.
Not only that, in additional model can hold some logic that bound to data, so every controller used the data can have same behavior of the logic. Let's say that a request has some mechanics like discounts or so. Instead of put the logic in controller or database, we can put it in model. So in summary, I will say that the model is quite a handy tool for data management.
The Popular MVC Design Pattern
If you need reason(s) why the desin pattern are needed in software programming, you can read mw previous post.
Honestly, at the first time I learnt this design pattern, I find it was a bit confusing. Moreover, I find it useless to separate model with the controller, even I can immediaetly find the importance to separate the view an controller. However after try to create a php project using codeigniter framework, I find the requirement are somewhat important.
Before talking further about MVC, let me tell you the basis of MVC. The view, to be simple are the user interface. It is related to everything what user sees, what user input, what user choose and logics of the UI to communicate with controller (in this case, form tag and ajax call are considered a view.
Controller on the contrary, receiving input from view, processing it with logics (if else, loop, mathematical logics, etc), getting the data from model, sending the data to model, and even choose what view will be displayed after all the process done.
Model is the object that you use in controller. Model which data will be displayed in view, which hold the logic to modify the data in storage (can be database, xml, pure text files, encoded file, etc), getting the data from storage, and hold the structure of data.
From that explanation, we can see that it is obvious to separate view with controller, in order to separate business logic with UI logic. But why is it needed for model to be separated with the controller, instead just handle the model (get and modify the data) in controller? We can get the explanation in this post.
Honestly, at the first time I learnt this design pattern, I find it was a bit confusing. Moreover, I find it useless to separate model with the controller, even I can immediaetly find the importance to separate the view an controller. However after try to create a php project using codeigniter framework, I find the requirement are somewhat important.
Before talking further about MVC, let me tell you the basis of MVC. The view, to be simple are the user interface. It is related to everything what user sees, what user input, what user choose and logics of the UI to communicate with controller (in this case, form tag and ajax call are considered a view.
Controller on the contrary, receiving input from view, processing it with logics (if else, loop, mathematical logics, etc), getting the data from model, sending the data to model, and even choose what view will be displayed after all the process done.
Model is the object that you use in controller. Model which data will be displayed in view, which hold the logic to modify the data in storage (can be database, xml, pure text files, encoded file, etc), getting the data from storage, and hold the structure of data.
From that explanation, we can see that it is obvious to separate view with controller, in order to separate business logic with UI logic. But why is it needed for model to be separated with the controller, instead just handle the model (get and modify the data) in controller? We can get the explanation in this post.
Design Pattern, How Important is it
Design pattern is usually be used in software application programming. There are some design pattern which is used widely by enterprise, or insividual programmer. But how important is this design pattern 'thing'?
The main purpose of design pattern is to separate the application interface (UI) with the business logic. Why is it needed to do such thing?
In my latest job, there was a project which need to be handed over to me. The project are using Asp.Net webform. The structure of the project are using event-driven structure, as the basis of Asp.Net webform design.
The business logic (lets say that as the logic to submit a request, validate the form or updating the request) are being done in code behind of aspx.cs form. To be worse, the business logic sometimes handled in asmx webservice and being triggered by jquery ajax, making it harder for me to decrypt it.
Well, the pain did not stop there. The design are making it harder to be modified. A little modification can cause errors in other places, and more effort are needed to unify the change in other places as well. This is, are contrary with principal of object oriented, which is encapsulation and reuseability.
So how can a design pattern be used to solve these usually founded problems? I will try to describe it in my future posts.
The main purpose of design pattern is to separate the application interface (UI) with the business logic. Why is it needed to do such thing?
In my latest job, there was a project which need to be handed over to me. The project are using Asp.Net webform. The structure of the project are using event-driven structure, as the basis of Asp.Net webform design.
The business logic (lets say that as the logic to submit a request, validate the form or updating the request) are being done in code behind of aspx.cs form. To be worse, the business logic sometimes handled in asmx webservice and being triggered by jquery ajax, making it harder for me to decrypt it.
Well, the pain did not stop there. The design are making it harder to be modified. A little modification can cause errors in other places, and more effort are needed to unify the change in other places as well. This is, are contrary with principal of object oriented, which is encapsulation and reuseability.
So how can a design pattern be used to solve these usually founded problems? I will try to describe it in my future posts.
C# Stored Procedures vs Linq
Dalam dot net programming, banyak cara bagi developer untuk melakukan hubungan dengan database dan mengaksesnya. Secara umum ada 2 cara yang umum digunakan yaitu menggunakan DataSet+SqlDataAdapter atau Linq.
Secara garis besar, kita dapat menggambarkan keuntungan Linq dibanding data adapter:
Secara garis besar, kita dapat menggambarkan keuntungan Linq dibanding data adapter:
- object oriented, sehingga tipe data yang diakses sudah terkonversi menjadi data type dot net. Hal ini membuat penggunaan tipe data yang lebih aman
- Linq memiliki query optimizer sendiri sehingga query dasar yang digunakan developer sudah diimprove secara otomatis
- relasi table dapat dilakukan secara obect-oriented sehingga lebih mudah digunakan saat development
- struktur objek Linq sangat bergantung pada struktur database, sehingga perubahan sekecil apapun akan memerlukan penangan dari sisi applikasi atau applikasi berpotensi break. Sementara mengubah stored procedures tidak memerlukan perubahaan dari sisi applikasi.
- sulit untuk menelusuri query-query yang digunakan (terutama yang kompleks). Tujuan dari penelusuran tersebut seperti saat debugging atau indexing
- stored procedures dapat digunakan untuk query yang simple hingga yang query kompleks seperti summarize atau pagination
C# Winforms vs WPF
Banyak sekali modul-modul applikasi yang dapat dibangun dan dipergunakan dengan menggunakan .Net C# Winforms. Winforms sendiri juga sudah merupakan framework yang bagus, sudah full-oop, event-driven dan stable. Namun mengapa Windows memutuskan untuk mengeluarkan framework yang lain, yaitu WPF, sebagai framework desktop lain di samping winforms? Berikut adalah perbedaan antara WPF dan Winforms.
- Winforms sangat mendukung architecture pattern MVC (model-view-controller), sementara WPF lebih mendukung menggunakan architecture pattern MVVM (model-view-viewmodel)
- Dalam arsitekturnya, Winforms adalah event-driven sementara WPF lebih mendukung binding
- Component (control) dalam WPF lebih customizable dibanding Winforms
- Struktur penulisan WPF adalah hampir sama dengan Silverlight, modul mirip flash yang dapat di-run dari browser
- Winforms menggunakan Windows API dalam men-render UI sementara WPF menggunakan directX sehingga lebih lightweight (less resource)
- Konstruksi UI winforms seluruhnya menggunakan codebehind, sementara WPF menggunakan XAML (walaupun dapat juga dilakukan dari codebehind)
- Pada WPF terdapat control "Style", yang dapat di-reuseable sehingga user tidak perlu membuat usercontrol sendiri untuk me-style kan controlnya.
C# Public Property vs Public Attribute
Well, setelah cukup lama bermain dengan C#, ada beberapa hal yang terkesan 'lucu' dalam pembelajaran. Hal tersebut adalah property vs attribute.
Dalam mendeklarasi class di C#, ada beberapa cara untuk merepresentasikan attribut, di antaranya adalah:
Dalam mendeklarasi class di C#, ada beberapa cara untuk merepresentasikan attribut, di antaranya adalah:
- Public attribute, yaitu dengan mendeklarasi attribute dengan access modifier public, sehingga mudah dapat digunakan oleh class lain
- Property, yaitu mendeklarasi public attribute dengan accessor get; dan/atau set;
- Function getter setter, cara ini digunakan umum oleh java
CUtility.Forms.CTextBoxCurrency
Digunakan untuk menggantikan TextBox asal .Net yang digunakan untuk menangani input currency. Merupakan extended dari CTextBoxNominal.
cTextBoxCurrency.CurrencyPre
Menentukan string yang akan digunakan sebagai mata uang, ditampilkan sebelum text.
cTextBoxCurrency.CurrencyPost
Menentukan string yang akan digunakan sebagai mata uang, ditampilkan setelah text.
Keyword: (C# custom textbox, C# textbox currency, C# textbox uang)
cTextBoxCurrency.CurrencyPre
Menentukan string yang akan digunakan sebagai mata uang, ditampilkan sebelum text.
cTextBoxCurrency.CurrencyPost
Menentukan string yang akan digunakan sebagai mata uang, ditampilkan setelah text.
CTextBoxCurrency cTextBoxCurrency = new CTextBoxCurrency();
cTextBoxCurrency.CurrencyPre = "Rp. "; // hasilnya Rp. 0
cTextBoxCurrency.CurrencyPre = "";
cTextBoxCurrency.CurrencyPost = " US$"; // hasilnya 0 US$Keyword: (C# custom textbox, C# textbox currency, C# textbox uang)
CUtility.Forms.CTextBox
Digunakan untuk menggantikan TextBox asal .Net dengan kustomisasi lebih banyak dan mudah.
cTextBox.InputMode
Menentukan karakter apa saja yang dapat diinput oleh user. Terdiri dari alpha, numeric, specialchar dan space. Dapat dikombinasikan dengan keyword '|' .
cTextBox.AllowedSpecialChar
Menentukan karakter apa saja di luar [a-zA-Z][0-9] dan spasi yang dapat diinput.
cTextBox.InputMode
Menentukan karakter apa saja yang dapat diinput oleh user. Terdiri dari alpha, numeric, specialchar dan space. Dapat dikombinasikan dengan keyword '|' .
CTextBox cTextBox = new CTextBox();
cTextBox.InputMode = InputMode.Alpha | InputMode.Numeric | InputMode.Space;
cTextBox.AllowedSpecialChar
Menentukan karakter apa saja di luar [a-zA-Z][0-9] dan spasi yang dapat diinput.
CTextBox cTextBox = new CTextBox();
cTextBox.InputMode = InputMode.SpecialChar;
cTextBox.AllowedSpecialChar = "[],.\\/\":;" ;
CUtility.Forms.CTextBoxNominal
Digunakan untuk pengganti TextBox bawaan .Net. Dikhususkan untuk menampung data nominal (angka).
cTextBoxNominal.AllowDecimal
Menentukan apakah boleh memasukkan nilai decimal (dengan karakter titik)
cTextBox.Nominal.AllowMinus
Menentukan apakah boleh memasukkan inputan minus (dengan karakter -)
cTextBoxNominal.TextToInt
Mengambil isi textbox yang telah diparse ke int. Jangan pergunakan ini untuk AllowDecimal = true. Fungsinya sama dengan int.Parse(cTextBoxNominal.Text).
cTextBoxNominal.TextToFloat
Mengambil isi textbox yang telah diparse ke float. Fungsinya sama dengan float.Parse(cTextBoxNominal.Text).
cTextBoxNominal.TextToDouble
Mengambil isi textbox yang telah diparse ke double. Fungsinya sama dengan double.Parse(cTextBoxNominal.Text).
Contoh:
cTextBoxNominal.AllowDecimal
Menentukan apakah boleh memasukkan nilai decimal (dengan karakter titik)
cTextBox.Nominal.AllowMinus
Menentukan apakah boleh memasukkan inputan minus (dengan karakter -)
cTextBoxNominal.TextToInt
Mengambil isi textbox yang telah diparse ke int. Jangan pergunakan ini untuk AllowDecimal = true. Fungsinya sama dengan int.Parse(cTextBoxNominal.Text).
cTextBoxNominal.TextToFloat
Mengambil isi textbox yang telah diparse ke float. Fungsinya sama dengan float.Parse(cTextBoxNominal.Text).
cTextBoxNominal.TextToDouble
Mengambil isi textbox yang telah diparse ke double. Fungsinya sama dengan double.Parse(cTextBoxNominal.Text).
Contoh:
CTextBoxNominal cTextBoxNominal = new CTextBoxNominal;
cTextBoxNominal.AllowDecimal = false;
cTextBoxNominal.AllowMinus = true;
int angka = cTextBoxNominal.TextToInt;
cTextBoxNominal.AllowDecimal = true;
float angka = cTextBoxNominal.TextToFloat;
double angka = cTextBoxNOminal.TextToDouble;
CUtility ver 1.0.1.1
Release kedua dari CUtility dengan beberapa perubahan:
- Penambahan CUtility.Print.Automated
- Optimasi CUtility.Print
- BugFix untuk CFloatForm AttachClick
- Optimasi untuk CTaskBar
- Perubahan modul untuk CTextBox dan CTextBoxCurrency
CUtility.Print.Automated
Pengembangan dari CUtility.Print, dan digunakan untuk melakukan fungsi print yang lebih baik. Keunggulan CUtility.Print.Automated dibanding CUtility.Print adalah:
Keyword: (C# print, C# print document, C# print table, C# print auto new page)
- Modular Support - fungsi print dapat dipisah-pisah menjadi bagian-bagian untuk mempermudah modifikasi
- Precalculated Height - fungsi print menghitung terlebih dulu tinggi dari objek yang akan dicetak, dan secara otomatis memindahkan ke halaman baru apabila dibutuhkan
- Groupable - perintah-perintah cetak dapat dikelompokkan secara hirarki untuk mempermudah modifikasi dan mendukung fungsi modular lebih lanjut
Keyword: (C# print, C# print document, C# print table, C# print auto new page)
CUtility.Print
Digunakan untuk menghasilkan tampilan cetakan yang lebih baik. Dilengkapi dengan fungsi-fungsi yang praktis dan mudah digunakan seperti Write, WriteLine, WriteCenter, DrawHorizontalLine, dsb.
Keunggulan dari CUtility.Print adalah:
Contoh hasil menggunakan CUtility.Print:
Fungsi-fungsi CUtility.Print dikembangkan lebih jauh ke dalam namespace CUtility.Print.Automated.
Keyword: (C# print, C# print document, C# print table, C# print utility)
Keunggulan dari CUtility.Print adalah:
- Memiliki fungsi-fungsi cetak yang mudah digunakan dan umum, seperti Write, WriteLine, WriteCenter
- Memiliki track cursor position sehingga pengaturan kursor cetak lebih mudah
- Mengingat font, brush dan pen yang digunakan dalam mencetak
- Mendukung pencetakan table
Contoh hasil menggunakan CUtility.Print:
Fungsi-fungsi CUtility.Print dikembangkan lebih jauh ke dalam namespace CUtility.Print.Automated.
Keyword: (C# print, C# print document, C# print table, C# print utility)
CUtility.Forms.CToolTip
Digunakan untuk menampilkan ToolTip dengan kustomisasi yang lebih dari ToolTip bawaan .Net.
cToolTip.Panel
Set panel yang akan digunakan untuk tampilan.
cToolTip.SetToolTip(Control control, string caption)
Mengeset Control yang akan mendapatkan ToolTip.
cToolTip.Panel
Set panel yang akan digunakan untuk tampilan.
cToolTip.Panel = new Panel(); // mengeset tampilan tooltip seperti new panel biasa
cToolTip.Panel = this.panelInfo; // mengeset tampilan tooltip sesuai dengan panelInfo yang ada dalam class
cToolTip.SetToolTip(Control control, string caption)
Mengeset Control yang akan mendapatkan ToolTip.
cToolTip.SetToolTip(label1, "A"); // mengeset object label1 agar mendapat tooltip. String yang dimasukkan tidak boleh kosong, namun tidak berpengaruh apa-apa.
CUtility.IOUtil
Digunakan untuk beberapa keperluan seperti path pada filename.
CUtility.IOUtil.RelativeFilePath(string filename)
Digunakan untuk mendapatkan path relatif dari filename (tidak memiliki label drive, dll). Berdasarkan pada application domain.
CUtility.IOUtil.AbsoluteFilePath(string filename, string location)
Digunakan untuk mendapatkan path absolut dari filename berdasarkan pada application domain.
CUtility.IOUtil.MD5Hash(string word)
Digunakan untuk mendapatkan enkripsi md5.
CUtility.IOUtil.IsDesignMode()
Digunakan untuk mengetahui design mode / running mode.
CUtility.IOUtil.MeasureString(string text, Font font)
Digunakan sebagai static function untuk menggantikan Graphics.MeasureString.
CUtility.IOUtil.RelativeFilePath(string filename)
Digunakan untuk mendapatkan path relatif dari filename (tidak memiliki label drive, dll). Berdasarkan pada application domain.
IOUtil.RelativeFilePath("C:\data\word.doc"); //return word.doc CUtility.IOUtil.AbsoluteFilePath(string filename, string location)
Digunakan untuk mendapatkan path absolut dari filename berdasarkan pada application domain.
IOUtil.AbsoluteFilePath("word.doc", "data"); //return C:\application\data\word.docCUtility.IOUtil.MD5Hash(string word)
Digunakan untuk mendapatkan enkripsi md5.
IOUtil.MD5Hash("Hello World"); //return encrypted "Hello World" wordCUtility.IOUtil.IsDesignMode()
Digunakan untuk mengetahui design mode / running mode.
CUtility.IOUtil.IsDesignMode(); //return true if in design modeCUtility.IOUtil.MeasureString(string text, Font font)
Digunakan sebagai static function untuk menggantikan Graphics.MeasureString.
CUtility.IOUtil.MeasureString("A", new Font("Times new roman", 12)); //return size dari A
CUtility.Validator
Digunakan untuk mengecek isi karakter atau angka.
CUtility.Validator.IsNum
Digunakan untuk mengecek apakah karakter atau string hanya berisi angka.
CUtility.Validator.IsAlpha
Digunakan untuk mengecek apakah karakter atau string hanya berisi karakter alfabet.
CUtility.Validator.IsAlNum
Digunakan untuk mengecek apakah karakter atau string hanya berisi karakter alfabet atau angka.
CUtility.Validator.IsNum
Digunakan untuk mengecek apakah karakter atau string hanya berisi angka.
CUtility.Validator.IsNum("123456"); //return true
CUtility.Validator.IsNum("A123456"); //return falseCUtility.Validator.IsAlpha
Digunakan untuk mengecek apakah karakter atau string hanya berisi karakter alfabet.
CUtility.Validator.IsAplha("ABCabc"); //return true
CUtility.Validator.IsAlpha("ABC1"); //return falseCUtility.Validator.IsAlNum
Digunakan untuk mengecek apakah karakter atau string hanya berisi karakter alfabet atau angka.
CUtility.Validator.IsAlNum("ABC123"); //return true
CUtility.Validator.IsAlNum("ABC123,."); //return false
Subscribe to:
Posts (Atom)
