コード例 #1
0
ファイル: MonthlyChargeModel.cs プロジェクト: omarkhd/gymk
 public bool Insert(Member m, DateTime start, DateTime end)
 {
     string fmt = "yyyy-MM-dd";
     string _start = start.ToString(fmt);
     string _end = end.ToString(fmt);
     return base.Insert(m.Id, null, _start, _end, null);
 }
コード例 #2
0
ファイル: MonthlyChargeModel.cs プロジェクト: omarkhd/gymk
 public bool UpdatePaymentOf(Member m, DateTime sd, Payment p)
 {
     string sql = "update " + this.TableName;
     sql += " set Payment = @p0";
     sql += " where Member = @p1 and StartDate = @p2";
     return (long) this.DoNonQuery(sql, p.Id, m.Id, sd.ToString("yyyy-MM-dd")) > 0;
 }
コード例 #3
0
ファイル: PaymentRuler.cs プロジェクト: omarkhd/gymk
 private static DateTime ComputeEndDate(Member m, int month, int year)
 {
     DateTime from_date = new DateTime(year, month, 1).AddMonths(1);
     DateTime next_start_date = PaymentRuler.ComputeStartDate(m, from_date.Month, from_date.Year);
     Console.WriteLine(next_start_date.AddDays(-1));
     return next_start_date.AddDays(-1);
 }
コード例 #4
0
ファイル: MemberModel.cs プロジェクト: omarkhd/gymk
        public static Member FromId(long id)
        {
            MemberModel mm = new MemberModel();
            IDataReader r = mm.GetById(id);
            Member m = null;
            if(r.Read())
            {
                m = new Member();
                m.Id = id;
                m.Active = (bool) r["Active"];
                m.Height = (float) r["Height"];
                m.Weight = (float) r["Weight"];
                m.Gender = (char) (int.Parse((string) r["Gender"]));
                //Console.Out.WriteLine(m.Gender);
                m.BirthDate = (DateTime) r["BirthDate"];
                m.PaymentDay = (int) ((long) r["PaymentDay"]);
                m.JoinDate = (DateTime) r["JoinDate"];
                m.Pack = (long) r["Pack"];
                m.BinImage = mm.GetImage(m);

                m.InnerClient = new Client();
                m.InnerClient.Id = id;
                m.InnerClient.Sync();

                m.InnerContact = new Contact();
                m.InnerContact.Id = long.TryParse(r["Contact"].ToString(), out m.InnerContact.Id) ? m.InnerContact.Id : 0;
                m.InnerContact.Sync();
            }

            return m;
        }
コード例 #5
0
ファイル: PaymentRuler.cs プロジェクト: omarkhd/gymk
        public static void ChargeMonth(Member m, int month, int year)
        {
            m.Sync();
            DateTime s = PaymentRuler.ComputeStartDate(m, month, year);
            DateTime e = PaymentRuler.ComputeEndDate(m, month, year);

            MonthlyChargeModel mcm = new MonthlyChargeModel();
            if(!mcm.Exists(m, s))
                mcm.Insert(m, s, e);
        }
コード例 #6
0
ファイル: MemberWizard.cs プロジェクト: omarkhd/gymk
 public MemberWizard()
 {
     SessionRegistry r = SessionRegistry.GetInstance();
     string gym = (string) r["gym_name"];
     this.WelcomeHeader = "Bienvenido al asistente de inscripción " + (gym == null ? "al gimnasio" : "a " + gym);
     this.NextEvent += this.OnNext;
     this.PreviousEvent += this.OnPrevious;
     this.Step = 0;
     this.TargetMember = new Member();
     this.SidebarImage = "w2.png";
     this.ClientId = 0;
 }
コード例 #7
0
ファイル: PaymentRuler.cs プロジェクト: omarkhd/gymk
        private static DateTime ComputeStartDate(Member m, int month, int year)
        {
            DateTime start_date;
            int day_to_pay = m.PaymentDay;
            int last_day_of_month = DateTime.DaysInMonth(year, month);

            if(day_to_pay > last_day_of_month)
                start_date = new DateTime(year, month, last_day_of_month).AddDays(day_to_pay - last_day_of_month);
            else
                start_date = new DateTime(year, month, day_to_pay);

            Console.Out.WriteLine(start_date);
            return start_date;
        }
コード例 #8
0
ファイル: PaymentRuler.cs プロジェクト: omarkhd/gymk
        public static void ChargeFirstMonth(Member m)
        {
            m.Sync();
            int month = DateTime.Now.Month;
            int year = DateTime.Now.Year;
            DateTime s = PaymentRuler.ComputeStartDate(m, month, year);
            DateTime e = PaymentRuler.ComputeEndDate(m, month, year);

            MonthlyChargeModel mcm = new MonthlyChargeModel();
            mcm.Insert(m, s, e);

            if(!m.ChargeFirstMonth)
            {
                Payment p = new Payment();
                p.Amount = 0;
                p.Discount = 0;
                PaymentModel pm = new PaymentModel();
                pm.Insert(p);
                p.Id = pm.LastInsertId;
                mcm.UpdatePaymentOf(m, s, p);
            }
        }
