Example #1
0
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            ledgermodel l = new ledgermodel(txtlname.Text, 3, txtladd.Text, txtlno.Text, txtlmail.Text);
            //Hashtable error = l.checkvalid();
            //int a = l.
              if (txtladd.Text.Trim().ToString() == "" || txtlmail.Text.Trim().ToString() == "" || txtlname.Text.Trim().ToString() == "" || txtlno.Text.Trim().ToString()=="")
              {
                  Show("Please Enter all Data of Supplier",2);
                  return;
              }
              if (!(Regex.IsMatch(txtlno.Text, @"^\+?(\d[\d-. ]+)?(\([\d-. ]+\))?[\d-. ]+\d$")) || txtlno.Text.Length < 6 || txtlno.Text.Length > 10)
              {
                  Show("Please Enter Valid Phone No.",2);
                  return;
              }
              if (!Regex.IsMatch(txtlmail.Text, @"^\S+@\S+$"))
              {
                  Show("Please Enter Valid Email id No.",2);
                  return;
              }

            if (l.insert(this))
            {
                Show("Supplier Saved",1);
                txtlname.ClearValue(TextBox.BorderBrushProperty);
                int sid = l.lastid();
                MessageBox.Show(sid.ToString());
                ledger nlb = new ledger()
                {
                    Lid = sid,
                    Lname= txtlname.Text,
                    Lgroup = 3,
                    Laddress = txtladd.Text,
                    Lphoneno = txtlno.Text,
                    Lemail = txtlmail.Text
                };
                ledgerbalance lb = new ledgerbalance() { Lid = sid, Lname = txtlname.Text, Balance = 0 };
                application.tb.Add(lb);
                if (url != null)
                {
                    string targetPath = @System.AppDomain.CurrentDomain.BaseDirectory + "\\images\\" + txtlname.Text + ".jpg";
                    System.IO.File.Copy(url, targetPath, true);
                    nlb.Limage = targetPath;
                }
                else
                {
                    nlb.Limage = @System.AppDomain.CurrentDomain.BaseDirectory + "\\images\\default.jpg";
                }
                lc.Add(nlb);
                clr();
            }
            else
            {
                Show("Supplier Not Saved",2);
            }
            //   l.showerror(error,this);
        }
Example #2
0
 public ObservableCollection<ledgerbalance> gettrialbalance()
 {
     ObservableCollection<ledgerbalance> tb = new ObservableCollection<ledgerbalance>();
     String q = "select l.l_id,l.l_name,l.l_groupid,iif(dr.dramt is null ,0 , dr.dramt) as damt , ";
     q += "  iif(cr.cramt is null , 0 ,cr.cramt) as cramt , ";
     q += "( iif(dr.dramt is null ,0 , dr.dramt) - iif(cr.cramt is null , 0 ,cr.cramt))as balance , l.l_phone ,l.l_email";
     q += " from ((SELECT  t_dr, SUM(t_dramt) AS dramt FROM  [transaction] GROUP BY t_dr ORDER BY t_dr ) dr ";
     q += " right outer  join ledger l on dr.t_dr = l.l_id )";
     q += " left outer  join  (SELECT  t_cr, SUM(t_cramt) AS cramt FROM  [transaction] ";
     q += "  GROUP BY t_cr ORDER BY t_cr ) cr on l.l_id = cr.t_cr";
     OleDbCommand cmd = new OleDbCommand(q, con);
     try
     {
         con.Open();
         OleDbDataReader dr =  cmd.ExecuteReader();
         while (dr.Read())
         {
             int gid;
             String phone, email;
             string baltype = "";
             if (double.Parse(dr.GetValue(5).ToString()) < 0)
             {
                 baltype = "dr";
             }
             else if (double.Parse(dr.GetValue(5).ToString()) == 0)
             {
                 baltype = "";
             }
             else
             {
                 baltype = "cr";
             }
             gid = (dr.GetValue(2)) == DBNull.Value ? 0 : int.Parse(dr.GetValue(2).ToString());
             phone = (dr.GetValue(6)) == DBNull.Value ? "" : dr.GetValue(6).ToString();
             email = (dr.GetValue(7)) == DBNull.Value ? "" : dr.GetValue(7).ToString();
             ledgerbalance lb = new ledgerbalance()
             {
                 Lid = int.Parse(dr.GetValue(0).ToString()),
                 Lname = dr.GetValue(1).ToString(),
                 Lgroup = gid,
                 Debittotal  = double.Parse(dr.GetValue(3).ToString()),
                 Credittotal = double.Parse(dr.GetValue(4).ToString()),
                 Balance = Math.Abs(Double.Parse(dr.GetValue(5).ToString())),
                 CurrBalance = Math.Abs(Double.Parse(dr.GetValue(5).ToString())).ToString("C2"),
                 BalanceType= baltype,
                 Lphoneno = phone,
                 Lemail = email
             };
             tb.Add(lb);
         }
         return tb;
     }
     catch (Exception e)
     {
         System.Windows.MessageBox.Show(e.ToString());
         return tb;
     }
     finally
     {
         con.Close();
     }
 }