Exemplo n.º 1
0
        public ActionResult Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }



            var data = GirisKontrol.EntranceControl(model.UserName, model.Password, AyarMetot.strcon);

            Session["Bayi"] = "";

            if (data.PersonelID == 0)
            {
                ModelState.AddModelError("", "Kullanıcı Bulunamadı.Kullanıcı Adı ve Şifrenizi Kontrol Ediniz!");
                return(View());
            }
            else
            {
                Session["UserName"]     = data.UserName;
                Session["PersonelID"]   = data.PersonelID;
                Session["PersonelType"] = data.PersonelType;
                if (data.PersonelType == 3)
                {
                    Session["Bayi"] = "Bayi";
                }
                Session["User"]          = data;
                Session["RaporGor"]      = data.RaporGor;
                Session["PersonelAdi"]   = data.PersonelAdi;
                Session["vDepoID"]       = data.vDepoID;
                Session["vKasaID"]       = data.vKasaID;
                Session["FirmaID"]       = data.FirmaID;
                ViewBag.AyarmetotFirmaID = data.FirmaID;
                Session["Company_Code"]  = data.Company_Code;
                Session["vBankaID"]      = data.vBankaID;
                Session["vKKTID"]        = data.vKKTID;
                Session["Grubu"]         = data.PersonelGrubu;
                AyarMetot.pKasaID        = Convert.ToInt32(data.vKasaID);
                try
                {
                    AyarMetot.pKKTID = Convert.ToInt32(data.vKKTID);
                }
                catch { }
                AyarMetot.pBankaID = Convert.ToInt32(data.vBankaID);

                Session["PaketTipi"] = data.PaketTipi;


                if (data.UserName == "tani")
                {
                    Session["PaketTipi"] = "Servis";
                }

                Session["sCariID"]   = data.sCariID;
                Session["FirmaKodu"] = data.FirmaKodu;
                Session["sCariID"]   = data.sCariID;


                ViewBag.ParaBirimi = data.PB;
                sayazilimEntities db = new sayazilimEntities();
                try
                {
                    Personel list = db.Personel.Where(x => x.ID == data.PersonelID).FirstOrDefault <Personel>();
                    ViewBag.TemsilciID = list.Adi;
                }
                catch (Exception e)
                {
                }



                if (Session["vDepoID"] != null)
                {
                    if (Session["vDepoID"].ToString() == "")
                    {
                        Session["vDepoID"] = 1;
                    }
                }
                else
                {
                    Session["vDepoID"] = 1;
                }

                using (SqlConnection bag = new SqlConnection(AyarMetot.strcon))
                {
                    if (bag.State == ConnectionState.Closed)
                    {
                        bag.Open();
                    }
                    using (SqlCommand sayarlar = new SqlCommand("Select * From Ayarlar where FirmaID=" + data.FirmaID, bag))
                    {
                        using (SqlDataReader dr = sayarlar.ExecuteReader())
                        {
                            while (dr.Read())
                            {
                                if (dr["vrsPBName"] != DBNull.Value)
                                {
                                    AyarMetot.PB_Long = dr["vrsPBName"].ToString();
                                }
                                if (dr["vrsPBCode"] != DBNull.Value)
                                {
                                    AyarMetot.PB_Short = dr["vrsPBCode"].ToString();
                                }
                                if (dr["NegatifUrunKontrolu"] != DBNull.Value)
                                {
                                    AyarMetot.NegatifUrunKontrolu = dr["NegatifUrunKontrolu"].ToString();
                                }
                                try
                                {
                                    if (dr["HizliBitir"] != DBNull.Value)
                                    {
                                        AyarMetot.HizliBitir = dr["HizliBitir"].ToString();
                                    }
                                }
                                catch { }

                                if (dr["SslDurumu"] != DBNull.Value)
                                {
                                    AyarMetot.MailSsl = Convert.ToBoolean(dr["SslDurumu"]);
                                }
                                if (dr["EmanetTakibi"] != DBNull.Value)
                                {
                                    AyarMetot.EmanetTakibi = Convert.ToBoolean(dr["EmanetTakibi"]);
                                }
                                if (dr["Fabrika"] != DBNull.Value)
                                {
                                    AyarMetot.EmanetTakibi = Convert.ToBoolean(dr["Fabrika"]);
                                }
                                if (dr["KodileArama"] != DBNull.Value)
                                {
                                    AyarMetot.KodileArama = Convert.ToBoolean(dr["KodileArama"]);
                                }
                                if (dr["fMail"] != DBNull.Value)
                                {
                                    AyarMetot.FMail = dr["fMail"].ToString();
                                }

                                if (dr["fMailSifre"] != DBNull.Value)
                                {
                                    if (dr["fMailSifre"].ToString() != "")
                                    {
                                        AyarMetot.fMailSifre = KODLA.Ac(dr["fMailSifre"].ToString(), AyarMetot.ilhan_Control);
                                    }
                                }
                                if (dr["fMailSender"] != DBNull.Value)
                                {
                                    AyarMetot.fMailSender = dr["fMailSender"].ToString();
                                }
                                if (dr["fPort"] != DBNull.Value)
                                {
                                    AyarMetot.FPort = Convert.ToInt32(dr["fPort"]);
                                }
                                if (dr["SMSUser"] != DBNull.Value)
                                {
                                    AyarMetot.SMSUser = dr["SMSUser"].ToString();
                                }
                                if (dr["SMSPass"] != DBNull.Value)
                                {
                                    if (dr["SMSPass"].ToString() != "")
                                    {
                                        try
                                        {
                                            AyarMetot.SMSPass = KODLA.Ac(dr["SMSPass"].ToString(),
                                                                         AyarMetot.ilhan_Control);
                                        }
                                        catch
                                        {
                                            AyarMetot.SMSPass = "";
                                        }
                                    }
                                }
                                if (dr["SMSSender"] != DBNull.Value)
                                {
                                    AyarMetot.SMSSender = dr["SMSSender"].ToString();
                                }
                                if (dr["PostaSunucu"] != DBNull.Value)
                                {
                                    AyarMetot.PostaSunucu = dr["PostaSunucu"].ToString();
                                }

                                if (dr["EFatPK"] != DBNull.Value)
                                {
                                    AyarMetot.CompanyaliciKutusu = dr["EFatPK"].ToString();
                                }
                                if (dr["EFatGB"] != DBNull.Value)
                                {
                                    AyarMetot.CompanyGIBKutusu = dr["EFatGB"].ToString();
                                }
                                if (dr["EFatKA"] != DBNull.Value)
                                {
                                    AyarMetot.CompanyKullanici = dr["EFatKA"].ToString();
                                }
                                if (dr["EFatSifre"] != DBNull.Value)
                                {
                                    AyarMetot.CompanySifre = dr["EFatSifre"].ToString();
                                }

                                if (dr["StokYuvarlamaSayisi"] != DBNull.Value)
                                {
                                    AyarMetot.Amount_Yuvarlama = Convert.ToInt32(dr["StokYuvarlamaSayisi"]);
                                }
                                if (dr["StokYuvarlamaSayisi"] != DBNull.Value)
                                {
                                    AyarMetot.Stok_Yuvarlama = Convert.ToInt32(dr["StokYuvarlamaSayisi"]);
                                }
                                if (dr["FiyatYuvarlamaSayisi"] != DBNull.Value)
                                {
                                    AyarMetot.Price_Yuvarlama = Convert.ToInt32(dr["FiyatYuvarlamaSayisi"]);
                                }
                                if (dr["GenelYuvarlamaSayisi"] != DBNull.Value)
                                {
                                    AyarMetot.YuvarlamaSayisi         = Convert.ToInt32(dr["GenelYuvarlamaSayisi"]);
                                    AyarMetot.General_YuvarlamaString = "N" + dr["GenelYuvarlamaSayisi"].ToString();
                                }
                                if (dr["SmsFirma"] != DBNull.Value)
                                {
                                    AyarMetot.SmsFirma = dr["SmsFirma"].ToString();
                                }
                                if (dr["OrtakBelge"] != DBNull.Value)
                                {
                                    AyarMetot.OrtakBelge = dr["OrtakBelge"].ToString();
                                }
                                if (dr["TerminalTuru"] != DBNull.Value)
                                {
                                    AyarMetot.ProTerminal = dr["TerminalTuru"].ToString();
                                }
                                if (dr["FaturaEkranindaCari"] != DBNull.Value)
                                {
                                    AyarMetot.FaturaEkranindaCari = Convert.ToBoolean(dr["FaturaEkranindaCari"]);
                                }
                                if (dr["OzelKodOrderNo"] != DBNull.Value)
                                {
                                    AyarMetot.OzelKodOrderNo = Convert.ToBoolean(dr["OzelKodOrderNo"]);
                                }
                                if (dr["FaturadaFireGirisi"] != DBNull.Value)
                                {
                                    AyarMetot.FaturadaFireGirisi = Convert.ToBoolean(dr["FaturadaFireGirisi"]);
                                }
                                if (dr["BoyutSecimi"] != DBNull.Value)
                                {
                                    AyarMetot.BoyutSecimi = dr["BoyutSecimi"].ToString();
                                }
                                try
                                {
                                    data.PaketTipi       = KODLA.Ac(dr["Version"].ToString(), AyarMetot.ilhan_Control);
                                    Session["PaketTipi"] = KODLA.Ac(dr["Version"].ToString(), AyarMetot.ilhan_Control);
                                }
                                catch
                                {
                                }

                                var pakettipi = Session["PaketTipi"].ToString();
                                break;
                            }
                        }
                    }
                }

                Session["TerminalTuru"] = AyarMetot.ProTerminal;
                data.TerminalTuru       = AyarMetot.ProTerminal;


                int firmaid = Convert.ToInt32(data.FirmaID);

                Firmalar fr = db.Firmalar.Where(x => x.FirmaID == firmaid).FirstOrDefault <Firmalar>();


                if (DateTime.Now < fr.KayitTarih)
                {
                    TimeSpan kalangun  = Convert.ToDateTime(fr.KayitTarih) - DateTime.Now;
                    int      kalangun2 = Convert.ToInt32(kalangun.TotalDays);
                    Session["KalanGun"] = kalangun2;

                    bool demodurum = Convert.ToBoolean(fr.Demo);
                    int  firmaid2  = Convert.ToInt32(fr.FirmaID);
                    var  stok      = db.Stok.Where(x => x.FirmaID == firmaid2).ToList();
                    var  cari      = db.Cari.Where(x => x.FirmaID == firmaid2).ToList();
                    Session["DemoDurum"] = demodurum.ToString();

                    if (demodurum == true)
                    {
                        Session["DemoDurum"] = "Demo";
                        ViewBag.DemoDurum    = "Demo";
                    }
                    else
                    {
                    }

                    if (demodurum == true && stok.Count == 0 && cari.Count == 0)
                    {
                        return(RedirectToAction("DemoAnasayfa", "AnaSayfa"));
                    }

                    if (data.PersonelGrubu == "Kurye")
                    {
                        return(RedirectToAction("Orders", "Orders"));
                    }
                    else if (data.PersonelType == 4)
                    {
                        return(RedirectToAction("Index", "ServisList"));
                    }
                    else if (data.PersonelType == 5)
                    {
                        return(RedirectToAction("OnMuhasebeAnaSayfa", "AnaSayfa"));
                    }
                    else if (data.PaketTipi == "Ön Muhasebe 1")
                    {
                        return(RedirectToAction("OnMuhasebeAnaSayfa", "AnaSayfa"));
                    }
                    else if (data.PaketTipi == "Ön Muhasebe 2")
                    {
                        return(RedirectToAction("OnMuhasebeAnaSayfa", "AnaSayfa"));
                    }
                    else if (data.PaketTipi == "Servis1")
                    {
                        return(RedirectToAction("AnaSayfa", "AnaSayfa"));
                    }
                    else if (data.PaketTipi == "Servis")
                    {
                        return(RedirectToAction("AnaSayfa", "AnaSayfa"));
                    }
                    else if (data.PaketTipi == "Servis2")
                    {
                        return(RedirectToAction("AnaSayfa", "AnaSayfa"));
                    }
                    else if (data.PaketTipi == "Ön Muhasebe 2")
                    {
                        return(RedirectToAction("OnMuhasebeAnaSayfa", "AnaSayfa"));
                    }
                    else if (data.PaketTipi == "Perakende 1")
                    {
                        return(RedirectToAction("OnMuhasebeAnaSayfa", "AnaSayfa"));
                    }
                    else
                    {
                        return(RedirectToAction("OnMuhasebeAnaSayfa", "AnaSayfa"));
                    }
                }
                else
                {
                    return(RedirectToAction("Login", "Login"));
                }
            }
        }
        public JsonResult UpdateSetting(FirmaDetail dk, Array[] data, Array[] carikat, Array[] serviskat, Array[] faturakat)
        {
            string         Message = "Kayıt Eklendi";
            int            firmaid = Convert.ToInt32(Session["FirmaID"].ToString());
            Ayarlar        car     = db.Ayarlar.Where(x => x.FirmaID == firmaid).FirstOrDefault <Ayarlar>();
            COMPANY_DETAIL fr      = db.COMPANY_DETAIL.Where(x => x.FirmaID == firmaid).FirstOrDefault <COMPANY_DETAIL>();


            dk.settings.FirmaID = Convert.ToInt16(Session["FirmaID"].ToString());
            dk.detail.FirmaID   = Convert.ToInt16(Session["FirmaID"].ToString());

            car.EFatKA       = dk.settings.EFatKA;
            car.Entegrator   = dk.settings.Entegrator;
            car.FaturaAutoNo = dk.settings.FaturaAutoNo;
            car.EFatSifre    = dk.settings.EFatSifre;
            car.EFatGB       = dk.settings.EFatGB;
            car.EIrsGB       = dk.settings.EIrsGB;
            car.EIrsKA       = dk.settings.EIrsKA;
            car.EIrsSF       = dk.settings.EIrsSF;
            if (dk.settings.Version != null)
            {
                car.Version = KODLA.Kapa(dk.settings.Version, AyarMetot.ilhan_Control);
            }
            car.KurumKodu    = dk.settings.KurumKodu;
            car.Terminalturu = dk.settings.Terminalturu;
            car.FPort        = dk.settings.FPort;
            car.fMail        = dk.settings.fMail;
            car.fMailSender  = dk.settings.fMailSender;
            if (dk.settings.fMailSifre != null)
            {
                car.fMailSifre = KODLA.Kapa(dk.settings.fMailSifre, AyarMetot.ilhan_Control);
            }
            else
            {
                car.fMailSifre = "";
            }
            car.PostaSunucu = dk.settings.PostaSunucu;
            car.SmsFirma    = dk.settings.SmsFirma;
            if (dk.settings.SMSPass != null)
            {
                car.SMSPass = KODLA.Kapa(dk.settings.SMSPass, AyarMetot.ilhan_Control);
            }
            else
            {
                car.SMSPass = "";
            }
            car.SMSSender     = dk.settings.SMSSender;
            car.SMSUser       = dk.settings.SMSUser;
            car.BorcMesajSonu = dk.settings.BorcMesajSonu;
            car.MesajSonu     = dk.settings.MesajSonu;
            if (dk.detail.FirmaAdi != null)
            {
                fr.FirmaAdi = dk.detail.FirmaAdi;
            }
            else
            {
                fr.FirmaAdi = "";
            }
            fr.VergiDairesi   = dk.detail.VergiDairesi;
            fr.Telefon        = dk.detail.Telefon;
            fr.IlgiliKisi     = dk.detail.IlgiliKisi;
            fr.VergiNo        = dk.detail.VergiNo;
            fr.Faks           = dk.detail.Faks;
            fr.Sehir          = dk.detail.Sehir;
            fr.Ilce           = dk.detail.Ilce;
            fr.PostaKodu      = dk.detail.PostaKodu;
            fr.Ilce           = dk.detail.Ilce;
            fr.Adres          = dk.detail.Adres;
            fr.SicilNo        = dk.detail.SicilNo;
            fr.WebSite        = dk.detail.WebSite;
            fr.MersisNo       = dk.detail.MersisNo;
            fr.TicaretSicilNo = dk.detail.TicaretSicilNo;
            string Sifre = "";

            if (car.SMSPass != "")
            {
                Sifre = KODLA.Ac(car.SMSPass, AyarMetot.ilhan_Control);
            }

            if (dk.settings.vrsPBName == "")
            {
                car.vrsPBName = "Türk Lirası";
                car.vrsPBCode = "TL";
            }

            else if (dk.settings.vrsPBName == "TL")
            {
                car.vrsPBName = "Türk Lirası";
                car.vrsPBCode = "TL";
            }
            else if (dk.settings.vrsPBName == "EUR")
            {
                car.vrsPBName = "Euro Üye Ülkeler";
                car.vrsPBCode = "EUR";
            }
            else if (dk.settings.vrsPBName == "USD")
            {
                car.vrsPBName = "ABD Doları";
                car.vrsPBCode = "USD";
            }



            for (int i = 0; i < data.Length; i++)
            {
                string ID    = "";
                string NAME  = "";
                int    kolon = 0;
                foreach (var veri in data[i])
                {
                    if (kolon == 0)
                    {
                        ID = veri.ToString();
                    }
                    else if (kolon == 1)
                    {
                        NAME = veri.ToString();
                    }

                    kolon++;
                }
                kolon = 0;

                using (SqlConnection con = new SqlConnection(AyarMetot.strcon))
                {
                    if (con.State == ConnectionState.Closed)
                    {
                        con.Open();
                    }

                    using (SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter("select * from STK_KATEGORI where ID='" + ID + "'", con))
                    {
                        using (SqlCommandBuilder cb = new SqlCommandBuilder(da))
                        {
                            DataSet ds1 = new DataSet();
                            da.Fill(ds1, "STK_KATEGORI");
                            DataRow[] adf = ds1.Tables["STK_KATEGORI"].Select("ID='" + ID + "'");
                            if (adf.Length != 0)
                            {
                                DataRow dr = adf[0];
                                dr["Name"] = NAME;
                                da.Update(ds1, "STK_KATEGORI");
                            }
                        }
                    }
                }
            }
            for (int i = 0; i < carikat.Length; i++)
            {
                string ID    = "";
                string NAME  = "";
                int    kolon = 0;
                foreach (var veri in carikat[i])
                {
                    if (kolon == 0)
                    {
                        ID = veri.ToString();
                    }
                    else if (kolon == 1)
                    {
                        NAME = veri.ToString();
                    }

                    kolon++;
                }
                kolon = 0;

                using (SqlConnection con = new SqlConnection(AyarMetot.strcon))
                {
                    if (con.State == ConnectionState.Closed)
                    {
                        con.Open();
                    }

                    using (SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter("select * from CARI_KATEGORI where ID='" + ID + "'", con))
                    {
                        using (SqlCommandBuilder cb = new SqlCommandBuilder(da))
                        {
                            DataSet ds1 = new DataSet();
                            da.Fill(ds1, "CARI_KATEGORI");
                            DataRow[] adf = ds1.Tables["CARI_KATEGORI"].Select("ID='" + ID + "'");
                            if (adf.Length != 0)
                            {
                                DataRow dr = adf[0];
                                dr["Name"] = NAME;
                                da.Update(ds1, "CARI_KATEGORI");
                            }
                        }
                    }
                }
            }
            for (int i = 0; i < serviskat.Length; i++)
            {
                string ID    = "";
                string NAME  = "";
                int    kolon = 0;
                foreach (var veri in serviskat[i])
                {
                    if (kolon == 0)
                    {
                        ID = veri.ToString();
                    }
                    else if (kolon == 1)
                    {
                        NAME = veri.ToString();
                    }

                    kolon++;
                }
                kolon = 0;

                using (SqlConnection con = new SqlConnection(AyarMetot.strcon))
                {
                    if (con.State == ConnectionState.Closed)
                    {
                        con.Open();
                    }

                    using (SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter("select * from SPECIAL_TECH where ID='" + ID + "'", con))
                    {
                        using (SqlCommandBuilder cb = new SqlCommandBuilder(da))
                        {
                            DataSet ds1 = new DataSet();
                            da.Fill(ds1, "SPECIAL_TECH");
                            DataRow[] adf = ds1.Tables["SPECIAL_TECH"].Select("ID='" + ID + "'");
                            if (adf.Length != 0)
                            {
                                DataRow dr = adf[0];
                                dr["Name"] = NAME;
                                da.Update(ds1, "SPECIAL_TECH");
                            }
                        }
                    }
                }
            }
            for (int i = 0; i < faturakat.Length; i++)
            {
                string ID    = "";
                string NAME  = "";
                int    kolon = 0;
                foreach (var veri in faturakat[i])
                {
                    if (kolon == 0)
                    {
                        ID = veri.ToString();
                    }
                    else if (kolon == 1)
                    {
                        NAME = veri.ToString();
                    }

                    kolon++;
                }
                kolon = 0;

                using (SqlConnection con = new SqlConnection(AyarMetot.strcon))
                {
                    if (con.State == ConnectionState.Closed)
                    {
                        con.Open();
                    }

                    using (SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter("select * from INVOICE_OZEL where ID='" + ID + "'", con))
                    {
                        using (SqlCommandBuilder cb = new SqlCommandBuilder(da))
                        {
                            DataSet ds1 = new DataSet();
                            da.Fill(ds1, "INVOICE_OZEL");
                            DataRow[] adf = ds1.Tables["INVOICE_OZEL"].Select("ID='" + ID + "'");
                            if (adf.Length != 0)
                            {
                                DataRow dr = adf[0];
                                dr["Name"] = NAME;
                                da.Update(ds1, "INVOICE_OZEL");
                            }
                        }
                    }
                }
            }

            db.SaveChanges();
            Message = "Kayıt Güncellendi";
            var result = new { sonuc = 1, Message = Message };

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 3
0
        public ActionResult Register(RegisterViewModal rg)
        {
            sayazilimEntities db = new sayazilimEntities();

            try
            {
                var firmalarlist = db.Firmalar.Where(x => x.FirmaEMail == rg.Email).ToList();

                if (firmalarlist.Count == 0)
                {
                    Firmalar fr = new Firmalar();

                    fr.FirmaAdi = rg.FirmaIsmi;
                    string sifre = rg.Password;
                    fr.FirmaEMail = rg.Email;
                    fr.FirmaTel   = rg.FirmaTel;
                    var firmalist = db.Firmalar.OrderByDescending(x => x.ID).FirstOrDefault();
                    if (firmalist != null)
                    {
                        int i = Convert.ToInt32(firmalist.FirmaID + 1);
                        fr.FirmaID = i;
                    }
                    else
                    {
                        fr.FirmaID = 2;
                    }

                    DateTime kayittarih = DateTime.Now;

                    kayittarih    = kayittarih.AddDays(15);
                    fr.KayitTarih = kayittarih;


                    Personel pr = new Personel();
                    pr.Adi           = "Admin";
                    pr.Soyadi        = "";
                    pr.Pozisyonu     = "Admin";
                    pr.PersonelGrubu = "Admin";
                    pr.FirmaID       = Convert.ToInt16(fr.FirmaID);
                    pr.sCariID       = -1;
                    pr.WebKA         = rg.KullaniciAdi;
                    pr.WebSifre      = GirisKontrol.hash(sifre, true);
                    fr.Demo          = true;
                    db.Personel.Add(pr);
                    db.Firmalar.Add(fr);
                    db.SaveChanges();



                    #region YeniFirmaKontrol
                    int firmaid = Convert.ToInt16(pr.FirmaID);
                    var setting = db.Ayarlar.Where(x => x.FirmaID == firmaid).ToList();
                    if (setting.Count == 0)
                    {
                        DataRow dt = null;
                        using (SqlConnection con = new SqlConnection(AyarMetot.conString))
                        {
                            if (con.State == ConnectionState.Closed)
                            {
                                con.Open();
                            }
                            using (SqlDataAdapter da =
                                       new System.Data.SqlClient.SqlDataAdapter(
                                           "select * from AYARLAR where ID='1'", con))
                            {
                                using (SqlCommandBuilder cb = new SqlCommandBuilder(da))
                                {
                                    DataSet ds = new DataSet();
                                    da.Fill(ds, "AYARLAR");
                                    DataRow[] adf = ds.Tables["AYARLAR"].Select("ID='1'");
                                    if (adf.Length != 0)
                                    {
                                        dt = adf[0];
                                    }
                                }
                            }
                        }
                        using (SqlConnection con = new SqlConnection(AyarMetot.strcon))
                        {
                            if (con.State == ConnectionState.Closed)
                            {
                                con.Open();
                            }
                            using (SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter("select Top 1 * from AYARLAR where FirmaID=" + firmaid.ToString(), con))
                            {
                                using (SqlCommandBuilder cb = new SqlCommandBuilder(da))
                                {
                                    DataSet ds = new DataSet();
                                    da.Fill(ds, "AYARLAR");
                                    DataRow df = ds.Tables["AYARLAR"].NewRow();
                                    df.ItemArray  = dt.ItemArray.Clone() as object[];
                                    df["FirmaID"] = fr.FirmaID;

                                    df["Version"]             = KODLA.Kapa(rg.Pakettipi, AyarMetot.ilhan_Control);
                                    df["fMail"]               = "";
                                    df["fMailSifre"]          = "";
                                    df["fMailSender"]         = "";
                                    df["SMSUser"]             = "";
                                    df["SMSPass"]             = "";
                                    df["MesajSonu"]           = "";
                                    df["BorcMesajSonu"]       = "";
                                    df["SmsSender"]           = "";
                                    df["EFatGB"]              = "";
                                    df["EFatKA"]              = "";
                                    df["EFatSifre"]           = "";
                                    df["EIrsKA"]              = "";
                                    df["EIrsSF"]              = "";
                                    df["KurumKodu"]           = "";
                                    df["EIrsGB"]              = "";
                                    df["Entegrator"]          = "";
                                    df["PostaSunucu"]         = "";
                                    df["ServisBorclandirsin"] = 1;
                                    string company_code = "SA01" + fr.FirmaID.ToString().PadLeft(3, '0');
                                    df["Company_Code"] = company_code;
                                    ds.Tables["AYARLAR"].Rows.Add(df);
                                    da.Update(ds, "AYARLAR");
                                }
                            }
                        }
                    }
                    var compony = db.COMPANY_DETAIL.Where(x => x.FirmaID == firmaid).ToList();
                    if (compony.Count == 0)
                    {
                        DataRow dt = null;
                        using (SqlConnection con = new SqlConnection(AyarMetot.conString))
                        {
                            if (con.State == ConnectionState.Closed)
                            {
                                con.Open();
                            }
                            using (SqlDataAdapter da =
                                       new System.Data.SqlClient.SqlDataAdapter(
                                           "select * from COMPANY_DETAIL where ID='1'", con))
                            {
                                using (SqlCommandBuilder cb = new SqlCommandBuilder(da))
                                {
                                    DataSet ds = new DataSet();
                                    da.Fill(ds, "COMPANY_DETAIL");
                                    DataRow[] adf = ds.Tables["COMPANY_DETAIL"].Select("ID='1'");
                                    if (adf.Length != 0)
                                    {
                                        dt = adf[0];
                                    }
                                }
                            }
                        }
                        using (SqlConnection con = new SqlConnection(AyarMetot.strcon))
                        {
                            if (con.State == ConnectionState.Closed)
                            {
                                con.Open();
                            }
                            using (SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter("select Top 1 * from COMPANY_DETAIL", con))
                            {
                                using (SqlCommandBuilder cb = new SqlCommandBuilder(da))
                                {
                                    DataSet ds = new DataSet();
                                    da.Fill(ds, "COMPANY_DETAIL");
                                    DataRow df = ds.Tables["COMPANY_DETAIL"].NewRow();
                                    df.ItemArray = dt.ItemArray.Clone() as object[];
                                    Firmalar frm = db.Firmalar.Where(x => x.FirmaID == firmaid).FirstOrDefault();
                                    df["FirmaAdi"] = frm.FirmaAdi;
                                    string company_code = "SA01" + fr.FirmaID.ToString().PadLeft(3, '0');
                                    df["Company_Code"] = company_code;
                                    Personel pb = db.Personel.OrderByDescending(x => x.ID).FirstOrDefault();
                                    df["IlgiliKisi"] = (pb.Adi + pb.Soyadi).TrimEnd();
                                    Firmalar dr = db.Firmalar.Where(x => x.FirmaID == firmaid).FirstOrDefault();
                                    df["Telefon"]        = dr.FirmaTel;
                                    df["Faks"]           = "";
                                    df["ePosta"]         = dr.FirmaEMail;
                                    df["WebSite"]        = "";
                                    df["VergiDairesi"]   = "";
                                    df["VergiNo"]        = "";
                                    df["Ulke"]           = "";
                                    df["Sehir"]          = "";
                                    df["PostaKodu"]      = "";
                                    df["Adres"]          = "";
                                    df["TicaretSicilNo"] = "";
                                    df["MersisNo"]       = "";
                                    df["Ilce"]           = "";
                                    df["FirmaID"]        = fr.FirmaID;

                                    ds.Tables["COMPANY_DETAIL"].Rows.Add(df);
                                    da.Update(ds, "COMPANY_DETAIL");
                                }
                            }
                        }
                    }

                    var stk_ktg = db.STK_KATEGORI.Where(x => x.FirmaID == firmaid).ToList();
                    if (stk_ktg.Count == 0)
                    {
                        int i = 7;
                        for (int j = 1; j < i; j++)
                        {
                            STK_KATEGORI stk = new STK_KATEGORI();
                            stk.FirmaID = fr.FirmaID;
                            stk.Name    = "Stok Kategori " + j;
                            string company_code = "SA01" + fr.FirmaID.ToString().PadLeft(3, '0');
                            stk.Company_Code = company_code;
                            db.STK_KATEGORI.Add(stk);
                            db.SaveChanges();
                        }
                    }

                    var special = db.SPECIAL_TECH.Where(x => x.FirmaID == firmaid).ToList();
                    if (special.Count == 0)
                    {
                        int i = 11;
                        for (int j = 1; j < i; j++)
                        {
                            SPECIAL_TECH stk = new SPECIAL_TECH();
                            stk.FirmaID = Convert.ToInt16(fr.FirmaID);
                            stk.Name    = "Özel Alan " + j;
                            string company_code = "SA01" + fr.FirmaID.ToString().PadLeft(3, '0');
                            stk.Company_Code = company_code;
                            db.SPECIAL_TECH.Add(stk);
                            db.SaveChanges();
                        }
                    }


                    var carikategori = db.CARI_KATEGORI.Where(x => x.FirmaID == firmaid).ToList();
                    if (carikategori.Count == 0)
                    {
                        int i = 7;
                        for (int j = 1; j < i; j++)
                        {
                            CARI_KATEGORI stk = new CARI_KATEGORI();
                            stk.FirmaID = firmaid;
                            stk.Name    = "Cari Kategori " + j;
                            string company_code = "SA01" + fr.FirmaID.ToString().PadLeft(3, '0');
                            stk.Company_Code = company_code;
                            db.CARI_KATEGORI.Add(stk);
                            db.SaveChanges();
                        }
                    }
                    var faturaekbilgi = db.INVOICE_OZEL.Where(x => x.FirmaID == firmaid).ToList();
                    if (carikategori.Count == 0)
                    {
                        int i = 9;
                        for (int j = 1; j < i; j++)
                        {
                            INVOICE_OZEL stk = new INVOICE_OZEL();
                            stk.FirmaID         = firmaid;
                            stk.Name            = "Fature Ek Bilgi " + j;
                            stk.EfaturadaGonder = false;
                            string company_code = "SA01" + fr.FirmaID.ToString().PadLeft(3, '0');
                            stk.Company_Code = company_code;
                            db.INVOICE_OZEL.Add(stk);
                            db.SaveChanges();
                        }
                    }


                    #endregion


                    Session["FirmaAdi"] = fr.FirmaAdi;
                    MailOkey(rg);
                    return(RedirectToAction("Login", "Login"));
                }
                else
                {
                    return(View());
                }
            }
            catch (Exception e)
            {
                return(View());
            }
        }
        // GET: Settings
        public ActionResult Index()
        {
            FirmaDetail          fd         = new FirmaDetail();
            COMPANY_DETAIL       cr         = new COMPANY_DETAIL();
            Ayarlar              ay         = new Ayarlar();
            List <Kategoriler>   kat        = new List <Kategoriler>();
            List <Kategoriler>   carikat    = new List <Kategoriler>();
            List <Kategoriler>   ServisKat  = new List <Kategoriler>();
            List <Kategoriler>   FaturaList = new List <Kategoriler>();
            List <CURRENCY_LIST> pbler      = new List <CURRENCY_LIST>();


            using (SqlConnection bag = new SqlConnection(AyarMetot.strcon))
            {
                if (bag.State == ConnectionState.Closed)
                {
                    bag.Open();
                }
                using (SqlCommand sayarlar = new SqlCommand("Select * From STK_KATEGORI Where FirmaID=" + Session["FirmaID"].ToString(), bag))
                {
                    using (SqlDataReader dr = sayarlar.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            Kategoriler KT = new Kategoriler();
                            KT.ID   = Convert.ToInt32(dr["ID"]);
                            KT.Name = dr["Name"].ToString();
                            kat.Add(KT);
                        }
                    }
                }
            }
            using (SqlConnection bag = new SqlConnection(AyarMetot.strcon))
            {
                if (bag.State == ConnectionState.Closed)
                {
                    bag.Open();
                }
                using (SqlCommand sayarlar = new SqlCommand("Select * From SPECIAL_TECH Where FirmaID=" + Session["FirmaID"].ToString(), bag))
                {
                    using (SqlDataReader dr = sayarlar.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            Kategoriler KT = new Kategoriler();
                            KT.ID   = Convert.ToInt32(dr["ID"]);
                            KT.Name = dr["Name"].ToString();
                            ServisKat.Add(KT);
                        }
                    }
                }
            }
            using (SqlConnection bag = new SqlConnection(AyarMetot.strcon))
            {
                if (bag.State == ConnectionState.Closed)
                {
                    bag.Open();
                }
                using (SqlCommand sayarlar = new SqlCommand("Select * From CARI_KATEGORI Where FirmaID=" + Session["FirmaID"].ToString(), bag))
                {
                    using (SqlDataReader dr = sayarlar.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            Kategoriler KT = new Kategoriler();
                            KT.ID   = Convert.ToInt32(dr["ID"]);
                            KT.Name = dr["Name"].ToString();
                            carikat.Add(KT);
                        }
                    }
                }
            }
            using (SqlConnection bag = new SqlConnection(AyarMetot.strcon))
            {
                if (bag.State == ConnectionState.Closed)
                {
                    bag.Open();
                }
                using (SqlCommand sayarlar = new SqlCommand("Select * From INVOICE_OZEL Where FirmaID=" + Session["FirmaID"].ToString(), bag))
                {
                    using (SqlDataReader dr = sayarlar.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            Kategoriler KT = new Kategoriler();
                            KT.ID   = Convert.ToInt32(dr["ID"]);
                            KT.Name = dr["Name"].ToString();
                            FaturaList.Add(KT);
                        }
                    }
                }
            }
            using (SqlConnection bag = new SqlConnection(AyarMetot.strcon))
            {
                string srg = "Select * From COMPANY_DETAIL where FirmaID=" + Session["FirmaID"].ToString();
                if (bag.State == ConnectionState.Closed)
                {
                    bag.Open();
                }
                using (SqlCommand sayarlar = new SqlCommand(srg, bag))
                {
                    using (SqlDataReader dr = sayarlar.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            cr.FirmaAdi       = dr["FirmaAdi"].ToString();
                            cr.VergiDairesi   = dr["VergiDairesi"].ToString();
                            cr.VergiNo        = dr["VergiNo"].ToString();
                            cr.Telefon        = dr["Telefon"].ToString();
                            cr.Faks           = dr["Faks"].ToString();
                            cr.ePosta         = dr["ePosta"].ToString();
                            cr.IlgiliKisi     = dr["IlgiliKisi"].ToString();
                            cr.Sehir          = dr["Sehir"].ToString();
                            cr.Ilce           = dr["Ilce"].ToString();
                            cr.PostaKodu      = dr["PostaKodu"].ToString();
                            cr.Adres          = dr["Adres"].ToString();
                            cr.SicilNo        = dr["SicilNo"].ToString();
                            cr.WebSite        = dr["WebSite"].ToString();
                            cr.MersisNo       = dr["MersisNo"].ToString();
                            cr.TicaretSicilNo = dr["TicaretSicilNo"].ToString();
                        }
                    }
                }
            }
            using (SqlConnection bag = new SqlConnection(AyarMetot.strcon))
            {
                if (bag.State == ConnectionState.Closed)
                {
                    bag.Open();
                }
                using (SqlCommand sayarlar = new SqlCommand("Select * From Ayarlar where FirmaID=" + Session["FirmaID"].ToString(), bag))
                {
                    using (SqlDataReader dr = sayarlar.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            ay.KurumKodu       = dr["KurumKodu"].ToString();
                            ay.Entegrator      = dr["Entegrator"].ToString();
                            ay.EFatGecis       = DateTime.Now;
                            ay.EFatKA          = dr["EFatKA"].ToString();
                            ay.EFatSifre       = dr["EFatSifre"].ToString();
                            ay.EFatGB          = dr["EFatGB"].ToString();
                            ay.FaturaGonderimi = dr["FaturaGonderimi"].ToString();
                            ay.EIrsGB          = dr["EIrsGB"].ToString();
                            ay.EIrsKA          = dr["EIrsKA"].ToString();
                            ay.EIrsSF          = dr["EIrsSF"].ToString();
                            ay.IrsaliyeAutoNo  = dr["IrsaliyeAutoNo"].ToString();
                            ay.vrsPBCode       = dr["vrsPBCode"].ToString();
                            ay.FPort           = Convert.ToInt32(dr["FPort"].ToString());
                            ay.fMail           = dr["fMail"].ToString();
                            ay.fMailSender     = dr["fMailSender"].ToString();
                            if (dr["fMailSifre"].ToString() != "")
                            {
                                ay.fMailSifre = KODLA.Ac(dr["fMailSifre"].ToString(), AyarMetot.ilhan_Control);
                            }
                            else
                            {
                                ay.fMailSifre = "";
                            }
                            ay.PostaSunucu = dr["PostaSunucu"].ToString();
                            ay.SmsFirma    = dr["SmsFirma"].ToString();
                            if (dr["SMSPass"].ToString() != "")
                            {
                                ay.SMSPass = KODLA.Ac(dr["SMSPass"].ToString(), AyarMetot.ilhan_Control);
                            }
                            else
                            {
                                ay.SMSPass = "";
                            }
                            ay.SMSSender     = dr["SMSSender"].ToString();
                            ay.SMSUser       = dr["SMSUser"].ToString();
                            ay.BorcMesajSonu = dr["BorcMesajSonu"].ToString();
                            ay.MesajSonu     = dr["MesajSonu"].ToString();
                        }
                    }
                }
            }
            var parabirimi = db.CURRENCY_LIST.Where(x => x.Durumu == true).ToList();

            foreach (var item in parabirimi)
            {
                CURRENCY_LIST cl = new CURRENCY_LIST();
                cl.ParaBirimi  = item.ParaBirimi;
                cl.ParaBirimiN = item.ParaBirimiN;
                pbler.Add(cl);
            }

            int FirmaID  = Convert.ToInt32(Session["FirmaID"].ToString());
            var renklist = db.RENKLER.Where(x => x.FirmaID == FirmaID).ToList();

            ViewBag.RenklerList = renklist.ToList();
            fd.ParaBirimleri    = pbler;
            fd.settings         = ay;
            fd.detail           = cr;
            fd.kat        = kat;
            fd.carikat    = carikat;
            fd.serviskat  = ServisKat;
            fd.FaturaList = FaturaList;

            return(View(fd));
        }