Hello experts,
can somebody guide how in a propertygrid a property to get valid webaddress using typeconvert can be set
Hello experts,
can somebody guide how in a propertygrid a property to get valid webaddress using typeconvert can be set
Hi @SushilAgarwal-8271,
What type of project is your project, winforms, Xamarin or other?
>> get valid webaddress using typeconvert can be set
Please explain in detail and provide more information or some related code about it.
Best Regards,
Daniel Zhang
Thanks DanielZhang.
Its a Winform Project For Financial Accouting. it has got many forms for Ledgers, Billing, Purchase, Banks, Cash Entry Etc.
these forms user wants some flags or properties to be set to change the behaviour or action in a form. this project is used by diffrent firms and every body has varying needs. so their choise should be consistently remain unless user changes them, earlier i was doint that using configuration manager but that is no good option beacuse as new builds for these varying users are given somes times user settings gets distubed and user start facing things which he was not expecting
so i thouht if user settings can be saved to a table in his database new build will not alter their settings saved in db. i found propertygrid is a very good UI, some of properties rely on web url. user can type those url as strintg, i wanted if that url can be verified ?
Thanks karenpayneoregon,
Good Learn about app.config retention. and how to build typeconverter example.
but how to verify webaddress in progpertygrid property when user enters is not coming to my mind. and that is waht i am searching for.
Hi karenpayneoregon,
Many Thanks for the code, surely i will try to build typeconverter using this and other examples provided by you and reply after its complete.
i am using .net framewrok 4.8, getting error, suggetion to use C# version 8.0 but it's not supported in 4.8, i can not move to .net core 3, but really want to switch to, has got stuck due to havy use of ssrs local report. even looking some guidance how .rdl can be used in .net core without sql server deployment.
sorry, i understand that i have mixed two questions and should put them separetly.
Hi @SushilAgarwal-8271,
What is the specific problem you encountered?
Best Regards,
Daniel Zhang
The following uses .NET Framework 4.8
In both buttons a validation check is performed prior to assigning an object to the property grid. When the Address property changes this triggers the validation and if validation false the prior value is set.

This will trigger a reset after leaving the input

