예제 #1
0
        /// <summary>
        /// 基于导入执行导出
        /// </summary>
        public void Execute(ExcelGlobalDTO <TEntity> excelGlobalDTO)
        {
            excelGlobalDTO.PerformanceMonitoring.Start("=========【导出】Excel处理======");

            //Excel处理
            ExcelHandle(excelGlobalDTO);

            //删除行
            DeleteRow <TEntity> deleteRow = new DeleteRow <TEntity>();

            deleteRow.DeleteRows(excelGlobalDTO);

            excelGlobalDTO.PerformanceMonitoring.Stop();

            //如果路径文件为空则不存储
            if (string.IsNullOrEmpty(excelGlobalDTO.FilePath) == true)
            {
                return;
            }

            //写入内容
            using (FileStream fs = new FileStream(excelGlobalDTO.FilePath, FileMode.Create))
            {
                excelGlobalDTO.Workbook.Write(fs);
                fs.Dispose();
                fs.Close();
            }
        }
        private void deleteRow()
        {
            try
            {
                MainWindowGuiData.IsBusy = true;

                var localSubItems = new SubtitleItems();
                foreach (var item in subtitleItemsDataInternal)
                {
                    localSubItems.Add(item);
                }

                DeleteRow.DeleteWholeRow(
                    localSubItems,
                    MainWindowGuiData.SelectedItem,
                    MainWindowGuiData.OpenedFilePath
                    );

                subtitleItemsDataInternal = localSubItems;
            }
            catch (Exception ex)
            {
                ExceptionLogger.LogExceptionToFile(ex);
                LogWindow.AddMessage(LogType.Error, ex.Message);
            }
            finally
            {
                MainWindowGuiData.IsBusy = false;
            }
        }
예제 #3
0
        public Response DeleteItemFromDB(DeleteRow delRowObj)
        {
            try
            {
                string tableName  = delRowObj.TableName.ToString();
                string schemaType = delRowObj.Type != null?delRowObj.Type.ToString() : string.Empty;

                var schema         = GetTableSchema(tableName, schemaType);
                var delItemList    = delRowObj.Data;//.Where(obj => obj.FormType == "DELETE").Select(s => s.Data).ToList();
                var identityColumn = schema.Where(s => s.IsIdentity == true).FirstOrDefault();
                Dictionary <string, string> result;
                if (identityColumn != null && delItemList.Count > 0)
                {
                    using (SqlConnection con = new SqlConnection(this._connectionString))
                    {
                        SqlCommand cmd = new SqlCommand();

                        con.Open();
                        cmd.Connection = con;

                        List <string> testt = new List <string>();
                        foreach (var item in delItemList)
                        {
                            result = JsonConvert.DeserializeObject <Dictionary <string, string> >(item.ToString());
                            testt.Add(result.Where(s => s.Key == identityColumn.ColumnName).Select(d => d.Value).FirstOrDefault());
                        }
                        string ids = string.Join(", ", testt.Select(id => id));
                        cmd.CommandText = string.Format("DELETE FROM {0} WHERE {1} IN ({2})", delRowObj.TableName, identityColumn.ColumnName, ids);
                        cmd.ExecuteNonQuery();
                    }
                }
                else
                {
                    return(new Response()
                    {
                        IsResponseSuccess = true, Message = "FAILED"
                    });
                }
                return(new Response()
                {
                    IsResponseSuccess = true, Message = "SUCCESS"
                });
            }
            catch (Exception ex)
            {
                return(new Response()
                {
                    IsResponseSuccess = false, Message = ex.Message.ToString()
                });
            }
        }
예제 #4
0
 /// <summary>
 /// Adds all functionality to a <see cref="DataGridView"/>, so that it can be edited directly.
 /// </summary>
 /// <param name="dataGridView"><see cref="DataGridView"/></param>
 /// <param name="catchCurrentRowState"></param>
 /// <param name="rowValidated"></param>
 /// <param name="deleteRow"></param>
 public static void AddDataGridViewEditingHandlers(DataGridView dataGridView, CatchCurrentRowState catchCurrentRowState, RowValidated rowValidated, DeleteRow deleteRow)
 {
     dataGridView.CellStateChanged += (sender, e) =>
     {
         catchCurrentRowState(sender, e);
     };
     dataGridView.RowValidated += (sender, e) =>
     {
         rowValidated(sender, e);
     };
     dataGridView.KeyUp += (sender, e) =>
     {
         deleteRow(sender, e);
     };
 }
 public Response DeleteItemFromDB(DeleteRow delRowObj)
 {
     return(_dynamicData.DeleteItemFromDB(delRowObj));
 }