Example #1
0
        private void newDay()
        {
            moneyDay md = null;

            DateTime day;
            FileStream fs = new FileStream(Server.MapPath("~") + "/Content/files/startdate.txt", FileMode.Open);

            StreamReader sr = new StreamReader(fs);

            string date = sr.ReadToEnd();
            sr.Close();
            fs.Close();
            System.Globalization.CultureInfo enUS = new System.Globalization.CultureInfo("en-US");
            DateTime.TryParseExact(date, "yyyy-MM-dd", enUS,
                                      System.Globalization.DateTimeStyles.None, out day);

            teethLabEntities db = new teethLabEntities();

            int credit = 0;

            if (db.moneyDays.Where(o => o.day.Year == day.Year &&
              o.day.Month == day.Month &&
               o.day.Day == day.Day
              ).Count() > 0)
            {

                md = db.moneyDays.Where(o => o.day.Year == day.Year &&
              o.day.Month == day.Month &&
               o.day.Day == day.Day).First();

                credit = md.credit;
            }
            else
            {

                //get last day credit
                int lastId = db.moneyDays.Max(o => o.id);
                credit = 0;
                if (lastId != 0)
                {
                    credit = db.moneyDays.Find(lastId).credit;
                }
                md = new moneyDay();
                md.credit = credit;
                md.day = day;
                db.moneyDays.Add(md);
                db.SaveChanges();

            }
            this.currentMoneyDay = md;
            this.currentCredit = credit;
        }
Example #2
0
        public void export()
        {
            int cost = 0;
            try
            {
                cost = int.Parse(Request.Form["cost"]);
            }
            catch (Exception e)
            {
                return;
            }
            int id = 0;
            try
            {
                id = int.Parse(Request.Form["id"]);
            }
            catch (Exception e)
            {

            }

            string name = Request.Form["name"];
            if (name == "" || name == null)
            {
                return;
            }
            string type = Request.Form["type"];

            teethLabEntities db = new teethLabEntities();

            int dayId = 0;
            DateTime day;
            CultureInfo enUS = new CultureInfo("en-US");
            DateTime.TryParseExact(Request.Form["day"], "yyyy-MM-dd", enUS,
                        DateTimeStyles.None, out day);

            moneyDay md = new moneyDay();

            if (db.moneyDays.Where(o => o.day.Year == day.Year
            && o.day.Month == day.Month
                && o.day.Day == day.Day).Count() > 0)
            {
                md = db.moneyDays.Where(o => o.day.Year == day.Year
                && o.day.Month == day.Month
                && o.day.Day == day.Day
                ).First();
                md.credit -= cost;
                db.Entry(md).State = System.Data.EntityState.Modified;

            }
            else
            {
                return;
            }

            db.SaveChanges();
            dayId = md.id;

            db = new teethLabEntities();
            money m = new money();
            m.dayId = dayId;

            m.fromTo = name;

            m.type = "export";
            m.value = cost;
            m.recieveDate = DateTime.Now;

            if (type == "new")
            {

            }
            else if (type == "Doctor")
            {
                m.doctorId = id;
            }
            else if (type == "Company")
            {
                m.companyId = id;
            }
            else if (type == "Employee")
            {
                m.employeeId = id;
            }

            db.Entry(m).State = System.Data.EntityState.Added;
            db.moneys.Add(m);
            db.SaveChanges();

            db = new teethLabEntities();
            if (type == "Company")
            {

                product p = new product();
                p.companyId = id;
                p.enterDate = day;
                p.name = name;//
                p.isFinished = false;
                p.price = cost;
                db.Entry(p).State = System.Data.EntityState.Added;

            }
            else if (type == "Doctor")
            {
                doctor doc = db.doctors.Find(id);
                db.Entry(doc).State = System.Data.EntityState.Modified;
                doc.depit += cost;

            }
            db.SaveChanges();
            Response.Write("success");
        }
Example #3
0
        //
        // GET: /Money/
        // sadrat w wardat
        public ActionResult Index()
        {
            teethLabEntities db = new teethLabEntities();
            List<doctor> doctors = db.doctors.Where(d => d.isActive == true).ToList();
            ViewData["doctors"] = doctors;
            ViewData["emps"] = db.employees.ToList();
            ViewData["companies"] = db.companies.ToList();
            DateTime now = DateTime.Now;
            int credit = 0;

            if (db.moneyDays.Where(o => o.day.Year == now.Year
                && o.day.Month == now.Month
                && o.day.Day == now.Day
                ).Count() <= 0)
            {
                //get last day credit
                int lastId = db.moneyDays.Max(o => o.id);
                credit = 0;
                if (lastId != 0)
                {
                    credit = db.moneyDays.Find(lastId).credit;
                }
                moneyDay md = new moneyDay();
                md.credit = credit;
                md.day = now;
                db.moneyDays.Add(md);
                db.SaveChanges();
            }
            else
            {

                credit = db.moneyDays.Where(o => o.day.Year == now.Year
                && o.day.Month == now.Month
                && o.day.Day == now.Day
                ).First().credit;
            }
            ViewData["credit"] = credit;
            return View();
        }
Example #4
0
        public void import()
        {
            //test changes in source control
            int cost, id = 0, receiptno = 0;
            try
            {
                receiptno = int.Parse(Request.Form["receiptno"]);
                cost = int.Parse(Request.Form["cost"]);
            }
            catch (Exception e)
            {
                Response.Write("Please enter cost and reciept number");
                return;
            }
            if (Request.Form["id"] != "" && Request.Form["id"] != null)
            {
                id = int.Parse(Request.Form["id"]);
            }
            string name = Request.Form["name"];

            if (Request.Form["day"] == "" || Request.Form["day"] == null)
            {
                Response.Write("you must select day first");

                return;
            }
            DateTime day;
            CultureInfo enUS = new CultureInfo("en-US");
            DateTime.TryParseExact(Request.Form["day"], "yyyy-MM-dd", enUS,
                        DateTimeStyles.None, out day);

            teethLabEntities db = new teethLabEntities();
            int dayId = 0;
            moneyDay md = new moneyDay();
            if (db.moneyDays.Where(o => o.day.Year == day.Year
                && o.day.Month == day.Month
                && o.day.Day == day.Day).Count() > 0)
            {
                md = db.moneyDays.Where(o => o.day.Year == day.Year
                && o.day.Month == day.Month
                && o.day.Day == day.Day
                ).First();
                md.credit += cost;
                db.Entry(md).State = System.Data.EntityState.Modified;

            }
            else
            {
                Response.Write("you must select day first");
                return;
            }

            db.SaveChanges();
            dayId = md.id;
            db = new teethLabEntities();

            money m = new money();
            m.dayId = dayId;
            if (id != 0)
            {
                m.doctorId = id;
                try
                {
                    m.fromTo = name;
                }
                catch (Exception e)
                {
                    m.fromTo = "طبيب";
                }
            }
            else if (name != "" || name != null)
            {
                m.fromTo = name;
            }
            if (db.moneys.Where(o => o.receiptno == receiptno).Count() > 0)
            {
                Response.Write("receipt number cannot duplicated");
                return;
            }
            m.receiptno = receiptno;
            m.type = "import";
            m.recieveDate = DateTime.Now;
            m.value = cost;
            db.Entry(m).State = System.Data.EntityState.Added;
            db.moneys.Add(m);
            db.SaveChanges();
            if (id != 0)
            {
                db = new teethLabEntities();
                doctor doc = db.doctors.Find(id);
                doc.depit -= cost;
                db.Entry(doc).State = System.Data.EntityState.Modified;
                db.SaveChanges();
            }
            Response.Write("success");
        }