Class to use with a web address property
using System.ComponentModel;
namespace PropertyGridConverterExample1
{
public class Item
{
[Category("Web site"), Description("Your web site")]
public string Name { get; set; }
[Category("Web site"), Description("Your web site")]
public string Address { get; set; }
[Category("Personal details"), Description("Your first name")]
public string FirstName { get; set; }
[Category("Personal details"), Description("Your last name")]
public string LastName { get; set; }
}
}
Web address validation class
using System;
using System.Text.RegularExpressions;
namespace PropertyGridConverterExample1
{
public class WebAddressHelper
{
public static bool UrlChecker1(string url)
{
bool tryCreateResult = Uri.TryCreate(url, UriKind.Absolute, out var uriResult);
return tryCreateResult && uriResult != null;
}
public static bool UrlChecker2(string url) => Uri.IsWellFormedUriString(url, UriKind.Absolute);
public static bool UrlChecker3(string url)
{
var pattern = @"^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$";
var regex = new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
return regex.IsMatch(url);
}
}
}
Form code
Has one property grid, two buttons
using System;
using System.Windows.Forms;
namespace PropertyGridConverterExample1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
propertyGrid.PropertyValueChanged += PropertyGridOnPropertyValueChanged;
}
private void PropertyGridOnPropertyValueChanged(object s, PropertyValueChangedEventArgs args)
{
switch (args.ChangedItem.Label)
{
case "Address" when !WebAddressHelper.UrlChecker3(args.ChangedItem.Value.ToString()):
case "Name" when string.IsNullOrWhiteSpace(args.ChangedItem.Value.ToString()):
InvalidMessageAndResetToLastValue(args);
break;
}
}
private void InvalidMessageAndResetToLastValue(PropertyValueChangedEventArgs e)
{
e.ChangedItem.PropertyDescriptor.SetValue(propertyGrid.SelectedObject, e.OldValue);
MessageBox.Show(@"Wrong Data", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
private void AssignGoodButton_Click(object sender, EventArgs e)
{
propertyGrid.SelectedObject = null;
var item = new Item()
{
FirstName = "Karen",
LastName = "Payne",
Name = "ABC",
Address = "https://stackoverflow.com/questions/"
};
if (WebAddressHelper.UrlChecker3(item.Address))
{
propertyGrid.SelectedObject = item;
}
else
{
MessageBox.Show(@"Invalid address");
}
}
private void AssignBadButton_Click(object sender, EventArgs e)
{
propertyGrid.SelectedObject = null;
var item = new Item()
{
FirstName = "Karen",
LastName = "Payne",
Name = "ABC",
Address = "http://foo.bar?q=Spaces should be encoded"
};
if (WebAddressHelper.UrlChecker3(item.Address))
{
propertyGrid.SelectedObject = item;
}
else
{
MessageBox.Show(@"Invalid address");
}
}
}
}
Hello,
In regards to new builds, see the following article which explains why and then provides a solution. If that does not work for you then for a PropertyGrid you will need to create a custom TypeConverter.
Example of a TypeConverter can be found here with sample code to work against a string splitting on commas, you would model your code to validate a web address,
Check web address is available. Don't have the time to provide a full example in a PropertyGrid but going with the TypeConverter example you should be able to adapt to it.
public static async Task<bool> CheckUrlStatus(string website)
{
return await Task.Run(async () =>
{
await Task.Delay(1);
try
{
var request = WebRequest.Create(website) as HttpWebRequest;
request.Method = "HEAD";
using var response = (HttpWebResponse)request.GetResponse();
return response.StatusCode == HttpStatusCode.OK;
}
catch
{
return false;
}
});
}
private async void checkAddressStatusButton_Click(object sender, EventArgs e)
{
var webAddress = "https://stackoverflowNotHere.com/";
checkAddressStatusButton.Enabled = false;
try
{
var results = await CheckUrlStatus(webAddress);
MessageBox.Show(results ? "Is valid" : "Is not valid");
}
finally
{
checkAddressStatusButton.Enabled = true;
}
}
Thanks karenpayneoregon,
Wow you simply made a complete program to address my issue, i am highly oblidged and suprised to see you dedication and experties in helping the needy.
but yet my one more simple issue is need some help.
actually i wanted to save these configuration setting in database table so that they will be loaded from there rather then config file.
how can i retrive setting from database table and assign them to properties windows and store back the used changes to table is now the last thinng remaing to do.
by some google searched i could find how to save it back but assiging the table values to properties value is at what i am stuck.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
using KIToolkit;
using System.Xml.Serialization;
using System.IO;
using System.Threading.Tasks;
using System.Net;
using System.Reflection;
namespace Kings.ERP
{
public partial class AppConfigSetUp : FormTabSSRS
{
public AppConfigSetUp()
{
InitializeComponent();
}
private object o0,o1;
private BindingSource bs;
private DataSet ds = new DataSet();
private void AppConfig_Load(object sender, EventArgs e)
{
Keyfield = "id";
LoadData();
BindControls();
bindNavigator1.ActionWhen();
DgvFilterManager dgvAppConfigFilter = new DgvFilterManager(dgvAppConfig);
//
ConfigMgr cm = new ConfigMgr();
//
Type t = cm.GetType();
string fieldName;
object propertyValue;
//https://blogs.msmvps.com/deborahk/iterate-through-the-properties-of-a-class/
// Get the type of this instance
// Use each property of the business object passed in
//foreach (PropertyInfo pi in t.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
//{
// //
// // Get the name and value of the property
// fieldName = pi.Name;
// // Get the value of the property
// propertyValue = pi.GetValue(cm, null);
// DataRow[] dr = ds.Tables["AppProperties"].Select("Name='" + fieldName + "'");
// if (dr.Length > 0
// && !dr[0]["value"].ToString().Equals("null") )
// {
// //https://docs.microsoft.com/en-us/dotnet/api/system.reflection.propertyinfo.setvalue?view=net-5.0
// // Change the instance property value.
// PropertyInfo piInstance = cm.GetProperty(fieldName);
// piInstance.SetValue(cm, dr[0]["value"]);
// //
// //how to cast it to propertytype
// //propertyValue = dr[0]["value"];
// //https://stackoverflow.com/questions/1089123/setting-a-property-by-reflection-with-a-string-value
// PropertyInfo propertyInfo = cm.GetType().GetProperty(fieldName);
// if (propertyInfo != null)
// {
// Type t1 = Nullable.GetUnderlyingType(propertyInfo.PropertyType) ?? propertyInfo.PropertyType;
// object safeValue = (propertyValue == null) ? null : Convert.ChangeType(propertyValue, t); ;
// propertyInfo.SetValue(cm, safeValue, null);
// }
// }
// else
// {
// continue;
// }
//}
//
pg.SelectedObject = cm;
//
}
private void LoadData()
{
CursorAdapter c0 = new CursorAdapter();
c0.SelectCmd = @"select a.id,a.KeyName,a.Value,a.uppercase,a.validlength,a.columntype
from dbo.AppConfig a";
c0.SendUpdate = true;
c0.SqlTable = "AppConfig";
c0.updatableFieldList = @"KeyName,Value ";
c0.keyfields = "id";
c0.AutoIncColumns = "id";
c0.BuildAdapter(ref ds, ref o0, SqlDataBase.FillType.Data);
CursorAdapter c1 = new CursorAdapter();
c1.SelectCmd = @"select a.Name,a.Value
from dbo.AppProperties a";
c1.SendUpdate = true;
c1.SqlTable = "AppProperties";
c1.updatableFieldList = @"Name,Value ";
c1.keyfields = "Name";
c1.BuildAdapter(ref ds, ref o1, SqlDataBase.FillType.Data);
}
private void BindControls()
{
dgvAppConfig.AutoGenerateColumns = false;
id.DataPropertyName = "id";
SettingName.DataPropertyName = "KeyName";
SettingValue.DataPropertyName = "value";
columntype.DataPropertyName = "columntype";
uppercase.DataPropertyName = "uppercase";
ValidLength.DataPropertyName = "validlength";
bs = new BindingSource(ds, "AppConfig");
bindNavigator1.BindingNavigator1.BindingSource = bs;
dgvAppConfig.DataSource = bs;
DgvSource = ds.Tables["AppConfig"];
}
private void bindNavigator1_BeforeUpdate()
{
Type t = pg.GetType();
string fieldName;
object propertyValue;
//https://blogs.msmvps.com/deborahk/iterate-through-the-properties-of-a-class/
// Get the type of this instance
// Use each property of the business object passed in
foreach (PropertyInfo pi in t.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
{
// Get the name and value of the property
fieldName = pi.Name;
// Get the value of the property
propertyValue = pi.GetValue(pg, null);
DataRow[] dr = ds.Tables["AppProperties"].Select("Name='" + fieldName + "'");
if (dr.Length>0)
{
dr[0]["Value"]= propertyValue == null ? "null" : propertyValue.ToString();
}
else
{
DataRow Ndr = ds.Tables["AppProperties"].NewRow();
Ndr["Name"] = fieldName;
Ndr["Value"] = propertyValue;
ds.Tables["AppProperties"].Rows.Add(Ndr);
}
}
}
private void bindNavigator1_tblUpdate()
{
try
{
SqlDataAdapter adpAppConfig = (SqlDataAdapter)o0;
SqlDataAdapter adpProperties = (SqlDataAdapter)o1;
adpAppConfig.Update(ds.Tables["AppConfig"]);
adpProperties.Update(ds.Tables["AppProperties"]);
ds.Tables["AppConfig"].AcceptChanges();
ds.Tables["AppProperties"].AcceptChanges();
}
catch (SqlException ex)
{
MessageBox.Show(ex.ToString());
}
}
private void dgvAppConfig_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.Value != null)
{
if (dgvAppConfig["columntype", e.RowIndex].Value.Equals("S")
&& dgvAppConfig["uppercase", e.RowIndex].Value.Equals(true))
{
e.Value = e.Value.ToString().ToUpper();
e.FormattingApplied = true;
}
}
}
//Load and save
//https://www.codeproject.com/Articles/27326/Load-and-Save-Data-Using-PropertyGrid
[Serializable()]
public class AppSettings
{
protected System.Drawing.Size _size;
public System.Drawing.Size WindowSize
{
get => _size;
set=>_size = value;
}
public static AppSettings Load()
{
XmlSerializer serializer = new XmlSerializer(typeof(AppSettings));
AppSettings retVal=null;
TextReader reader;
bool fileNotFound=true;
try
{
reader = new StreamReader("MyAppSettings.xml");
}
catch (FileNotFoundException ex)
{
// Take the defaults
fileNotFound = true;
}
if (fileNotFound)
{
retVal = new AppSettings();
retVal.WindowSize = new System.Drawing.Size(600, 600);
}
else
{
// Read it from the file
//11th apr 2021 commented du to error
//retVal = (AppSettings)serializer.Deserialize(reader);
//reader.Close();
}
return retVal;
}
public void Save()
{
XmlSerializer serializer = new XmlSerializer(typeof(AppSettings));
TextWriter writer = new StreamWriter("MyAppSettings.xml");
serializer.Serialize(writer, this);
writer.Close();
}
}
//load and save
private static async Task<bool> CheckUrlStatus(string website)
{
/*
* solution from m.s.forum
https://docs.microsoft.com/en-us/answers/questions/352019/propertygrid-webadress.html?childToView=354082#answer-354082
*/
return await Task.Run(async () =>
{
await Task.Delay(1);
try
{
var request = System.Net.WebRequest.Create(website) as HttpWebRequest;
request.Method = "HEAD";
using (var response = (HttpWebResponse)request.GetResponse())
{
//response = (HttpWebResponse)request.GetResponse();
return response.StatusCode == HttpStatusCode.OK;
}
}
catch
{
return false;
}
});
}
private async void btncheckAddressStatus_Click_1(object sender, EventArgs e)
{
var webAddress = "https://stackoverflowNotHere.com/";
btncheckAddressStatus.Enabled = false;
try
{
var results = await CheckUrlStatus(webAddress);
MessageBox.Show(results ? "Is valid" : "Is not valid");
}
finally
{
btncheckAddressStatus.Enabled = true;
}
}
private void btnSaveProperties_Click(object sender, EventArgs e)
{
Type t = pg.GetType();
string fieldName;
object propertyValue;
//https://blogs.msmvps.com/deborahk/iterate-through-the-properties-of-a-class/
// Get the type of this instance
// Use each property of the business object passed in
foreach (PropertyInfo pi in t.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
{
// Get the name and value of the property
fieldName = pi.Name;
propertyValue = pi.GetValue(pg, null);
DataRow[] dr = ds.Tables["AppProperties"].Select("Name='" + fieldName + "'");
if (dr.Length > 0)
{
// Get the value of the property
dr[0]["Value"] = propertyValue == null ? "null" : propertyValue.ToString();
}
else
{
DataRow Ndr = ds.Tables["AppProperties"].NewRow();
Ndr["Name"] = fieldName;
Ndr["Value"] = propertyValue;
ds.Tables["AppProperties"].Rows.Add(Ndr);
}
}
}
}
}
//How To Use a type converter with a PropertyGrid control in C#
//http://csharphelper.com/blog/2014/09/use-a-type-converter-with-a-propertygrid-control-in-c/
/*
Getting the Most Out of the .NET Framework PropertyGrid Control
https://docs.microsoft.com/en-us/previous-versions/dotnet/articles/aa302326(v=msdn.10)?redirectedfrom=MSDN
*/
//paid propertygrid SPG
//https://marketplace.visualstudio.com/items?itemName=VisualHint.SmartPropertyGridNetforWinForms
//https://www.cyotek.com/blog/creating-a-custom-typeconverter-part-1
//Use a type converter with a PropertyGrid control in C#
//http://csharphelper.com/blog/2014/09/use-a-type-converter-with-a-propertygrid-control-in-c/
//validate all properties example
//https://social.msdn.microsoft.com/Forums/en-US/76193820-fac6-4023-9bc4-d2139ecff0f8/validation-of-property-grid-using-c?forum=csharplanguage
//https://www.levelextreme.com/Home/ShowHeader?Activator=23&ID=38766
//https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.design.iwindowsformseditorservice?redirectedfrom=MSDN&view=net-5.0
//use list
//http://www.reza-aghaei.com/how-to-edit-a-list-of-string-in-propertygrid-using-a-uitypeeditor/
using System;
using System.ComponentModel;
using System.Globalization;
using System.Reflection;
using System.Design;
using System.Windows.Forms;
using System.Threading.Tasks;
using System.Net;
/* Properties Various Settings
[Browsable(bool)] "To show property or not"
[ReadOnly(bool)] "Ability to edit property"
[Category(string)] "Group of property"
[Description(string)] "Property description, which can be a hint"
[DisplayName(string)] "Display Name property"
*/
namespace Kings.ERP
{
//SalesLinkedToProduction, 0-No,1-Pre Gst based on oc_link,2-based on issue opening + mfg - sales
public enum Sales2Production
{
Not_Applicable,
Oc_Link,
Purchase_StockEntry
}
public enum LcSales
{
Not_Applicable,
Labour_Charges,
Against_Grn
}
public enum Period
{
Day,
Week,
Fortnight,
Month,
Quarter,
Half_Year,
Year
}
//https://docs.microsoft.com/en-us/dotnet/api/system.dayofweek?view=net-5.0
public enum DaysOfWeek
{
Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday
}
[DefaultPropertyAttribute("Name")]
public class ConfigMgr
{
bool
Billno_OnSave = false,
pvno_OnSave = false,
GRNno_OnSave = false,
OC_OnSave = false,
OA_OnSave = false,
IssueSlip_OnSave = false,
Purchase_OnGrn = false,
SalePackingDetailes = false,
bag_packet_qty = false,
MdiFixedImage = false,
SaleRateFromGRN = false,
//
BillItemsOnOaItems = false,
//
BillDateWithoutTime = true,
Purchase_po = true,
QcOnGrn = true,
BillDateEditable = true,
AllowNegativeStock = true;
private string
CommonFilePath = @"\\192.168.100.3\erpfiles",
PdiIdentityKey = "jaiho",
//GSPName = "TaxPro_Production",
//AuthUrl = "https://api.taxprogsp.co.in/eivital/v1.03",
//BaseUrl = "https://api.taxprogsp.co.in/eicore/v1.03",
//EwbByIRN = "https://api.taxprogsp.co.in/eiewb/v1.03",
//CancelEwbUrl = "https://api.taxprogsp.co.in/v1.03",
UserName = "API_MFPL",
Password = "Mfpl@2021",
MdiImage = @"..\..\Resources\ChesskingBW.jpg",
SlideShowImageFolder = @"C:\Users\Sushil\Pictures",
//KI_Email = "asushil@gmail.com",
mail_server = "smtp.gmail.com",
Mahindra_Ac = "2-252",
BackgroundImage = @"..\..\Resources\chesskingbw.jpg",
ServerReportPath = @"http://server/reportserver";
private int
MdiSlideTimer = 10000,
s_cashgl = 1,
s_debtorgl = 2,
s_creditorgl = 3,
s_drivergl = 15,
CodeGroupInterVal = 25,
mail_port = 587,
PosDefaultQty = 1;
//Bill To MultiGRn Link at Kimya set it to 2 otheriwse 0,LC Sales, Labour Sales
LcSales SaleGrnLinq = LcSales.Not_Applicable;
[CategoryAttribute("Sales"), DescriptionAttribute("Labour Charges Work Billing Methods")]
public LcSales _SaleGrnLinq
{
get => SaleGrnLinq;
set => SaleGrnLinq = value;
}
[CategoryAttribute("Sales"), DescriptionAttribute("Verify Production Stock While Billing")]
Sales2Production SalesLinkedToProduction = Sales2Production.Not_Applicable;
public Sales2Production _SalesLinkedToProduction
{
get => SalesLinkedToProduction;
set => SalesLinkedToProduction = value;
}
[CategoryAttribute("Sales"), DescriptionAttribute("Show Item List Having Order Acceptance Entry")]
[TypeConverter(typeof(DyasOfWeekConverter1))]
public bool _BillItemsOnOaItems
{
get => BillItemsOnOaItems;
set => BillItemsOnOaItems = value;
}
[CategoryAttribute("Sales"), DescriptionAttribute("Point Of Sale Default Qty.")]
public int _PosDefaultQty
{
get => PosDefaultQty;
set => PosDefaultQty = value;
}
[CategoryAttribute("Reports"), DescriptionAttribute("Sql Server Reports Path")]
//[Category("Reports")]
//[Description("Sql Server Reports Path")]
////[EditorAttribute(typeof(System.Windows.Forms.Design.FileNameEditor), typeof(System.Drawing.Design.UITypeEditor))]
////your poject should refer to System.Design.dll .net 4.0, and using System.Design
//[EditorAttribute(typeof(System.Windows.Forms.Design.FolderNameEditor), typeof(System.Drawing.Design.UITypeEditor))]
public string _ServerReportPath
{
get => ServerReportPath;
set => ServerReportPath = value;
}
[CategoryAttribute("Ledgers"), DescriptionAttribute("Mahindra A/c. No.")]
public string _Mahindra_Ac
{
get => Mahindra_Ac;
set => Mahindra_Ac = value;
}
[CategoryAttribute("Bansal ERP"), DescriptionAttribute("Back Ground Image File")]
[EditorAttribute(typeof(System.Windows.Forms.Design.FileNameEditor), typeof(System.Drawing.Design.UITypeEditor))]
public string _BackgroundImage
{
get => BackgroundImage;
set => BackgroundImage = value;
}
//[CategoryAttribute("E-Mail"), DescriptionAttribute("Send E-mail From A/c.")]
//public string _KI_Email
//{
// get =>KI_Email;
// set =>KI_Email=value;
//}
[CategoryAttribute("E-Mail"), DescriptionAttribute("Mail Server Name")]
public string _mail_server
{
get => mail_server;
set => mail_server = value;
}
[CategoryAttribute("E-Mail"), DescriptionAttribute("Google Default Port is 587")]
public int _mail_port
{
get => mail_port;
set => mail_port = value;
}
[CategoryAttribute("Bansal ERP"), DescriptionAttribute("Q.C.Code Each Group Id Gap")]
public int _CodeGroupInterVal
{
get => CodeGroupInterVal;
set => CodeGroupInterVal = value;
}
//https://www.codeproject.com/Articles/6294/Description-Enum-TypeConverter
DaysOfWeek WeeklyOff = DaysOfWeek.Sunday;
[CategoryAttribute("Bansal ERP"), DescriptionAttribute("Weekly off")]
//[TypeConverter(typeof(DyasOfWeekConverter))]
public DaysOfWeek _WeeklyOff
{
get => WeeklyOff;
set => WeeklyOff = value;
}
Period SeePastDataOf = Period.Week;
[CategoryAttribute("Bansal ERP"), DescriptionAttribute("Shiow Data Of Past")]
//[TypeConverter(typeof(DyasOfWeekConverter))]
public Period _SeePastDataOf
{
get => SeePastDataOf;
set => SeePastDataOf = value;
}
//
ImageLayout MdiImageLayout = ImageLayout.Center;
[CategoryAttribute("Slide Show"), DescriptionAttribute("Show Your Products Images settings")]
public ImageLayout _MdiImageLayout
{
get => MdiImageLayout;
set => MdiImageLayout = value;
}
[CategoryAttribute("Slide Show"), DescriptionAttribute("Set Show Next Slide in Milliseconds")]
public int _MdiSlideTimer
{
get => MdiSlideTimer;
set => MdiSlideTimer = value;
}
[CategoryAttribute("Sales"), DescriptionAttribute("Sales Rate From Grn\nKimaya Engginering")]
[TypeConverter(typeof(YesNoClassConverter))]
public bool _SaleRateFromGRN
{
get => SaleRateFromGRN;
set => SaleRateFromGRN = value;
}
[CategoryAttribute("Slide Show"), DescriptionAttribute("set Single Image or Show From Folder")]
[TypeConverter(typeof(YesNoClassConverter))]
public bool _MdiFixedImage
{
get => MdiFixedImage;
set => MdiFixedImage = value;
}
[CategoryAttribute("Slide Show"), DescriptionAttribute("Show Your Products Images settings")]
[EditorAttribute(typeof(System.Windows.Forms.Design.FolderNameEditor), typeof(System.Drawing.Design.UITypeEditor))]
public string _SlideShowImageFolder
{
get => SlideShowImageFolder;
set => SlideShowImageFolder = value;
}
[CategoryAttribute("Slide Show"), DescriptionAttribute("Show Your Products Images settings")]
[EditorAttribute(typeof(System.Windows.Forms.Design.FileNameEditor), typeof(System.Drawing.Design.UITypeEditor))]
public string _MdiImage
{
get => MdiImage;
set => MdiImage = value;
}
[CategoryAttribute("Sales"), DescriptionAttribute("Is Negative Stock allowed ?")]
[TypeConverter(typeof(YesNoClassConverter))]
public bool _AllowNegativeStock
{
get => AllowNegativeStock;
set => AllowNegativeStock = value;
}
[CategoryAttribute("Sales"), DescriptionAttribute("Yes:User Can Changed Bill Date, No:System Date")]
[TypeConverter(typeof(YesNoClassConverter))]
public bool _BillDateEditable
{
get => BillDateEditable;
set => BillDateEditable = value;
}
[CategoryAttribute("GRN"), DescriptionAttribute("Show Q.C. while MAking GRN")]
[TypeConverter(typeof(YesNoClassConverter))]
public bool _QcOnGrn
{
get => QcOnGrn;
set => QcOnGrn = value;
}
[CategoryAttribute("Purchase"), DescriptionAttribute("Check P.O. On Purchase Entry ")]
[TypeConverter(typeof(YesNoClassConverter))]
public bool _Purchase_po
{
get => Purchase_po;
set => Purchase_po = value;
}
[CategoryAttribute("Sales"), DescriptionAttribute("Exclude Time From Bill Date")]
[TypeConverter(typeof(YesNoClassConverter))]
public bool _BillDateWithoutTime
{
get => BillDateWithoutTime;
set => BillDateWithoutTime = value;
}
[CategoryAttribute("Sales"), DescriptionAttribute("Fetch Bag_packet_qty from item master")]
[TypeConverter(typeof(YesNoClassConverter))]
public bool _bag_packet_qty
{
get => bag_packet_qty;
set => bag_packet_qty = value;
}
[CategoryAttribute("Sales"), DescriptionAttribute("Set Packing Details")]
[TypeConverter(typeof(YesNoClassConverter))]
public bool _SalePackingDetailes
{
get => SalePackingDetailes;
set => SalePackingDetailes = value;
}
[CategoryAttribute("Numbering"), DescriptionAttribute("Will Generate Document Number if No:on Entry,Yes:On Save")]
[TypeConverter(typeof(YesNoClassConverter))]
public bool _Purchase_OnGrn
{
get => Purchase_OnGrn;
set => Purchase_OnGrn = value;
}
[CategoryAttribute("Numbering"), DescriptionAttribute("Will Generate Document Number if No: on Entry, Yes: On Save")]
[TypeConverter(typeof(YesNoClassConverter))]
public bool _IssueSlip_OnSave
{
get => IssueSlip_OnSave;
set => IssueSlip_OnSave = value;
}
[CategoryAttribute("Numbering"), DescriptionAttribute("Will Generate Document Number if No:on Entry,Yes:On Save")]
[TypeConverter(typeof(YesNoClassConverter))]
public bool _OA_OnSave
{
get => OA_OnSave;
set => OA_OnSave = value;
}
[CategoryAttribute("Numbering"), DescriptionAttribute("Will Generate Document Number if No:on Entry,Yes:On Save")]
[TypeConverter(typeof(YesNoClassConverter))]
public bool _OC_OnSave
{
get => OC_OnSave;
set => OC_OnSave = value;
}
[CategoryAttribute("Numbering"), DescriptionAttribute("Will Generate Document Number if No:on Entry,Yes:On Save")]
[TypeConverter(typeof(YesNoClassConverter))]
public bool _GRNno_OnSave
{
get => GRNno_OnSave;
set => GRNno_OnSave = value;
}
[CategoryAttribute("Numbering"), DescriptionAttribute("Will Generate Document Number if No:on Entry,Yes:On Save")]
[TypeConverter(typeof(YesNoClassConverter))]
public bool _Billno_OnSave
{
get => Billno_OnSave;
set => Billno_OnSave = value;
}
[CategoryAttribute("Numbering"), DescriptionAttribute("Will Generate Document Number if No:on Entry,Yes:On Save")]
[TypeConverter(typeof(YesNoClassConverter))]
public bool _pvno_OnSave
{
get => pvno_OnSave;
set => pvno_OnSave = value;
}
[Category("Reports")]
[Description("Report Folder Path ")]
//[EditorAttribute(typeof(System.Windows.Forms.Design.FileNameEditor), typeof(System.Drawing.Design.UITypeEditor))]
//your poject should refer to System.Design.dll .net 4.0, and using System.Design
[EditorAttribute(typeof(System.Windows.Forms.Design.FolderNameEditor), typeof(System.Drawing.Design.UITypeEditor))]
public string _CommonFilePath
{
get => CommonFilePath;
set => CommonFilePath = value;
}
//[CategoryAttribute("E-Invoice GSP"), DescriptionAttribute("GSP Name")]
//public string _GSPName { get => GSPName; set => GSPName = value; }
//[CategoryAttribute("E-Invoice GSP"), DescriptionAttribute("Authentication web URL")]
//public string _AuthUrl { get => AuthUrl; set => AuthUrl = value; }
//[CategoryAttribute("E-Invoice GSP"), DescriptionAttribute("Base web URL")]
//public string _BaseUrl { get => BaseUrl; set => BaseUrl = value; }
//[CategoryAttribute("E-Invoice GSP"), DescriptionAttribute("IRN web URL")]
//public string _EwbByIRN { get => EwbByIRN; set => EwbByIRN = value; }
//[CategoryAttribute("E-Invoice GSP"), DescriptionAttribute("Cancell IRN web URL")]
//public string _CancelEwbUrl { get => CancelEwbUrl; set => CancelEwbUrl = value; }
[CategoryAttribute("E-Invoice GSP"), DescriptionAttribute("E-invoice Via GSP User Name")]
public string _UserName { get => UserName; set => UserName = value; }
[CategoryAttribute("E-Invoice GSP"), DescriptionAttribute("E-invoice Via GSP User Password")]
public string _Password { get => Password; set => Password = value; }
[CategoryAttribute("Ledgers"), DescriptionAttribute("Customer G.L.Id")]
public int _s_debtorgl
{
get => s_debtorgl;
set => s_debtorgl = value;
}
[CategoryAttribute("Ledgers"), DescriptionAttribute("Cash On Hand ID")]
public int _s_cashgl
{
get => s_cashgl;
set => s_cashgl = value;
}
[CategoryAttribute("Ledgers"), DescriptionAttribute("Suppliers G.L.ID")]
public int _s_creditorgl
{
get => s_creditorgl;
set => s_creditorgl = value;
}
[CategoryAttribute("Ledgers"), DescriptionAttribute("Drivers G.L.ID")]
public int _s_drivergl
{
get { return s_drivergl; }
set { s_drivergl = value; }
}
//
[CategoryAttribute("PDI"), DescriptionAttribute("PDI Auto Fill Key")]
public string _PdiIdentityKey
{
get { return PdiIdentityKey; }
set { PdiIdentityKey = value; }
}
public ConfigMgr()
{
//
// TODO: Add constructor logic here
//
}
}
class YesNoClassConverter : BooleanConverter
{
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destType)
{
return (bool)value ? "Yes" : "No";
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
return (string)value == "Yes";
}
}
public class DyasOfWeekConverter : EnumConverter
{
private Type _enumType;
/// <summary>Initializing instance</summary>
/// <param name="type">type Enum</param>
///this is only one function, that you must
///to change. All another functions for enums
///you can use by Ctrl+C/Ctrl+V
public DyasOfWeekConverter(Type type) : base(type)
{
_enumType = type;
}
public override bool CanConvertTo(ITypeDescriptorContext context, Type destType)
{
return destType == typeof(string);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destType)
{
FieldInfo fi = _enumType.GetField(Enum.GetName(_enumType, value));
DescriptionAttribute dna =
(DescriptionAttribute)Attribute.GetCustomAttribute(
fi, typeof(DescriptionAttribute));
if (dna != null)
return dna.Description;
else
return value.ToString();
}
public override bool CanConvertFrom(ITypeDescriptorContext context, Type srcType)
{
return srcType == typeof(string);
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
foreach (FieldInfo fi in _enumType.GetFields())
{
DescriptionAttribute dna =
(DescriptionAttribute)Attribute.GetCustomAttribute(fi, typeof(DescriptionAttribute));
if ((dna != null) && ((string)value == dna.Description))
return Enum.Parse(_enumType, fi.Name);
}
return Enum.Parse(_enumType, (string)value);
}
}
public class DyasOfWeekConverter1 : EnumConverter
{
/*
https://social.msdn.microsoft.com/Forums/vstudio/en-US/c71938b7-aff1-4fcb-aeff-a07457220ec4/how-do-i-display-enumerations-nicer-in-a-property-grid?forum=csharpgeneral
*/
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return sourceType == typeof(string);
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
return Enum.Parse(typeof(DayOfWeek), value.ToString().ToUpper().Replace(' ', '_'));
}
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
return destinationType == typeof(string);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
string s = value.ToString();
int i = s.IndexOf('_');
return s[0] + s.Substring(1, i - 1).ToLower() + ' ' + s[i + 1] + s.Substring(i + 2).ToLower();
}
public DyasOfWeekConverter1() : base(typeof(DayOfWeek)) { }
}
}
If I have answered your original question than mark it as the answer. Then start a new question and I will help you tomorrow. But first close this question by marking the reply which resolved then non-database aspect. When you start the new question confirm the database type eg. SQL-Server for instance.
8 people are following this question.