using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace migrate_data
{
    public class MDspecObj
    {
        private string mDspecInsert = "Insert Into z_mdspec(ID, [RPM Part Number], [ERN], [Replaces], [Application], [OE/Reman], [Basic Class], [Status], [Same As], [Except], [Make From], [Float], [Volts], [Rot], [TermP], [Drive], [Pinion], [Pitch], [Switch], [SwP], [HO], [SAE], [MtgH], [FTF], [Opening], [Treatment], [Curve], [Remarks], [JSP], [Suction Port], [Pressure Port], [Suction Fitting], [Pressure Fitting], [Additional Parts], [Gasket], [Change], [Service Type], [Notes], [Service Replacement Ref], [SRR Except], [Metal Tag], [Tag Number], [Paper Tag], [Other Tag], [Signed], [Date Signed], [Checked], [Date Checked], [Effective Date], [Obsolete], [Box], [Reason for change], [Work Instruction], [PLRV], [Bracket], [RTV], [Hz], [Weight], [FAC Required], [FAC Completed], [Validation])"
                                                  + "values({0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, {13}, {14}, {15}, {16}, {17}, {18}, {19}, {20}, {21}, {22}, {23}, {24}, {25}, {26}, {27}, {28}, {29}, {30}, {31}, {32}, {33}, {34}, {35}, {36}, {37}, {38}, {39}, {40}, {41}, {42}, {43}, {44}, {45}, {46}, {47}, {48}, {49}, {50}, {51}, {52}, {53}, {54}, {55}, {56}, {57}, {58}, {59}, {60})";

        #region Properties
        public int id { get; set; }//0
        public string number { get; set; }//1
        public string ern { get; set; }//2
        public string replaces { get; set; }//3
        public string application { get; set; }//4
        public string oereman { get; set; }//5
        public string basicclass { get; set; }//6
        public string status { get; set; }//7
        public string sameas { get; set; }//8
        public string except { get; set; }//9
        public string makefrom { get; set; }//10
        public string floatStr { get; set; }//11
        public string volts { get; set; }//12
        public string rot { get; set; }//13
        public string termp { get; set; }//14
        public string drive { get; set; }//15
        public string pinion { get; set; }//16
        public string pitch { get; set; }//17
        public string swtch { get; set; }//18
        public string swp { get; set; }//19
        public string ho { get; set; }//20
        public string sae { get; set; }//21
        public string mtgh { get; set; }//22
        public string ftf { get; set; }//23
        public string opening { get; set; }//24
        public string treatment { get; set; }//25
        public string curve { get; set; }//26
        public string remarks { get; set; }//27
        public int? jsp { get; set; }//28
        public string suctionport { get; set; }//29
        public string pressureport { get; set; }//30
        public string suctionfitting { get; set; }//31
        public string pressurefitting { get; set; }//32
        public string additionalparts { get; set; }//33
        public string gasket { get; set; }//34
        public int? change { get; set; }//35
        public string servicetype { get; set; }//36
        public string notes { get; set; }//37
        public string servicereplacementref { get; set; }//38
        public string srrexcept { get; set; }//39
        public string metaltag { get; set; }//40
        public string tagnumber { get; set; }//41
        public string papertag { get; set; }//42
        public string othertag { get; set; }//43
        public string signed { get; set; }//44
        public DateTime? datesigned { get; set; }//45
        public string chkd { get; set; }//46
        public DateTime? datechecked { get; set; }//47
        public DateTime? effectivedate { get; set; }//48
        public int? obsolete { get; set; }//49
        public string box { get; set; }//50
        public string reasonforchange { get; set; }//51
        public string workinstruction { get; set; }//52
        public int? plrv { get; set; }//53
        public int? bracket { get; set; }//54
        public int? rtv { get; set; }//55
        public string hz { get; set; }//56
        public string weight { get; set; }//57
        public int? facrequired { get; set; }//58
        public int? faccompleted { get; set; }//59
        public string validation { get; set; }//60
        #endregion
        
        public string SingleQuotes(string str)
        {
            if (string.IsNullOrEmpty(str))
                return "null";
            else return string.Format("'{0}'", str);
        }

        public int? ConvertBit(int? i)
        {
            if (i == null) return null;
            else if (i < 0) return 1;
            else return 0;
        }

        public DateTime? DateVal(string dt)
        {
            bool isValid = false;
            DateTime date;
            isValid = DateTime.TryParse(dt, out date);
            if (isValid) return date;
            else return null;
        }

        public void SetVals(DataRow row)
        {
            int i = 0;
            this.id = Convert.ToInt32(row.ItemArray[i]); i = i + 1;//0
            this.number = SingleQuotes(row.ItemArray[i].ToString());i = i + 1;//1
            this.ern = SingleQuotes(row.ItemArray[i].ToString().Replace("'", ""));i = i + 1;//2
            this.replaces = SingleQuotes(row.ItemArray[i].ToString().Replace("'", ""));i = i + 1;//3
            this.application = SingleQuotes(row.ItemArray[i].ToString().Replace("'", ""));i = i + 1;//4
            this.oereman = SingleQuotes(row.ItemArray[i].ToString().Replace("'", ""));i = i + 1;//5
            this.basicclass = SingleQuotes(row.ItemArray[i].ToString().Replace("'", ""));i = i + 1;//6
            this.status = SingleQuotes(row.ItemArray[i].ToString().Replace("'", "")); i = i + 1;//7
            this.sameas = SingleQuotes(row.ItemArray[i].ToString().Replace("'", ""));i = i + 1;//8
            this.except = SingleQuotes(row.ItemArray[i].ToString().Replace("'", ""));i = i + 1;//9
            this.makefrom = SingleQuotes(row.ItemArray[i].ToString().Replace("'", ""));i = i + 1;//10
            this.floatStr = SingleQuotes(row.ItemArray[i].ToString().Replace("'", ""));i = i + 1;//11
            this.volts = SingleQuotes(row.ItemArray[i].ToString().Replace("'", ""));i = i + 1;//12
            this.rot = SingleQuotes(row.ItemArray[i].ToString().Replace("'", ""));i = i + 1;//13
            this.termp = SingleQuotes(row.ItemArray[i].ToString().Replace("'", ""));i = i + 1;//14
            this.drive = SingleQuotes(row.ItemArray[i].ToString().Replace("'", ""));i = i + 1;//15
            this.pinion = SingleQuotes(row.ItemArray[i].ToString().Replace("'", ""));i = i + 1;//16
            this.pitch = SingleQuotes(row.ItemArray[i].ToString().Replace("'", ""));i = i + 1;//17
            this.swtch = SingleQuotes(row.ItemArray[i].ToString().Replace("'", "")); i = i + 1;//18
            this.swp = SingleQuotes(row.ItemArray[i].ToString().Replace("'", "")); i = i + 1;//19
            this.ho = SingleQuotes(row.ItemArray[i].ToString().Replace("'", "")); i = i + 1;//20
            this.sae = SingleQuotes(row.ItemArray[i].ToString().Replace("'", ""));i = i + 1;//21
            this.mtgh = SingleQuotes(row.ItemArray[i].ToString().Replace("'", ""));i = i + 1;//22
            this.ftf = SingleQuotes(row.ItemArray[i].ToString().Replace("'", ""));i = i + 1;//23
            this.opening = SingleQuotes(row.ItemArray[i].ToString().Replace("'", "")); i = i + 1;//24
            this.treatment = SingleQuotes(row.ItemArray[i].ToString().Replace("'", ""));  i = i + 1;//25
            this.curve = SingleQuotes(row.ItemArray[i].ToString().Replace("'", ""));  i = i + 1;//26
            this.remarks = SingleQuotes(row.ItemArray[i].ToString().Replace("'", ""));  i = i + 1;//27
            this.jsp = row.ItemArray[i] == DBNull.Value ? null : ConvertBit((int?)Convert.ToInt32(row.ItemArray[i]));  
            i = i + 1;//28
            this.suctionport = SingleQuotes(row.ItemArray[i].ToString().Replace("'", ""));   i = i + 1;//29
            this.pressureport = SingleQuotes(row.ItemArray[i].ToString().Replace("'", ""));  i = i + 1;//30
            this.suctionfitting = SingleQuotes(row.ItemArray[i].ToString().Replace("'", ""));   i = i + 1;//31
            this.pressurefitting = SingleQuotes(row.ItemArray[i].ToString().Replace("'", ""));  i = i + 1;//32
            this.additionalparts = SingleQuotes(row.ItemArray[i].ToString().Replace("'", "")); i = i + 1;//33
            this.gasket = SingleQuotes(row.ItemArray[i].ToString().Replace("'", ""));  i = i + 1;//34
            this.change = row.ItemArray[i] == DBNull.Value ? null : ConvertBit((int?)Convert.ToInt32(row.ItemArray[i])); i = i + 1;//35
            this.servicetype = SingleQuotes(row.ItemArray[i].ToString().Replace("'", "")); i = i + 1;//36
            this.notes = SingleQuotes(row.ItemArray[i].ToString().Replace("'", ""));  i = i + 1;//37
            this.servicereplacementref = SingleQuotes(row.ItemArray[i].ToString().Replace("'", "")); i = i + 1;//38
            this.srrexcept = SingleQuotes(row.ItemArray[i].ToString().Replace("'", ""));  i = i + 1;//39
            this.metaltag = SingleQuotes(row.ItemArray[i].ToString().Replace("'", "")); i = i + 1;//40
            this.tagnumber = SingleQuotes(row.ItemArray[i].ToString().Replace("'", "")); i = i + 1;//41
            this.papertag = SingleQuotes(row.ItemArray[i].ToString().Replace("'", ""));i = i + 1;//42
            this.othertag = SingleQuotes(row.ItemArray[i].ToString().Replace("'", "")); i = i + 1;//43
            this.signed = SingleQuotes(row.ItemArray[i].ToString().Replace("'", "")); i = i + 1;//44
            this.datesigned = DateVal(row.ItemArray[9].ToString()); i = i + 1;//45
            this.chkd = SingleQuotes(row.ItemArray[i].ToString().Replace("'", "")); i = i + 1;//46
            this.datechecked = DateVal(row.ItemArray[9].ToString()); i = i + 1;//47
            this.effectivedate = DateVal(row.ItemArray[9].ToString()); i = i + 1;//48
            this.obsolete = row.ItemArray[i] == DBNull.Value ? null : ConvertBit((int?)Convert.ToInt32(row.ItemArray[i]));i = i + 1;//49
            this.box = SingleQuotes(row.ItemArray[i].ToString().Replace("'", "")); i = i + 1;//50
            this.reasonforchange = SingleQuotes(row.ItemArray[i].ToString().Replace("'", "")); i = i + 1;//51
            this.workinstruction = SingleQuotes(row.ItemArray[i].ToString().Replace("'", "")); i = i + 1;//52
            this.plrv = row.ItemArray[i] == DBNull.Value ? null : ConvertBit((int?)Convert.ToInt32(row.ItemArray[i])); i = i + 1;//53
            this.bracket = row.ItemArray[i] == DBNull.Value ? null : ConvertBit((int?)Convert.ToInt32(row.ItemArray[i])); i = i + 1;//54
            this.rtv = row.ItemArray[i] == DBNull.Value ? null :ConvertBit((int?)Convert.ToInt32(row.ItemArray[i])); i = i + 1;//55
            this.hz = SingleQuotes(row.ItemArray[i].ToString().Replace("'", "")); i = i + 1;//56
            this.weight = SingleQuotes(row.ItemArray[i].ToString().Replace("'", ""));i = i + 1;//57
            this.facrequired = row.ItemArray[i] == DBNull.Value ? null : ConvertBit((int?)Convert.ToInt32(row.ItemArray[i])); i = i + 1;//58
            this.faccompleted = row.ItemArray[i] == DBNull.Value ? null : ConvertBit((int?)Convert.ToInt32(row.ItemArray[i])); i = i + 1;//59
            this.validation = SingleQuotes(row.ItemArray[i].ToString().Replace("'", ""));//60
        }

        public string Qry()
        {
            return string.Format(mDspecInsert,
                this.id //0
                , this.number//1
                , this.ern//2
                , this.replaces//3
                , this.application//4
                , this.oereman//5
                , this.basicclass//6
                , this.status//7
                , this.sameas//8
                , this.except//9
                , this.makefrom//10
                , this.floatStr//11
                , this.volts//12
                , this.rot//13
                , this.termp//14
                , this.drive//15
                , this.pinion//16
                , this.pitch//17
                , this.swtch//18
                , this.swp//19
                , this.ho//20
                , this.sae//21
                , this.mtgh//22
                , this.ftf//23
                , this.opening//24
                , this.treatment//25
                , this.curve//26
                , this.remarks//27
                , this.jsp == null ? "null" : jsp.ToString()//28
                , this.suctionport//29
                , this.pressureport//30
                , this.suctionfitting//31
                , this.pressurefitting//32
                , this.additionalparts//33
                , this.gasket//34
                , this.change//35
                , this.servicetype//36
                , this.notes//37
                , this.servicereplacementref//38
                , this.srrexcept//39
                , this.metaltag//40
                , this.tagnumber//41
                , this.papertag//42
                , this.othertag//43
                , this.signed//44
                , this.datesigned == null ? "null" : this.datesigned.ToString()//45
                , this.chkd//46
                , this.datechecked == null ? "null" : this.datechecked.ToString()//47
                , this.effectivedate == null ? "null" : this.effectivedate.ToString()//48
                , this.obsolete == null ? "null" : this.obsolete.ToString()//49
                , this.box//50
                , this.reasonforchange//51
                , this.workinstruction//52
                , this.plrv == null ? "null" : this.plrv.ToString()//53
                , this.bracket == null ? "null" : this.bracket.ToString()//54
                , this.rtv == null ? "null" : this.rtv.ToString()//55
                , this.hz//56
                , this.weight//57
                , this.facrequired//58
                , this.faccompleted//59
                , this.validation//60
                );
        }
    }
}
