using System;
using System.Data;
using System.IO;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.Text;
using System.Globalization;
[Serializable]
[Microsoft.SqlServer.Server.SqlUserDefinedType(Format.UserDefined, MaxByteSize = 8000,
IsByteOrdered = true, ValidationMethodName = "ValidatePesel")]
public struct Pesel : INullable, IBinarySerialize
{
private bool is_Null;
private string _s;
public bool IsNull
{
get
{
return (is_Null);
}
}
public static Pesel Null
{
get
{
Pesel p = new Pesel();
p.is_Null = true;
return p;
}
}
// Use StringBuilder to provide string representation of UDT.
public override string ToString()
{
if (this.IsNull)
return "NULL";
else
{
//Pesel p = new Pesel();
return s.ToString();
}
}
[SqlMethod(OnNullCall = false)]
public static Pesel Parse(SqlString ss)
{
if (ss.IsNull)
{
return Null;
}
Pesel p = new Pesel();
p.s = (string)ss;
return p;
}
public string s
{
get
{
return this._s;
}
set
{
string temp = _s;
_s = value;
if (!ValidatePesel())
{
_s = temp;
throw new ArgumentException("Invalid X coordinate value.");
}
}
}
public void Read(BinaryReader r)
{
_s = r.ReadString();
}
public void Write(BinaryWriter w)
{
string ss = _s.ToString();
w.Write(ss);
}
public bool ValidatePesel()
{
int[] weights = { 1, 3, 7, 9, 1, 3, 7, 9, 1, 3 };
bool result = false;
if (_s.Length == 11)
{
int controlSum = CalculateControlSum(_s.ToString(), weights);
int controlNum = controlSum % 10;
controlNum = 10 - controlNum;
if (controlNum == 10)
{
controlNum = 0;
}
int lastDigit = int.Parse(_s[_s.Length - 1].ToString());
result = controlNum == lastDigit;
}
return result;
}
public static int CalculateControlSum(string input, int[] weights, int offset = 0)
{
int controlSum = 0;
for (int i = 0; i < input.Length - 1; i++)
{
controlSum += weights[i + offset] * int.Parse(input[i].ToString());
}
return controlSum;
}
public static string BirthDate()
{
if (ValidatePesel())
{
string birth = new SqlString("Dzien: " + _s.Substring(4, 2) + "Miesiąc: " + _s.Substring(2, 2) + "Rok: "_s.Substring(0, 2));
return birth;
}
return null;
}
}
Kod wyrzuca błąd w Visual Studio 2015. Proszę o pomoc.