コード例 #9
0
ファイル: MemberModel.cs プロジェクト: omarkhd/gymk
        public byte[] GetImage(Member m)
        {
            SqliteCommand cmd = this.Db.CreateCommand();
            cmd.CommandText = "select Photo from Member where Id = " + m.Id;
            AppHelper.Log(cmd.CommandText);
            IDataReader r = cmd.ExecuteReader();
            byte[] bytes = new byte[0];
            if(r.Read())
            {
                try
                {
                    long length = r.GetBytes(0, 0, null, 0, 0);
                    if(length > 0)
                    {
                        bytes = new byte[length];
                        r.GetBytes(0, (long) 0, bytes, 0, bytes.Length);
                    }
                }

                catch(Exception) {}
            }

            return bytes;
        }
コード例 #10
0
ファイル: MonthlyChargeModel.cs プロジェクト: omarkhd/gymk
 public bool Exists(Member m, DateTime start)
 {
     string sql = "select count(*) from " + this.TableName;
     sql += " where Member = @p0 and StartDate = @p1";
     return ((long) this.DoScalar(sql, m.Id, start.ToString("yyyy-MM-dd"))) > 0;
 }
コード例 #11
0
ファイル: MemberModel.cs プロジェクト: omarkhd/gymk
 public bool Update(Member m, string attr, object key)
 {
     return this.UpdateById(m.Id, attr, key);
 }
コード例 #12
0
ファイル: PaymentRuler.cs プロジェクト: omarkhd/gymk
 public static void ChargeMonth(Member m)
 {
     PaymentRuler.ChargeMonth(m, DateTime.Today.Month, DateTime.Today.Year);
 }
コード例 #13
0
ファイル: MemberModel.cs プロジェクト: omarkhd/gymk
        public void SetImage(Member m)
        {
            string sql = "update " + this.TableName + " set Photo = @p0 where Id = @p1";
            if(m.BinImage == null || m.BinImage.Length == 0)
                this.DoNonQuery(sql, null, m.Id);

            else
            {
                SqliteCommand cmd = this.Db.CreateCommand();
                SqliteParameter p0 = new SqliteParameter("@p0", DbType.Binary, m.BinImage.Length);
                p0.Value = m.BinImage;
                SqliteParameter p1 = new SqliteParameter("@p1", m.Id);

                cmd.CommandText = sql;
                cmd.Parameters.Add(p0);
                cmd.Parameters.Add(p1);
                AppHelper.Log(cmd.CommandText);
                cmd.ExecuteNonQuery();
            }
        }
コード例 #14
0
ファイル: MemberModel.cs プロジェクト: omarkhd/gymk
        public bool Insert(Member m)
        {
            long id = m.InnerClient.Id;
            object contact = (m.InnerContact.Id == 0 ? null : (object) m.InnerContact.Id);
            string bd = m.BirthDate.ToString("yyyy-MM-dd");
            string jd = m.JoinDate.ToString("yyyy-MM-dd");
            bool i_success = base.Insert(id, true, m.Height, m.Weight, m.Gender, bd, m.PaymentDay, jd, m.Pack, contact, null);

            if(i_success)
                this.SetImage(m);

            return i_success;
        }
