public JsonResult yeniPersonel(Personel pr, Yetkiler yt)
        {
            string   Message = "Kayıt Eklendi";
            var      result  = new { sonuc = 0, Message = Message };
            Personel per     = null;

            if (pr.ID == -1)
            {
                per          = new Personel();
                per          = pr;
                per.PB       = "Varsayılan";
                per.vKasaID  = pr.vKasaID;
                per.vBankaID = pr.vBankaID;

                per.sCariID = Convert.ToInt32(Session["sCariID"].ToString());
                per.FirmaID = Convert.ToInt16(Session["FirmaID"].ToString());
                string firmaid      = Session["FirmaID"].ToString();
                string company_code = "SA01" + firmaid.PadLeft(3, '0');
                per.Company_Code = company_code;
                try
                {
                    per.WebSifre = GirisKontrol.hash(pr.WebSifre, true);
                }
                catch (Exception e)
                {
                }


                try
                {
                    db.Personel.Add(per);
                    db.SaveChanges();

                    Personel person = db.Personel.OrderByDescending(x => x.ID).FirstOrDefault <Personel>();

                    Yetkiler yetki = new Yetkiler();
                    yetki = yt;

                    yetki.PersonelID   = person.ID;
                    yetki.FirmaID      = Convert.ToInt16(Session["FirmaID"].ToString());
                    firmaid            = Session["FirmaID"].ToString();
                    company_code       = "SA01" + firmaid.PadLeft(3, '0');
                    yetki.Company_Code = company_code;
                    db.Yetkiler.Add(yetki);
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    Message = "Kayıt eklenirken bir hata oluştu.";
                    result  = new { sonuc = 0, Message = Message };
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                per = db.Personel.Where(x => x.ID == pr.ID).FirstOrDefault <Personel>();


                per.ID            = pr.ID;
                per.Adi           = pr.Adi;
                per.Soyadi        = pr.Soyadi;
                per.PersonelGrubu = pr.PersonelGrubu;
                per.Milleti       = pr.Milleti;
                per.TCNo          = pr.TCNo;
                per.Cinsiyet      = pr.Cinsiyet;
                per.Telefon1      = pr.Telefon1;
                per.Adres         = pr.Adres;
                per.EkBilgiler    = pr.EkBilgiler;
                per.BabaAdi       = pr.BabaAdi;
                per.Maasi         = pr.Maasi;
                per.IL            = pr.IL;
                per.Ilce          = pr.Ilce;
                per.EPosta        = pr.EPosta;
                per.SicilNo       = pr.SicilNo;
                per.WebKA         = pr.WebKA;

                try
                {
                    per.WebSifre = GirisKontrol.hash(pr.WebSifre, true);
                }
                catch (Exception e)
                {
                }


                per.Telefon2 = pr.Telefon2;
                per.vKasaID  = pr.vKasaID;
                per.vBankaID = pr.vBankaID;


                Yetkiler yetki = db.Yetkiler.Where(x => x.PersonelID == per.ID).FirstOrDefault <Yetkiler>();


                yetki.StokEG      = yt.StokEG;
                yetki.StokSil     = yt.StokSil;
                yetki.CariEG      = yt.CariEG;
                yetki.CariSil     = yt.CariSil;
                yetki.FaturaEG    = yt.FaturaEG;
                yetki.FaturaSil   = yt.FaturaSil;
                yetki.KasaEG      = yt.KasaEG;
                yetki.KasaSil     = yt.KasaSil;
                yetki.BankaEG     = yt.BankaEG;
                yetki.BankaSil    = yt.BankaSil;
                yetki.ServisEG    = yt.ServisEG;
                yetki.ServisSil   = yt.ServisSil;
                yetki.PersonelEG  = yt.PersonelEG;
                yetki.PersonelSil = yt.PersonelSil;
                yetki.KrediKEG    = yt.KrediKEG;
                yetki.KrediKSil   = yt.KrediKSil;
                yetki.MaasEG      = yt.MaasEG;
                yetki.MaasSil     = yt.MaasSil;

                yetki.YazdirSec            = yt.YazdirSec;
                yetki.KasaIslem            = yt.KasaIslem;
                yetki.BankaIslem           = yt.BankaIslem;
                yetki.ServisIslem          = yt.ServisIslem;
                yetki.PersonelGorme        = yt.PersonelGorme;
                yetki.IslemSilme           = yt.IslemSilme;
                yetki.RaporGorme           = yt.RaporGorme;
                yetki.Hatirlatma           = yt.Hatirlatma;
                yetki.GelirGiderIslem      = yt.GelirGiderIslem;
                yetki.MesajGonderme        = yt.MesajGonderme;
                yetki.IslemGorme           = yt.IslemGorme;
                yetki.DepoGorme            = yt.DepoGorme;
                yetki.CariKartGor          = yt.CariKartGor;
                yetki.CariBakiyeGor        = yt.CariBakiyeGor;
                yetki.HizliSatisMenusuGor  = yt.HizliSatisMenusuGor;
                yetki.SadeceKendiCarisi    = yt.SadeceKendiCarisi;
                yetki.StokKartGor          = yt.StokKartGor;
                yetki.StokBakiyeGor        = yt.StokBakiyeGor;
                yetki.KendiDepoMiktari     = yt.KendiDepoMiktari;
                yetki.FiyatDegistirme      = yt.FiyatDegistirme;
                yetki.DusukFiyatSatis      = yt.DusukFiyatSatis;
                yetki.EIrsaliyeKullan      = yt.EIrsaliyeKullan;
                yetki.KasaDevri            = yt.KasaDevri;
                yetki.KasaBankaBakGor      = yt.KasaBankaBakGor;
                yetki.UretimGorunumuKullan = yt.UretimGorunumuKullan;
                yetki.HizliSatisSime       = yt.HizliSatisSime;

                db.SaveChanges();
                Message = "Kayıt Güncellendi";
            }

            result = new { sonuc = 1, Message = Message };
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public JsonResult yeniCari(Cari cr, string alacakINT, string borcINT)
        {
            ViewBag.Sıradaki = AyarMetot.GetNumara;
            Cari car = null;

            int    islemsonuc = 1;
            string Message    = "Kayıt Eklendi";

            if (cr.ID == -1 || cr.ID == 0)
            {
                int firmaidsrg = Convert.ToInt32(Session["FirmaID"].ToString());
                var list       = db.Cari.Where(x => x.FirmaKodu == cr.FirmaKodu && x.FirmaID == firmaidsrg).ToList();
                if (list.Count == 0)
                {
                    car       = new Cari();
                    car       = cr;
                    car.WebKA = cr.WebKA;
                    try
                    {
                        car.WebSifre = GirisKontrol.hash(cr.WebSifre, true);
                    }
                    catch (Exception e)
                    {
                    }


                    if (cr.paraBirimi == null)
                    {
                        car.paraBirimi = "TL";
                    }
                    else
                    {
                        car.paraBirimi = cr.paraBirimi;
                    }

                    car.CariList = true;
                    if (cr.MusteriTemsilcisi == null)
                    {
                        cr.MusteriTemsilcisi = 1;
                    }

                    try
                    {
                        car.FirmaID = (short)Convert.ToInt32(Session["FirmaID"]);
                    }
                    catch (Exception e)
                    {
                        car.FirmaID = 1;
                    }

                    if (car.KTipi != "BAYİİ")
                    {
                        car.DepoID = -1;
                    }
                    else
                    {
                        car.DepoID = cr.DepoID;
                    }

                    car.FirmaID = Convert.ToInt16(Session["FirmaID"].ToString());
                    string firmaid      = Session["FirmaID"].ToString();
                    string company_code = "SA01" + firmaid.PadLeft(3, '0');
                    car.Company_Code = company_code;
                    db.Cari.Add(car);
                    db.SaveChanges();
                    decimal alacak = 0;
                    decimal borc   = 0;
                    if (alacakINT != "")
                    {
                        alacak = Convert.ToDecimal(alacakINT);
                    }
                    if (borcINT != "")
                    {
                        borc = Convert.ToDecimal(borcINT);
                    }
                    var carilist = db.Cari.OrderByDescending(x => x.ID).Take(1).ToList();

                    foreach (var item in carilist)
                    {
                        if (alacak > 0)
                        {
                            Bakiyeekle("CAF", item.ID, alacak, item.paraBirimi);
                        }

                        if (borc > 0)
                        {
                            Bakiyeekle("CBF", item.ID, borc, item.paraBirimi);
                        }
                    }
                }
                else
                {
                    islemsonuc = 0;
                    Message    = "Aynı Firma Koduna Ait Ver Mevcuttur.";
                }
            }
            else
            {
                car = db.Cari.Where(x => x.ID == cr.ID).FirstOrDefault <Cari>();

                car.CariUnvan      = cr.CariUnvan;
                car.FirmaKodu      = cr.FirmaKodu;
                car.Il             = cr.Il;
                car.Yetkili        = cr.Yetkili;
                car.GSM            = cr.GSM;
                car.Telefon1       = cr.Telefon1;
                car.PostaKodu      = cr.PostaKodu;
                car.Ilce           = cr.Ilce;
                car.Faks           = cr.Faks;
                car.Iskonto        = cr.Iskonto;
                car.MersisNo       = cr.MersisNo;
                car.TicaretSicilNo = cr.TicaretSicilNo;
                car.VergiDr        = cr.VergiDr;
                car.VergiNo        = cr.VergiNo;
                car.Adres          = cr.Adres;
                car.EkBilgi        = cr.EkBilgi;
                car.EPosta         = cr.EPosta;
                car.KTipi          = cr.KTipi;
                car.StokFG         = cr.StokFG;
                car.CariGrubu      = cr.CariGrubu;
                car.Milleti        = cr.Milleti;
                car.WebKA          = cr.WebKA;
                car.paraBirimi     = cr.paraBirimi;
                try
                {
                    car.WebSifre = GirisKontrol.hash(cr.WebSifre, true);
                }
                catch { }
                db.SaveChanges();
                islemsonuc = 1;
                Message    = "Kayıt Güncellendi";
            }

            var result = new { sonuc = islemsonuc, Message = Message };

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Example #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());
            }
        }