protected void Page_Load(object sender, EventArgs e)
 {
     using (var da = new stokKartTableAdapter())
     {
         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.stokKod.StartsWith(query) || row.StokAdi.ToLower().Contains(query.ToLower())
                          select new { Kod = row.stokKod, HesapAdi = row.StokAdi, 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.GetDataByStokKod(query);
             if (dt.Count == 1)
             {
                 JSON = JsonConvert.SerializeObject(dt.Select(row => new { Kod = row.stokKod, HesapAdi = row.StokAdi, 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.stokKod.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;
         }
     }
 }
Example #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            stockPictures = new DataSet.StokKartResimDataTable();

            if (IsPostBack)
            {
                stockCode = Request.Params["StockQueryCode"];
                using (var daAccountPlan = new HesapPlaniTableAdapter())
                using (var daStock = new stokKartTableAdapter())
                using (var daStockPicture = new StokKartResimTableAdapter())
                {
                    stocks = daStock.GetData();
                    if (Request.Params["GetStock"] != null)
                    {
                        stock = stocks.FirstOrDefault(s => s.stokKod == stockCode);
                        if (stock != null)
                        {
                            purchaseLibraName = daAccountPlan.GetDataByKod(stock.AlısMizanKodu)[0].HesapAdi;
                            sellingLibraName = daAccountPlan.GetDataByKod(stock.SatısMizanKodu)[0].HesapAdi;
                            stockPictures = daStockPicture.GetDataByStokKod(stockCode);
                        }
                        else
                        {
                            Master.ShowMessage(String.Format("{0} nolu stok kartı bulunmuyor.", stockCode), PageMaster.MsgType.Error);
                        }
                    }
                    else if(Request.Params["SaveStock"] != null)
                    {
                        var stockName = Request.Params["StockName"];
                        var barcode = Request.Params["Barcode"];
                        var type = Request.Params["Type"];
                        var group = Request.Params["Group"];
                        var uniqueCode1 = Request.Params["UniqueCode1"];
                        var uniqueCode2 = Request.Params["UniqueCode2"];
                        var currency = Request.Params["Currency"];
                        var unit = Request.Params["Unit"];
                        var purchasePrice = Request.Params["PurchasePrice"].trimMoney().getMoney();
                        var salePrice = Request.Params["SalePrice"].trimMoney().getMoney();
                        var costPrice = Request.Params["CostPrice"].trimMoney().getMoney();
                        var minStock = Int32.Parse(Request.Params["MinStock"]);
                        var maxStock = Int32.Parse(Request.Params["MaxStock"]);
                        var taxRate = Int32.Parse(Request.Params["TaxRate"]);
                        var user = Request.Params["User"];
                        var stockCheckDate = Request.Params["StockCheckDate"];
                        var stockCheckAmount = Request.Params["StockCheckAmount"];
                        var stockSaveDate = "";
                        var description = Request.Params["Description"];
                        var webCategory = Request.Params["WebCategory"];
                        var webOpen = Request.Params["WebOpen"] != null;
                        var purchaseLibraCode = Request.Params["PurchaseLibraCode"];
                        var saleLibraCode = Request.Params["SaleLibraCode"];
                        var parentCode = stockCode.Substring(0, stockCode.LastIndexOf('.'));
                        var webPriceOpen = Request.Params["WebPriceOpen"] != null;

                        int? error = null;

                        if (daStock.GetDataByStokKod(stockCode).Count > 0)
                        {
                            daStock.UpdateQuery(stockCode, 0, stockName, barcode, type, group, uniqueCode1, uniqueCode2, unit, purchasePrice, costPrice, 0, salePrice,
                                maxStock, minStock, taxRate, user, null, null, null, description, webCategory, webOpen, purchaseLibraCode, saleLibraCode, parentCode, webPriceOpen, ref error);
                        }
                        else
                        {
                            daStock.InsertQuery(stockCode, stockName, barcode, type, group, uniqueCode1, uniqueCode2, unit, purchasePrice, costPrice, 0, salePrice, maxStock, minStock,
                                taxRate, user, null, null, null, description, webCategory, webOpen, purchaseLibraCode, saleLibraCode, parentCode,webPriceOpen, ref error);
                        }

                        if (error == null)
                        {
                            Master.ShowMessage("Kaydetme işlemi tamamlandı.", PageMaster.MsgType.Info);
                            stock = daStock.GetDataByStokKod(stockCode)[0];
                            stockPictures = daStockPicture.GetDataByStokKod(stockCode);
                            purchaseLibraName = daAccountPlan.GetDataByKod(stock.AlısMizanKodu)[0].HesapAdi;
                            sellingLibraName = daAccountPlan.GetDataByKod(stock.SatısMizanKodu)[0].HesapAdi;
                        }
                        else
                        {
                            Master.ShowMessage("Kaydetme işlemi sırasında hata oluştu: " + error,PageMaster.MsgType.Error);
                        }

                    }
                    else if (Request.Params["DeleteStock"] != null)
                    {

                        var pictures = daStockPicture.GetDataByStokKod(stockCode);

                        foreach (var picture in pictures)
                        {
                            var imgUrl = MapPath(ImgLocation + "/" + picture.ResimUrl);
                            File.Delete(imgUrl);
                        }

                        daStockPicture.DeleteByStockCode(stockCode);
                        daStock.DeleteQuery(stockCode);

                        Master.ShowMessage("Silme işlemi tamamlandı.", PageMaster.MsgType.Info);

                        stockCode = "";
                    }

                }
            }
        }