private void dgvList_Click(object sender, EventArgs e) { if (dgvList.CurrentRow != null) { this.dgvList.DefaultCellStyle.SelectionBackColor = System.Drawing.SystemColors.ControlLightLight; try { hallList = dataBindingSource.DataSource as List <CustomDataTypes.HallInfo>; if (TheaterInfo.TheaterId != null) { foreach (var tmp in hallList) { tmp.TheaterId = TheaterInfo.TheaterId; } } if (dgvList.CurrentRow.Cells["HallId"].Value != null) { hallInfo = hallList.Where(p => p.HallId == dgvList.CurrentRow.Cells["HallId"].Value.ToString()).FirstOrDefault(); if (hallInfo != null) { BindData(); } } } catch { } } }
public CustomDataTypes.HallInfo NewData() { string lastId; // 使用创建时间先后来获取最后ID if (dataBindingSource.DataSource != null) { hallList = dataBindingSource.DataSource as List <CustomDataTypes.HallInfo>; if (TheaterInfo.TheaterId != null) { foreach (var tmp in hallList) { tmp.TheaterId = TheaterInfo.TheaterId; } } CustomDataTypes.HallInfo lastData = hallList.OrderByDescending(p => p.Created).FirstOrDefault(); // 不能两条记录的创建时间一样,避免主键重复 if (lastData != null && lastData.Created == DateTime.Now) { throw new Exception(); } if (lastData != null) { lastId = lastData.HallId; } else { lastId = "0"; } } else { lastId = "0"; } string newId; // 生成新的Id(这里长度是12位) try { newId = string.Format("{0:D2}", Convert.ToInt64(lastId) + 1); } catch { newId = string.Format("{0:D2}", 1); } CustomDataTypes.HallInfo data = new CustomDataTypes.HallInfo(); data.HallId = newId; // 更新数据基础值 data.Created = DateTime.Now; data.Updated = data.Created; data.ActiveFlag = true; data.TheaterId = TheaterInfo.TheaterId; return(data); }
public frmGetXML() { InitializeComponent(); TheaterInfo = new CustomDataTypes.TheaterInfo(); hallInfo = new CustomDataTypes.HallInfo(); BindDataTheater(); hallList = new List <CustomDataTypes.HallInfo>(); dataBindingSource = new BindingSource(); dgvList.DataSource = dataBindingSource; }
private void btnAdd_Click(object sender, EventArgs e) { try { hallInfo = NewData(); dataBindingSource.Add(hallInfo); dataBindingSource.MoveLast(); BindData(); } catch (Exception ex) { MessageBox.Show(ex.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void SetInfo(DataSet ds) { DateTime starttime = DateTime.Now; DateTime endTime = DateTime.Now; try { starttime = Convert.ToDateTime(ds.Tables["dtTime"].Rows[0]["StartTime"].ToString()); endTime = Convert.ToDateTime(ds.Tables["dtTime"].Rows[0]["EndTime"].ToString()); } catch { //MessageBox.Show("授权文件起始时间和截止时间设置不正确,无法将该文件导进!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); //return; } //if ((starttime.Date > DateTime.Now.Date) // || (endTime.Date < DateTime.Now.Date)) //{ // MessageBox.Show("不在授权文件的有效期内,无法将该文件导进!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); // return; //} dtpStart.Value = starttime; dtpEnd.Value = endTime; FillModule(ds.Tables["dtModule"]); try { TheaterInfo.TheaterId = ds.Tables["TheaterInformation"].Rows[0]["TheaterId"].ToString(); } catch { } try { TheaterInfo.TheaterName = ds.Tables["TheaterInformation"].Rows[0]["TheaterName"].ToString(); } catch { } try { TheaterInfo.TheaterType = ds.Tables["TheaterInformation"].Rows[0]["TheaterType"].ToString(); } catch { } try { TheaterInfo.Corporation = ds.Tables["TheaterInformation"].Rows[0]["Corporation"].ToString(); } catch { } try { TheaterInfo.Telephone = ds.Tables["TheaterInformation"].Rows[0]["Telephone"].ToString(); } catch { } try { TheaterInfo.Manager = ds.Tables["TheaterInformation"].Rows[0]["Manager"].ToString(); } catch { } try { TheaterInfo.Halls = Convert.ToInt32(ds.Tables["TheaterInformation"].Rows[0]["Halls"].ToString()); } catch { } try { TheaterInfo.Seats = Convert.ToInt32(ds.Tables["TheaterInformation"].Rows[0]["Seats"].ToString()); } catch { } try { TheaterInfo.Province = ds.Tables["TheaterInformation"].Rows[0]["Province"].ToString(); } catch { } try { TheaterInfo.City = ds.Tables["TheaterInformation"].Rows[0]["City"].ToString(); } catch { } try { TheaterInfo.District = ds.Tables["TheaterInformation"].Rows[0]["District"].ToString(); } catch { } try { TheaterInfo.PostCode = ds.Tables["TheaterInformation"].Rows[0]["PostCode"].ToString(); } catch { } try { TheaterInfo.Address = ds.Tables["TheaterInformation"].Rows[0]["Address"].ToString(); } catch { } try { TheaterInfo.TheaterCode = ds.Tables["TheaterInformation"].Rows[0]["TheaterCode"].ToString(); } catch { } try { TheaterInfo.CineChainId = ds.Tables["TheaterInformation"].Rows[0]["CineChainId"].ToString(); } catch { } try { TheaterInfo.SerialNumber = ds.Tables["TheaterInformation"].Rows[0]["SerialNumber"].ToString(); } catch { } try { TheaterInfo.Rating = ds.Tables["TheaterInformation"].Rows[0]["Rating"].ToString(); } catch { } try { TheaterInfo.Fax = ds.Tables["TheaterInformation"].Rows[0]["Fax"].ToString(); } catch { } try { TheaterInfo.Mobile = ds.Tables["TheaterInformation"].Rows[0]["Mobile"].ToString(); } catch { } try { TheaterInfo.Version = ds.Tables["TheaterInformation"].Rows[0]["Version"].ToString(); } catch { } try { TheaterInfo.Created = Convert.ToDateTime(ds.Tables["TheaterInformation"].Rows[0]["Created"].ToString()); } catch { } try { TheaterInfo.Updated = Convert.ToDateTime(ds.Tables["TheaterInformation"].Rows[0]["Updated"].ToString()); } catch { } try { TheaterInfo.ServerModle = ds.Tables["TheaterInformation"].Rows[0]["ServerModle"].ToString(); } catch { } try { TheaterInfo.ServerCPU = ds.Tables["TheaterInformation"].Rows[0]["ServerCPU"].ToString(); } catch { } try { TheaterInfo.ServerMemory = ds.Tables["TheaterInformation"].Rows[0]["ServerMemory"].ToString(); } catch { } try { TheaterInfo.ServerHardDriver = ds.Tables["TheaterInformation"].Rows[0]["ServerHardDriver"].ToString(); } catch { } try { TheaterInfo.Clients = Convert.ToInt32(ds.Tables["TheaterInformation"].Rows[0]["Clients"].ToString()); } catch { } foreach (DataRow tmp in ds.Tables["HallInformation"].Rows) { CustomDataTypes.HallInfo hallInfo = new CustomDataTypes.HallInfo(); try { hallInfo.HallId = tmp["HallId"].ToString(); } catch { } try { hallInfo.TheaterId = tmp["TheaterId"].ToString(); } catch { } try { hallInfo.HallName = tmp["HallName"].ToString(); } catch { } try { hallInfo.Seats = Convert.ToInt32(tmp["Seats"].ToString()); } catch { } try { hallInfo.Levels = Convert.ToInt32(tmp["Levels"].ToString()); } catch { } try { hallInfo.Screen = tmp["Screen"].ToString(); } catch { } try { hallInfo.Projector = tmp["Projector"].ToString(); } catch { } try { hallInfo.PlayMode = tmp["PlayMode"].ToString(); } catch { } try { hallInfo.SoundSystem = tmp["SoundSystem"].ToString(); } catch { } try { hallInfo.Description = tmp["Description"].ToString(); } catch { } try { hallInfo.Created = Convert.ToDateTime(tmp["Created"].ToString()); } catch { } try { hallInfo.Updated = Convert.ToDateTime(tmp["Updated"].ToString()); } catch { } try { hallInfo.ActiveFlag = Convert.ToBoolean(tmp["ActiveFlag"].ToString()); } catch { } try { hallInfo.BarColour = tmp["BarColour"].ToString(); } catch { } hallList.Add(hallInfo); } }