コード例 #15
0
ファイル: MembersWindow.cs プロジェクト: omarkhd/gymk
        private void DoOk(object sender, EventArgs args)
        {
            Member m = new Member();
            m.Id = this.CurrentClient.Id;
            m.Sync();
            MemberModel mm = new MemberModel();

            if(m.Active != this.ActiveCheck.Active)
                mm.Update(m, "Active", this.ActiveCheck.Active);

            if(this.ImageToSave != null && this.ImageToSave.Length != m.BinImage.Length)
            {
                m.BinImage = this.ImageToSave;
                mm.SetImage(m);
            }

            if(m.Weight != this.WeightSpin.Value)
                mm.Update(m, "Weight", this.WeightSpin.Value);

            if(m.Height != this.HeightSpin.Value)
                mm.Update(m, "Height", this.HeightSpin.Value);

            char ctrl_gender = this.GenderCombo.Active == 0 ? 'm' : 'f';
            if(m.Gender != ctrl_gender)
                mm.Update(m, "Gender", ctrl_gender);

            if(m.BirthDate.CompareTo(this.BirthdayWidget.Date) != 0)
                mm.Update(m, "BirthDate", this.BirthdayWidget.Date.ToString("yyyy-MM-dd"));

            if(m.InnerContact.Id == 0 && !string.IsNullOrEmpty(this.ContactNameEntry.Text.Trim() + this.ContactPhoneEntry.Text.Trim()))
            {
                DbModel model = new DbModel("Contact");
                model.Insert(null, this.ContactNameEntry.Text.Trim(), this.ContactPhoneEntry.Text.Trim());
                long last = model.LastInsertId;
                mm.Update(m, "Contact", last);
            }

            else if(m.InnerContact.Name != this.ContactNameEntry.Text || m.InnerContact.PhoneNumber != this.ContactPhoneEntry.Text)
            {
                DbModel model = new DbModel("Contact");
                model.UpdateById(m.InnerContact.Id, "Name", this.ContactNameEntry.Text.Trim());
                model.UpdateById(m.InnerContact.Id, "PhoneNumber", this.ContactPhoneEntry.Text.Trim());
            }

            Client c = m.InnerClient;
            ClientModel cm = new ClientModel();
            if(c.Name != this.NameEntry.Text)
                cm.Update(c, "Name", this.NameEntry.Text.Trim());

            if(c.Surname != this.SurnameEntry.Text)
                cm.Update(c, "Surname", this.SurnameEntry.Text.Trim());

            if(c.Address != this.AddressEntry.Text)
                cm.Update(c, "Address", this.AddressEntry.Text.Trim());

            omarkhd.Validation.Validator v = new omarkhd.Validation.Validator();
            v.SetRule(this.PhoneEntry.Text, "phone", omarkhd.Validation.ValidationRule.Natural);
            if(c.PhoneNumber != this.PhoneEntry.Text && v.Run().Status)
                cm.Update(c, "PhoneNumber", this.PhoneEntry.Text.Trim());

            v = new omarkhd.Validation.Validator();
            v.SetRule(this.EmailEntry.Text, "email", omarkhd.Validation.ValidationRule.Email);

            if(c.Email != this.EmailEntry.Text && v.Run().Status)
                cm.Update(c, "Email", this.EmailEntry.Text.Trim());

            this.DoCancel(null, null);
        }
コード例 #16
0
ファイル: MembersWindow.cs プロジェクト: omarkhd/gymk
        private void SelectCurrent(object sender, EventArgs args)
        {
            this.ClearForm();
            this.PhotoButton.Sensitive = true;
            this.PhotoButton.Relief = ReliefStyle.None;
            //default client info
            Client c = (Client) this.MembersNodeView.NodeSelection.SelectedNode;
            this.CurrentClient = c;
            Member m = new Member();
            m.Id = c.Id;
            m.Sync();
            c = m.InnerClient;

            //client info
            this.ActiveCheck.Active = m.Active;
            this.IdLabel.Text = c.Id.ToString("0000");
            this.NameEntry.Text = c.Name;
            this.SurnameEntry.Text = c.Surname;
            this.AddressEntry.Text = c.Address;
            this.PhoneEntry.Text = c.PhoneNumber;
            this.EmailEntry.Text = c.Email;

            //member info
            this.WeightSpin.Value = m.Weight;
            this.HeightSpin.Value = m.Height;
            this.GenderCombo.Active = m.Gender == 'm' ? 0 : 1;
            this.BirthdayWidget.Date = m.BirthDate;
            this.ContactNameEntry.Text = !string.IsNullOrEmpty(m.InnerContact.Name) ? m.InnerContact.Name : "";
            this.ContactPhoneEntry.Text = !string.IsNullOrEmpty(m.InnerContact.PhoneNumber) ? m.InnerContact.PhoneNumber : "";
            if(m.BinImage != null && m.BinImage.Length > 0)
            {
                foreach(Widget widget in this.PhotoButton.Children)
                    this.PhotoButton.Remove(widget);

                int h = this.PhotoButton.Allocation.Height;
                int w = this.PhotoButton.Allocation.Width;
                Gdk.Pixbuf pixbuf = new Gdk.Pixbuf(m.BinImage);

                double x_scale = (double) w / pixbuf.Width;
                double y_scale = (double) h / pixbuf.Height;
                double scale = Math.Min(x_scale, y_scale);
                pixbuf = pixbuf.ScaleSimple((int) (pixbuf.Width * scale), (int) (pixbuf.Height * scale), Gdk.InterpType.Bilinear);
                this.PhotoButton.Add(new Gtk.Image(pixbuf));
                this.PhotoButton.ShowAll();
            }

            //payment info
            this.PaymentDaySpin.Value = m.PaymentDay;
            this.SinceWidget.Date = m.JoinDate;
            PackModel pm = new PackModel();
            IDataReader reader = pm.GetById(m.Pack);
            if(reader.Read())
            {
                string name = (string) reader["Name"];
                long packs = pm.Count();
                for(int i = 0; i < packs; i++)
                {
                    this.PackCombo.Active = i;
                    string text = this.PackCombo.ActiveText;
                    if(name == text)
                        break;
                }
            }

            //conf
            this.EditButton.Sensitive = true;
        }
コード例 #17
0
ファイル: MemberModel.cs プロジェクト: omarkhd/gymk
 public bool Update(Member m)
 {
     return false;
 }