using System; using System.Collections.Generic; using System.Linq; using System.Text; using Sybase.DataWindow.Web; using System.Globalization; namespace CoreSavingLibrary { public class DwThDate { private WebDataWindowControl dwMain; private CultureInfo th; private List oriName; private List thName; private String id; private String clientId; private int count; public int Count { get { return count; } } public List OriName { get { return oriName; } } public List ThName { get { return thName; } } public String ID { get { return id; } } public String ClientID { get { return clientId; } } public WebDataWindowControl DwMain { get { return dwMain; } } private void BeforeConstructorEnd(WebDataWindowControl dwMain) { this.dwMain = dwMain; this.count = 0; this.thName = new List(); this.oriName = new List(); this.th = new CultureInfo("th-TH"); this.id = dwMain.ID; this.clientId = dwMain.ClientID; } public DwThDate(WebDataWindowControl dwMain) { this.dwMain = dwMain; this.count = 0; this.thName = new List(); this.oriName = new List(); this.th = new CultureInfo("th-TH"); } public DwThDate(WebDataWindowControl dwMain, PageWebSheet w_sheet_xx_xxxxxxx) { BeforeConstructorEnd(dwMain); w_sheet_xx_xxxxxxx.AddThDate(this); } public DwThDate(WebDataWindowControl dwMain, PageWebDialog w_dlg_xx_xxxxxxx) { BeforeConstructorEnd(dwMain); w_dlg_xx_xxxxxxx.AddThDate(this); } public void Add(String OriginColumnName, String ThColumnName) { this.thName.Add(ThColumnName); this.dwMain.Modify(ThColumnName + ".EditMask.Mask='xx/xx/xxxx'"); this.oriName.Add(OriginColumnName); this.count++; } public int Eng2ThaiAllRow() { int iii = 0; for (int i = 1; i < dwMain.RowCount + 1; i++) { for (int j = 0; j < count; j++) { try { DateTime dt = dwMain.GetItemDateTime(i, oriName[j]); dwMain.SetItemString(i, thName[j], dt.ToString("ddMMyyyy", th)); } catch { dwMain.SetItemString(i, thName[j], "00000000"); } iii++; } } dwMain.ResetUpdateStatus(); dwMain.SaveDataCache(); return iii; } public int Thai2EngAllRow() { int iii = 0; for (int i = 1; i < dwMain.RowCount + 1; i++) { for (int j = 0; j < count; j++) { try { String dt = dwMain.GetItemString(i, thName[j]); if (dt.Length == 8) { DateTime dtm = DateTime.ParseExact(dt, "ddMMyyyy", WebUtil.TH); dwMain.SetItemDateTime(i, oriName[j], dtm); } else { throw new Exception("Length != 8"); } } catch { dwMain.SetItemNull(i, oriName[j]); dwMain.SetItemString(i, thName[j], "00000000"); } iii++; } } dwMain.ResetUpdateStatus(); dwMain.SaveDataCache(); return iii; } } }