/// <summary> /// เชคอายุ หุ้น /// </summary> /// <param name="createDate"></param> private int CheckAgeOfShared(DateTime createDate) { foreach (var item in SingletonAgeOfShare.Instance().AgeOfShare) { if (int.Parse(createDate.ToString("yyyyMMdd")) < int.Parse(item.TermStart.ToString("yyyyMMdd")) && int.Parse(createDate.ToString("yyyyMMdd")) < int.Parse(item.TermEnd.ToString("yyyyMMdd"))) { return(item.Id); } else { if (int.Parse(createDate.ToString("yyyyMMdd")) > int.Parse(item.TermStart.ToString("yyyyMMdd")) && int.Parse(createDate.ToString("yyyyMMdd")) <= int.Parse(item.TermEnd.ToString("yyyyMMdd"))) { return(item.Id); } } } return(2); }
private void ManageMemberForm_Load(object sender, EventArgs e) { dateTimePicker1.CustomFormat = " dd / MM / yyyy"; comboBox2.SelectedIndex = 0; Singleton.SingletonShared.Instance(); SingletonAgeOfShare.Instance(); reload(); var Bg = Singleton.SingletonBudgetYearNew.Instance().BudgetYear.Where(w => w.Enable == true).Select(s => new { ThaiYear = s.ThaiYear, IsCurrent = s.IsCurrent }).OrderByDescending(o => o.IsCurrent).ToList(); if (Bg == null) { MessageBox.Show("Not have BudgetYear"); return; } DataTable dtbg = Library.ConvertToDataTable(Bg); comboBox1.DataSource = dtbg; comboBox1.DisplayMember = dtbg.Columns["ThaiYear"].ToString(); comboBox1.ValueMember = dtbg.Columns["IsCurrent"].ToString(); comboBox1.SelectedIndex = 0; }
public void BinddingAddShared(decimal value) { DateTime dateEnd = Singleton.SingletonThisBudgetYear.Instance().ThisYear.EndDate; textBoxTotalShared.Text = (value + old) + ""; for (int i = 0; i < dataGridView2.Rows.Count; i++) { int id = int.Parse(dataGridView2.Rows[i].Cells[col2Id].Value.ToString()); if (id == 0) { dataGridView2.Rows.RemoveAt(i); continue; } } // add dataGridView2 // แปลง วันที่ thai เป็น EN string dateShared = maskedTextBoxCreateDate.Text; var split = dateShared.Split('/'); var yyyy = int.Parse(split[2]) - 543; DateTime dateshared = new DateTime(yyyy, int.Parse(split[1]), int.Parse(split[0])); var ageOfShared = SingletonAgeOfShare.Instance().AgeOfShare.ToList(); int c = int.Parse(dateshared.ToString("yyyyMMdd")); int f = int.Parse(ageOfShared.FirstOrDefault().TermStart.ToString("yyyyMMdd")); string sharedAge = ""; if (c < f) { // แปล ว่า ครบปี แน่ๆ sharedAge = "ครบปี"; fkAgeOfShared = ageOfShared.FirstOrDefault().Id; } else { bool isTerm = false; foreach (var item in ageOfShared) { if (Library.CheckAgeOfShared(dateshared, item.TermStart, item.TermEnd)) { isTerm = true; sharedAge = item.ShareAge + " เดือน"; if (item.ShareAge == 12) { sharedAge = "ครบปี"; } fkAgeOfShared = item.Id; break; } } } ///////////////////Edit 1 //DateTime dateshared = DateTime.Parse(localDate.ToString("en-GB")); //int yearShared = localDate.Year; //var diffMonths = (dateEnd.Month + dateEnd.Year) - (localDate.Month + localDate.Year); //DateDiff dateDiff = new DateDiff(date1, date2); ///////////////////Edit 2 //int diffMonths = Library.MonthDiff(dateshared, dateEnd); //if (diffMonths >= 12) //{ // sharedAge = "ครบปี"; //} //else //{ // sharedAge = diffMonths + " เดือน"; //} //Console.WriteLine(diffMonths + ""); dataGridView2.Rows.Add (0, value, maskedTextBoxCreateDate.Text, Library.ConvertDecimalToStringForm(SingletonShared.Instance().Share.Value *value), Singleton.SingletonAuthen.Instance().Name //,sharedAge ); this.value = value; }