using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.IO;
using System.Globalization;



public static class myfunction
{

   


    public enum dataConvertMode
    {
        toGregorian = 0,
        toPersian = 1
    }
   
    public static string convertDate(string strDate, dataConvertMode convertMode, float addDay = 0)
    {
        PersianCalendar cal = new PersianCalendar();
        if (convertMode == dataConvertMode.toGregorian)
        {
            DateTime dt = cal.ToDateTime(Convert.ToInt32(strDate.Substring(0, 4)), Convert.ToInt32(strDate.Substring(5, 2)),
                                            Convert.ToInt32(strDate.Substring(8, 2)), 0, 0, 0, 0, 0);
            return dt.AddDays(addDay).ToShortDateString();
        }
        else
        {
            DateTime myDate = Convert.ToDateTime(strDate).AddDays(addDay);
            string Year, Day, Month;
            Year = cal.GetYear(myDate).ToString();
            Month = cal.GetMonth(myDate).ToString();
            Day = cal.GetDayOfMonth(myDate).ToString();
            Day = (Day.Length == 1) ? "0" + Day : Day;
            Month = (Month.Length == 1) ? "0" + Month : Month;
            return (Year + '/' + Month + '/' + Day);
        }
    }
 

    
  

        private static string[] yekan = new string[10] { "صفر", "یک", "دو", "سه", "چهار", "پنج", "شش", "هفت", "هشت", "نه" };
        private static string[] dahgan = new string[10] { "", "", "بیست", "سی", "چهل", "پنجاه", "شصت", "هفتاد", "هشتاد", "نود" };
        private static string[] dahyek = new string[10] { "ده", "یازده", "دوازده", "سیزده", "چهارده", "پانزده", "شانزده", "هفده", "هجده", "نوزده" };
        //array[10..19]
        private static string[] sadgan = new string[10] { "", "یکصد", "دویست", "سیصد", "چهارصد", "پانصد", "ششصد", "هفتصد", "هشتصد", "نهصد" };
        private static string[] basex = new string[5] { "", "هزار", "میلیون", "میلیارد", "تریلیون" };


        private static string getnum3(int num3)
        {
            try
            {
                string s = "";
                int d3, d12;
                d12 = num3 % 100;
                d3 = num3 / 100;
                if (d3 != 0)
                    s = sadgan[d3] + " و ";
                if ((d12 >= 10) && (d12 <= 19))
                {
                    s = s + dahyek[d12 - 10];
                }
                else
                {
                    int d2 = d12 / 10;
                    if (d2 != 0)
                        s = s + dahgan[d2] + " و ";
                    int d1 = d12 % 10;
                    if (d1 != 0)
                        s = s + yekan[d1] + " و ";
                    s = s.Substring(0, s.Length - 3);
                };
                return s;
            }
            catch { return ""; }
        }

        public static string numtostr(string snum)
        {
            try
            {
                string stotal = "";
                if (snum == "0")
                {
                    return yekan[0];
                }
                else
                {
                    snum = snum.PadLeft(((snum.Length - 1) / 3 + 1) * 3, '0');
                    int L = snum.Length / 3 - 1;
                    for (int i = 0; i <= L; i++)
                    {
                        int b = int.Parse(snum.Substring(i * 3, 3));
                        if (b != 0)
                            stotal = stotal + getnum3(b) + " " + basex[L - i] + " و ";
                    }
                    stotal = stotal.Substring(0, stotal.Length - 3);
                }
                return stotal;
            }
            catch { return ""; }
        }

        internal static string convertDate(int p, int p_2, int p_3, int p_4)
        {
            throw new NotImplementedException();
        }
}




//    using System.Collections.Specialized;


//using Microsoft.SqlServer.Management.Common;


//using Microsoft.SqlServer.Management.Smo;

//Server svr;

//StringCollection sc;

//svr = new Server();

//sc = new StringCollection();

//sc.Add(@"c:\test.mdf");

//svr.AttachDatabase("test", sc);






