Spliting string in C# is one of the most interesting part. you can also perform your business logic operation on spliting part.
Hare is a list of serial no comes from database, i split the Serial no then just increment id no +1 on maximum serial no, and return to UI.
i also check hare is the serial no is in current year.
Enjoy...
Hare is a list of serial no comes from database, i split the Serial no then just increment id no +1 on maximum serial no, and return to UI.
i also check hare is the serial no is in current year.
internal string GetNewSerialNo()
{
string refence = "";
DateTime dt = DateTime.Now;
List<RFQ> _listAllRef =new List<RFQ>();
foreach (var objrfq in rfqDalObj.GetNewSerialNo())
{
string[] splitedRef = (objrfq.SerialNO).Split('-');
if(DateTime.Now.Year.ToString()==splitedRef[1])
{
_listAllRef.Add(objrfq);
}
}
List<int> rfqSerials = new List<int>();
if (_listAllRef.Count > 0)
{
foreach (var obj in _listAllRef)
{
string[] splitedRef = (obj.SerialNO).Split('-');
string[] splitedMainId = splitedRef[0].Split('Q');
rfqSerials.Add(Convert.ToInt32(splitedMainId[1]));
}
refence = "RFQ"+ (rfqSerials.Max() + 1) + "-" + dt.Year;
}
else
{
refence = "RFQ10001" + "-" + dt.Year;
}
return refence;
}
Enjoy...
Comments
Post a Comment