Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            accountCode = Request.Params["AccountCode"];
            using (var da = new CariKartTableAdapter())
            {
                accounts = da.GetData();
                if (IsPostBack)
                {
                    if (Request.Params["GetAccount"] != null)
                    {
                        accountCode = Request.Params["AccountQueryCode"];
                        var dt = da.GetDataByCariKod(accountCode);
                        if (dt.Count > 0)
                        {
                            account = dt[0];
                            //TODO
                        }
                        else
                        {
                            Master.ShowMessage(String.Format("{0} numaralı cari hesap bulunmuyor.", accountCode), PageMaster.MsgType.Info);
                        }
                    }
                    else if (Request.Params["SaveAccount"] != null)
                    {
                        var parentCode = accountCode.Substring(0, accountCode.LastIndexOf('.'));
                        var accountName = Request.Params["AccountName"];
                        var officer = Request.Params["Officer"];
                        var adress = Request.Params["Adress"];
                        var taxOffice = Request.Params["TaxOffice"];
                        var taxNo = Request.Params["TaxNo"];
                        var phone = Request.Params["Phone"];
                        var fax = Request.Params["Fax"];
                        var group = Request.Params["Group"];
                        var currency = Request.Params["Currency"];
                        var riskLimit = Decimal.Parse(Request.Params["RiskLimit"].trimMoney());
                        var email = Request.Params["Email"];
                        var web = Request.Params["Web"];
                        var ackMail = Request.Params["AcknowledgementEmail"] != null;
                        var termRate = Int32.Parse(Request.Params["TermRate"]);
                        var termDays = Int32.Parse(Request.Params["TermDays"]);
                        var libraCode = Request.Params["LibraCode"];
                        DateTime? agrDate = null;
                        DateTime temp;
                        if (DateTime.TryParseExact(Request.Params["Date"], "dd.MM.yyyy", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AllowWhiteSpaces, out temp)) agrDate = temp;
                        var agrTotal = Request.Params["Total"].trimMoney().getMoney();
                        var agrNet = Request.Params["Net"];
                        var cityCode = Int32.Parse(Request.Params["City"]);
                        var district = Request.Params["District"];
                        var type = Int32.Parse(Request.Params["Type"]);
                        var buyer = type == 1 || type == 3;
                        var seller = type == 2 || type == 3;
                        var uniqueCode = (String)Request.Params["UniqueCode"];
                        uniqueCode = uniqueCode != "" ? uniqueCode : null;
                        var checkLimit = Decimal.Parse(Request.Params["CheckLimit"].trimMoney());
                        var user = Request.Params["User"];
                        user = user != "" ? user : null;
                        var discountRate = Int32.Parse(Request.Params["DiscountRate"]);

                        int? error = null;

                        if (Request.Params["ExistingAccount"] == "true")
                        {

                            try
                            {
                                da.UpdateQuery(accountCode, parentCode, accountName, group, riskLimit, currency, agrDate, agrTotal, agrNet, officer, adress, taxOffice, taxNo, phone
                            , fax, email, web, ackMail, termRate, termDays, libraCode, cityCode, district,buyer,seller,checkLimit,uniqueCode,user,discountRate, ref error);
                            }
                            catch (System.Data.SqlClient.SqlException exception)
                            {
                                if (exception.Number == 547)
                                {
                                    error = -99;
                                }
                                else
                                {
                                    throw;
                                }

                            }
                            if (error == -1)
                            {
                                Master.ShowMessage("Mizan kodu olarak kullanılan hesap kodlarının \"Alt\" olarak atanmış olması gerekir", PageMaster.MsgType.Error);
                            }
                            else if(error == -2)
                            {
                                Master.ShowMessage(String.Format("Girilen özel kodun ({0}) tekrarı başka bir cari kartta bulunuyor.",uniqueCode), PageMaster.MsgType.Error);
                            }
                            else if (error == -99)
                            {
                                Master.ShowMessage(String.Format("Geçersiz mizan kodu. ({0})", libraCode), PageMaster.MsgType.Error);
                            }
                            else
                            {

                                Master.ShowMessage(string.Format("{0} ({1}) cari hesap kartı güncellendi.", accountName, accountCode), PageMaster.MsgType.Info);
                            }
                        }
                        else
                        {
                            //using (var daHesapPlani = new HesapPlaniTableAdapter())
                            //{
                            //    if (daHesapPlani.GetDataByKod(accountCode).Count > 0)
                            //    {
                            //        Master.ShowMessage(String.Format("({0} nolu hesap, hesap planında mevcut.", accountCode), PageMaster.MsgType.Error);
                            //        return;
                            //    }
                            //    else
                            //    {
                            //        var parentCode = accountCode.Substring(0, accountCode.LastIndexOf('.'));
                            //        int? error = null;
                            //        daHesapPlani.InsertMethod(accountCode, parentCode, accountName, "Alt", ref error);

                            //        if (error == -1)
                            //        {
                            //            Master.ShowMessage(String.Format("Önce \"{0}\" nolu hesabın oluşturulması gerekli.", parentCode), PageMaster.MsgType.Error);
                            //            return;
                            //        }
                            //        else if (error == -2)
                            //        {
                            //            Master.ShowMessage(String.Format("Alt olarak atanmış hesabın({0}) altına yeni hesap açılamaz.", parentCode), PageMaster.MsgType.Error);
                            //            return;
                            //        }
                            //    }
                            //}

                            try
                            {
                                da.InsertQuery(accountCode, parentCode, accountName, group, 0, riskLimit, currency, agrDate, agrTotal, agrNet, officer,
                                    adress, taxOffice, taxNo, phone, fax, email, web,user, DateTime.Now, ackMail, termRate, termDays, libraCode,cityCode,district,
                                    buyer,seller,checkLimit,uniqueCode,discountRate, ref error);
                            }
                            catch (System.Data.SqlClient.SqlException exception)
                            {
                                if (exception.Number == 547)
                                {
                                    error = -99;
                                }
                                else if (exception.Number == 2627)
                                {
                                    error = -100;
                                }
                                else
                                {
                                    throw;
                                }

                            }
                            if (error == -1)
                            {
                                Master.ShowMessage("Mizan kodu olarak kullanılan hesap kodlarının \"Alt\" olarak atanmış olması gerekir", PageMaster.MsgType.Error);
                            }
                            else if (error == -2)
                            {
                                Master.ShowMessage(String.Format("Önce ({0}) nolu üst hesabın açılması gerekiyor.", parentCode), PageMaster.MsgType.Error);

                            }
                            else if (error == -3)
                            {
                                Master.ShowMessage(String.Format("({0}) nolu üst hesabın \"Alt\" olarak atanması gerekir",parentCode), PageMaster.MsgType.Error);
                            }
                            else if(error == -4)
                            {
                                Master.ShowMessage(String.Format("Girilen özel kodun ({0}) tekrarı başka bir cari kartta bulunuyor.",uniqueCode), PageMaster.MsgType.Error);

                            }
                            else if (error == -99)
                            {
                                Master.ShowMessage(String.Format("Geçersiz mizan kodu. ({0})", libraCode), PageMaster.MsgType.Error);
                            }
                            else if (error == -100)
                            {
                                Master.ShowMessage(String.Format("({0}) nolu başka bir cari hesap bulunuyor.", accountCode), PageMaster.MsgType.Error);

                            }
                            else
                            {

                                Master.ShowMessage(String.Format("{0} ({1}) isimli yeni cari hesap kartı oluşturuldu.", accountName, accountCode)
                                    , PageMaster.MsgType.Info);
                            }

                        }

                        if (error < 0)
                        {
                            account = accounts.NewCariKartRow();
                            account.adres = adress;
                            account.bilglendirmeMaili = ackMail;
                            account.borcAlacakDurumu = agrNet;
                            account.cariAd = accountName;
                            account.cariKod = accountCode;
                            account.eMail = email;
                            account.fax = fax;
                            account.Gurup = group;
                            account.MizanKodu = libraCode;
                            if (agrTotal.HasValue) account.mutabakatMiktari = agrTotal.Value;
                            if (agrDate.HasValue) account.mutabakatTarihi = agrDate.Value;
                            account.paraBirimi = currency;
                            account.risklimiti = riskLimit;
                            account.tel = phone;
                            account.VadeGunu = termDays;
                            account.VadeOrani = termRate;
                            account.vergiDairesi = taxOffice;
                            account.vergiNo = taxNo;
                            account.web = web;
                            account.yetkili = officer;
                            account.IlKodu = cityCode;
                            account.Ilce = district;
                            account.Alici = buyer;
                            account.Satici = seller;
                            account.CekLimiti = checkLimit;
                            account.OzelKod = uniqueCode;
                            account.kullanici = user;
                        }
                        else
                        {

                            account = da.GetDataByCariKod(accountCode)[0];
                        }

                    }
                    else if (Request.Params["DeleteAccount"] != null)
                    {
                        var deleted = da.DeleteQuery(accountCode);
                        if (deleted > 0)
                        {
                            Master.ShowMessage(String.Format("{0} numaralı cari hesap silindi.", accountCode)
                                   , PageMaster.MsgType.Info);
                            accountCode = "";

                        }
                        else
                        {
                            Master.ShowMessage(String.Format("{0} nolu cari hesap bulunmuyor.", accountCode), PageMaster.MsgType.Error);
                        }
                    }

                    if (account != null && !String.IsNullOrEmpty(account.MizanKodu))
                    {
                        using (var daHesapPlani = new HesapPlaniTableAdapter())
                        {
                            var accountPlan = daHesapPlani.GetDataByKod(account.MizanKodu);
                            libraName = accountPlan.Count > 0 ? accountPlan[0].HesapAdi : "";
                        }
                    }

                }
            }
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     using (var da = new CariKartTableAdapter())
     {
         var requestType = Request.Params["requestType"].ToString();
         if (requestType == "query")
         {
             var dt = da.GetData();
             //var tWriter = new StringWriter();
             var query = Request.Params["query"];
             var max = Request.Params["max"];
             var source = from row in dt
                          where row.cariKod.StartsWith(query) || row.cariAd.ToLower().Contains(query.ToLower())
                          select new { Kod = row.cariKod, HesapAdi = row.cariAd, row.UstKod };
             JSON = JsonConvert.SerializeObject(source); //TODO self reference loop oluştuğu için source kullanıldı, sil
             //jsSerializer.Serialize(tWriter, dt.Rows);
             //JSON = tWriter.GetStringBuilder().ToString();
         }
         else if (requestType == "get")
         {
             var query = Request.Params["query"];
             var dt = da.GetDataByCariKod(query);
             if (dt.Count == 1)
             {
                 JSON = JsonConvert.SerializeObject(dt.Select(row => new { Kod = row.cariKod, HesapAdi = row.cariAd, row.UstKod }));
             }else
             {
                 JSON = "[]";
             }
         }
         else if (requestType == "nextChild")
         {
             var dt = da.GetData();
             var code = Request.Params["code"];
             var nextChild = "";
             var maxCodeVal = 0;
             var maxCode = "";
             foreach (var row in dt.Where(r => r.UstKod == code))
             {
                 var childCode = row.cariKod.Split('.').Last();
                 var codeVal = Int32.Parse(childCode);
                 if (maxCodeVal < codeVal)
                 {
                     maxCodeVal = codeVal;
                     maxCode = childCode;
                 }
             }
             var mask = "";
             if (maxCodeVal > 0)
             {
                 mask = new String('0', maxCode.Length);
             }
             else
             {
                 if (code.Contains('.'))
                 {
                     mask = "000";
                 }
                 else
                 {
                     mask = "00";
                 }
             }
             nextChild = code + "." + (maxCodeVal + 1).ToString(mask);
             JSON = nextChild;
         }
     }
 }